feat: implement user profile page and integrate profile fetching logic in AccountPopover and ApplicationLayout components

This commit is contained in:
2025-07-11 14:41:06 +05:00
parent d1fdcc873a
commit a20c939c91
4 changed files with 152 additions and 82 deletions

View File

@ -1,8 +1,9 @@
"use server";
import { VerifyUserDetails } from "@/lib/person";
import { revalidatePath } from "next/cache";
import { redirect } from "next/navigation";
import { CreateClient } from "./ninja/client";
import { getServerSession } from "next-auth";
import { authOptions } from "@/app/auth";
import type { User, UserProfile } from "@/lib/types/user";
import { handleApiResponse } from "@/utils/tryCatch";
export async function VerifyUser(userId: string) {
// const user = await prisma.user.findUnique({
@ -52,72 +53,37 @@ export async function VerifyUser(userId: string) {
// revalidatePath("/users");
}
export async function Rejectuser({
userId,
reason,
}: { userId: string; reason: string }) {
// const user = await prisma.user.findUnique({
// where: {
// id: userId,
// },
// });
// if (!user) {
// throw new Error("User not found");
// }
// await SendUserRejectionDetailSMS({
// details: reason,
// phoneNumber: user.phoneNumber,
// });
// await prisma.user.delete({
// where: {
// id: userId,
// },
// });
revalidatePath("/users");
redirect("/users");
}
export const SendUserRejectionDetailSMS = async ({
details,
phoneNumber,
}: {
details: string;
phoneNumber: string;
}) => {
try {
const respose = await fetch(`${process.env.SMS_API_BASE_URL}/api/sms`, {
method: "POST",
export async function getProfile() {
const session = await getServerSession(authOptions);
const response = await fetch(
`${process.env.SARLINK_API_BASE_URL}/api/auth/profile/`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Bearer ${process.env.SMS_API_KEY}`,
Authorization: `Token ${session?.apiToken}`,
},
body: JSON.stringify({
check_delivery: false,
number: phoneNumber,
message: details,
}),
});
const data = await respose.json();
console.log(data);
return data;
} catch (error) {
console.error(error);
}
};
},
);
export async function AddDevice({
name,
mac_address,
user_id,
}: { name: string; mac_address: string; user_id: string }) {
// const newDevice = await prisma.device.create({
// data: {
// name: name,
// mac: mac_address,
// userId: user_id,
// },
// });
revalidatePath("/devices");
// return newDevice;
return handleApiResponse<User>(response, "getProfile");
}
export async function getProfileById(userId: string) {
const session = await getServerSession(authOptions);
const response = await fetch(
`${process.env.SARLINK_API_BASE_URL}/api/auth/users/${userId}/`,
{
method: "GET",
headers: {
"Content-Type": "application/json",
Authorization: `Token ${session?.apiToken}`,
},
},
);
return handleApiResponse<UserProfile>(response, "getProfilebyId");
}