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

This commit is contained in:
2025-04-20 07:40:31 +05:00
parent ac11fee754
commit ba91d2c8d4
5 changed files with 51 additions and 18 deletions

View File

@ -1,8 +1,9 @@
import { getPayment } from "@/actions/payment";
import { getPayment, getProfile } from "@/actions/payment";
import { authOptions } from "@/app/auth";
import CancelPaymentButton from "@/components/billing/cancel-payment-button";
import ClientErrorMessage from "@/components/client-error-message";
import DevicesToPay from "@/components/devices-to-pay";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
import { tryCatch } from "@/utils/tryCatch";
import { getServerSession } from "next-auth";
@ -20,21 +21,28 @@ export default async function PaymentPage({
if (error.message === "Invalid token.") redirect("/auth/signin");
return <ClientErrorMessage message={error.message} />;
}
const [userError, userProfile] = await tryCatch(getProfile());
if (userError) {
if (userError.message === "Invalid token.") redirect("/auth/signin");
return <ClientErrorMessage message={userError.message} />;
}
return (
<div>
<div className="flex justify-between items-center border-[1px] rounded-md border-dashed font-bold title-bg py-4 px-4 mb-4 mx-2">
<h3 className="text-sarLinkOrange text-2xl">Payment</h3>
<div className="flex gap-4 items-center">
<span
<div className="flex flex-col gap-4 items-end w-full">
<Button
disabled
className={cn(
"text-sm border px-4 py-2 rounded-md uppercase font-semibold",
"rounded-md !opacity-100 uppercase font-semibold",
payment?.paid
? "text-green-500 bg-green-500/20"
: "text-yellow-500 bg-yellow-700",
: "text-yellow-500 bg-yellow-900",
)}
>
{payment?.paid ? "Paid" : "Pending"}
</span>
</Button>
<CancelPaymentButton paymentId={paymentId} />
</div>
</div>
@ -44,7 +52,7 @@ export default async function PaymentPage({
className="pb-4 gap-4 flex sm:flex-row flex-col items-start justify-start"
>
<DevicesToPay
user={session?.user || undefined}
user={userProfile || undefined}
payment={payment || undefined}
/>
</div>