From 191e5300acba9d0689d249038aada8aaf06c3eea Mon Sep 17 00:00:00 2001 From: kris-liu-smile Date: Thu, 13 Apr 2023 11:00:31 +0800 Subject: [PATCH] fix: delete the state not used by global --- .../storefront/src/components/B3GlobalTip.tsx | 2 +- apps/storefront/src/components/B3Tip.tsx | 2 +- .../src/components/RegisteredCloseButton.tsx | 12 ------ .../src/components/layout/B3LayoutTip.tsx | 2 +- apps/storefront/src/hooks/useSetOpen.ts | 10 ++++- apps/storefront/src/pages/login/Login.tsx | 7 ---- .../dynamicallyVariable/context/config.ts | 2 - .../src/shared/global/context/config.ts | 40 +------------------ 8 files changed, 13 insertions(+), 64 deletions(-) diff --git a/apps/storefront/src/components/B3GlobalTip.tsx b/apps/storefront/src/components/B3GlobalTip.tsx index e4e70f0f..b6f57dcd 100644 --- a/apps/storefront/src/components/B3GlobalTip.tsx +++ b/apps/storefront/src/components/B3GlobalTip.tsx @@ -5,7 +5,7 @@ import { import { MsgsProps, -} from '@/shared/global/context/config' +} from '@/shared/dynamicallyVariable/context/config' import { B3Tip, diff --git a/apps/storefront/src/components/B3Tip.tsx b/apps/storefront/src/components/B3Tip.tsx index 921e4622..1a840395 100644 --- a/apps/storefront/src/components/B3Tip.tsx +++ b/apps/storefront/src/components/B3Tip.tsx @@ -8,7 +8,7 @@ import { import { TipMessagesProps, MsgsProps, -} from '@/shared/global/context/config' +} from '@/shared/dynamicallyVariable/context/config' interface B3TipProps extends TipMessagesProps { handleItemClose: (id: number | string) => void, diff --git a/apps/storefront/src/components/RegisteredCloseButton.tsx b/apps/storefront/src/components/RegisteredCloseButton.tsx index 5f4dd123..76fdc701 100644 --- a/apps/storefront/src/components/RegisteredCloseButton.tsx +++ b/apps/storefront/src/components/RegisteredCloseButton.tsx @@ -34,9 +34,7 @@ export function RegisteredCloseButton(props: CloseButtonProps) { state: { isCheckout, isCloseGotoBCHome, - isLoginStatusChange, }, - dispatch, } = useContext(GlobaledContext) const handleCloseForm = () => { @@ -47,16 +45,6 @@ export function RegisteredCloseButton(props: CloseButtonProps) { isOpen: false, openUrl: '', }) - - if (isLoginStatusChange) { - window.location.reload() - dispatch({ - type: 'common', - payload: { - isLoginStatusChange: false, - }, - }) - } } } diff --git a/apps/storefront/src/components/layout/B3LayoutTip.tsx b/apps/storefront/src/components/layout/B3LayoutTip.tsx index d67395b4..73399a37 100644 --- a/apps/storefront/src/components/layout/B3LayoutTip.tsx +++ b/apps/storefront/src/components/layout/B3LayoutTip.tsx @@ -17,7 +17,7 @@ import { import { MsgsProps, -} from '@/shared/global/context/config' +} from '@/shared/dynamicallyVariable/context/config' const B3LayoutTip = () => { const { diff --git a/apps/storefront/src/hooks/useSetOpen.ts b/apps/storefront/src/hooks/useSetOpen.ts index b48a349f..4b17b130 100644 --- a/apps/storefront/src/hooks/useSetOpen.ts +++ b/apps/storefront/src/hooks/useSetOpen.ts @@ -7,6 +7,10 @@ import { GlobaledContext, } from '@/shared/global' +import { + DynamicallyVariableedContext, +} from '@/shared/dynamicallyVariable' + const { height: defaultHeight, overflow: defaultOverflow, @@ -16,6 +20,10 @@ const useSetOpen = (isOpen: boolean, openUrl?: string, params?: CustomFieldItems const { dispatch, } = useContext(GlobaledContext) + + const { + dispatch: dispatchMsg, + } = useContext(DynamicallyVariableedContext) useEffect(() => { if (isOpen) { // The iframe screen is removed @@ -45,7 +53,7 @@ const useSetOpen = (isOpen: boolean, openUrl?: string, params?: CustomFieldItems document.body.style.overflow = defaultOverflow // close all tips - dispatch({ + dispatchMsg({ type: 'common', payload: { tipMessage: { diff --git a/apps/storefront/src/pages/login/Login.tsx b/apps/storefront/src/pages/login/Login.tsx index 1ee2e210..76c9a334 100644 --- a/apps/storefront/src/pages/login/Login.tsx +++ b/apps/storefront/src/pages/login/Login.tsx @@ -262,13 +262,6 @@ export default function Login(props:RegisteredProps) { } else { const info = await getCurrentCustomerInfo(dispatch) - dispatch({ - type: 'common', - payload: { - isLoginStatusChange: true, - }, - }) - if (info?.userType === 3 && info?.role === 3) { navigate('/dashboard') } else { diff --git a/apps/storefront/src/shared/dynamicallyVariable/context/config.ts b/apps/storefront/src/shared/dynamicallyVariable/context/config.ts index d55ce17d..a93d4a03 100644 --- a/apps/storefront/src/shared/dynamicallyVariable/context/config.ts +++ b/apps/storefront/src/shared/dynamicallyVariable/context/config.ts @@ -35,7 +35,6 @@ export interface DynamicallyVariableState { saveText?: string, saveFn?: () => void, }, - isCloseScrollBar: boolean, } export const initState = { @@ -47,7 +46,6 @@ export const initState = { message: '', cancelText: 'Cancel', }, - isCloseScrollBar: false, } export interface DynamicallyVariableAction { diff --git a/apps/storefront/src/shared/global/context/config.ts b/apps/storefront/src/shared/global/context/config.ts index f8ed1d34..cd29a095 100644 --- a/apps/storefront/src/shared/global/context/config.ts +++ b/apps/storefront/src/shared/global/context/config.ts @@ -1,6 +1,5 @@ import { Dispatch, - ReactElement, ReactNode, } from 'react' @@ -16,23 +15,6 @@ export interface CustomerInfo { } export type AlertTip = 'error' | 'info' | 'success' | 'warning' -export interface MsgsProps { - title?: string, - msg?: string, - jsx?: () => ReactElement, - id: string | number, - type: AlertTip - isClose?: boolean, - vertical?: 'top' | 'bottom' - horizontal?: 'left' | 'right' | 'center' -} -export interface TipMessagesProps{ - msgs?: Array | [], - autoHideDuration?: number, - vertical?: 'top' | 'bottom' - horizontal?: 'left' | 'right' | 'center' - isClose?: boolean -} export interface State { stateCode?: string, stateName?: string, @@ -80,8 +62,6 @@ export interface GlobalState { isCloseGotoBCHome: boolean, BcToken: string, isB2BUser: boolean, - isLogin: boolean, - isLoginStatusChange: boolean, customerId: number | string, customer: CustomerInfo, companyInfo: { @@ -97,7 +77,7 @@ export interface GlobalState { salesRepCompanyId: string, salesRepCompanyName: string, B3UserId: number | string, - tipMessage: TipMessagesProps, + // tipMessage: TipMessagesProps, addressConfig?: { key: string, isEnabled: string, @@ -118,15 +98,6 @@ export interface GlobalState { cartQuoteEnabled: boolean, shoppingListEnabled: boolean, quoteConfig: CustomFieldItems[], - globalMessageDialog: { - open: boolean, - title: string, - message: string, - cancelText?: string, - cancelFn?: () => void, - saveText?: string, - saveFn?: () => void, - }, currencies: { channelCurrencies: channelCurrenciesProps, currencies: currencyProps, @@ -140,8 +111,6 @@ export const initState = { isCloseGotoBCHome: false, BcToken: B3SStorage.get('BcToken') || '', isB2BUser: B3SStorage.get('isB2BUser') || false, - isLogin: false, - isLoginStatusChange: false, customerId: B3SStorage.get('B3CustomerId') || '', B3UserId: B3SStorage.get('B3UserId') || '', emailAddress: B3SStorage.get('B3EmailAddress') || '', @@ -165,7 +134,6 @@ export const initState = { }, logo: '', isCompanyAccount: false, - tipMessage: {}, storeEnabled: false, storeName: '', currentChannelId: 1, @@ -175,12 +143,6 @@ export const initState = { cartQuoteEnabled: false, shoppingListEnabled: false, quoteConfig: [], - globalMessageDialog: { - open: false, - title: '', - message: '', - cancelText: 'Cancel', - }, currencies: B3SStorage.get('currencies') || {}, openAPPParams: { quoteBtn: '',