"use client"; import { UserX } from "lucide-react"; import { useActionState, useEffect, useState } from "react"; import { toast } from "sonner"; import { rejectUser } from "@/actions/user-actions"; // import { Rejectuser } from "@/actions/user-actions"; import { Button } from "@/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Label } from "@/components/ui/label"; import type { UserProfile } from "@/lib/types/user"; import { cn } from "@/lib/utils"; import { Textarea } from "../ui/textarea"; export type RejectUserFormState = { message: string; fieldErrors?: { rejection_details?: string[]; }; payload?: FormData; }; export const initialState: RejectUserFormState = { message: "", fieldErrors: {}, }; export default function UserRejectDialog({ user }: { user: UserProfile }) { const [open, setOpen] = useState(false); const [state, formAction, isPending] = useActionState(rejectUser, initialState); useEffect(() => { if (state.message && state !== initialState) { if (state.fieldErrors && Object.keys(state.fieldErrors).length > 0) { toast.error(state.message); } else if (!state.fieldErrors) { toast.success("User rejected successfully!"); setOpen(false); } else { toast.error(state.message); } } }, [state]); return ( Are you sure?
  • Name: {user.first_name} {user.last_name}
  • ID Card: {user.id_card}
  • Address: {user.address}
  • DOB:{" "} {new Date(user.dob ?? "").toLocaleDateString("en-US", { month: "short", day: "2-digit", year: "numeric", })}
  • Phone Number: {user.mobile}