sarlink-portal/components/billing/cancel-payment-button.tsx
i701 b932fcf03c
Some checks failed
Build and Push Docker Images / Build and Push Docker Images (push) Failing after 1m15s
TEMPORARY FIX TO TEST BUILD
2025-04-10 23:18:19 +05:00

37 lines
919 B
TypeScript

"use client";
import { cancelPayment } from "@/actions/payment";
import { tryCatch } from "@/utils/tryCatch";
import { Loader2, Trash2 } from "lucide-react";
import { useRouter } from "next/navigation";
import React from "react";
import { toast } from "sonner";
import { Button } from "../ui/button";
export default function CancelPaymentButton({
paymentId,
}: { paymentId: string }) {
const router = useRouter();
const [loading, setLoading] = React.useState(false);
return (
<Button
onClick={async () => {
setLoading(true);
const [error, x] = await tryCatch(cancelPayment({ id: paymentId }));
console.log(x);
if (error) {
toast.error(error.message);
setLoading(false);
} else {
router.replace("/devices");
}
}}
disabled={loading}
variant={"destructive"}
>
Cancel Payment
{loading ? <Loader2 className="animate-spin" /> : <Trash2 />}
</Button>
);
}