refactor: reorder imports and improve variable naming in CancelPaymentButton component 🔨

This commit is contained in:
2025-07-06 22:39:16 +05:00
parent e984705849
commit 837cc35ad3

View File

@ -1,11 +1,11 @@
"use client"; "use client";
import { cancelPayment } from "@/actions/payment";
import { tryCatch } from "@/utils/tryCatch";
import { Loader2, Trash2 } from "lucide-react"; import { Loader2, Trash2 } from "lucide-react";
import { useRouter } from "next/navigation"; import { useRouter } from "next/navigation";
import React from "react"; import React from "react";
import { toast } from "sonner"; import { toast } from "sonner";
import { cancelPayment } from "@/actions/payment";
import { tryCatch } from "@/utils/tryCatch";
import { Button } from "../ui/button"; import { Button } from "../ui/button";
export default function CancelPaymentButton({ export default function CancelPaymentButton({
@ -17,12 +17,16 @@ export default function CancelPaymentButton({
<Button <Button
onClick={async () => { onClick={async () => {
setLoading(true); setLoading(true);
const [error, x] = await tryCatch(cancelPayment({ id: paymentId })); const [error, payment] = await tryCatch(cancelPayment({ id: paymentId }));
console.log(x); console.log(payment);
if (error) { if (error) {
toast.error(error.message); toast.error(error.message);
setLoading(false); setLoading(false);
} else { } else {
toast.success("Payment cancelled successfully!", {
description: `Your payment of ${payment?.amount} MVR has been cancelled.`,
closeButton: true,
});
router.replace("/devices"); router.replace("/devices");
} }
}} }}