Skip to content

Commit 9d13664

Browse files
committed
feat: add disable options on product page while loading
1 parent 2be5564 commit 9d13664

File tree

4 files changed

+46
-10
lines changed

4 files changed

+46
-10
lines changed

src/modules/products/components/mobile-actions/index.tsx

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type MobileActionsProps = {
2424
handleAddToCart: () => void
2525
isAdding?: boolean
2626
show: boolean
27+
optionsDisabled: boolean
2728
}
2829

2930
const MobileActions: React.FC<MobileActionsProps> = ({
@@ -36,6 +37,7 @@ const MobileActions: React.FC<MobileActionsProps> = ({
3637
handleAddToCart,
3738
isAdding,
3839
show,
40+
optionsDisabled,
3941
}) => {
4042
const { state, open, close } = useToggleState()
4143

@@ -71,7 +73,10 @@ const MobileActions: React.FC<MobileActionsProps> = ({
7173
leaveFrom="opacity-100"
7274
leaveTo="opacity-0"
7375
>
74-
<div className="bg-white flex flex-col gap-y-3 justify-center items-center text-large-regular p-4 h-full w-full border-t border-gray-200" data-testid="mobile-actions">
76+
<div
77+
className="bg-white flex flex-col gap-y-3 justify-center items-center text-large-regular p-4 h-full w-full border-t border-gray-200"
78+
data-testid="mobile-actions"
79+
>
7580
<div className="flex items-center gap-x-2">
7681
<span data-testid="mobile-title">{product.title}</span>
7782
<span></span>
@@ -98,7 +103,12 @@ const MobileActions: React.FC<MobileActionsProps> = ({
98103
)}
99104
</div>
100105
<div className="grid grid-cols-2 w-full gap-x-4">
101-
<Button onClick={open} variant="secondary" className="w-full" data-testid="mobile-actions-button">
106+
<Button
107+
onClick={open}
108+
variant="secondary"
109+
className="w-full"
110+
data-testid="mobile-actions-button"
111+
>
102112
<div className="flex items-center justify-between w-full">
103113
<span>
104114
{variant
@@ -150,7 +160,10 @@ const MobileActions: React.FC<MobileActionsProps> = ({
150160
leaveFrom="opacity-100"
151161
leaveTo="opacity-0"
152162
>
153-
<Dialog.Panel className="w-full h-full transform overflow-hidden text-left flex flex-col gap-y-3" data-testid="mobile-actions-modal">
163+
<Dialog.Panel
164+
className="w-full h-full transform overflow-hidden text-left flex flex-col gap-y-3"
165+
data-testid="mobile-actions-modal"
166+
>
154167
<div className="w-full flex justify-end pr-6">
155168
<button
156169
onClick={close}
@@ -171,6 +184,7 @@ const MobileActions: React.FC<MobileActionsProps> = ({
171184
current={options[option.id]}
172185
updateOption={updateOptions}
173186
title={option.title}
187+
disabled={optionsDisabled}
174188
/>
175189
</div>
176190
)

src/modules/products/components/option-select/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,27 @@ type OptionSelectProps = {
99
current: string
1010
updateOption: (option: Record<string, string>) => void
1111
title: string
12-
'data-testid'?: string
12+
disabled: boolean
13+
"data-testid"?: string
1314
}
1415

1516
const OptionSelect: React.FC<OptionSelectProps> = ({
1617
option,
1718
current,
1819
updateOption,
1920
title,
20-
'data-testid': dataTestId
21+
"data-testid": dataTestId,
22+
disabled,
2123
}) => {
2224
const filteredOptions = option.values.map((v) => v.value).filter(onlyUnique)
2325

2426
return (
2527
<div className="flex flex-col gap-y-3">
2628
<span className="text-sm">Select {title}</span>
27-
<div className="flex flex-wrap justify-between gap-2" data-testid={dataTestId}>
29+
<div
30+
className="flex flex-wrap justify-between gap-2"
31+
data-testid={dataTestId}
32+
>
2833
{filteredOptions.map((v) => {
2934
return (
3035
<button
@@ -38,6 +43,7 @@ const OptionSelect: React.FC<OptionSelectProps> = ({
3843
v !== current,
3944
}
4045
)}
46+
disabled={disabled}
4147
data-testid="option-button"
4248
>
4349
{v}

src/modules/products/components/product-actions/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import ProductPrice from "../product-price"
1818
type ProductActionsProps = {
1919
product: PricedProduct
2020
region: Region
21+
disabled?: boolean
2122
}
2223

2324
export type PriceType = {
@@ -30,6 +31,7 @@ export type PriceType = {
3031
export default function ProductActions({
3132
product,
3233
region,
34+
disabled,
3335
}: ProductActionsProps) {
3436
const [options, setOptions] = useState<Record<string, string>>({})
3537
const [isAdding, setIsAdding] = useState(false)
@@ -138,6 +140,7 @@ export default function ProductActions({
138140
updateOption={updateOptions}
139141
title={option.title}
140142
data-testid="product-options"
143+
disabled={!!disabled || isAdding}
141144
/>
142145
</div>
143146
)
@@ -151,7 +154,7 @@ export default function ProductActions({
151154

152155
<Button
153156
onClick={handleAddToCart}
154-
disabled={!inStock || !variant}
157+
disabled={!inStock || !variant || !!disabled || isAdding}
155158
variant="primary"
156159
className="w-full h-10"
157160
isLoading={isAdding}
@@ -173,6 +176,7 @@ export default function ProductActions({
173176
handleAddToCart={handleAddToCart}
174177
isAdding={isAdding}
175178
show={!inView}
179+
optionsDisabled={!!disabled || isAdding}
176180
/>
177181
</div>
178182
</>

src/modules/products/templates/index.tsx

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ const ProductTemplate: React.FC<ProductTemplateProps> = ({
2929

3030
return (
3131
<>
32-
<div className="content-container flex flex-col small:flex-row small:items-start py-6 relative" data-testid="product-container">
32+
<div
33+
className="content-container flex flex-col small:flex-row small:items-start py-6 relative"
34+
data-testid="product-container"
35+
>
3336
<div className="flex flex-col small:sticky small:top-48 small:py-0 small:max-w-[300px] w-full py-8 gap-y-6">
3437
<ProductInfo product={product} />
3538
<ProductTabs product={product} />
@@ -40,13 +43,22 @@ const ProductTemplate: React.FC<ProductTemplateProps> = ({
4043
<div className="flex flex-col small:sticky small:top-48 small:py-0 small:max-w-[300px] w-full py-8 gap-y-12">
4144
<ProductOnboardingCta />
4245
<Suspense
43-
fallback={<ProductActions product={product} region={region} />}
46+
fallback={
47+
<ProductActions
48+
disabled={true}
49+
product={product}
50+
region={region}
51+
/>
52+
}
4453
>
4554
<ProductActionsWrapper id={product.id} region={region} />
4655
</Suspense>
4756
</div>
4857
</div>
49-
<div className="content-container my-16 small:my-32" data-testid="related-products-container">
58+
<div
59+
className="content-container my-16 small:my-32"
60+
data-testid="related-products-container"
61+
>
5062
<Suspense fallback={<SkeletonRelatedProducts />}>
5163
<RelatedProducts product={product} countryCode={countryCode} />
5264
</Suspense>

0 commit comments

Comments
 (0)