diff --git a/apps/storefront/src/pages/invoice/utils/payment.ts b/apps/storefront/src/pages/invoice/utils/payment.ts index 58a7b12a..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 { @@ -19,19 +18,11 @@ export const gotoInvoiceCheckoutUrl = async ( params: BcCartData, isReplaceCurrentUrl?: boolean ) => { - const { checkoutUrl, cartId } = await getCheckouUrlAndCart(params) + const { checkoutUrl } = await getCheckouUrlAndCart(params) - try { - await attemptCheckoutLoginAndRedirect( - cartId, - checkoutUrl, - isReplaceCurrentUrl - ) - } catch (e) { - if (isReplaceCurrentUrl) { - window.location.replace(checkoutUrl) - } else { - window.location.href = checkoutUrl - } + 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 ed75f822..f181ee58 100644 --- a/apps/storefront/src/pages/quote/components/QuoteDetailFooter.tsx +++ b/apps/storefront/src/pages/quote/components/QuoteDetailFooter.tsx @@ -1,17 +1,12 @@ -import { useContext } from 'react' import { useLocation } from 'react-router-dom' import { useB3Lang } from '@b3/lang' import { Box } from '@mui/material' import { CustomButton } from '@/components' import { useMobile } from '@/hooks' -import { GlobaledContext } from '@/shared/global' import { b2bQuoteCheckout, bcQuoteCheckout } from '@/shared/service/b2b' 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 globalStore = useContext(GlobaledContext) 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 (!globalStore.state.customer) { - 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 207ee87c..00000000 --- a/apps/storefront/src/utils/b3checkout.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { b2bCheckoutLogin } from '@/shared/service/b2b/graphql/checkout' -import * as cryptoJs from '@/utils/cryptoJs' - -const redirect = (url: string, isReplaceCurrentUrl?: boolean) => { - if (isReplaceCurrentUrl) { - window.location.replace(url) - } else { - window.location.href = url - } -} -// comment for deploy -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', cryptoJs.cipherText(quoteId)) - sessionStorage.setItem( - 'quoteDate', - cryptoJs.cipherText(date?.toString() || '') - ) -}