From e4001bfe96b6e1546ee140383bae9c8b7bc55d85 Mon Sep 17 00:00:00 2001 From: Stef Winterswijk Date: Mon, 21 Oct 2024 09:48:24 +0200 Subject: [PATCH] Update packages --- src/api/fetchers.msw.ts | 32 +++--- src/api/fetchers.schemas.ts | 1 + src/api/fetchers.ts | 104 +++++++++--------- .../PublicationPackageReportUploadModal.tsx | 66 ++++++++++- .../components/Package.tsx | 25 +---- .../PublicationPackages/components/utils.ts | 21 ++++ 6 files changed, 158 insertions(+), 91 deletions(-) diff --git a/src/api/fetchers.msw.ts b/src/api/fetchers.msw.ts index 9b2755a5..37ccdb93 100644 --- a/src/api/fetchers.msw.ts +++ b/src/api/fetchers.msw.ts @@ -18771,6 +18771,21 @@ export const getPublicationVersionsVersionUuidAttachmentsPostMockHandler = ( ) } +export const getPublicationVersionsVersionUuidPdfExportPostMockHandler = () => { + return http.post( + '*/publication-versions/:versionUuid/pdf_export', + async () => { + await delay(1000) + return new HttpResponse(null, { + status: 200, + headers: { + 'Content-Type': 'application/json', + }, + }) + } + ) +} + export const getPublicationVersionsVersionUuidPackagesPostMockHandler = ( overrideResponse?: | PublicationPackageCreatedResponse @@ -18803,21 +18818,6 @@ export const getPublicationVersionsVersionUuidPackagesPostMockHandler = ( ) } -export const getPublicationVersionsVersionUuidPdfExportPostMockHandler = () => { - return http.post( - '*/publication-versions/:versionUuid/pdf_export', - async () => { - await delay(1000) - return new HttpResponse(null, { - status: 200, - headers: { - 'Content-Type': 'application/json', - }, - }) - } - ) -} - export const getPublicationActPackagesGetMockHandler = ( overrideResponse?: | PagedResponsePublicationPackage @@ -19605,8 +19605,8 @@ export const getOmgevingsbeleidAPIMock = () => [ getPublicationVersionsVersionUuidGetMockHandler(), getPublicationVersionsVersionUuidPostMockHandler(), getPublicationVersionsVersionUuidAttachmentsPostMockHandler(), - getPublicationVersionsVersionUuidPackagesPostMockHandler(), getPublicationVersionsVersionUuidPdfExportPostMockHandler(), + getPublicationVersionsVersionUuidPackagesPostMockHandler(), getPublicationActPackagesGetMockHandler(), getPublicationActPackagesActPackageUuidDownloadGetMockHandler(), getPublicationActPackagesActPackageUuidReportPostMockHandler(), diff --git a/src/api/fetchers.schemas.ts b/src/api/fetchers.schemas.ts index 41628696..fc817b35 100644 --- a/src/api/fetchers.schemas.ts +++ b/src/api/fetchers.schemas.ts @@ -3799,6 +3799,7 @@ export interface ActCreate { Document_Type: DocumentType Environment_UUID: string Title: string + Work_Other?: string } export interface AcknowledgedRelationSide { diff --git a/src/api/fetchers.ts b/src/api/fetchers.ts index 21ce189f..dc4de234 100644 --- a/src/api/fetchers.ts +++ b/src/api/fetchers.ts @@ -19423,159 +19423,159 @@ export const usePublicationVersionsVersionUuidAttachmentsPost = < } /** - * @summary Create new Publication Act Package + * @summary Download Publication Version as Pdf */ -export const publicationVersionsVersionUuidPackagesPost = ( +export const publicationVersionsVersionUuidPdfExportPost = ( versionUuid: string, - publicationPackageCreate: PublicationPackageCreate + publicationPackagePdf: PublicationPackagePdf ) => { - return customInstance({ - url: `/publication-versions/${versionUuid}/packages`, + return customInstance({ + url: `/publication-versions/${versionUuid}/pdf_export`, method: 'POST', headers: { 'Content-Type': 'application/json' }, - data: publicationPackageCreate, + data: publicationPackagePdf, }) } -export const getPublicationVersionsVersionUuidPackagesPostMutationOptions = < +export const getPublicationVersionsVersionUuidPdfExportPostMutationOptions = < TError = HTTPValidationError, TContext = unknown >(options?: { mutation?: UseMutationOptions< - Awaited>, + Awaited>, TError, - { versionUuid: string; data: PublicationPackageCreate }, + { versionUuid: string; data: PublicationPackagePdf }, TContext > }): UseMutationOptions< - Awaited>, + Awaited>, TError, - { versionUuid: string; data: PublicationPackageCreate }, + { versionUuid: string; data: PublicationPackagePdf }, TContext > => { const { mutation: mutationOptions } = options ?? {} const mutationFn: MutationFunction< - Awaited>, - { versionUuid: string; data: PublicationPackageCreate } + Awaited>, + { versionUuid: string; data: PublicationPackagePdf } > = props => { const { versionUuid, data } = props ?? {} - return publicationVersionsVersionUuidPackagesPost(versionUuid, data) + return publicationVersionsVersionUuidPdfExportPost(versionUuid, data) } return { mutationFn, ...mutationOptions } } -export type PublicationVersionsVersionUuidPackagesPostMutationResult = +export type PublicationVersionsVersionUuidPdfExportPostMutationResult = NonNullable< - Awaited> + Awaited> > -export type PublicationVersionsVersionUuidPackagesPostMutationBody = - PublicationPackageCreate -export type PublicationVersionsVersionUuidPackagesPostMutationError = +export type PublicationVersionsVersionUuidPdfExportPostMutationBody = + PublicationPackagePdf +export type PublicationVersionsVersionUuidPdfExportPostMutationError = HTTPValidationError /** - * @summary Create new Publication Act Package + * @summary Download Publication Version as Pdf */ -export const usePublicationVersionsVersionUuidPackagesPost = < +export const usePublicationVersionsVersionUuidPdfExportPost = < TError = HTTPValidationError, TContext = unknown >(options?: { mutation?: UseMutationOptions< - Awaited>, + Awaited>, TError, - { versionUuid: string; data: PublicationPackageCreate }, + { versionUuid: string; data: PublicationPackagePdf }, TContext > }): UseMutationResult< - Awaited>, + Awaited>, TError, - { versionUuid: string; data: PublicationPackageCreate }, + { versionUuid: string; data: PublicationPackagePdf }, TContext > => { const mutationOptions = - getPublicationVersionsVersionUuidPackagesPostMutationOptions(options) + getPublicationVersionsVersionUuidPdfExportPostMutationOptions(options) return useMutation(mutationOptions) } /** - * @summary Download Publication Act as Pdf + * @summary Create new Publication Act Package */ -export const publicationVersionsVersionUuidPdfExportPost = ( +export const publicationVersionsVersionUuidPackagesPost = ( versionUuid: string, - publicationPackagePdf: PublicationPackagePdf + publicationPackageCreate: PublicationPackageCreate ) => { - return customInstance({ - url: `/publication-versions/${versionUuid}/pdf_export`, + return customInstance({ + url: `/publication-versions/${versionUuid}/packages`, method: 'POST', headers: { 'Content-Type': 'application/json' }, - data: publicationPackagePdf, + data: publicationPackageCreate, }) } -export const getPublicationVersionsVersionUuidPdfExportPostMutationOptions = < +export const getPublicationVersionsVersionUuidPackagesPostMutationOptions = < TError = HTTPValidationError, TContext = unknown >(options?: { mutation?: UseMutationOptions< - Awaited>, + Awaited>, TError, - { versionUuid: string; data: PublicationPackagePdf }, + { versionUuid: string; data: PublicationPackageCreate }, TContext > }): UseMutationOptions< - Awaited>, + Awaited>, TError, - { versionUuid: string; data: PublicationPackagePdf }, + { versionUuid: string; data: PublicationPackageCreate }, TContext > => { const { mutation: mutationOptions } = options ?? {} const mutationFn: MutationFunction< - Awaited>, - { versionUuid: string; data: PublicationPackagePdf } + Awaited>, + { versionUuid: string; data: PublicationPackageCreate } > = props => { const { versionUuid, data } = props ?? {} - return publicationVersionsVersionUuidPdfExportPost(versionUuid, data) + return publicationVersionsVersionUuidPackagesPost(versionUuid, data) } return { mutationFn, ...mutationOptions } } -export type PublicationVersionsVersionUuidPdfExportPostMutationResult = +export type PublicationVersionsVersionUuidPackagesPostMutationResult = NonNullable< - Awaited> + Awaited> > -export type PublicationVersionsVersionUuidPdfExportPostMutationBody = - PublicationPackagePdf -export type PublicationVersionsVersionUuidPdfExportPostMutationError = +export type PublicationVersionsVersionUuidPackagesPostMutationBody = + PublicationPackageCreate +export type PublicationVersionsVersionUuidPackagesPostMutationError = HTTPValidationError /** - * @summary Download Publication Act as Pdf + * @summary Create new Publication Act Package */ -export const usePublicationVersionsVersionUuidPdfExportPost = < +export const usePublicationVersionsVersionUuidPackagesPost = < TError = HTTPValidationError, TContext = unknown >(options?: { mutation?: UseMutationOptions< - Awaited>, + Awaited>, TError, - { versionUuid: string; data: PublicationPackagePdf }, + { versionUuid: string; data: PublicationPackageCreate }, TContext > }): UseMutationResult< - Awaited>, + Awaited>, TError, - { versionUuid: string; data: PublicationPackagePdf }, + { versionUuid: string; data: PublicationPackageCreate }, TContext > => { const mutationOptions = - getPublicationVersionsVersionUuidPdfExportPostMutationOptions(options) + getPublicationVersionsVersionUuidPackagesPostMutationOptions(options) return useMutation(mutationOptions) } diff --git a/src/components/Modals/PublicationModals/PublicationPackageReportUploadModal/PublicationPackageReportUploadModal.tsx b/src/components/Modals/PublicationModals/PublicationPackageReportUploadModal/PublicationPackageReportUploadModal.tsx index 996657fe..30509181 100644 --- a/src/components/Modals/PublicationModals/PublicationPackageReportUploadModal/PublicationPackageReportUploadModal.tsx +++ b/src/components/Modals/PublicationModals/PublicationPackageReportUploadModal/PublicationPackageReportUploadModal.tsx @@ -1,26 +1,34 @@ import { + Badge, Button, File, formatBytes, + formatDate, FormikFileUpload, Text, } from '@pzh-ui/components' import { TrashCan } from '@pzh-ui/icons' +import { useQueryClient } from '@tanstack/react-query' import { Form, Formik, FormikHelpers, FormikProps } from 'formik' import { useMemo } from 'react' import { + getPublicationActReportsGetQueryKey, + getPublicationAnnouncementReportsGetQueryKey, usePublicationActReportsGet, usePublicationAnnouncementReportsGet, } from '@/api/fetchers' import { LoaderSpinner } from '@/components/Loader' import Modal from '@/components/Modal' import { useActions } from '@/components/Publications/PublicationPackages/components/actions' +import { getStatus } from '@/components/Publications/PublicationPackages/components/utils' import useModalStore from '@/store/modalStore' import { ModalStateMap } from '../../types' const PublicationPackageReportUploadModal = () => { + const queryClient = useQueryClient() + const setActiveModal = useModalStore(state => state.setActiveModal) const modalState = useModalStore( state => state.modalStates['publicationPackageReportUpload'] @@ -39,7 +47,13 @@ const PublicationPackageReportUploadModal = () => { data: payload, }) .then(() => { - helpers.setSubmitting(false) + queryClient.invalidateQueries({ + queryKey: + modalState.publicationType === 'act' + ? getPublicationActReportsGetQueryKey() + : getPublicationAnnouncementReportsGetQueryKey(), + }) + helpers.resetForm() }) } @@ -96,8 +110,6 @@ const InnerForm = ({ const reports = modalState.publicationType === 'act' ? actReports : announcementReports - console.log(reports) - const removeFile = (file: File) => () => { const newFiles = [...values.uploaded_files] newFiles.splice(newFiles.indexOf(file), 1) @@ -173,6 +185,54 @@ const InnerForm = ({ )} + {!!reports?.results.length && ( +
+ + Laatst geĆ¼ploade rapporten + +
    + {reports.results.map(file => { + const status = getStatus(file.Report_Status) + + return ( +
  • +
    + + {file.Filename} + +
    + + {formatDate( + new Date( + file.Created_Date + 'Z' + ), + "dd-MM-yyyy 'om' kk:mm" + )} + + {status && ( + + )} +
    +
    +
  • + ) + })} +
+
+ )} ) } diff --git a/src/components/Publications/PublicationPackages/components/Package.tsx b/src/components/Publications/PublicationPackages/components/Package.tsx index 4bd37a9b..f9e0f6be 100644 --- a/src/components/Publications/PublicationPackages/components/Package.tsx +++ b/src/components/Publications/PublicationPackages/components/Package.tsx @@ -12,7 +12,7 @@ import useModalStore from '@/store/modalStore' import { PublicationType } from '../../types' import { useActions } from './actions' -import { getIndicatorClass } from './utils' +import { getIndicatorClass, getStatus } from './utils' interface PackageProps extends PublicationPackage { publicationType: PublicationType @@ -65,25 +65,10 @@ const Package = ({ [Report_Status] ) - const status = useMemo((): BadgeProps | undefined => { - switch (Report_Status) { - case 'pending': - return { - text: 'In afwachting', - variant: 'yellow', - } - case 'valid': - return { - text: 'Goedgekeurd', - variant: 'green', - } - case 'failed': - return { - text: 'Gefaald', - variant: 'red', - } - } - }, [Report_Status]) + const status = useMemo( + (): BadgeProps | undefined => getStatus(Report_Status), + [Report_Status] + ) return (
diff --git a/src/components/Publications/PublicationPackages/components/utils.ts b/src/components/Publications/PublicationPackages/components/utils.ts index 66c1be50..1f028c6d 100644 --- a/src/components/Publications/PublicationPackages/components/utils.ts +++ b/src/components/Publications/PublicationPackages/components/utils.ts @@ -1,3 +1,4 @@ +import { BadgeProps } from '@pzh-ui/components' import clsx from 'clsx' /** @@ -12,3 +13,23 @@ export const getIndicatorClass = (isSucceeded?: boolean) => 'border-pzh-green-500 bg-pzh-green-500': isSucceeded, } ) + +export const getStatus = (status?: string): BadgeProps | undefined => { + switch (status) { + case 'pending': + return { + text: 'In afwachting', + variant: 'yellow', + } + case 'valid': + return { + text: 'Goedgekeurd', + variant: 'green', + } + case 'failed': + return { + text: 'Gefaald', + variant: 'red', + } + } +}