refactor: update payment types and user interface, enhance error handling, and adjust API base URL
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 3m14s

This commit is contained in:
2025-04-05 23:25:17 +05:00
parent aa18484475
commit 9e2a2f430e
15 changed files with 596 additions and 423 deletions

View File

@ -5,12 +5,14 @@ import DeviceCard from "@/components/device-card";
import NumberInput from "@/components/number-input";
import { Button } from "@/components/ui/button";
import { deviceCartAtom, numberOfMonths } from "@/lib/atoms";
import type { PaymentType } from "@/lib/types";
import type { NewPayment, Payment } from "@/lib/backend-types";
import { tryCatch } from "@/utils/tryCatch";
import { useAtom, useAtomValue, useSetAtom } from "jotai";
import { CircleDollarSign, Loader2 } from "lucide-react";
import { useSession } from "next-auth/react";
import { usePathname } from "next/navigation";
import { useEffect, useState } from "react";
import { toast } from "sonner";
export default function DevicesForPayment() {
const baseAmount = 100;
const discountPercentage = 75;
@ -37,12 +39,10 @@ export default function DevicesForPayment() {
return null;
}
const data: PaymentType = {
numberOfMonths: months,
userId: session?.data?.user?.id ?? "",
deviceIds: devices.map((device) => device.id),
amount: Number.parseFloat(total.toFixed(2)),
paid: false,
const data: NewPayment = {
amount: 100,
number_of_months: 2,
device_ids: devices.map((device) => device.id),
};
return (
@ -69,7 +69,12 @@ export default function DevicesForPayment() {
<Button
onClick={async () => {
setDisabled(true);
await createPayment(data);
const [error, respose] = await tryCatch(createPayment(data));
if (error) {
setDisabled(false);
toast.error(error.message);
return;
}
setDeviceCart([]);
setMonths(1);
setDisabled(false);