diff --git a/src/pages/WellCase/HistoryTable.jsx b/src/pages/WellCase/HistoryTable.jsx new file mode 100644 index 0000000..b37969a --- /dev/null +++ b/src/pages/WellCase/HistoryTable.jsx @@ -0,0 +1,73 @@ +import { memo, useEffect, useState } from 'react' +import { Empty, Timeline } from 'antd' +import moment from 'moment' + +import { useWell } from '@asb/context' +import DownloadLink from '@components/DownloadLink' +import LoaderPortal from '@components/LoaderPortal' +import { invokeWebApiWrapperAsync } from '@components/factory' +// import { makeColumn, makeDateColumn, Table } from '@components/Table' +import { formatDate } from '@utils' +import { UserView } from '@asb/components/views' + +// const columns = [ +// makeColumn('Файл', 'file', { +// render: (file) => ( +// +// ), +// }), +// makeDateColumn('Дата загрузки', 'date', undefined, undefined, { +// defaultSortOrder: 'descend', +// }), +// ] + +export const HistoryTable = memo(({ users, category }) => { + const [isLoading, setIsLoading] = useState(false) + const [files, setFiles] = useState([]) + + const [well] = useWell() + + useEffect(() => { + invokeWebApiWrapperAsync( + async () => { + const files = [{ uploadDate: moment().format(), id: 0, idWell: 0 }] + files.sort((a, b) => moment(a.uploadDate) - moment(b.uploadDate)) + const fileSource = files.map((file) => ({ + file, + date: file.uploadDate, + user: users.find(({ id }) => id === file.idAuthor) ?? null, + })) + setFiles(fileSource) // Получаем список файлов и записываем в state + }, + setIsLoading, + `Не удалось загрузить историю файлов категории "${category.caption}"`, + ) + }, [well, category]) + + return ( + + {files.length > 0 ? ( + + {files.map(({ date, user, file }) => ( + + {formatDate(date)} + + + + ))} + + ) : ( + + )} + {/* */} + + ) +}) + +export default HistoryTable + diff --git a/src/pages/WellCase/WellCaseEditor.jsx b/src/pages/WellCase/WellCaseEditor.jsx new file mode 100644 index 0000000..b9fb51e --- /dev/null +++ b/src/pages/WellCase/WellCaseEditor.jsx @@ -0,0 +1,22 @@ +import { memo, useCallback, useState } from 'react' +import { Modal, Transfer } from 'antd' + +import { useWell } from '@asb/context' + +export const WellCaseEditor = memo(({ show, onClose }) => { + const [users, setUsers] = useState([]) + + const [well] = useWell() + + const onModalOk = useCallback(() => { + onClose(true) + }, []) + + return ( + onClose(false)} onOk={onModalOk}> + + + ) +}) + +export default WellCaseEditor diff --git a/src/pages/WellCase/index.jsx b/src/pages/WellCase/index.jsx new file mode 100644 index 0000000..0fcbed3 --- /dev/null +++ b/src/pages/WellCase/index.jsx @@ -0,0 +1,92 @@ +import { memo, useCallback, useEffect, useMemo, useState } from 'react' +import { Button } from 'antd' + +import { useWell } from '@asb/context' +import { UserView } from '@components/views' +import DownloadLink from '@components/DownloadLink' +import LoaderPortal from '@components/LoaderPortal' +import { invokeWebApiWrapperAsync } from '@components/factory' +import { makeColumn, makeDateColumn, makeTextColumn, Table } from '@components/Table' +import { delay, wrapPrivateComponent } from '@utils' + +import WellCaseEditor from './WellCaseEditor' +import { HistoryTable } from './HistoryTable' + +const columns = [ + makeTextColumn('Категория', 'caption'), + makeColumn('Файл', 'file', { + render: (file) => file ? ( + + ) : ( + Файл не загружен + ), + }), + makeDateColumn('Дата загрузки', 'uploadDate'), + makeColumn('Ответственные', 'responsible', { + render: (responsible) => responsible.map((user) => ( + + )), + }), +] + +const WellCase = memo(() => { + const [isLoading, setIsLoading] = useState(false) + const [categories, setCategories] = useState([]) + const [canEdit, setCanEdit] = useState(false) + const [showEdit, setShowEdit] = useState(false) + const [users, setUsers] = useState([]) + + const [well] = useWell() + + const updateTable = useCallback(() => { + invokeWebApiWrapperAsync( + async () => { + await delay(1000) + const categories = [{ responsible: [{}] }] + + setCanEdit(true) + const showingCategories = categories.filter((cat) => cat.responsible && cat.responsible?.length > 0) + setCategories(showingCategories) + }, + setIsLoading, + 'Не удалось загрузить список категорий', + ) + }, [well]) + + const onEditClose = useCallback((changed = false) => { + setShowEdit(false) + if (changed) updateTable() + }, [updateTable]) + + const expandable = useMemo(() => ({ + expandedRowRender: (category) => ( + + ) + }), [users]) + + useEffect(() => updateTable(), [updateTable]) + + return ( + <> + + {canEdit && ( + + )} +
+ + + + ) +}) + +export default wrapPrivateComponent(WellCase, { + title: 'Дело скважины', + route: 'well_case', + requirements: [], +})