Disable sold-out variants in picker; default to first in-stock option

Sold-out variant buttons now show "Sold Out" and can't be selected.
The picker also defaults to the first in-stock variation instead of
always starting on variations[0], which could be out of stock.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
chris 2026-06-18 11:08:17 -04:00
parent 904fa91bad
commit f1537402b5

View File

@ -50,7 +50,9 @@ export default function ColorPicker({ product, maxColors, onClose, editingEntry
const [notes, setNotes] = useState(editingEntry?.notes ?? '') const [notes, setNotes] = useState(editingEntry?.notes ?? '')
const [activeImg, setActiveImg] = useState(0) const [activeImg, setActiveImg] = useState(0)
const [userVariationId, setUserVariationId] = useState<string | undefined>( const [userVariationId, setUserVariationId] = useState<string | undefined>(
() => editingEntry?.selectedVariationId ?? product.variations[0]?.id () => editingEntry?.selectedVariationId
?? product.variations.find((v) => v.inventory === null || v.inventory > 0)?.id
?? product.variations[0]?.id
) )
// Vinyl state // Vinyl state
@ -285,21 +287,29 @@ export default function ColorPicker({ product, maxColors, onClose, editingEntry
<div className="field" style={{ marginBottom: '1.25rem' }}> <div className="field" style={{ marginBottom: '1.25rem' }}>
<label className="label is-small">Size / Option</label> <label className="label is-small">Size / Option</label>
<div className="buttons"> <div className="buttons">
{selectableVariations.map((v) => ( {selectableVariations.map((v) => {
const varSoldOut = v.inventory !== null && v.inventory <= 0
return (
<button <button
key={v.id} key={v.id}
type="button" type="button"
className={`button is-small${v.id === (userVariation?.id) ? ' is-info' : ''}`} className={`button is-small${v.id === (userVariation?.id) ? ' is-info' : ''}`}
onClick={() => { setUserVariationId(v.id); setActiveImg(0) }} disabled={varSoldOut}
style={varSoldOut ? { opacity: 0.5, cursor: 'not-allowed' } : undefined}
onClick={() => { if (!varSoldOut) { setUserVariationId(v.id); setActiveImg(0) } }}
> >
{v.name} {v.name}
{v.priceCents > 0 && ( {varSoldOut
? <span style={{ marginLeft: 6, fontSize: '0.78em' }}>Sold Out</span>
: v.priceCents > 0 && (
<span style={{ marginLeft: 6, opacity: 0.75, fontSize: '0.78em' }}> <span style={{ marginLeft: 6, opacity: 0.75, fontSize: '0.78em' }}>
{fmt(v.priceCents)} {fmt(v.priceCents)}
</span> </span>
)} )
}
</button> </button>
))} )
})}
</div> </div>
</div> </div>
)} )}