Skip to content

Commit

Permalink
fix: moving sales rep variables to redux slice (#996)
Browse files Browse the repository at this point in the history
* fix: moving sales rep variables to redux slice
  • Loading branch information
deov31 authored Apr 10, 2024
1 parent 06d6826 commit 7def8f8
Show file tree
Hide file tree
Showing 36 changed files with 230 additions and 127 deletions.
5 changes: 3 additions & 2 deletions apps/storefront/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ export default function App() {
} = useContext(GlobaledContext)

const storeDispatch = useAppDispatch()
const isAgenting = useAppSelector(({ b2bFeatures }) => b2bFeatures.isAgenting)

const isAgenting = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.isAgenting
)
const customerId = useAppSelector(({ company }) => company.customer.id)
const emailAddress = useAppSelector(
({ company }) => company.customer.emailAddress
Expand Down
4 changes: 3 additions & 1 deletion apps/storefront/src/components/B3Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,9 @@ export default function B3Dialog<T>({

const [isMobile] = useMobile()

const isAgenting = useAppSelector(({ b2bFeatures }) => b2bFeatures.isAgenting)
const isAgenting = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.isAgenting
)

const handleSaveClick = () => {
if (handRightClick) {
Expand Down
4 changes: 3 additions & 1 deletion apps/storefront/src/components/CompanyCredit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ const permissionRoles = [0, 1, 2]
function CompanyCredit() {
const role = useAppSelector(({ company }) => company.customer.role)

const isAgenting = useAppSelector(({ b2bFeatures }) => b2bFeatures.isAgenting)
const isAgenting = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.isAgenting
)

const [isEnabled, setEnabled] = useState<boolean>(false)

Expand Down
4 changes: 3 additions & 1 deletion apps/storefront/src/components/extraTip/CheckoutTip.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ function CheckoutTip(props: CheckoutTipProps) {
const [isMobile] = useMobile()
const role = useAppSelector(({ company }) => company.customer.role)

const isAgenting = useAppSelector(({ b2bFeatures }) => b2bFeatures.isAgenting)
const isAgenting = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.isAgenting
)

const { href } = window.location

Expand Down
4 changes: 3 additions & 1 deletion apps/storefront/src/components/layout/B3MobileLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ export default function B3MobileLayout({

const role = useAppSelector(({ company }) => company.customer.role)

const isAgenting = useAppSelector(({ b2bFeatures }) => b2bFeatures.isAgenting)
const isAgenting = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.isAgenting
)

const {
state: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import useMobile from '@/hooks/useMobile'
import { CustomStyleContext } from '@/shared/customStyleButtton'
import { GlobaledContext } from '@/shared/global'
import { superAdminEndMasquerade } from '@/shared/service/b2b'
import { setIsAgenting, useAppDispatch, useAppSelector } from '@/store'
import { clearMasqueradeCompany, useAppDispatch,useAppSelector } from '@/store'
import { B3SStorage } from '@/utils'

import {
Expand All @@ -39,13 +39,21 @@ export default function B3MasquradeGobalTip(props: B3MasquradeGobalTipProps) {
const { isOpen, setOpenPage } = props
const customerId = useAppSelector(({ company }) => company.customer.id)
const {
state: { salesRepCompanyName, salesRepCompanyId, B3UserId },
state: { B3UserId },
dispatch,
} = useContext(GlobaledContext)

const isAgenting = useAppSelector(({ b2bFeatures }) => b2bFeatures.isAgenting)
const appDispatch = useAppDispatch()

const salesRepCompanyId = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.id
)
const salesRepCompanyName = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.companyName
)
const isAgenting = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.isAgenting
)

const { hash, href } = window.location

const b3Lang = useB3Lang()
Expand Down Expand Up @@ -95,10 +103,6 @@ export default function B3MasquradeGobalTip(props: B3MasquradeGobalTipProps) {
})
} else {
await superAdminEndMasquerade(+salesRepCompanyId, +B3UserId)
appDispatch(setIsAgenting({ isAgenting: false }))
B3SStorage.delete('salesRepCompanyId')
B3SStorage.delete('salesRepCompanyName')
B3SStorage.delete('salesRepCustomerGroupId')
dispatch({
type: 'common',
payload: {
Expand All @@ -107,6 +111,14 @@ export default function B3MasquradeGobalTip(props: B3MasquradeGobalTipProps) {
salesRepCustomerGroupId: '',
},
})

appDispatch(clearMasqueradeCompany())
dispatch({
type: 'common',
payload: {
isAgenting: false,
},
})
setOpenPage({
isOpen: true,
openUrl: '/dashboard',
Expand Down
4 changes: 3 additions & 1 deletion apps/storefront/src/hooks/useRole.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ const useRole = () => {
} = useContext(GlobaledContext)
const role = useAppSelector(({ company }) => company.customer.role)

const isAgenting = useAppSelector(({ b2bFeatures }) => b2bFeatures.isAgenting)
const isAgenting = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.isAgenting
)

const [roleText, setRoleText] = useState('')

Expand Down
14 changes: 8 additions & 6 deletions apps/storefront/src/pages/accountSetting/AccountSetting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ function AccountSetting() {
const customer = useAppSelector(({ company }) => company.customer)
const role = useAppSelector(({ company }) => company.customer.role)
const {
state: {
isB2BUser,
currentChannelId,
salesRepCompanyId,
},
state: { isB2BUser, currentChannelId },
} = useContext(GlobaledContext)

const isAgenting = useAppSelector(({ b2bFeatures }) => b2bFeatures.isAgenting)
const salesRepCompanyId = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.id
)

const isAgenting = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.isAgenting
)

const {
state: {
Expand Down
14 changes: 7 additions & 7 deletions apps/storefront/src/pages/address/Address.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,18 +48,18 @@ function Address() {
const companyInfoId = useAppSelector(({ company }) => company.companyInfo.id)
const role = useAppSelector(({ company }) => company.customer.role)
const {
state: {
isB2BUser,
salesRepCompanyId,
addressConfig,
},
state: { isB2BUser, addressConfig },
dispatch,
} = useContext(GlobaledContext)

const isAgenting = useAppSelector(({ b2bFeatures }) => b2bFeatures.isAgenting)

const b3Lang = useB3Lang()

const salesRepCompanyId = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.id
)
const isAgenting = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.isAgenting
)
const isExtraLarge = useCardListColumn()
const [paginationTableRef] = useTableRef()

Expand Down
6 changes: 5 additions & 1 deletion apps/storefront/src/pages/dashboard/Dashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,14 +125,18 @@ function B3Mean({

function Dashboard(props: DashboardProps) {
const {
state: { B3UserId, salesRepCompanyId = 0 },
state: { B3UserId = 0 },
dispatch,
} = useContext(GlobaledContext)
const customerId = useAppSelector(({ company }) => company.customer.id)

const { setOpenPage } = props
const b3Lang = useB3Lang()

const salesRepCompanyId = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.id
)

const [currentSalesRepCompanyId, setCurrentSalesRepCompanyId] =
useState<number>(+salesRepCompanyId)

Expand Down
4 changes: 3 additions & 1 deletion apps/storefront/src/pages/invoice/Invoice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ function Invoice() {
const currentDate = new Date().getTime()
const b3Lang = useB3Lang()
const role = useAppSelector(({ company }) => company.customer.role)
const isAgenting = useAppSelector(({ b2bFeatures }) => b2bFeatures.isAgenting)
const isAgenting = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.isAgenting
)
const juniorOrSenior = +role === 1 || role === 2
const navigate = useNavigate()
const [isMobile] = useMobile()
Expand Down
4 changes: 3 additions & 1 deletion apps/storefront/src/pages/invoice/components/B3Pulldown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ function B3Pulldown({
}: B3PulldownProps) {
const platform = useAppSelector(({ global }) => global.storeInfo.platform)
const role = useAppSelector(({ company }) => company.customer.role)
const isAgenting = useAppSelector(({ b2bFeatures }) => b2bFeatures.isAgenting)
const isAgenting = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.isAgenting
)
const juniorOrSenior = +role === 1 || role === 2
const [anchorEl, setAnchorEl] = useState<HTMLElement | null>(null)
const [isCanPay, setIsCanPay] = useState<boolean>(true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ function InvoiceFooter(props: InvoiceFooterProps) {
const [selectedAccount, setSelectedAccount] = useState<number | string>(0)
const [currentToken, setCurrentToken] = useState<string>('$')

const isAgenting = useAppSelector(({ b2bFeatures }) => b2bFeatures.isAgenting)
const isAgenting = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.isAgenting
)

const containerStyle = isMobile
? {
Expand Down
16 changes: 7 additions & 9 deletions apps/storefront/src/pages/login/Login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,16 @@ export default function Login(props: RegisteredProps) {
const b3Lang = useB3Lang()

const {
state: {
isCheckout,
logo,
B3UserId,
salesRepCompanyId = 0,
registerEnabled,
},
state: { isCheckout, logo, B3UserId, registerEnabled },
dispatch,
} = useContext(GlobaledContext)

const isAgenting = useAppSelector(({ b2bFeatures }) => b2bFeatures.isAgenting)

const salesRepCompanyId = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.id
)
const isAgenting = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.isAgenting
)
const {
state: {
loginPageButton,
Expand Down
10 changes: 8 additions & 2 deletions apps/storefront/src/pages/order/Order.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,19 @@ interface OrderProps {

function Order({ isCompanyOrder = false }: OrderProps) {
const {
state: { isB2BUser, salesRepCompanyId },
state: { isB2BUser },
} = useContext(GlobaledContext)
const companyB2BId = useAppSelector(({ company }) => company.companyInfo.id)
const role = useAppSelector(({ company }) => company.customer.role)
const isAgenting = useAppSelector(({ b2bFeatures }) => b2bFeatures.isAgenting)
const b3Lang = useB3Lang()

const salesRepCompanyId = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.id
)
const isAgenting = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.isAgenting
)

const [isRequestLoading, setIsRequestLoading] = useState(false)

const [allTotal, setAllTotal] = useState(0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ function OrderCard(props: OrderCardProps) {

const b3Lang = useB3Lang()

const isAgenting = useAppSelector(({ b2bFeatures }) => b2bFeatures.isAgenting)
const isAgenting = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.isAgenting
)

const dialogData = [
{
Expand Down
4 changes: 1 addition & 3 deletions apps/storefront/src/pages/pdp/PDP.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
} from '@/shared/service/b2b'
import { store, useAppSelector } from '@/store'
import {
B3SStorage,
getDefaultCurrencyInfo,
getValidOptionsList,
globalSnackbar,
Expand Down Expand Up @@ -104,8 +103,7 @@ export const addProductsToShoppingList = async ({
b3Lang,
}: AddProductsToShoppingListParams) => {
const { currency_code: currencyCode } = getDefaultCurrencyInfo()
const companyInfoId = store.getState().company.companyInfo.id
const companyId = companyInfoId || B3SStorage.get('salesRepCompanyId')
const { id: companyId } = store.getState().company.companyInfo
const getProducts = isB2BUser ? searchB2BProducts : searchBcProducts

const { productsSearch } = await getProducts({
Expand Down
4 changes: 3 additions & 1 deletion apps/storefront/src/pages/quickorder/Quickorder.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ function Quickorder() {
} = useContext(GlobaledContext)
const role = useAppSelector(({ company }) => company.customer.role)

const isAgenting = useAppSelector(({ b2bFeatures }) => b2bFeatures.isAgenting)
const isAgenting = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.isAgenting
)

const [isMobile] = useMobile()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import { useAppSelector } from '@/store'
import {
addQuoteDraftProducts,
b2bLogger,
B3SStorage,
b3TriggerCartNumber,
calculateProductListPrice,
currencyFormat,
Expand Down Expand Up @@ -231,7 +230,7 @@ function QuickOrderFooter(props: QuickOrderFooterProps) {
return
}

const companyId = companyInfoId || B3SStorage.get('salesRepCompanyId')
const companyId = companyInfoId

const { productsSearch: getInventoryInfos } =
await getVariantInfoByProductId({
Expand Down
4 changes: 3 additions & 1 deletion apps/storefront/src/pages/quote/QuoteDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,9 @@ function QuoteDetail() {
({ company }) => company.customer.customerGroupId
)
const role = useAppSelector(({ company }) => company.customer.role)
const isAgenting = useAppSelector(({ b2bFeatures }) => b2bFeatures.isAgenting)
const isAgenting = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.isAgenting
)
const [isMobile] = useMobile()

const b3Lang = useB3Lang()
Expand Down
8 changes: 6 additions & 2 deletions apps/storefront/src/pages/quote/QuoteDraft.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,6 @@ function QuoteDraft({ setOpenPage }: QuoteDraftProps) {
isB2BUser,
B3UserId,
currentChannelId,
salesRepCompanyId,
salesRepCompanyName,
countriesList,
currentChannelId: channelId,
openAPPParams,
Expand All @@ -124,6 +122,12 @@ function QuoteDraft({ setOpenPage }: QuoteDraftProps) {
const draftQuoteList = useAppSelector(
({ quoteInfo }) => quoteInfo.draftQuoteList
)
const salesRepCompanyId = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.id
)
const salesRepCompanyName = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.companyName
)

const {
state: {
Expand Down
9 changes: 6 additions & 3 deletions apps/storefront/src/pages/quote/QuotesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,19 @@ function QuotesList() {

const [isMobile] = useMobile()

const companyB2BId = useAppSelector(({ company }) => company.companyInfo.id)
const customer = useAppSelector(({ company }) => company.customer)
const {
state: { isB2BUser, salesRepCompanyId, openAPPParams, currentChannelId },
state: { isB2BUser, openAPPParams, currentChannelId },
dispatch,
} = useContext(GlobaledContext)

const companyB2BId = useAppSelector(({ company }) => company.companyInfo.id)
const customer = useAppSelector(({ company }) => company.customer)
const draftQuoteListLength = useAppSelector(
({ quoteInfo }) => quoteInfo.draftQuoteList.length
)
const salesRepCompanyId = useAppSelector(
({ b2bFeatures }) => b2bFeatures.masqueradeCompany.id
)

useEffect(() => {
const initFilter = async () => {
Expand Down
Loading

0 comments on commit 7def8f8

Please sign in to comment.