mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-04-20 03:50:20 +00:00
- Updated `next.config.ts` to include remote image patterns for user verification. - Introduced `VerifyUserDetails` function in `lib/person.ts` to validate user data against national records. - Added `usePerson` hook for fetching national data based on ID card. - Enhanced `signup` and `signin` functions in `auth-actions.ts` to handle user verification status and send notifications for pending verifications. - Refactored `VerifyUser` function in `user-actions.ts` to incorporate national data validation. - Improved UI components in the user verification page to display both database and national information. - Updated `InputReadOnly` component to support customizable label classes for better styling. These changes improve the user verification process, ensuring data integrity and enhancing the overall user experience.
96 lines
4.2 KiB
TypeScript
96 lines
4.2 KiB
TypeScript
import InputReadOnly from '@/components/input-read-only';
|
|
import { Badge } from '@/components/ui/badge';
|
|
import UserRejectDialog from '@/components/user/user-reject-dialog';
|
|
import { UserVerifyDialog } from '@/components/user/user-verify-dialog';
|
|
import usePerson from '@/hooks/use-person';
|
|
|
|
import prisma from '@/lib/db';
|
|
import type { TNationalPerson } from '@/lib/types';
|
|
import Image from 'next/image';
|
|
import React from 'react'
|
|
|
|
export default async function VerifyUserPage({
|
|
params,
|
|
}: {
|
|
params: Promise<{
|
|
userId: string;
|
|
}>;
|
|
}) {
|
|
const userId = (await params).userId
|
|
const dbUser = await prisma.user.findUnique({
|
|
where: {
|
|
id: userId,
|
|
},
|
|
include: {
|
|
island: {
|
|
include: {
|
|
atoll: true
|
|
}
|
|
}
|
|
}
|
|
})
|
|
|
|
const nationalData = await usePerson({ idCard: dbUser?.id_card ?? "" })
|
|
return (
|
|
<div>
|
|
<div className='flex items-center justify-between text-gray-500 text-2xl font-bold title-bg py-4 px-2 mb-4'>
|
|
<h3 className="">
|
|
Verify user
|
|
</h3>
|
|
<div className='flex gap-2'>
|
|
{dbUser && !dbUser?.verified && <UserVerifyDialog user={dbUser} />}
|
|
{dbUser && !dbUser?.verified && <UserRejectDialog user={dbUser} />}
|
|
{dbUser?.verified && <Badge variant={"secondary"} className='bg-lime-500'>Verified</Badge>}
|
|
</div>
|
|
|
|
</div>
|
|
<div className='grid grid-cols-1 md:grid-cols-2 gap-4 items-start justify-start'>
|
|
<div id="database-information">
|
|
<h4 className='p-2 rounded font-semibold'>Database Information</h4>
|
|
<div className='shadow p-2 rounded-lg title-bg space-y-1 my-2 grid grid-cols-1 md:grid-cols-2 gap-2'>
|
|
<InputReadOnly labelClassName='text-sarLinkOrange' label="ID Card" value={dbUser?.id_card ?? ""} />
|
|
<InputReadOnly labelClassName='text-sarLinkOrange' label="Name" value={dbUser?.name ?? ""} />
|
|
<InputReadOnly labelClassName='text-sarLinkOrange' label="House Name" value={dbUser?.address ?? ""} />
|
|
<InputReadOnly labelClassName='text-sarLinkOrange' label="Island" value={dbUser?.island?.name ?? ""} />
|
|
<InputReadOnly labelClassName='text-sarLinkOrange' label="Atoll" value={dbUser?.island?.atoll.name ?? ""} />
|
|
|
|
<InputReadOnly labelClassName='text-sarLinkOrange' label="DOB" value={new Date(dbUser?.dob ?? "").toLocaleDateString("en-US", {
|
|
month: "short",
|
|
day: "2-digit",
|
|
year: "numeric",
|
|
})} />
|
|
<InputReadOnly labelClassName='text-sarLinkOrange' label="Phone Number" value={dbUser?.phoneNumber ?? ""} />
|
|
</div>
|
|
</div>
|
|
<div id="national-information">
|
|
<h4 className='p-2 rounded font-semibold'>National Information</h4>
|
|
<div className='shadow p-2 rounded-md title-bg space-y-1 my-2 grid grid-cols-1 md:grid-cols-2 gap-2'>
|
|
<InputReadOnly labelClassName='text-green-500' label="ID Card" value={nationalData?.nic ?? ""} />
|
|
<InputReadOnly labelClassName='text-green-500' label="Name" value={nationalData?.name_en ?? ""} />
|
|
<InputReadOnly labelClassName='text-green-500' label="House Name" value={nationalData?.house_name_en ?? ""} />
|
|
<InputReadOnly labelClassName='text-green-500' label="Island" value={nationalData?.island_name_en ?? ""} />
|
|
<InputReadOnly labelClassName='text-green-500' label="Atoll" value={nationalData?.atoll_en ?? ""} />
|
|
<InputReadOnly labelClassName='text-green-500' label="DOB" value={new Date(nationalData?.dob ?? "").toLocaleDateString("en-US", {
|
|
month: "short",
|
|
day: "2-digit",
|
|
year: "numeric",
|
|
})} />
|
|
<InputReadOnly labelClassName='text-green-500' label="Phone Number" value={nationalData?.primary_contact ?? ""} />
|
|
<div className='flex flex-col col-span-2 items-center justify-center'>
|
|
<Image
|
|
src={nationalData.image_url}
|
|
height={100}
|
|
width={100}
|
|
className='object-fit aspect-square rounded-full'
|
|
alt='id photo'
|
|
/>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
)
|
|
}
|