From b3cdf86adfe7b062ffe52e5effb871bfc38bd7bd Mon Sep 17 00:00:00 2001 From: kris-liu-smile Date: Fri, 16 Jun 2023 10:24:28 +0800 Subject: [PATCH] fix: issue with Super Admin logging out after completing a quote BUN-1172 --- .../src/components/layout/B3AccountInfo.tsx | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/apps/storefront/src/components/layout/B3AccountInfo.tsx b/apps/storefront/src/components/layout/B3AccountInfo.tsx index 724319d8..f0d649e1 100644 --- a/apps/storefront/src/components/layout/B3AccountInfo.tsx +++ b/apps/storefront/src/components/layout/B3AccountInfo.tsx @@ -4,6 +4,8 @@ import { Box } from '@mui/material' import { useMobile } from '@/hooks' import { GlobaledContext } from '@/shared/global' +import { superAdminEndMasquerade } from '@/shared/service/b2b' +import { B3SStorage } from '@/utils' import B3DropDown from '../B3DropDown' @@ -29,14 +31,37 @@ export default function B3AccountInfo({ closeSidebar }: B3AccountInfoProps) { const { state: { customer: { firstName = '', lastName = '' }, + B3UserId, + salesRepCompanyId = 0, + isAgenting, }, + dispatch, } = useContext(GlobaledContext) const navigate = useNavigate() - const handleItemClick = (item: ListProps) => { + const handleItemClick = async (item: ListProps) => { if (item.key === 'logout') { - navigate('/login?loginFlag=3') + try { + if (isAgenting) { + await superAdminEndMasquerade(+salesRepCompanyId, +B3UserId) + + B3SStorage.delete('isAgenting') + B3SStorage.delete('salesRepCompanyId') + B3SStorage.delete('salesRepCompanyName') + + dispatch({ + type: 'common', + payload: { + salesRepCompanyId: '', + salesRepCompanyName: '', + isAgenting: false, + }, + }) + } + } finally { + navigate('/login?loginFlag=3') + } } else if (item.type === 'path') { navigate(item.key) }