Skip to content

Commit

Permalink
fix: submit quote info
Browse files Browse the repository at this point in the history
  • Loading branch information
BrianJiang2021 committed Dec 2, 2024
1 parent 5407a2f commit 247e108
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions apps/storefront/src/pages/QuoteDraft/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ import {
ContactInfoKeys,
QuoteExtraFields,
QuoteFormattedItemsProps,
QuoteInfo as QuoteInfoType,
ShippingAddress,
} from '@/types/quotes';
import { B3LStorage, channelId, snackbar, storeHash } from '@/utils';
import b2bLogger from '@/utils/b3Logger';
import { addQuoteDraftProducts, getVariantInfoOOSAndPurchase } from '@/utils/b3Product/b3Product';
import { deleteCartData } from '@/utils/cartUtils';
import validateObject from '@/utils/quoteUtils';
Expand Down Expand Up @@ -330,11 +332,11 @@ function QuoteDraft({ setOpenPage }: PageProps) {
return addresssaveInfo;
};

const handleSaveInfoClick = async () => {
const saveInfo = cloneDeep(quoteinfo);
const handleCollectingData = async (saveInfo: QuoteInfoType) => {
if (contactInfoRef?.current) {
const contactInfo = await contactInfoRef.current.getContactInfoValue();
if (!contactInfo) return;
if (!contactInfo) return false;

saveInfo.contactInfo = {
name: contactInfo?.name,
email: contactInfo?.email,
Expand All @@ -350,6 +352,17 @@ function QuoteDraft({ setOpenPage }: PageProps) {
value: field.name ? contactInfo[field.name] : '',
}));
saveInfo.extraFields = extraFieldsInfo;

return true;
}
return false;
};

const handleSaveInfoClick = async () => {
const saveInfo = cloneDeep(quoteinfo);
if (contactInfoRef?.current) {
const datas = await handleCollectingData(saveInfo);
if (!datas) return;
}

const { shippingAddress, billingAddress } = getAddress();
Expand Down Expand Up @@ -426,6 +439,11 @@ function QuoteDraft({ setOpenPage }: PageProps) {
setLoading(true);
try {
const info = cloneDeep(quoteinfo);
if (isEdit && contactInfoRef?.current) {
const datas = await handleCollectingData(info);
if (!datas) return;
}

const contactInfo = info?.contactInfo || {};

const quoteTitle = contactInfo?.quoteTitle || '';
Expand Down Expand Up @@ -607,11 +625,7 @@ function QuoteDraft({ setOpenPage }: PageProps) {
setQuoteSubmissionResponseOpen(true);
}
} catch (error: any) {
if (error.message && error.message.length > 0) {
snackbar.error(error.message, {
isClose: true,
});
}
b2bLogger.error(error);
} finally {
setLoading(false);
}
Expand Down

0 comments on commit 247e108

Please sign in to comment.