From 599c7651e05250e4a03b98f34c4bd7d15c7daa34 Mon Sep 17 00:00:00 2001 From: kris-liu-smile Date: Tue, 11 Jul 2023 10:17:53 +0800 Subject: [PATCH] fix: address not populating inside a quote --- .../storefront/src/pages/quote/QuoteDraft.tsx | 40 ++++++++++++++----- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/apps/storefront/src/pages/quote/QuoteDraft.tsx b/apps/storefront/src/pages/quote/QuoteDraft.tsx index 3ea6165f..47881305 100644 --- a/apps/storefront/src/pages/quote/QuoteDraft.tsx +++ b/apps/storefront/src/pages/quote/QuoteDraft.tsx @@ -273,6 +273,22 @@ function QuoteDraft({ setOpenPage }: QuoteDraftProps) { init() }, []) + const getAddress = () => { + const addresssaveInfo = { + shippingAddress: {}, + billingAddress: {}, + } + if (billingRef?.current) { + addresssaveInfo.billingAddress = billingRef.current.getContactInfoValue() + } + if (shippingRef?.current) { + addresssaveInfo.shippingAddress = + shippingRef.current.getContactInfoValue() + } + + return addresssaveInfo + } + const handleSaveInfoClick = async () => { const saveInfo = { ...info, @@ -282,12 +298,11 @@ function QuoteDraft({ setOpenPage }: QuoteDraftProps) { if (!contactInfo) return saveInfo.contactInfo = contactInfo } - if (billingRef?.current) { - saveInfo.billingAddress = billingRef.current.getContactInfoValue() - } - if (shippingRef?.current) { - saveInfo.shippingAddress = shippingRef.current.getContactInfoValue() - } + + const { shippingAddress, billingAddress } = getAddress() + + saveInfo.shippingAddress = shippingAddress + saveInfo.billingAddress = billingAddress const isComplete = Object.keys(saveInfo.contactInfo).every( (key: string) => { @@ -424,12 +439,17 @@ function QuoteDraft({ setOpenPage }: QuoteDraftProps) { return newAddress } - const shippingAddress = info?.shippingAddress - ? perfectAddress(info.shippingAddress) + const { + shippingAddress: editShippingAddress, + billingAddress: editBillingAddress, + } = getAddress() + + const shippingAddress = editShippingAddress + ? perfectAddress(editShippingAddress) : {} - const billingAddress = info?.billingAddress - ? perfectAddress(info.billingAddress) + const billingAddress = editBillingAddress + ? perfectAddress(editBillingAddress) : {} let allPrice = 0