Skip to content

Commit

Permalink
fix: address permission for quoteDraft
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 committed Jan 21, 2025
1 parent 5a53c4d commit f9f0b44
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
4 changes: 3 additions & 1 deletion apps/storefront/src/components/B3Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export interface B3DialogProps<T> {
dialogContentSx?: SxProps<Theme>;
dialogSx?: SxProps<Theme>;
dialogWidth?: string;
backdropClick?: boolean;
}

export default function B3Dialog<T>({
Expand All @@ -64,6 +65,7 @@ export default function B3Dialog<T>({
fullWidth = false,
disabledSaveBtn = false,
dialogWidth = '',
backdropClick = false,
}: B3DialogProps<T>) {
const container = useRef<HTMLInputElement | null>(null);

Expand All @@ -90,7 +92,7 @@ export default function B3Dialog<T>({
};

const handleCloseClick = (reason?: string) => {
if (reason === 'backdropClick') return;
if (reason === 'backdropClick' && !backdropClick) return;
if (handleLeftClick) handleLeftClick();
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ function HierarchyDialog({
loading={loading}
handleLeftClick={handleClose}
handRightClick={handleSwitchCompanyClick}
backdropClick
dialogSx={{
'& .MuiDialogTitle-root': {
border: 0,
Expand Down
28 changes: 23 additions & 5 deletions apps/storefront/src/pages/QuoteDraft/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { cloneDeep, concat, uniq } from 'lodash-es';
import CustomButton from '@/components/button/CustomButton';
import { getContrastColor } from '@/components/outSideComponents/utils/b3CustomStyles';
import B3Spin from '@/components/spin/B3Spin';
import { useMobile, useSetCountry } from '@/hooks';
import { permissionLevels } from '@/constants';
import { useMobile, useSetCountry, useValidatePermissionWithComparisonType } from '@/hooks';
import { CustomStyleContext } from '@/shared/customStyleButton';
import { GlobalContext } from '@/shared/global';
import {
Expand Down Expand Up @@ -186,6 +187,12 @@ function QuoteDraft({ setOpenPage }: PageProps) {

const quoteSummaryRef = useRef<QuoteSummaryRef | null>(null);

const [isAddressCompanyHierarchy] = useValidatePermissionWithComparisonType({
level: permissionLevels.COMPANY_SUBSIDIARIES,
code: b2bPermissionsMap.getAddressesPermission,
containOrEqual: 'equal',
});

useSetCountry();

const contactInfoRef = useRef<InfoRefProps | null>(null);
Expand Down Expand Up @@ -213,9 +220,20 @@ function QuoteDraft({ setOpenPage }: PageProps) {
try {
if (isB2BUser) {
const companyId = companyB2BId || salesRepCompanyId;
const {
addresses: { edges: addressB2BList = [] },
} = await getB2BCustomerAddresses(+companyId);

let addressB2BList = [];
const fetchAddresses = async (id: number) => {
const {
addresses: { edges },
} = await getB2BCustomerAddresses(id);
return edges;
};

if (!selectCompanyHierarchyId) {
addressB2BList = await fetchAddresses(+companyId);
} else if (selectCompanyHierarchyId && isAddressCompanyHierarchy) {
addressB2BList = await fetchAddresses(+selectCompanyHierarchyId);
}

const shippingDefaultAddress = addressB2BList.find(
(item: B2BAddress) => item?.node?.isDefaultShipping === 1,
Expand Down Expand Up @@ -314,7 +332,7 @@ function QuoteDraft({ setOpenPage }: PageProps) {
init();
// disabling as we only need to run this once and values at starting render are good enough
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [selectCompanyHierarchyId, isAddressCompanyHierarchy]);

const quoteAndExtraFieldsInfo = useMemo(() => {
const contactInfo: CustomFieldItems = quoteInfoOrigin.contactInfo || {};
Expand Down

0 comments on commit f9f0b44

Please sign in to comment.