diff --git a/apps/web/api/ius/query.ts b/apps/web/api/ius/query.ts index 9b14b22..06b5e10 100644 --- a/apps/web/api/ius/query.ts +++ b/apps/web/api/ius/query.ts @@ -77,11 +77,20 @@ export async function getDocumentTypes({ pageUrlParams }: Input) { .then((res) => res); } +export async function getDocuments({ pageUrlParams }: Input) { + const url = createUrl({ ...pageUrlParams, route: '/documents' }); + + return api + .get(url) + .res((res) => res.json()) + .then((res) => res); +} + export async function uploadDocument({ pageUrlParams, document, formData, -}: Input & { document: Pick; formData: FormData }) { +}: Input & { document: Pick; formData: FormData }) { const url = createUrl({ ...pageUrlParams, route: '/document', diff --git a/apps/web/api/ius/types.ts b/apps/web/api/ius/types.ts index 8027dfc..9a34861 100644 --- a/apps/web/api/ius/types.ts +++ b/apps/web/api/ius/types.ts @@ -11,16 +11,24 @@ export type MetaObject = { type Value = any; -export type Document = { +export type DocumentType = { documentTypeId: string; name: string; }; +export type Document = { + documentId: string; + documentTypeId: string; + href: string; + name: string; +}; + export type ResponseGetData = Record; export type ResponseMetaData = Record; export type ResponseConfig = { title: string }; export type ResponseConditions = string; -export type ResponseDocumentTypes = Document[]; +export type ResponseDocumentTypes = DocumentType[]; +export type ResponseDocuments = Document[]; export type HttpError = { errors: string[]; diff --git a/apps/web/app/ius/[slug]/page.tsx b/apps/web/app/ius/[slug]/page.tsx index 50f686a..8115a1a 100644 --- a/apps/web/app/ius/[slug]/page.tsx +++ b/apps/web/app/ius/[slug]/page.tsx @@ -30,8 +30,9 @@ export default async function Page(pageProps: PageProps) { apiIUS.getMetaData({ pageUrlParams }), apiIUS.getConfig({ pageUrlParams }), apiIUS.getDocumentTypes({ pageUrlParams }), - ]).then(([data, metaData, { title }, documentTypes]) => { - const props = { data, documentTypes, metaData, pageUrlParams, title }; + apiIUS.getDocuments({ pageUrlParams }), + ]).then(([data, metaData, { title }, documentTypes, documents]) => { + const props = { data, documentTypes, documents, metaData, pageUrlParams, title }; return
; }); diff --git a/apps/web/components/Form/Files.tsx b/apps/web/components/Form/Files.tsx index f74fb52..04bb0c2 100644 --- a/apps/web/components/Form/Files.tsx +++ b/apps/web/components/Form/Files.tsx @@ -1,10 +1,41 @@ import { FormContext } from './context/form-context'; import type { Props } from './types'; -import type { Document } from '@/api/ius/types'; +import type * as IUS from '@/api/ius/types'; +import { getUrls } from '@/config/urls'; +import { ArrowDownTrayIcon } from '@heroicons/react/24/solid'; +import Link from 'next/link'; import { useContext } from 'react'; import { Heading, InputFile } from 'ui'; -function File({ documentTypeId, name }: Document) { +const { URL_IUS } = getUrls(); + +type DownloadDocumentProps = Pick; + +function DownloadDocument({ document }: DownloadDocumentProps) { + return document ? ( + +
+ + Скачать +
+ + ) : ( + false + ); +} + +type FileProps = { + readonly document: IUS.Document | undefined; + readonly documentType: IUS.DocumentType; +}; + +function File({ document, documentType }: FileProps) { + const { documentTypeId, name } = documentType; const { formFiles, setFormFiles } = useContext(FormContext); const handleFileChange = (event: React.ChangeEvent) => { @@ -17,20 +48,25 @@ function File({ documentTypeId, name }: Document) { }; return ( -
+
+
); } -export function Files({ documentTypes }: Props) { +export function Files({ documentTypes, documents }: Props) { return (
Документы
- {documentTypes.map((document) => ( - + {documentTypes.map((documentType) => ( + x.documentTypeId === documentType.documentTypeId)} + /> ))}
diff --git a/apps/web/components/Form/context/form-context.tsx b/apps/web/components/Form/context/form-context.tsx index 4747dd2..0c3d825 100644 --- a/apps/web/components/Form/context/form-context.tsx +++ b/apps/web/components/Form/context/form-context.tsx @@ -1,4 +1,4 @@ -import type { Document } from '@/api/ius/types'; +import type { DocumentType } from '@/api/ius/types'; import type { PageUrlParams } from '@/utils/url'; import type { PropsWithChildren } from 'react'; import { createContext, useMemo, useState } from 'react'; @@ -6,7 +6,7 @@ import { createContext, useMemo, useState } from 'react'; type FormStatus = 'pending' | 'edit' | 'success' | 'error'; type FormState = { status: FormStatus; text?: string }; -type FormFile = Document & { file: File }; +type FormFile = DocumentType & { file: File }; type ContextType = { readonly formFiles: FormFile[]; diff --git a/apps/web/components/Form/types.ts b/apps/web/components/Form/types.ts index 86fc6e6..e4fcd24 100644 --- a/apps/web/components/Form/types.ts +++ b/apps/web/components/Form/types.ts @@ -3,7 +3,8 @@ import type { PageUrlParams } from '@/utils/url'; export type Props = { readonly data: IUS.ResponseGetData; - documentTypes: IUS.ResponseDocumentTypes; + readonly documentTypes: IUS.ResponseDocumentTypes; + readonly documents: IUS.ResponseDocuments; readonly metaData: IUS.ResponseMetaData; readonly pageUrlParams: PageUrlParams; readonly title: string;