import React, { useCallback, useState } from 'react' import { Flex } from 'theme-ui' import type { PropsWithChildren } from 'react' import Spinner from '../../../Spinner' import type { Item } from '../../types' import { NumericStepper } from '../../../ProductQuantity/NumericStepper' interface Props { item: T variant: string disabled?: boolean updateItem: (item: T, oldItem?: T) => PromiseLike | unknown } const MinicartDrawerQuantity = ({ updateItem, item, variant: v, disabled: isDisabled = false, }: PropsWithChildren>) => { const [isLoading, setIsLoading] = useState(false) const variant = `${v}.quantity` const onChange = useCallback( async (quantity: number) => { if (quantity === item.quantity) { return } try { setIsLoading(true) await updateItem({ ...item, quantity }, item) } finally { setIsLoading(false) } }, [item, updateItem] ) return ( {isLoading && ( )} ) } export default MinicartDrawerQuantity