import { useEffect, useState, type ChangeEvent, type FormEvent } from "react"; import { Alert, AlertDescription, AlertIcon, Button, FormControl, FormLabel, Input, Spinner, Stack, Text } from "./chakra-compat"; import { FcGoogle } from "react-icons/fc"; import type { AccountInviteTokenState } from "./types"; type InviteAcceptFormTexts = { loadingLabel: string; invalidLinkLabel: string; emailLabel: string; nameLabel: string; passwordLabel: string; passwordConfirmLabel: string; submitLabel: string; googleLabel: string; }; type InviteAcceptFormProps = { texts: InviteAcceptFormTexts; tokenState: AccountInviteTokenState; loading?: boolean; initialName?: string | null; showGoogleSignIn?: boolean; googleLoading?: boolean; onSubmit: (values: { name: string; password: string; passwordConfirm: string }) => void | Promise; onGoogleSignIn?: () => void | Promise; }; export function InviteAcceptForm({ texts, tokenState, loading = false, initialName = null, showGoogleSignIn = false, googleLoading = false, onSubmit, onGoogleSignIn }: InviteAcceptFormProps) { const [name, setName] = useState(initialName ?? ""); useEffect(() => { setName(initialName ?? ""); }, [initialName, tokenState.status]); function handleSubmit(event: FormEvent) { event.preventDefault(); const form = new FormData(event.currentTarget); void onSubmit({ name: String(form.get("name") ?? ""), password: String(form.get("password") ?? ""), passwordConfirm: String(form.get("passwordConfirm") ?? "") }); } if (tokenState.status === "loading") { return ( {texts.loadingLabel} ); } if (tokenState.status === "invalid") { return ( {tokenState.error || texts.invalidLinkLabel} ); } return ( {texts.emailLabel}
{texts.nameLabel} ) => setName(event.target.value)} /> {texts.passwordLabel} {texts.passwordConfirmLabel}
{showGoogleSignIn && onGoogleSignIn ? ( ) : null}
); }