diff --git a/src/pages/Reports/DailyReport/ReportEditor.jsx b/src/pages/Reports/DailyReport/ReportEditor.jsx index 7ed3776..18697f1 100644 --- a/src/pages/Reports/DailyReport/ReportEditor.jsx +++ b/src/pages/Reports/DailyReport/ReportEditor.jsx @@ -16,9 +16,15 @@ const Item = memo(({ style, ...other }) => ( + makeColumn('От (дата, время)', 'dateStart', { width: 200, render: (_, { disabled, onChange, checkIsDateBusy }) => ( - + )}), ]), @@ -122,7 +128,7 @@ const table2Summary = () => ( ) -export const ReportEditor = memo(({ visible, data, onDone, onCancel }) => { +export const ReportEditor = memo(({ visible, data, onDone, onCancel, checkIsDateBusy }) => { const [form] = Form.useForm() const [isInvalid, setIsInvalid] = useState(false) const [isLoading, setIsLoading] = useState(false) @@ -150,22 +156,25 @@ export const ReportEditor = memo(({ visible, data, onDone, onCancel }) => { else await DailyReportService.add(idWell, formData) onDone?.(formData) + form.resetFields() }, setIsLoading, 'Не удалось сохранить суточный рапорт', 'Сохранение суточного рапорта', - ), [data, onDone, idWell]) + ), [data, onDone, idWell, form]) const onDateChange = useCallback((date) => invokeWebApiWrapperAsync( async () => { if (data) return - const newData = await DailyReportService.getOrGenerate(idWell, date.toISOString()) + const newData = await DailyReportService.getOrGenerate(idWell, date.format('YYYY-MM-DD') + 'Z') + if (checkIsDateBusy(moment(newData.reportDate))) + throw 'Рапорт на данную дату уже существует' setFields(newData) }, setIsLoading, 'Не удалось загрузить автозаполняемые данные для нового рапорта', 'Получение автозаполняемых данных суточного рапорта', - ), [idWell, data, setFields]) + ), [idWell, data, setFields, checkIsDateBusy]) return ( { onChange={onFormChange} > - + @@ -201,7 +215,7 @@ export const ReportEditor = memo(({ visible, data, onDone, onCancel }) => { bordered size={'small'} columns={table1Columns} - dataSource={[{ key: '', disabled: !!data, onChange: onDateChange }]} + dataSource={[{ key: '', disabled: !!data, onChange: onDateChange, checkIsDateBusy }]} pagination={false} /> diff --git a/src/pages/Reports/DailyReport/index.jsx b/src/pages/Reports/DailyReport/index.jsx index ae6379e..b9129a7 100644 --- a/src/pages/Reports/DailyReport/index.jsx +++ b/src/pages/Reports/DailyReport/index.jsx @@ -1,11 +1,11 @@ import moment from 'moment' -import { Button, DatePicker } from 'antd' +import { Button } from 'antd' import { FileExcelOutlined, EditOutlined, PlusOutlined } from '@ant-design/icons' import { memo, useCallback, useContext, useEffect, useMemo, useState } from 'react' import { IdWellContext } from '@asb/context' import LoaderPortal from '@components/LoaderPortal' -import { Table, makeDateColumn, makeColumn } from '@components/Table' +import { DateRangeWrapper, Table, makeDateColumn, makeColumn } from '@components/Table' import { download, invokeWebApiWrapperAsync } from '@components/factory' import { DailyReportService } from '@api' import { arrayOrDefault } from '@utils' @@ -33,8 +33,10 @@ export const DailyReport = memo(() => { useEffect(updateTable, [updateTable]) + const checkIsDateBusy = useCallback((current) => current.isAfter(moment(), 'day') || data.some((row) => moment(row.reportDate).isSame(current, 'day')), [data]) + const columns = useMemo(() => [ - makeDateColumn('Дата', 'reportDate', undefined, undefined, { width: 300 }), + makeDateColumn('Дата', 'reportDate', undefined, 'YYYY.MM.DD', { width: 300 }), makeColumn('', '', { width: 200, render: (_, report) => ( <>