aretherecookies-mobile/js/modals/CategoryModal.js
2019-06-22 15:48:52 +00:00

43 lines
1.1 KiB
JavaScript

// @flow
import React, { PureComponent } from 'react';
import typeof FoodItemRecord from '../records/FoodItemRecord';
import { CATEGORIES } from '../constants/CategoryConstants';
import { getCategoryText } from '../helpers/CategoryHelpers';
import FullScreenModal from './FullScreenModal';
import { type Category } from '../constants/CategoryConstants';
import PickerItemRow from '../components/PickerItemRow';
type Props = {
onClose: () => void,
onUpdate: (c: Category) => void,
foodItem: FoodItemRecord,
};
class CategoryModal extends PureComponent {
static displayName = 'NameModal';
props: Props;
updateAndClose = (item: string) => {
this.props.onUpdate(item);
this.props.onClose();
};
render() {
const { onClose, foodItem } = this.props;
return (
<FullScreenModal title="Category" onClose={onClose}>
{CATEGORIES.map(category => (
<PickerItemRow
key={category}
isSelected={foodItem && foodItem.category === category}
text={getCategoryText(category)}
onPress={() => this.updateAndClose(category)}
/>
))}
</FullScreenModal>
);
}
}
export default CategoryModal;