diff --git a/ui-dashboard/src/app.tsx b/ui-dashboard/src/app.tsx index 56d56c8..6bb4079 100644 --- a/ui-dashboard/src/app.tsx +++ b/ui-dashboard/src/app.tsx @@ -156,20 +156,16 @@ const App: React.FC = () => { }; const listMerchant = async () => { - if (!user) { - return; + if (user && newMerchantId) { + await getMerchant(newMerchantId); } - - if (!newMerchantId) return; - - await getMerchant(newMerchantId); - setIsLoading(false); }; await getCookie(); await getMe(); await listMerchants(); await listMerchant(); + setIsLoading(false); }; useMount(async () => { diff --git a/ui-dashboard/src/hooks/use-merchant-id.ts b/ui-dashboard/src/hooks/use-merchant-id.ts index f04d316..46b7ad9 100644 --- a/ui-dashboard/src/hooks/use-merchant-id.ts +++ b/ui-dashboard/src/hooks/use-merchant-id.ts @@ -14,6 +14,8 @@ const useMerchantId = (): MerchantIdState => { setMerchantId(merchantId); if (merchantId) { localStorage.set("merchantId", merchantId); + } else { + localStorage.remove("merchantId"); } }; diff --git a/ui-dashboard/src/pages/manage-merchants-page/manage-merchants-page.tsx b/ui-dashboard/src/pages/manage-merchants-page/manage-merchants-page.tsx index d5dc04e..8527289 100644 --- a/ui-dashboard/src/pages/manage-merchants-page/manage-merchants-page.tsx +++ b/ui-dashboard/src/pages/manage-merchants-page/manage-merchants-page.tsx @@ -85,10 +85,7 @@ const ManageMerchantsPage: React.FC = () => { await getMerchants(); const nextMerchant = merchants?.find((merchantItem) => merchantItem.id !== merchant.id); - - if (nextMerchant) { - setMerchantId(nextMerchant.id); - } + setMerchantId(nextMerchant ? nextMerchant.id : null); openNotification(`Merchant ${merchant.name} has been deleted`, "Thank you for being with us"); } catch (error) {