"use client"; 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 { User } from "@/lib/types/user"; import { cn } from "@/lib/utils"; import { zodResolver } from "@hookform/resolvers/zod"; import { UserX } from "lucide-react"; import { useState } from "react"; import { type SubmitHandler, useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; import { Textarea } from "../ui/textarea"; const validationSchema = z.object({ reason: z.string().min(5, { message: "Reason is required" }), }); export default function UserRejectDialog({ user }: { user: User }) { const [disabled, setDisabled] = useState(false); const [open, setOpen] = useState(false); const { register, handleSubmit, formState: { errors }, } = useForm>({ resolver: zodResolver(validationSchema), }); const onSubmit: SubmitHandler> = (data) => { setDisabled(true); console.log(data); toast.promise( Rejectuser({ userId: String(user.id), reason: data.reason, }), { loading: "Rejecting...", success: () => { setDisabled(false); setOpen((prev) => !prev); return "Rejected!"; }, error: (error) => { setDisabled(false); return error.message || "Something went wrong"; }, }, ); setDisabled(false); }; return ( Are you sure you want to{" "} reject this user?
  • 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}