Skip to content
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

Fix add to cart behavior when initiallyOpened prop is 'always' #116

Merged
merged 1 commit into from
Dec 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed

- Assembly options will now be correctly added to the cart when `initiallyOpened` prop is set to `always`

## [2.11.3] - 2022-07-19

### Fixed
Expand Down
6 changes: 5 additions & 1 deletion react/ProductAssemblyOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ interface Props {
initiallyOpened?: 'always' | 'required'
}

const ProductAssemblyOptions: FC<Props> = ({ children, initiallyOpened }) => {
const ProductAssemblyOptions: FC<Props> = ({
children,
initiallyOpened = 'required',
}) => {
const assemblyOptions = useAssemblyOptions()

if (!assemblyOptions) {
Expand All @@ -20,6 +23,7 @@ const ProductAssemblyOptions: FC<Props> = ({ children, initiallyOpened }) => {
{Object.keys(assemblyOptions).map((assemblyOptionId) => (
<ProductAssemblyGroupContextProvider
key={assemblyOptionId}
initiallyOpened={initiallyOpened}
assemblyOption={assemblyOptions[assemblyOptionId]}
>
<ProductAssemblyOptionsGroup initiallyOpened={initiallyOpened}>
Expand Down
6 changes: 6 additions & 0 deletions react/components/ProductAssemblyContext/Group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,12 @@ const useRecursiveDispatch = ({
export const ProductAssemblyGroupContextProvider: FC<ProductAssemblyGroupContextProviderProps> = ({
assemblyOption,
children,
initiallyOpened = 'required',
}) => {
if (initiallyOpened === 'always') {
assemblyOption.optin = true
}

const [state, dispatch] = useReducer(reducer, assemblyOption, initState)

const recursiveDispatch = useRecursiveDispatch({
Expand Down Expand Up @@ -141,6 +146,7 @@ function getGroupPath(assemblyTreePath?: TreePath[]) {

interface ProductAssemblyGroupContextProviderProps {
assemblyOption: AssemblyOptionGroupState
initiallyOpened?: string
}

export const useProductAssemblyGroupDispatch = () =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ interface Props {
initiallyOpened?: 'always' | 'required'
}

const ProductAssemblyOptionsGroup: FC<Props> = ({
children,
initiallyOpened = 'required',
}) => {
const ProductAssemblyOptionsGroup: FC<Props> = ({ children }) => {
const intl = useIntl()
const handles = useCssHandles(CSS_HANDLES)
const assemblyOptionGroup = useProductAssemblyGroupState() as AssemblyOptionGroupState
Expand All @@ -52,7 +49,7 @@ const ProductAssemblyOptionsGroup: FC<Props> = ({

return (
<Fragment>
{assemblyOptionGroup.optin === false && initiallyOpened === 'required' ? (
{assemblyOptionGroup.optin === false ? (
<Button variation="secondary" onClick={changeOptinInput}>
<IOMessage
id="store/product-customizer.add-assembly"
Expand Down