Skip to content

Commit

Permalink
Merge pull request #372 from medusajs/fix/product-actions
Browse files Browse the repository at this point in the history
fix: Use option IDs instead of titles
  • Loading branch information
olivermrbl authored Oct 4, 2024
2 parents 4b904bc + ce46b6f commit 0c1fbe8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/modules/products/components/product-actions/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ type ProductActionsProps = {
disabled?: boolean
}

const optionsAsKeymap = (variantOptions: any) => {
const optionsAsKeymap = (variantOptions: HttpTypes.StoreProductVariant["options"]) => {
return variantOptions?.reduce((acc: Record<string, string>, varopt: any) => {
acc[varopt.option.title] = varopt.value
acc[varopt.option_id] = varopt.value
return acc
}, {})
}
Expand Down Expand Up @@ -56,10 +56,10 @@ export default function ProductActions({
}, [product.variants, options])

// update the options when a variant is selected
const setOptionValue = (title: string, value: string) => {
const setOptionValue = (optionId: string, value: string) => {
setOptions((prev) => ({
...prev,
[title]: value,
[optionId]: value,
}))
}

Expand Down Expand Up @@ -117,7 +117,7 @@ export default function ProductActions({
<div key={option.id}>
<OptionSelect
option={option}
current={options[option.title ?? ""]}
current={options[option.id]}
updateOption={setOptionValue}
title={option.title ?? ""}
data-testid="product-options"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const OptionSelect: React.FC<OptionSelectProps> = ({
"data-testid": dataTestId,
disabled,
}) => {
const filteredOptions = option.values?.map((v) => v.value)
const filteredOptions = (option.values ?? []).map((v) => v.value)

return (
<div className="flex flex-col gap-y-3">
Expand All @@ -28,10 +28,10 @@ const OptionSelect: React.FC<OptionSelectProps> = ({
className="flex flex-wrap justify-between gap-2"
data-testid={dataTestId}
>
{filteredOptions?.map((v) => {
{filteredOptions.map((v) => {
return (
<button
onClick={() => updateOption(option.title ?? "", v ?? "")}
onClick={() => updateOption(option.id, v)}
key={v}
className={clx(
"border-ui-border-base bg-ui-bg-subtle border text-small-regular h-10 rounded-rounded p-2 flex-1 ",
Expand Down

0 comments on commit 0c1fbe8

Please sign in to comment.