"use client"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import Link from "next/link"; import { signup } from "@/actions/auth-actions"; import { cn } from "@/lib/utils"; import type { Island, Prisma } from "@prisma/client"; import { Loader2 } from "lucide-react"; import { useSearchParams } from "next/navigation"; import * as React from "react"; import { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectTrigger, SelectValue, } from "@/components/ui/select"; type AtollWithIslands = Prisma.AtollGetPayload<{ include: { islands: true; }; }>; export default function SignUpForm({ atolls }: { atolls: AtollWithIslands[] }) { const [atoll, setAtoll] = React.useState(); const [islands, setIslands] = React.useState(); const [actionState, action, isPending] = React.useActionState(signup, { message: "", }); React.useEffect(() => { setIslands(atoll?.islands); }, [atoll]); const params = useSearchParams(); const phoneNumberFromUrl = params.get("phone_number"); const NUMBER_WITHOUT_DASH = phoneNumberFromUrl?.split("-").join(""); if (actionState.db_error === "invalidPersonValidation") { return ( <>
{actionState.message}
Go to {" "} login
) } return (
{actionState?.errors?.fieldErrors.name && ( {actionState?.errors?.fieldErrors.name} )}
{actionState?.errors?.fieldErrors?.id_card?.[0] && ( {actionState?.errors.fieldErrors.id_card[0]} )} {actionState?.db_error === "id_card" && ( {actionState?.message} )}
{actionState?.errors?.fieldErrors?.address && ( {actionState?.errors?.fieldErrors?.address} )}
{actionState?.errors?.fieldErrors?.dob && ( {actionState?.errors?.fieldErrors?.dob} )}
{actionState?.errors?.fieldErrors.accNo && ( {actionState?.errors?.fieldErrors.accNo} )}
{actionState?.errors?.fieldErrors?.phone_number?.[0] && ( {actionState?.errors.fieldErrors.phone_number[0]} )} {actionState?.db_error === "phone_number" && ( {actionState?.message} )}
{actionState?.errors?.fieldErrors?.terms && ( {actionState?.errors?.fieldErrors?.terms} )}
{actionState?.errors?.fieldErrors?.policy && ( {actionState?.errors?.fieldErrors?.policy} )}
Already have an account?{" "} login
); }