sourcebot/packages/web/src/app/[domain]/components/submitAccountRequestButton.tsx
Michael Sukkarieh 173a56ab64
Revamp onboarding flow (#376)
* sign up copy nits

* first pass at new onboarding page

* wip join onboard logic

* refactor auth provider fetch logic

* add member approval and invite link flag logic

* update join request flow and remove jit logic

* onboard guard

* nits, onboard role check, invite link enabled check

* fix bg color issue in onboarding page

* refactor onboard UI

* ui nits and more onboarding resource cards

* revamp auth docs

* change member approval default behavior and updated docs

* merge prisma migrations

* add id to resource card

* feedback

* feedback

* feedback and fixed build

* settings drop down UI nit

* ui nits

* handle join when max capacity case

* add news data for member toggle

* refactor for public access case

* add iap bridge to onboard logic

* fetch member approval req and invite link enabled flag on server

* ui nits

* fix invite link enable toggle snapping issue

* ui nits

* styling and ui nits, pass in invite id from server

* add mcp resource in onboard step

* get invite link in server

* fix build issue

* refactor docs on config

* minor doc nit
2025-07-14 20:14:41 -07:00

67 lines
No EOL
2.2 KiB
TypeScript

"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"
interface SubmitButtonProps {
domain: string
userId: string
}
export function SubmitAccountRequestButton({ domain, userId }: SubmitButtonProps) {
const { toast } = useToast()
const router = useRouter()
const [isSubmitting, setIsSubmitting] = useState(false)
const handleSubmit = async () => {
setIsSubmitting(true)
const result = await createAccountRequest(userId, domain)
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();
}}>
<input type="hidden" name="domain" value={domain} />
<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>
)
}