import { Checkbox, Spinner } from '@chakra-ui/react' import React, { useState } from 'react' import { getAuth } from '~/libs/auth' import { CartItem } from '~/types/cart' import { upsertUserCart } from '~/services/cart' import { useCartStore } from '../stores/useCartStore' type Props = { item: CartItem } const CartItemSelect = ({ item }: Props) => { const auth = getAuth() const { loadCart } = useCartStore() const [isLoad, setIsLoad] = useState(false) const handleChange = async (e: React.ChangeEvent) => { if (typeof auth !== 'object') return setIsLoad(true) await upsertUserCart({ userId: auth.id, type: item.cart_type, id: item.id, qty: item.quantity, selected: e.target.checked }) await loadCart(auth.id) setIsLoad(false) } return (
{isLoad && ( )} {!isLoad && ( )}
) } export default CartItemSelect