refactor: update axios client import, enhance device and payment handling, and add cancel payment button component
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 6m28s

This commit is contained in:
2025-04-08 21:37:51 +05:00
parent daab793592
commit 7e49bf119a
14 changed files with 270 additions and 178 deletions

View File

@ -10,7 +10,7 @@ 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 { redirect, usePathname } from "next/navigation";
import { useEffect, useState } from "react";
import { toast } from "sonner";
export default function DevicesForPayment() {
@ -35,7 +35,7 @@ export default function DevicesForPayment() {
setTotal(baseAmount + (devices.length + 1 - 1) * discountPercentage);
}, [months, devices.length]);
if (pathname === "/payment") {
if (pathname === "/payments") {
return null;
}
@ -45,6 +45,9 @@ export default function DevicesForPayment() {
device_ids: devices.map((device) => device.id),
};
if (disabled) {
return "Please wait...";
}
return (
<div className="max-w-lg mx-auto space-y-4 px-4">
<div className="flex max-h-[calc(100svh-400px)] flex-col overflow-auto pb-4 gap-4">
@ -69,15 +72,15 @@ export default function DevicesForPayment() {
<Button
onClick={async () => {
setDisabled(true);
const [error, respose] = await tryCatch(createPayment(data));
const [error, response] = await tryCatch(createPayment(data));
if (error) {
setDisabled(false);
toast.error(error.message);
toast.error(JSON.stringify(error, null, 2));
return;
}
setDeviceCart([]);
setMonths(1);
setDisabled(false);
redirect(`/payments/${response.id}`);
}}
className="w-full"
disabled={devices.length === 0 || disabled}