add admin checks for admin pages and run biome formating 🔨
All checks were successful
Build and Push Docker Images / Build and Push Docker Images (push) Successful in 11m8s

This commit is contained in:
2025-07-25 13:31:12 +05:00
parent aedf7cdf7d
commit 9b2f2c1528
127 changed files with 6577 additions and 6334 deletions

View File

@@ -16,32 +16,33 @@ import { tryCatch } from "@/utils/tryCatch";
// } from "@/components/ui/select";
export default async function UserUpdate({
params,
params,
}: {
params: Promise<{
userId: string;
}>;
params: Promise<{
userId: string;
}>;
}) {
const { userId } = await params;
const session = await getServerSession(authOptions);
if (!session?.user?.is_admin) return null
const [error, user] = await tryCatch(getProfileById(userId));
const { userId } = await params;
const session = await getServerSession(authOptions);
if (!session?.user?.is_admin) return redirect("/devices?page=1");
const [error, user] = await tryCatch(getProfileById(userId));
if (error) {
if (error.message === "UNAUTHORIZED") {
redirect("/auth/signin");
} else {
return <ClientErrorMessage message={error.message} />;
}
}
if (error) {
if (error.message === "UNAUTHORIZED") {
redirect("/auth/signin");
} else {
return <ClientErrorMessage message={error.message} />;
}
}
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="text-sarLinkOrange text-2xl">Upload user user agreement</h3>
</div>
<UserAgreementForm user={user} />
</div>
);
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="text-sarLinkOrange text-2xl">
Upload user user agreement
</h3>
</div>
<UserAgreementForm user={user} />
</div>
);
}

View File

@@ -16,32 +16,31 @@ import { tryCatch } from "@/utils/tryCatch";
// } from "@/components/ui/select";
export default async function UserUpdate({
params,
params,
}: {
params: Promise<{
userId: string;
}>;
params: Promise<{
userId: string;
}>;
}) {
const { userId } = await params;
const session = await getServerSession(authOptions);
if (!session?.user?.is_admin) return null
const [error, user] = await tryCatch(getProfileById(userId));
const { userId } = await params;
const session = await getServerSession(authOptions);
if (!session?.user?.is_admin) return redirect("/devices?page=1");
const [error, user] = await tryCatch(getProfileById(userId));
if (error) {
if (error.message === "UNAUTHORIZED") {
redirect("/auth/signin");
} else {
return <ClientErrorMessage message={error.message} />;
}
}
if (error) {
if (error.message === "UNAUTHORIZED") {
redirect("/auth/signin");
} else {
return <ClientErrorMessage message={error.message} />;
}
}
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="text-sarLinkOrange text-2xl">Verify user</h3>
</div>
<UserUpdateForm user={user} />
</div>
);
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="text-sarLinkOrange text-2xl">Verify user</h3>
</div>
<UserUpdateForm user={user} />
</div>
);
}

View File

@@ -22,7 +22,9 @@ export default async function VerifyUserPage({
const userId = (await params).userId;
const [error, dbUser] = await tryCatch(getProfileById(userId));
const [nationalDataEror, nationalData] = await tryCatch(getNationalPerson({ idCard: dbUser?.id_card ?? "" }))
const [nationalDataEror, nationalData] = await tryCatch(
getNationalPerson({ idCard: dbUser?.id_card ?? "" }),
);
if (nationalDataEror) {
console.warn("Error fetching national data:", nationalDataEror);
}
@@ -47,19 +49,23 @@ export default async function VerifyUserPage({
<div className="flex flex-wrap gap-2">
{dbUser && !dbUser?.verified && <UserVerifyDialog user={dbUser} />}
{dbUser && !dbUser?.verified && <UserRejectDialog user={dbUser} />}
<Link href={'update'}>
<Link href={"update"}>
<Button className="hover:cursor-pointer">
<PencilIcon />
Update User
</Button>
</Link>
<Link href={'agreement'}>
<Link href={"agreement"}>
<Button className="hover:cursor-pointer">
<FileTextIcon />
Update Agreement
</Button>
</Link>
<Link href={dbUser?.agreement || "#"} target="_blank" rel="noopener noreferrer">
<Link
href={dbUser?.agreement || "#"}
target="_blank"
rel="noopener noreferrer"
>
<Button className="hover:cursor-pointer">
<EyeIcon />
View Agreement
@@ -114,9 +120,7 @@ export default async function VerifyUserPage({
<InputReadOnly
showCheck
checkTrue={
dbUserDob === nationalDob
}
checkTrue={dbUserDob === nationalDob}
labelClassName="text-sarLinkOrange"
label="DOB"
value={new Date(dbUser?.dob ?? "").toLocaleDateString("en-US", {
@@ -134,7 +138,7 @@ export default async function VerifyUserPage({
/>
</div>
</div>
{(
{
<div id="national-information">
<h4 className="p-2 rounded font-semibold">National Information</h4>
<div className="bg-green-800/10 shadow p-2 rounded-lg border border-dashed border-green-800 space-y-1 my-2 grid grid-cols-1 md:grid-cols-2 gap-2">
@@ -198,7 +202,7 @@ export default async function VerifyUserPage({
</div>
</div>
</div>
)}
}
</div>
</div>
);