aretherecookies-mobile/js/modals/QuantityModal.js

38 lines
956 B
JavaScript
Raw Normal View History

// @flow
import React from 'react';
import { getQuantityDropdownText } from '../helpers/QuantityHelpers';
import { type Quantity, QUANTITIES } from '../constants/QuantityConstants';
2019-06-22 15:48:52 +00:00
import FullScreenModal from './FullScreenModal';
2020-04-17 22:50:23 -05:00
import { typeof Product } from '../records/ProductRecord';
2019-06-22 15:48:52 +00:00
import PickerItemRow from '../components/PickerItemRow';
type Props = {
onClose: () => void,
2020-04-17 22:50:23 -05:00
product: Product,
2019-06-22 15:48:52 +00:00
onUpdate: (q: Quantity) => void,
};
const QuantityModal = (props: Props) => {
2020-04-17 22:50:23 -05:00
const { product, onUpdate, onClose } = props;
const onPress = (q: Quantity) => () => {
2019-06-22 15:48:52 +00:00
onUpdate(q);
onClose();
};
return (
2019-06-22 15:48:52 +00:00
<FullScreenModal title="Quantity" onClose={onClose}>
{QUANTITIES.map((quantity: Quantity) => (
<PickerItemRow
key={quantity}
text={getQuantityDropdownText(quantity)}
2020-04-17 22:50:23 -05:00
isSelected={quantity === product.quantity}
2019-06-22 15:48:52 +00:00
onPress={onPress(quantity)}
/>
))}
2019-06-22 15:48:52 +00:00
</FullScreenModal>
);
};
2019-06-22 15:48:52 +00:00
export default QuantityModal;