Skip to content

Commit

Permalink
fix: accountsetting date is require error
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 authored and libruce committed Nov 16, 2023
1 parent 24ce25d commit 3805d69
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 9 deletions.
13 changes: 9 additions & 4 deletions apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
getTemPlateConfig,
handleHideRegisterPage,
loginInfo,
logoutSession,
openPageByClick,
removeBCMenus,
setStorefrontConfig,
Expand Down Expand Up @@ -185,7 +186,7 @@ export default function App() {
setChannelStoreType(currentChannelId)
// await getTaxZoneRates()

const getInfo = await Promise.all([
await Promise.all([
getCustomerInfo(),
getStoreTaxZoneRates(),
setStorefrontConfig(dispatch, currentChannelId),
Expand All @@ -198,7 +199,6 @@ export default function App() {
isAgenting,
}

console.log(getInfo, 'info')
if (!customerId || isRelogin) {
const info = await getCurrentCustomerInfo(dispatch)
if (info) {
Expand All @@ -211,7 +211,7 @@ export default function App() {
!href.includes('checkout') &&
!(customerId && !window.location.hash)
) {
gotoAllowedAppPage(+userInfo.role, gotoPage)
await gotoAllowedAppPage(+userInfo.role, gotoPage)
}

if (customerId) {
Expand Down Expand Up @@ -267,14 +267,19 @@ export default function App() {
const init = async () => {
if (isClickEnterBtn && isPageComplete && currentClickedUrl) {
// graphql bc
const { customer } = await getCustomerInfo()
const {
data: { customer },
} = await getCustomerInfo()

const gotoUrl = openPageByClick({
href: currentClickedUrl,
role,
isRegisterAndLogin,
isAgenting,
})
if (!customer) {
logoutSession()
}

setOpenPage({
isOpen: true,
Expand Down
11 changes: 10 additions & 1 deletion apps/storefront/src/pages/accountSetting/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,16 @@ function sendEmail(data: any, extraFields: any) {
const val = formFields.find(
(field: Partial<Fields>) => field.name === item.bcLabel
).value
formData.append(`FormField[1][${key}]`, val)
if (item.type === 'date') {
const time = val.split('-')
if (!val && time.length !== 3) return
const [year, month, day] = time
formData.append(`FormFieldYear[1][${key}]`, year)
formData.append(`FormFieldMonth[1][${key}]`, month)
formData.append(`FormFieldDay[1][${key}]`, day)
} else {
formData.append(`FormField[1][${key}]`, val)
}
}
})
}
Expand Down
11 changes: 8 additions & 3 deletions apps/storefront/src/shared/routes/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { matchPath } from 'react-router-dom'

import { GlobalState, QuoteConfigProps } from '@/shared/global/context/config'
import { getCustomerInfo } from '@/shared/service/bc'
import { B3SStorage } from '@/utils'
import { B3SStorage, logoutSession } from '@/utils'

const OrderList = lazy(() => import('../../pages/order/MyOrder'))

Expand Down Expand Up @@ -389,9 +389,14 @@ const gotoAllowedAppPage = async (
return
}

const { customer } = await getCustomerInfo()
const {
data: { customer },
} = await getCustomerInfo()

if (!customer) gotoPage('/login')
if (!customer) {
logoutSession()
gotoPage('/login')
}

const { hash, pathname } = window.location
let url = hash.split('#')[1] || ''
Expand Down
15 changes: 15 additions & 0 deletions apps/storefront/src/utils/b3logout.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { B3SStorage } from './b3Storage'

export const logoutSession = () => {
B3SStorage.delete('B3UserId')
B3SStorage.delete('companyStatus')
B3SStorage.delete('B3Role')
B3SStorage.delete('B3CustomerInfo')
B3SStorage.delete('realRole')
B3SStorage.delete('B3CustomerInfo')
B3SStorage.delete('B3CustomerId')
B3SStorage.delete('nextPath')
B3SStorage.delete('B3EmailAddress')
}

export default {}
1 change: 1 addition & 0 deletions apps/storefront/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import {
} from './loginInfo'
import { validatorRules } from './validatorRules'

export { logoutSession } from './b3logout'
export * from './b3Product/b3Product'
export * from './basicConfig'
export * from './masquerade'
Expand Down
2 changes: 1 addition & 1 deletion apps/storefront/src/utils/loginInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export const getCompanyUserInfo = async (
isB2BUser = false
) => {
try {
if (!emailAddress) return undefined
if (!emailAddress || !customerId) return undefined

const {
companyUserInfo: {
Expand Down

0 comments on commit 3805d69

Please sign in to comment.