mirror of
https://github.com/i701/sarlink-portal.git
synced 2025-07-01 03:05:55 +00:00
feat: add getProfile function and integrate user profile retrieval in payment and layout components
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m47s
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m47s
This commit is contained in:
@ -4,6 +4,7 @@ import { Wallet } from "@/components/wallet";
|
||||
import { ModeToggle } from "@/components/theme-toggle";
|
||||
import { AppSidebar } from "@/components/ui/app-sidebar";
|
||||
|
||||
import { getProfile } from "@/actions/payment";
|
||||
import { authOptions } from "@/app/auth";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import {
|
||||
@ -11,6 +12,7 @@ import {
|
||||
SidebarProvider,
|
||||
SidebarTrigger,
|
||||
} from "@/components/ui/sidebar";
|
||||
import { tryCatch } from "@/utils/tryCatch";
|
||||
import { getServerSession } from "next-auth";
|
||||
import { redirect } from "next/navigation";
|
||||
import { AccountPopover } from "./account-popver";
|
||||
@ -21,6 +23,11 @@ export async function ApplicationLayout({
|
||||
const session = await getServerSession(authOptions);
|
||||
|
||||
if (!session) return redirect("/auth/signin");
|
||||
const [userError, userProfile] = await tryCatch(getProfile());
|
||||
if (userError) {
|
||||
if (userError.message === "Invalid token.") redirect("/auth/signin");
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<SidebarProvider>
|
||||
<AppSidebar />
|
||||
@ -30,7 +37,7 @@ export async function ApplicationLayout({
|
||||
<div className="flex items-center gap-2 ">
|
||||
<SidebarTrigger className="-ml-1" />
|
||||
<Separator orientation="vertical" className="mr-2 h-4" />
|
||||
<div className="text-sm font-mono px-2 p-1 rounded-md bg-green-500/10 text-green-900 dark:text-green-400">
|
||||
<div className="text-xs font-mono px-2 p-1 rounded-md bg-green-500/10 text-green-900 dark:text-green-400">
|
||||
Welcome,{" "}
|
||||
<span className="font-semibold">
|
||||
{session?.user?.first_name} {session?.user?.last_name}
|
||||
@ -39,7 +46,7 @@ export async function ApplicationLayout({
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<Wallet walletBalance={session?.user?.wallet_balance || 0} />
|
||||
<Wallet walletBalance={userProfile?.wallet_balance || 0} />
|
||||
<ModeToggle />
|
||||
<AccountPopover />
|
||||
</div>
|
||||
|
@ -9,6 +9,7 @@ import {
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import type { Payment } from "@/lib/backend-types";
|
||||
import type { User } from "@/lib/types/user";
|
||||
import {
|
||||
BadgeDollarSign,
|
||||
Clipboard,
|
||||
@ -16,7 +17,6 @@ import {
|
||||
Loader2,
|
||||
Wallet,
|
||||
} from "lucide-react";
|
||||
import type { User } from "next-auth";
|
||||
import { useState } from "react";
|
||||
import { toast } from "sonner";
|
||||
import { Button } from "./ui/button";
|
||||
@ -33,9 +33,7 @@ export default function DevicesToPay({
|
||||
return null;
|
||||
}
|
||||
// 100+(n−1)×75
|
||||
// const walletBalance = user?.walletBalance ?? 0;
|
||||
// TODO - get wallet balance from backend
|
||||
const walletBalance = 110;
|
||||
const walletBalance = user?.wallet_balance ?? 0;
|
||||
|
||||
const isWalletPayVisible = walletBalance > (payment?.amount ?? 0);
|
||||
|
||||
|
Reference in New Issue
Block a user