import React from 'react'; import { Form, FormikProps } from 'formik'; import _ from 'lodash'; import moment from 'moment'; import Input from '../components/Input'; import Button from '../components/Button'; import Select from '../components/Select'; import Paper from '../components/Paper'; import hooks from '../hooks/useAPIClient'; const mapper = (item: any) => ({ key: item._id, label: item.name }); const WaybillForm: React.FC = ({ setFieldValue, values }) => { const { data: products } = hooks.products.useList(); const { data: contractors } = hooks.contractors.useList(); if (!values.date) setFieldValue('date', moment().format('YYYY-MM-DD')); if (!values.contractorId && contractors?.length) setFieldValue('contractorId', contractors[0]._id); const handleAddRecord = () => setFieldValue('records', [...values.records, { productId: _.map(products, '_id').reduce((acc, id) => { return acc || (!_.map(values.records, 'productId').includes(id) && id); }, false), price: '', quantity: 1, }]); const handleRemoveRecord = (index: number) => () => { const records = [...values.records]; records.splice(index, 1); setFieldValue('records', records); }; return (
{values.records.map((record, index) => (
))}
); }; export default WaybillForm;