Skip to content

Commit

Permalink
fix: price error when super admin masqurading
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlLiu2023 committed Sep 8, 2023
1 parent cd7d7e5 commit 74504fa
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,13 @@ export default function B3MasquradeGobalTip(props: B3MasquradeGobalTipProps) {
B3SStorage.delete('isAgenting')
B3SStorage.delete('salesRepCompanyId')
B3SStorage.delete('salesRepCompanyName')
B3SStorage.delete('salesRepCustomerGroupId')
dispatch({
type: 'common',
payload: {
salesRepCompanyId: '',
salesRepCompanyName: '',
salesRepCustomerGroupId: '',
isAgenting: false,
},
})
Expand Down
2 changes: 2 additions & 0 deletions apps/storefront/src/shared/global/context/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ export interface GlobalState {
isAgenting: boolean
salesRepCompanyId: string
salesRepCompanyName: string
salesRepCustomerGroupId: string
B3UserId: number | string
tipMessage: TipMessagesProps
addressConfig?: {
Expand Down Expand Up @@ -144,6 +145,7 @@ export const initState = {
isAgenting: B3SStorage.get('isAgenting') || false,
salesRepCompanyId: B3SStorage.get('salesRepCompanyId') || '',
salesRepCompanyName: B3SStorage.get('salesRepCompanyName') || '',
salesRepCustomerGroupId: B3SStorage.get('salesRepCustomerGroupId') || '',
customer: B3SStorage.get('B3CustomerInfo') || {
firstName: '',
lastName: '',
Expand Down
1 change: 1 addition & 0 deletions apps/storefront/src/shared/service/b2b/graphql/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const getAgentInfoQl = (customerId: string | number) => `{
superAdminMasquerading(customerId: ${customerId}) {
companyName,
bcGroupName,
customerGroupId,
companyStatus,
id
}
Expand Down
14 changes: 5 additions & 9 deletions apps/storefront/src/utils/b3Product/b3Product.ts
Original file line number Diff line number Diff line change
Expand Up @@ -599,22 +599,14 @@ const getBulkPrice = (calculatedPrices: any, qty: number) => {
maximum,
discount_type: discountType,
discount_amount: bulkPrice,
}: // tax_discount_amount: taxDiscountAmount,
any) => {
// const taxExclusive = taxDiscountAmount?.tax_exclusive || 0
// const taxInclusive = taxDiscountAmount?.tax_inclusive || 0
// const newPrice = isTax ? tax : bulkPrice

}: any) => {
if (qty >= minimum && qty <= (maximum || qty)) {
switch (discountType) {
case 'fixed':
// price -= +basePrice - newPrice
finalDiscount = 0
enteredPrice = bulkPrice
break
case 'percent':
// basePrice *= newPrice / 100
// price -= +basePrice
finalDiscount =
enteredPrice * +(bulkPrice / 100).toFixed(decimalPlaces)
break
Expand Down Expand Up @@ -659,10 +651,14 @@ interface CalculatedProductPrice {

const getCustomerGroupId = () => {
let customerGroupId = 0
const isAgenting = B3SStorage.get('isAgenting') || false
const B3CustomerInfo = B3SStorage.get('B3CustomerInfo')
if (B3CustomerInfo && Object.keys(B3CustomerInfo).length !== 0) {
customerGroupId = B3CustomerInfo.customerGroupId
}
const salesRepCustomerGroupId = B3SStorage.get('salesRepCustomerGroupId') || 0
if (isAgenting) return +salesRepCustomerGroupId || customerGroupId

return customerGroupId
}

Expand Down
9 changes: 8 additions & 1 deletion apps/storefront/src/utils/loginInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export const clearCurrentCustomerInfo = async (dispatch: DispatchProps) => {
B3SStorage.set('salesRepCompanyName', '')
B3SStorage.set('nextPath', '')
B3SStorage.set('salesRepCompanyId', '')
B3SStorage.set('salesRepCustomerGroupId', '')
B3SStorage.set('isAgenting', '')

B3SStorage.set('isShowBlockPendingAccountOrderCreationTip', {
Expand Down Expand Up @@ -257,17 +258,23 @@ export const agentInfo = async (
try {
const data: any = await getAgentInfo(customerId)
if (data?.superAdminMasquerading) {
const { id, companyName } = data.superAdminMasquerading
const {
id,
companyName,
customerGroupId = 0,
} = data.superAdminMasquerading

B3SStorage.set('isAgenting', true)
B3SStorage.set('salesRepCompanyId', id)
B3SStorage.set('salesRepCompanyName', companyName)
B3SStorage.set('salesRepCustomerGroupId', customerGroupId)
dispatch({
type: 'common',
payload: {
isAgenting: true,
salesRepCompanyId: id,
salesRepCompanyName: companyName,
salesRepCustomerGroupId: customerGroupId,
},
})
}
Expand Down
6 changes: 5 additions & 1 deletion apps/storefront/src/utils/masquerade.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ export const startMasquerade = async ({
// get data to be saved on global
const data = await getAgentInfo(customerId)
if (!data?.superAdminMasquerading) return
const { id, companyName } = data.superAdminMasquerading
const { id, companyName, customerGroupId = 0 } = data.superAdminMasquerading

B3SStorage.set('isAgenting', true)
B3SStorage.set('salesRepCompanyId', id)
B3SStorage.set('salesRepCompanyName', companyName)
B3SStorage.set('salesRepCustomerGroupId', customerGroupId)

dispatch({
type: 'common',
payload: {
salesRepCompanyId: id,
salesRepCompanyName: companyName,
salesRepCustomerGroupId: customerGroupId,
isAgenting: true,
isB2BUser: true,
},
Expand All @@ -60,12 +62,14 @@ export const endMasquerade = async ({
B3SStorage.delete('isAgenting')
B3SStorage.delete('salesRepCompanyId')
B3SStorage.delete('salesRepCompanyName')
B3SStorage.delete('salesRepCustomerGroupId')

dispatch({
type: 'common',
payload: {
salesRepCompanyId: '',
salesRepCompanyName: '',
salesRepCustomerGroupId: '',
isAgenting: false,
},
})
Expand Down

0 comments on commit 74504fa

Please sign in to comment.