diff options
| author | Miqdad <ahmadmiqdad27@gmail.com> | 2025-06-11 14:00:19 +0700 |
|---|---|---|
| committer | Miqdad <ahmadmiqdad27@gmail.com> | 2025-06-11 14:00:19 +0700 |
| commit | 65cc2af8ba7bf6ced66572cdec779bef8cace564 (patch) | |
| tree | 4ca7e0ee59da9b61a2999d116bb8ab28ff675472 /src-migrate/modules/cart/components/ItemSelect.tsx | |
| parent | 54636b53685422d495adce95b491f7b10585cb5c (diff) | |
| parent | 5669295b8cff1a9c9e559dd263599123a2ad6e92 (diff) | |
Merge branch 'new-release' of https://bitbucket.org/altafixco/next-indoteknik into biteship-merge
Diffstat (limited to 'src-migrate/modules/cart/components/ItemSelect.tsx')
| -rw-r--r-- | src-migrate/modules/cart/components/ItemSelect.tsx | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src-migrate/modules/cart/components/ItemSelect.tsx b/src-migrate/modules/cart/components/ItemSelect.tsx index 72ab49aa..f95ee36c 100644 --- a/src-migrate/modules/cart/components/ItemSelect.tsx +++ b/src-migrate/modules/cart/components/ItemSelect.tsx @@ -11,11 +11,11 @@ import { checkboxUpdateState, } from '~/utils/cart'; -type Props = { +interface Props { item: CartItem; -}; +} -const CartItemSelect = ({ item }: Props) => { +const CartItemSelect: React.FC<Props> = ({ item }) => { const auth = getAuth(); const { updateCartItem, cart, loadCart } = useCartStore(); const [isUpdating, setIsUpdating] = useState<boolean>(false); @@ -23,7 +23,7 @@ const CartItemSelect = ({ item }: Props) => { // Subscribe to global checkbox update state useEffect(() => { - const handleUpdateStateChange = (isUpdating) => { + const handleUpdateStateChange = (isUpdating: boolean): void => { // This component doesn't need to react to global state changes // Individual checkboxes are managed independently }; @@ -36,7 +36,10 @@ const CartItemSelect = ({ item }: Props) => { useEffect(() => { if (isUpdating) return; - const selectedItems = getSelectedItemsFromCookie(); + const selectedItems = getSelectedItemsFromCookie() as Record< + number, + boolean + >; const storedState = selectedItems[item.id]; if (storedState !== undefined) { @@ -62,7 +65,7 @@ const CartItemSelect = ({ item }: Props) => { }, [item.id, item.selected, localSelected, cart, updateCartItem, isUpdating]); const handleChange = useCallback( - async (e: React.ChangeEvent<HTMLInputElement>) => { + async (e: React.ChangeEvent<HTMLInputElement>): Promise<void> => { if (typeof auth !== 'object' || !cart || isUpdating) return; const newSelectedState = e.target.checked; @@ -70,7 +73,7 @@ const CartItemSelect = ({ item }: Props) => { // Update local state immediately setLocalSelected(newSelectedState); setIsUpdating(true); - checkboxUpdateState.startUpdate(item.id); + checkboxUpdateState.startUpdate(); try { // Update cookie immediately for responsive UI @@ -107,14 +110,13 @@ const CartItemSelect = ({ item }: Props) => { loadCart(auth.id); } finally { setIsUpdating(false); - checkboxUpdateState.endUpdate(item.id); + checkboxUpdateState.endUpdate(); } }, [auth, cart, item, isUpdating, updateCartItem, loadCart] ); - const isDisabled = - isUpdating || checkboxUpdateState.isCheckboxUpdating(item.id); + const isDisabled: boolean = isUpdating; return ( <div className='w-6 my-auto relative'> |
