diff --git a/apps/storefront/src/pages/invoice/Payment.tsx b/apps/storefront/src/pages/invoice/Payment.tsx index 5496bb01..2729b64e 100644 --- a/apps/storefront/src/pages/invoice/Payment.tsx +++ b/apps/storefront/src/pages/invoice/Payment.tsx @@ -1,19 +1,15 @@ import { useEffect, useState } from 'react' -import { useSelector } from 'react-redux' import { useNavigate, useParams } from 'react-router-dom' import { useB3Lang } from '@b3/lang' import { Box } from '@mui/material' import { B3Dialog, Loading } from '@/components' import { getInvoiceDetail } from '@/shared/service/b2b' -import { globalStateSelector } from '@/store' import { B3SStorage, snackbar } from '@/utils' import { gotoInvoiceCheckoutUrl } from './utils/payment' function Payment() { - const globalState = useSelector(globalStateSelector) - const [loadding, setLoadding] = useState(false) const [open, setOpen] = useState(false) @@ -61,11 +57,7 @@ function Payment() { currency: code, } - await gotoInvoiceCheckoutUrl( - data, - globalState.storeInfo.platform, - true - ) + await gotoInvoiceCheckoutUrl(data, true) } catch (error: unknown) { snackbar.error( (error as CustomFieldItems)?.message || diff --git a/apps/storefront/src/pages/invoice/components/B3Pulldown.tsx b/apps/storefront/src/pages/invoice/components/B3Pulldown.tsx index 1ef2a692..53442874 100644 --- a/apps/storefront/src/pages/invoice/components/B3Pulldown.tsx +++ b/apps/storefront/src/pages/invoice/components/B3Pulldown.tsx @@ -1,12 +1,10 @@ import { MouseEvent, useContext, useEffect, useState } from 'react' -import { useSelector } from 'react-redux' import { useNavigate } from 'react-router-dom' import MoreHorizIcon from '@mui/icons-material/MoreHoriz' import { IconButton, Menu, MenuItem } from '@mui/material' import { styled } from '@mui/material/styles' import { GlobaledContext } from '@/shared/global' -import { globalStateSelector } from '@/store' import { InvoiceList } from '@/types/invoice' import { snackbar } from '@/utils' @@ -34,7 +32,6 @@ function B3Pulldown({ setInvoiceId, handleOpenHistoryModal, }: B3PulldownProps) { - const globalState = useSelector(globalStateSelector) const { state: { role, isAgenting }, } = useContext(GlobaledContext) @@ -109,7 +106,7 @@ function B3Pulldown({ return } - await gotoInvoiceCheckoutUrl(params, globalState.storeInfo.platform, false) + await gotoInvoiceCheckoutUrl(params) } const viewPaymentHistory = async () => { diff --git a/apps/storefront/src/pages/invoice/components/InvoiceFooter.tsx b/apps/storefront/src/pages/invoice/components/InvoiceFooter.tsx index 663e2ab0..a8915007 100644 --- a/apps/storefront/src/pages/invoice/components/InvoiceFooter.tsx +++ b/apps/storefront/src/pages/invoice/components/InvoiceFooter.tsx @@ -1,11 +1,9 @@ import { useContext, useEffect, useState } from 'react' -import { useSelector } from 'react-redux' import { useB3Lang } from '@b3/lang' import { Box, Button, Grid, Typography } from '@mui/material' import { useMobile } from '@/hooks' import { GlobaledContext } from '@/shared/global' -import { globalStateSelector } from '@/store' import { BcCartData, BcCartDataLineItem, @@ -21,7 +19,6 @@ interface InvoiceFooterProps { } function InvoiceFooter(props: InvoiceFooterProps) { - const globalState = useSelector(globalStateSelector) const b3Lang = useB3Lang() const allCurrencies = B3SStorage.get('currencies') const [isMobile] = useMobile() @@ -105,11 +102,7 @@ function InvoiceFooter(props: InvoiceFooterProps) { currency, } - await gotoInvoiceCheckoutUrl( - params, - globalState.storeInfo.platform, - false - ) + await gotoInvoiceCheckoutUrl(params) } } diff --git a/apps/storefront/src/pages/invoice/utils/payment.ts b/apps/storefront/src/pages/invoice/utils/payment.ts index d69de2fe..6bd70974 100644 --- a/apps/storefront/src/pages/invoice/utils/payment.ts +++ b/apps/storefront/src/pages/invoice/utils/payment.ts @@ -1,6 +1,5 @@ import { getInvoiceCheckoutUrl } from '@/shared/service/b2b' import { BcCartData } from '@/types/invoice' -import { attemptCheckoutLoginAndRedirect } from '@/utils/b3checkout' export const getCheckouUrlAndCart = async (params: BcCartData) => { const { @@ -17,30 +16,13 @@ export const getCheckouUrlAndCart = async (params: BcCartData) => { export const gotoInvoiceCheckoutUrl = async ( params: BcCartData, - platform: string, isReplaceCurrentUrl?: boolean ) => { - const { checkoutUrl, cartId } = await getCheckouUrlAndCart(params) - const handleStencil = () => { - if (isReplaceCurrentUrl) { - window.location.replace(checkoutUrl) - } else { - window.location.href = checkoutUrl - } - } - - if (platform === 'bigcommerce') { - handleStencil() - } + const { checkoutUrl } = await getCheckouUrlAndCart(params) - try { - await attemptCheckoutLoginAndRedirect( - cartId, - checkoutUrl, - isReplaceCurrentUrl - ) - } catch (e) { - console.error(e) - handleStencil() + if (isReplaceCurrentUrl) { + window.location.replace(checkoutUrl) + } else { + window.location.href = checkoutUrl } } diff --git a/apps/storefront/src/pages/quote/components/QuoteDetailFooter.tsx b/apps/storefront/src/pages/quote/components/QuoteDetailFooter.tsx index 59ab6ef6..f181ee58 100644 --- a/apps/storefront/src/pages/quote/components/QuoteDetailFooter.tsx +++ b/apps/storefront/src/pages/quote/components/QuoteDetailFooter.tsx @@ -1,4 +1,3 @@ -import { useSelector } from 'react-redux' import { useLocation } from 'react-router-dom' import { useB3Lang } from '@b3/lang' import { Box } from '@mui/material' @@ -6,12 +5,8 @@ import { Box } from '@mui/material' import { CustomButton } from '@/components' import { useMobile } from '@/hooks' import { b2bQuoteCheckout, bcQuoteCheckout } from '@/shared/service/b2b' -import { globalStateSelector } from '@/store' import { getSearchVal } from '@/utils' -import { - attemptCheckoutLoginAndRedirect, - setQuoteToStorage, -} from '@/utils/b3checkout' +import * as cryptoJs from '@/utils/cryptoJs' interface QuoteDetailFooterProps { quoteId: string @@ -22,7 +17,6 @@ interface QuoteDetailFooterProps { function QuoteDetailFooter(props: QuoteDetailFooterProps) { const { quoteId, role, isAgenting, status } = props - const globalState = useSelector(globalStateSelector) const [isMobile] = useMobile() const b3Lang = useB3Lang() const location = useLocation() @@ -45,19 +39,20 @@ function QuoteDetailFooter(props: QuoteDetailFooterProps) { id: +quoteId, }) - setQuoteToStorage(quoteId, date) const { quoteCheckout: { - quoteCheckout: { checkoutUrl, cartId }, + quoteCheckout: { checkoutUrl }, }, } = res - if (globalState.storeInfo.platfom === 'bigcommerce') { - window.location.href = checkoutUrl - return - } + sessionStorage.setItem('isNewStorefront', JSON.stringify(true)) + sessionStorage.setItem('quoteCheckoutId', cryptoJs.cipherText(quoteId)) + sessionStorage.setItem( + 'quoteDate', + cryptoJs.cipherText(date?.toString() || '') + ) - await attemptCheckoutLoginAndRedirect(cartId, checkoutUrl as string) + window.location.href = checkoutUrl } catch (err) { console.error(err) } diff --git a/apps/storefront/src/shared/service/b2b/graphql/checkout.ts b/apps/storefront/src/shared/service/b2b/graphql/checkout.ts deleted file mode 100644 index a4619db4..00000000 --- a/apps/storefront/src/shared/service/b2b/graphql/checkout.ts +++ /dev/null @@ -1,18 +0,0 @@ -import B3Request from '../../request/b3Fetch' - -const checkoutLogin = `mutation checkoutLogin($cartData: CheckoutLoginType!) { - checkoutLogin( - cartData: $cartData - ) { - result { - redirectUrl - } - } -}` - -// eslint-disable-next-line import/prefer-default-export -export const b2bCheckoutLogin = (data: CustomFieldItems): CustomFieldItems => - B3Request.graphqlB2B({ - query: checkoutLogin, - variables: data, - }) diff --git a/apps/storefront/src/utils/b3checkout.ts b/apps/storefront/src/utils/b3checkout.ts deleted file mode 100644 index 17fe3c27..00000000 --- a/apps/storefront/src/utils/b3checkout.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { b2bCheckoutLogin } from '@/shared/service/b2b/graphql/checkout' -import { cipherText } from '@/utils/cryptoJs' - -const redirect = (url: string, isReplaceCurrentUrl?: boolean) => { - if (isReplaceCurrentUrl) { - window.location.replace(url) - } else { - window.location.href = url - } -} - -export const attemptCheckoutLoginAndRedirect = async ( - cartId: any, - defaultCheckoutUrl: string, - isReplaceCurrentUrl?: boolean -) => { - try { - const resLogin = await b2bCheckoutLogin({ - cartData: { cartId }, - }) - - const { - checkoutLogin: { result }, - } = resLogin - - redirect(result.redirectUrl, isReplaceCurrentUrl) - } catch (e) { - redirect(defaultCheckoutUrl, isReplaceCurrentUrl) - } -} - -export const setQuoteToStorage = (quoteId: string, date: any) => { - sessionStorage.setItem('isNewStorefront', JSON.stringify(true)) - sessionStorage.setItem('quoteCheckoutId', cipherText(quoteId)) - sessionStorage.setItem( - 'quoteDate', - cipherText(date?.toString() || '') - ) -}