sarlink-portal/components/user/user-verify-dialog.tsx
i701 9021f01ff4 Add Agreements page, enhance Devices and Users components with sorting and filtering options, and implement user verification dialogs
- Introduced a new Agreements page for managing agreements in the dashboard.
- Enhanced the Devices page by adding sorting and filtering options for better device management.
- Updated the Users page to include sorting functionality and improved layout.
- Implemented user verification and rejection dialogs for better user management.
- Added InputReadOnly component for displaying user information in a read-only format.
- Refactored search component to improve usability and visual consistency.
2024-12-01 23:19:31 +05:00

78 lines
2.2 KiB
TypeScript

"use client";
import { VerifyUser } from "@/actions/user-actions";
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from "@/components/ui/alert-dialog";
import { Button } from "@/components/ui/button";
import type { User } from "@prisma/client";
import { Check, CheckCheck } from "lucide-react";
import { useState } from "react";
import { toast } from "sonner";
export function UserVerifyDialog({ user }: { user: User }) {
const userId = user.id;
const [disabled, setDisabled] = useState(false);
return (
<AlertDialog>
<AlertDialogTrigger asChild>
<Button
variant={user.verified ? "secondary" : "default"}
disabled={disabled || user.verified}
>
{user.verified ? <CheckCheck size={16} /> : <Check size={16} />}
{user.verified ? "Verified" : "Verify"}
</Button>
</AlertDialogTrigger>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Are you sure?</AlertDialogTitle>
<AlertDialogDescription>
Are you sure you want to verify the following user?
<span className="inline-block my-4">
<li>Name: {user.name}</li>
<li>ID Card: {user.id_card}</li>
<li>Address: {user.address}</li>
<li>DOB: {new Date(user.dob ?? "").toLocaleDateString("en-US", {
month: "short",
day: "2-digit",
year: "numeric",
})}</li>
<li>Phone Number: {user.phoneNumber}</li>
</span>
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
disabled={disabled}
onClick={() => {
setDisabled(true);
toast.promise(VerifyUser(userId), {
loading: "Verifying...",
success: () => {
setDisabled(false);
return "User Verified!";
},
error: () => {
setDisabled(false);
return "Something went wrong";
},
});
}}
>
{disabled ? "Verifying..." : "Verify"}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
}