Skip to content

Commit

Permalink
Revert "Bc victor/bun 1682/redirect only headless (#882)"
Browse files Browse the repository at this point in the history
This reverts commit c9beccc.
  • Loading branch information
BrianJiang2021 authored and libruce committed Dec 26, 2023
1 parent 52ce297 commit 12d5862
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 115 deletions.
10 changes: 1 addition & 9 deletions apps/storefront/src/pages/invoice/Payment.tsx
Original file line number Diff line number Diff line change
@@ -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<boolean>(false)

const [open, setOpen] = useState<boolean>(false)
Expand Down Expand Up @@ -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 ||
Expand Down
5 changes: 1 addition & 4 deletions apps/storefront/src/pages/invoice/components/B3Pulldown.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -34,7 +32,6 @@ function B3Pulldown({
setInvoiceId,
handleOpenHistoryModal,
}: B3PulldownProps) {
const globalState = useSelector(globalStateSelector)
const {
state: { role, isAgenting },
} = useContext(GlobaledContext)
Expand Down Expand Up @@ -109,7 +106,7 @@ function B3Pulldown({
return
}

await gotoInvoiceCheckoutUrl(params, globalState.storeInfo.platform, false)
await gotoInvoiceCheckoutUrl(params)
}

const viewPaymentHistory = async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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()
Expand Down Expand Up @@ -105,11 +102,7 @@ function InvoiceFooter(props: InvoiceFooterProps) {
currency,
}

await gotoInvoiceCheckoutUrl(
params,
globalState.storeInfo.platform,
false
)
await gotoInvoiceCheckoutUrl(params)
}
}

Expand Down
28 changes: 5 additions & 23 deletions apps/storefront/src/pages/invoice/utils/payment.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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
}
}
23 changes: 9 additions & 14 deletions apps/storefront/src/pages/quote/components/QuoteDetailFooter.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
import { useSelector } from 'react-redux'
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 { 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
Expand All @@ -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()
Expand All @@ -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)
}
Expand Down
18 changes: 0 additions & 18 deletions apps/storefront/src/shared/service/b2b/graphql/checkout.ts

This file was deleted.

39 changes: 0 additions & 39 deletions apps/storefront/src/utils/b3checkout.ts

This file was deleted.

0 comments on commit 12d5862

Please sign in to comment.