From ec69b6f0131939ebfbff1d5082b1229f7b58799b Mon Sep 17 00:00:00 2001
From: it-fixcomart <it@fixcomart.co.id>
Date: Sat, 21 Sep 2024 11:08:50 +0700
Subject: <iman> add try catch

---
 src/lib/checkout/components/FinishCheckout.jsx | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

(limited to 'src/lib/checkout/components/FinishCheckout.jsx')

diff --git a/src/lib/checkout/components/FinishCheckout.jsx b/src/lib/checkout/components/FinishCheckout.jsx
index 1be5c841..4a67b252 100644
--- a/src/lib/checkout/components/FinishCheckout.jsx
+++ b/src/lib/checkout/components/FinishCheckout.jsx
@@ -6,6 +6,7 @@ import odooApi from '@/core/api/odooApi';
 import useDevice from '@/core/hooks/useDevice';
 import useAuth from '@/core/hooks/useAuth';
 import axios from 'axios';
+import { toast } from 'react-hot-toast';
 
 const FinishCheckout = ({ query }) => {
   const [data, setData] = useState();
@@ -27,10 +28,20 @@ const FinishCheckout = ({ query }) => {
 
   // Kirim email ketika komponen ini dimount atau sesuai kondisi
   const sendEmail = async () => {
-    await axios.post(
-      `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/finish-checkout?orderName=${query?.order_id}`,
-      {}
-    );
+    try {
+      const send = await axios.post(
+        `${process.env.NEXT_PUBLIC_SELF_HOST}/api/shop/finish-checkout?orderName=${query?.order_id}`,
+        {}
+      );
+      if (send.status === 200) {
+        toast.success('Berhasil mengirim rincian pesanan');
+      } else {
+        toast.error('Gagal mengirimkan rincian pesanan');
+      }
+    } catch (error) {
+      console.error(error);
+      toast.error('Gagal mengirimkan rincian pesanan');
+    }
   };
 
   return (
-- 
cgit v1.2.3

