-
Notifications
You must be signed in to change notification settings - Fork 214
@W-20038640 Fix: 400 Error #3443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
35c14ae
fbe45f6
522a602
c753399
ae16d45
cd8c75a
351310f
303104c
9048a9f
d4d6311
83d33af
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,8 +22,38 @@ import {useIntl} from 'react-intl' | |
| * A Modal that contains Product View | ||
| */ | ||
| const ProductViewModal = ({product, isOpen, onClose, ...props}) => { | ||
| // Controlled variation values state for modal (doesn't use URL params) | ||
| const [controlledVariationValues, setControlledVariationValues] = React.useState({}) | ||
|
|
||
| const productViewModalData = useProductViewModal(product) | ||
|
|
||
| // Auto-select variation attributes with only one value | ||
| React.useEffect(() => { | ||
| if (!productViewModalData.product?.variationAttributes) return | ||
|
|
||
| const autoSelections = {} | ||
| productViewModalData.product.variationAttributes.forEach((attr) => { | ||
| if (attr.values?.length === 1 && !controlledVariationValues[attr.id]) { | ||
| autoSelections[attr.id] = attr.values[0].value | ||
| } | ||
| }) | ||
|
|
||
| if (Object.keys(autoSelections).length > 0) { | ||
| setControlledVariationValues((prev) => ({ | ||
| ...prev, | ||
| ...autoSelections | ||
| })) | ||
| } | ||
| }, [productViewModalData.product?.variationAttributes, controlledVariationValues]) | ||
|
|
||
| // Handle variation changes in controlled mode | ||
| const handleVariationChange = React.useCallback((attributeId, value) => { | ||
| setControlledVariationValues((prev) => ({ | ||
| ...prev, | ||
| [attributeId]: value | ||
| })) | ||
| }, []) | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see all 3 are using same code for auto selection of variant product. Also its being used at 3 places, can we extract it out in some util/helper ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also do we need this auto selection now ? Does it help with the 400 bug ? How ?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need to refactor the duplicated code from:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Since we are changing architecture for one modal, we should not let other modals use the URL architecture. All three needed the same refactoring because they all display products with variations that were previously using URL state. The auto-selection logic was already there before in the old code - we just had to re-implement it in the new React state approach. Previously, auto-selection happened via URL parameters. Now, we're doing it in react state. Yes, I'll refactor duplicate code
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sf-deepali-bharmal @sf-cboscenco I changed it A test was failing where clicking the update button on a product view modal was not sending the error notification if the update failed. I couldn't find how fix it and I was suspecting the changes to modals caused this. So I reverted making changes to other modals.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @sf-shikhar-prasoon Please test all three modals. |
||
| const intl = useIntl() | ||
| const label = intl.formatMessage( | ||
| { | ||
|
|
@@ -44,6 +74,8 @@ const ProductViewModal = ({product, isOpen, onClose, ...props}) => { | |
| imageSize="sm" | ||
| product={productViewModalData.product} | ||
| isLoading={productViewModalData.isFetching} | ||
| controlledVariationValues={controlledVariationValues} | ||
| onVariationChange={handleVariationChange} | ||
| {...props} | ||
| /> | ||
| </ModalBody> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.