-
Notifications
You must be signed in to change notification settings - Fork 306
Expand file tree
/
Copy pathsubmitAccountRequestButton.tsx
More file actions
62 lines (57 loc) · 2.06 KB
/
Copy pathsubmitAccountRequestButton.tsx
File metadata and controls
62 lines (57 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
"use client"
import { Button } from "@/components/ui/button"
import { Clock } from "lucide-react"
import { useState } from "react"
import { useToast } from "@/components/hooks/use-toast"
import { createAccountRequest } from "@/actions"
import { isServiceError } from "@/lib/utils"
import { useRouter } from "next/navigation"
export function SubmitAccountRequestButton() {
const { toast } = useToast()
const router = useRouter()
const [isSubmitting, setIsSubmitting] = useState(false)
const handleSubmit = async () => {
setIsSubmitting(true)
const result = await createAccountRequest()
if (!isServiceError(result)) {
if (result.existingRequest) {
toast({
title: "Request Already Submitted",
description: "Your request to join the organization has already been submitted. Please wait for it to be approved.",
variant: "default",
})
} else {
toast({
title: "Request Submitted",
description: "Your request to join the organization has been submitted.",
variant: "default",
})
}
// Refresh the page to trigger layout re-render and show PendingApprovalCard
router.refresh()
} else {
toast({
title: "Failed to Submit",
description: `There was an error submitting your request. Reason: ${result.message}`,
variant: "destructive",
})
}
setIsSubmitting(false)
}
return (
<form onSubmit={(e) => {
e.preventDefault();
handleSubmit();
}}>
<Button
type="submit"
className="flex items-center gap-2"
variant="outline"
disabled={isSubmitting}
>
<Clock className="h-4 w-4" />
{isSubmitting ? "Submitting..." : "Submit Request"}
</Button>
</form>
)
}