From 44afa589c9ced88aa4dcd93181d9e068d79603ea Mon Sep 17 00:00:00 2001 From: FIN-IT_AndriFP Date: Tue, 6 Jan 2026 11:21:14 +0700 Subject: (andri) fix sort pilih variant --- .../product-detail/components/Information.tsx | 35 +++++++++++----------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'src-migrate') diff --git a/src-migrate/modules/product-detail/components/Information.tsx b/src-migrate/modules/product-detail/components/Information.tsx index 25ca3709..c565682f 100644 --- a/src-migrate/modules/product-detail/components/Information.tsx +++ b/src-migrate/modules/product-detail/components/Information.tsx @@ -103,23 +103,20 @@ const Information = ({ product }: Props) => { } }, [slaVariant, isLoading, setSla]); - const handleOnChange = (vals: any) => { - setDisableFilter(true); - let code = vals.replace(/\s-\s.*$/, '').trim(); - let variant = variantOptions.find((item) => item.code === code); - setSelectedVariant(variant); - setInputValue( - variant?.code + - (variant?.attributes[0] ? ' - ' + variant?.attributes[0] : '') - ); +const handleOnChange = (vals: any) => { +    setDisableFilter(true); +    let code = vals.replace(/\s-\s.*$/, '').trim(); +    let variant = product?.variants.find((item) => item.code === code); +    if (variant) { - const filteredOptions = product?.variants.filter( - (item) => item !== variant - ); - const newOptions = [variant, ...filteredOptions]; - setVariantOptions(newOptions); - } - }; +    setSelectedVariant(variant); +    setInputValue( +      variant?.code + +        (variant?.attributes[0] ? ' - ' + variant?.attributes[0] : '') +    ); + setVariantOptions(product?.variants); +    } +  }; const handleOnKeyUp = (e: any) => { setDisableFilter(false); @@ -166,7 +163,11 @@ const Information = ({ product }: Props) => { - {variantOptions.map((option, cid) => ( + {variantOptions + .sort((a: any, b: any) => { + return a.code.localeCompare(b.code, undefined, { numeric: true, sensitivity: 'base' }); + }) + .map((option, cid) => (