Skip to content

Commit

Permalink
feat: jump to the page when the token expires
Browse files Browse the repository at this point in the history
  • Loading branch information
b3aton committed Jan 18, 2023
1 parent 799abaa commit 8df0a62
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
6 changes: 5 additions & 1 deletion apps/storefront/src/pages/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export default function Login(props:RegisteredProps) {
} = props

const [logo, setLogo] = useState('')
const [showTipInfo, setShowTipInfo] = useState<boolean>(true)
const [flag, setLoginFlag] = useState<string>('')
const [loginAccount, setLoginAccount] = useState<LoginConfig>({
emailAddress: '',
Expand Down Expand Up @@ -159,6 +160,9 @@ export default function Login(props:RegisteredProps) {
} = location

const loginFlag = getLoginFlag(search, 'loginFlag')
const showTipInfo = getLoginFlag(search, 'showTip') !== 'false'

setShowTipInfo(showTipInfo)

if (loginFlag) setLoginFlag(loginFlag)

Expand Down Expand Up @@ -337,7 +341,7 @@ export default function Login(props:RegisteredProps) {
}

{
flag && (
flag && showTipInfo && (
<Box
sx={{
padding: '0 5%',
Expand Down
22 changes: 11 additions & 11 deletions apps/storefront/src/pages/registered/Registered.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,19 +141,19 @@ export default function Registered(props: RegisteredProps) {
} = await storeB2BBasicInfo()
const registerLogo = getRegisterLogo(quoteConfig)

const newAddressInformationFields = b2bAccountFormFields.address.map((addressFields: Partial<RegisterFieldsItems>):Partial<RegisterFieldsItems> => {
const newAddressInformationFields = b2bAccountFormFields.address?.map((addressFields: Partial<RegisterFieldsItems>):Partial<RegisterFieldsItems> => {
if (addressFields.name === 'country') {
addressFields.options = countries
}
return addressFields
})
}) || []

const newBCAddressInformationFields = bcAccountFormFields.address.map((addressFields: Partial<RegisterFieldsItems>):Partial<RegisterFieldsItems> => {
const newBCAddressInformationFields = bcAccountFormFields.address?.map((addressFields: Partial<RegisterFieldsItems>):Partial<RegisterFieldsItems> => {
if (addressFields.name === 'country') {
addressFields.options = countries
}
return addressFields
})
}) || []

if (dispatch) {
dispatch({
Expand All @@ -163,20 +163,20 @@ export default function Registered(props: RegisteredProps) {
isLoading: false,
storeName,
// account
contactInformation: [...b2bAccountFormFields.contactInformation],
bcContactInformation: [...bcAccountFormFields.contactInformation],
additionalInformation: [...b2bAccountFormFields.additionalInformation],
bcAdditionalInformation: [...bcAccountFormFields.additionalInformation],
contactInformation: [...(b2bAccountFormFields.contactInformation || [])],
bcContactInformation: [...(bcAccountFormFields.contactInformation || [])],
additionalInformation: [...(b2bAccountFormFields.additionalInformation || [])],
bcAdditionalInformation: [...(bcAccountFormFields.additionalInformation || [])],
// detail
companyExtraFields: [],
companyInformation: [...b2bAccountFormFields?.businessDetails || []],
companyInformation: [...(b2bAccountFormFields?.businessDetails || [])],
companyAttachment: [...companyAttachmentsFields(b3Lang)],
addressBasicFields: [...newAddressInformationFields],
bcAddressBasicFields: [...newBCAddressInformationFields],
countryList: [...countries],
// password
passwordInformation: [...b2bAccountFormFields.password],
bcPasswordInformation: [...bcAccountFormFields.password],
passwordInformation: [...(b2bAccountFormFields.password || [])],
bcPasswordInformation: [...(bcAccountFormFields.password || [])],

},
})
Expand Down
15 changes: 12 additions & 3 deletions apps/storefront/src/shared/service/request/fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,19 @@ function b3Fetch(path: string, init: any, type?: string, customMessage = false)
}
}
if (type === RequestType.B2BGraphql) {
if (res?.errors?.length && res.errors[0].message) {
reject(res.errors[0].message)
const errors = res?.errors?.length ? res.errors[0] : {}
const {
message = '',
extensions = {},
} = errors

if (extensions.code === 40101) {
window.location.href = '#/login?loginFlag=3&showTip=false'
snackbar.error(message)
} else if (message) {
reject(message)
if (!customMessage) {
snackbar.error(res.errors[0].message)
snackbar.error(message)
}
} else {
resolve(res.data)
Expand Down

0 comments on commit 8df0a62

Please sign in to comment.