From 5ea759da209435a8ad5a8fab98fa1b6b048dd221 Mon Sep 17 00:00:00 2001 From: Stef Winterswijk Date: Tue, 24 Sep 2024 15:29:43 +0200 Subject: [PATCH 1/4] Tweaks --- .../PublicationNotification.tsx | 38 ++++++++++--------- .../Modules/ModuleDetail/ModuleDetail.tsx | 6 +-- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/components/Publications/PublicationNotification/PublicationNotification.tsx b/src/components/Publications/PublicationNotification/PublicationNotification.tsx index 0c912d0c..f924fb7b 100644 --- a/src/components/Publications/PublicationNotification/PublicationNotification.tsx +++ b/src/components/Publications/PublicationNotification/PublicationNotification.tsx @@ -1,3 +1,7 @@ +import { Button, Notification, formatDate } from '@pzh-ui/components' +import { useQueryClient } from '@tanstack/react-query' +import { useMemo } from 'react' + import { getPublicationAnnouncementsGetQueryKey, usePublicationActPackagesActPackageUuidCreateAnnouncementPost, @@ -7,9 +11,7 @@ import { PublicationPackage, PublicationVersion, } from '@/api/fetchers.schemas' -import { Button, Notification, formatDate } from '@pzh-ui/components' -import { useQueryClient } from '@tanstack/react-query' -import { useMemo } from 'react' + import { PublicationType } from '../types' interface PublicationNotificationProps { @@ -41,19 +43,26 @@ const PublicationNotification = ({ }, }) - if (publicationType === 'act') { - const announcementDate = useMemo( - () => - version?.Announcement_Date && - formatDate(new Date(version.Announcement_Date), 'd LLLL yyyy'), - [version] - ) + const actAnnouncementDate = useMemo( + () => + version?.Announcement_Date && + formatDate(new Date(version.Announcement_Date), 'd LLLL yyyy'), + [version] + ) + const announcementDate = useMemo( + () => + announcement?.Announcement_Date && + formatDate(new Date(announcement.Announcement_Date), 'd LLLL yyyy'), + [announcement] + ) + + if (publicationType === 'act') { return (
- announcement?.Announcement_Date && - formatDate(new Date(announcement.Announcement_Date), 'd LLLL yyyy'), - [announcement] - ) - return (
{ const [activeTab, setActiveTab] = useState(tab || 'objecten') - const { - data: { Module: module } = {}, - isLoading, - isModuleManager, - } = useModule() + const { data: { Module: module } = {}, isLoading } = useModule() const handleTabChange: TabsProps['onSelectionChange'] = key => { setActiveTab(key as TabType) From d9eb1d6b055132fcc0fc127f8b78b844574a385d Mon Sep 17 00:00:00 2001 From: Stef Winterswijk Date: Mon, 14 Oct 2024 15:11:04 +0200 Subject: [PATCH 2/4] Add Modal for reports --- .../PublicationPackageReportUploadModal.tsx | 23 +++++++++++++++++++ .../index.ts | 1 + .../Modals/PublicationModals/index.ts | 2 ++ src/components/Modals/types.ts | 4 ++++ .../components/Package.tsx | 19 +++++++++++---- .../ModuleDetail/components/TabDecisions.tsx | 2 ++ src/utils/handleError.ts | 12 ++++++---- 7 files changed, 54 insertions(+), 9 deletions(-) create mode 100644 src/components/Modals/PublicationModals/PublicationPackageReportUploadModal/PublicationPackageReportUploadModal.tsx create mode 100644 src/components/Modals/PublicationModals/PublicationPackageReportUploadModal/index.ts diff --git a/src/components/Modals/PublicationModals/PublicationPackageReportUploadModal/PublicationPackageReportUploadModal.tsx b/src/components/Modals/PublicationModals/PublicationPackageReportUploadModal/PublicationPackageReportUploadModal.tsx new file mode 100644 index 00000000..ab4c012f --- /dev/null +++ b/src/components/Modals/PublicationModals/PublicationPackageReportUploadModal/PublicationPackageReportUploadModal.tsx @@ -0,0 +1,23 @@ +import { FormikFileUpload } from '@pzh-ui/components' +import { Form, Formik } from 'formik' + +import Modal from '@/components/Modal' + +const PublicationPackageReportUploadModal = () => { + const handleSubmit = () => {} + + return ( + + +
+ + +
+
+ ) +} + +export default PublicationPackageReportUploadModal diff --git a/src/components/Modals/PublicationModals/PublicationPackageReportUploadModal/index.ts b/src/components/Modals/PublicationModals/PublicationPackageReportUploadModal/index.ts new file mode 100644 index 00000000..1152c97f --- /dev/null +++ b/src/components/Modals/PublicationModals/PublicationPackageReportUploadModal/index.ts @@ -0,0 +1 @@ +export { default } from './PublicationPackageReportUploadModal' diff --git a/src/components/Modals/PublicationModals/index.ts b/src/components/Modals/PublicationModals/index.ts index 7d2b4e69..08b59599 100644 --- a/src/components/Modals/PublicationModals/index.ts +++ b/src/components/Modals/PublicationModals/index.ts @@ -1,9 +1,11 @@ import PublicationAnnouncementUpdateModal from './PublicationAnnouncementUpdateModal' import PublicationEditModal from './PublicationEditModal' +import PublicationPackageReportUploadModal from './PublicationPackageReportUploadModal' import PublicationVersionEditModal from './PublicationVersionEditModal' export { PublicationAnnouncementUpdateModal, PublicationEditModal, + PublicationPackageReportUploadModal, PublicationVersionEditModal, } diff --git a/src/components/Modals/types.ts b/src/components/Modals/types.ts index f21ed67e..27a4bb1a 100644 --- a/src/components/Modals/types.ts +++ b/src/components/Modals/types.ts @@ -42,6 +42,7 @@ export type ModalType = | 'publicationVersionAbort' | 'publicationAnnouncementPackages' | 'publicationAnnouncementUpdate' + | 'publicationPackageReportUpload' export interface ModalStateMap { moduleEditObject: { @@ -81,4 +82,7 @@ export interface ModalStateMap { publicationAnnouncementUpdate: { announcementUuid: string } + publicationPackageReportUpload: { + packageUUID: string + } } diff --git a/src/components/Publications/PublicationPackages/components/Package.tsx b/src/components/Publications/PublicationPackages/components/Package.tsx index fe304d7b..b0d6b463 100644 --- a/src/components/Publications/PublicationPackages/components/Package.tsx +++ b/src/components/Publications/PublicationPackages/components/Package.tsx @@ -6,9 +6,9 @@ import { EyeLight, } from '@pzh-ui/icons' import { useMemo } from 'react' -import { Link } from 'react-router-dom' import { PublicationPackage } from '@/api/fetchers.schemas' +import useModalStore from '@/store/modalStore' import { useActions } from './actions' import { getIndicatorClass } from './utils' @@ -30,6 +30,8 @@ const Package = ({ versionUUID, canPublicate, }: PackageProps) => { + const setActiveModal = useModalStore(state => state.setActiveModal) + const { downloadPackage } = useActions({ publicationUUID, versionUUID, @@ -108,20 +110,27 @@ const Package = ({
Gedownload op {downloadDate} {!isLocked && canPublicate && ( - + )}
{canPublicate && ( diff --git a/src/pages/protected/Modules/ModuleDetail/components/TabDecisions.tsx b/src/pages/protected/Modules/ModuleDetail/components/TabDecisions.tsx index e36e5eb9..eddc2b3d 100644 --- a/src/pages/protected/Modules/ModuleDetail/components/TabDecisions.tsx +++ b/src/pages/protected/Modules/ModuleDetail/components/TabDecisions.tsx @@ -21,6 +21,7 @@ import { LoaderSpinner } from '@/components/Loader' import { PublicationAnnouncementUpdateModal, PublicationEditModal, + PublicationPackageReportUploadModal, PublicationVersionEditModal, } from '@/components/Modals/PublicationModals' import PublicationFolder from '@/components/Publications/PublicationFolder' @@ -38,6 +39,7 @@ const TabDecisions = () => ( + ) diff --git a/src/utils/handleError.ts b/src/utils/handleError.ts index 81c90f7f..927bfc5b 100644 --- a/src/utils/handleError.ts +++ b/src/utils/handleError.ts @@ -11,10 +11,14 @@ const ERRORS: { [key: string]: string } = { } const handleError = (err: Error, helpers: FormikHelpers) => { - err.data?.detail?.forEach(item => { - helpers.setFieldError(item.loc.join('.'), ERRORS[item.msg] || item.msg) - helpers.setFieldTouched(item.loc.join('.'), true) - }) + Array.isArray(err.data?.detail) && + err.data?.detail?.forEach(item => { + helpers.setFieldError( + item.loc.join('.'), + ERRORS[item.msg] || item.msg + ) + helpers.setFieldTouched(item.loc.join('.'), true) + }) helpers.setSubmitting(false) } From 8e960442dc2d7f0e98722ece2a9a0eb553fb542e Mon Sep 17 00:00:00 2001 From: Stef Winterswijk Date: Tue, 15 Oct 2024 15:19:38 +0200 Subject: [PATCH 3/4] Update Publication reports functionality --- package.json | 2 +- .../PublicationAnnouncementUpdateModal.tsx | 5 + .../PublicationPackageReportUploadModal.tsx | 171 +++++++++++++++++- src/components/Modals/types.ts | 4 + .../PublicationPackages.tsx | 2 + .../components/Package.tsx | 13 +- .../components/PackageCreate.tsx | 5 +- .../components/Packages.tsx | 13 ++ .../PublicationPackages/components/actions.ts | 89 +++++++-- yarn.lock | 10 +- 10 files changed, 288 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index adf94ca5..4cbcc7d5 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,7 @@ "type": "module", "dependencies": { "@headlessui/react": "^1.7.17", - "@pzh-ui/components": "^0.0.570", + "@pzh-ui/components": "^0.0.575", "@pzh-ui/config": "^0.0.70", "@pzh-ui/css": "^0.0.100", "@pzh-ui/icons": "^0.0.69", diff --git a/src/components/Modals/PublicationModals/PublicationAnnouncementUpdateModal/PublicationAnnouncementUpdateModal.tsx b/src/components/Modals/PublicationModals/PublicationAnnouncementUpdateModal/PublicationAnnouncementUpdateModal.tsx index e6039c41..505cd8cc 100644 --- a/src/components/Modals/PublicationModals/PublicationAnnouncementUpdateModal/PublicationAnnouncementUpdateModal.tsx +++ b/src/components/Modals/PublicationModals/PublicationAnnouncementUpdateModal/PublicationAnnouncementUpdateModal.tsx @@ -50,6 +50,11 @@ const PublicationAnnouncementUpdateModal = () => { ) const handleSubmit = (payload: PublicationAnnouncementEdit) => { + if (payload.Announcement_Date && payload.Procedural) { + payload.Procedural.Procedural_Announcement_Date = + payload.Announcement_Date + } + mutate({ announcementUuid: modalState?.announcementUuid, data: payload, diff --git a/src/components/Modals/PublicationModals/PublicationPackageReportUploadModal/PublicationPackageReportUploadModal.tsx b/src/components/Modals/PublicationModals/PublicationPackageReportUploadModal/PublicationPackageReportUploadModal.tsx index ab4c012f..996657fe 100644 --- a/src/components/Modals/PublicationModals/PublicationPackageReportUploadModal/PublicationPackageReportUploadModal.tsx +++ b/src/components/Modals/PublicationModals/PublicationPackageReportUploadModal/PublicationPackageReportUploadModal.tsx @@ -1,23 +1,180 @@ -import { FormikFileUpload } from '@pzh-ui/components' -import { Form, Formik } from 'formik' +import { + Button, + File, + formatBytes, + FormikFileUpload, + Text, +} from '@pzh-ui/components' +import { TrashCan } from '@pzh-ui/icons' +import { Form, Formik, FormikHelpers, FormikProps } from 'formik' +import { useMemo } from 'react' +import { + usePublicationActReportsGet, + usePublicationAnnouncementReportsGet, +} from '@/api/fetchers' +import { LoaderSpinner } from '@/components/Loader' import Modal from '@/components/Modal' +import { useActions } from '@/components/Publications/PublicationPackages/components/actions' +import useModalStore from '@/store/modalStore' + +import { ModalStateMap } from '../../types' const PublicationPackageReportUploadModal = () => { - const handleSubmit = () => {} + const setActiveModal = useModalStore(state => state.setActiveModal) + const modalState = useModalStore( + state => state.modalStates['publicationPackageReportUpload'] + ) as ModalStateMap['publicationPackageReportUpload'] + + const { uploadReports } = useActions(modalState || {}) + + const handleSubmit = ( + payload: { uploaded_files: File[] }, + helpers: FormikHelpers<{ uploaded_files: never[] }> + ) => { + uploadReports + .mutateAsync({ + actPackageUuid: modalState.packageUUID, + announcementPackageUuid: modalState.packageUUID, + data: payload, + }) + .then(() => { + helpers.setSubmitting(false) + }) + } return ( - -
- - + + {props => } +
+ +
) } +const InnerForm = ({ + values, + setFieldValue, + isSubmitting, +}: FormikProps) => { + const modalState = useModalStore( + state => state.modalStates['publicationPackageReportUpload'] + ) as ModalStateMap['publicationPackageReportUpload'] + + const { data: actReports } = usePublicationActReportsGet( + { + act_package_uuid: modalState.packageUUID, + }, + { + query: { + enabled: modalState.publicationType === 'act', + }, + } + ) + + const { data: announcementReports } = usePublicationAnnouncementReportsGet( + { + announcement_package_uuid: modalState.packageUUID, + }, + { + query: { + enabled: modalState.publicationType === 'announcement', + }, + } + ) + + 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) + + setFieldValue('uploaded_files', newFiles) + } + + const count = useMemo( + () => values.uploaded_files.length, + [values.uploaded_files] + ) + + return ( +
+ + {!!values.uploaded_files.length && ( +
+ + Geselecteerde bestanden + +
    + {values.uploaded_files.map((file, index) => ( +
  • +
    + + {file.path} + +
    + + {formatBytes(file.size)} + + +
    +
    +
  • + ))} +
+ +
+ )} + + ) +} + export default PublicationPackageReportUploadModal diff --git a/src/components/Modals/types.ts b/src/components/Modals/types.ts index 27a4bb1a..d72f20ab 100644 --- a/src/components/Modals/types.ts +++ b/src/components/Modals/types.ts @@ -9,6 +9,8 @@ import { } from '@/api/fetchers.schemas' import { Error } from '@/utils/handleError' +import { PublicationType } from '../Publications/types' + export type ModalType = | 'regulationAdd' | 'regulationDelete' @@ -83,6 +85,8 @@ export interface ModalStateMap { announcementUuid: string } publicationPackageReportUpload: { + publicationType: PublicationType + publicationUUID: string packageUUID: string } } diff --git a/src/components/Publications/PublicationPackages/PublicationPackages.tsx b/src/components/Publications/PublicationPackages/PublicationPackages.tsx index 024745f4..1493fbc4 100644 --- a/src/components/Publications/PublicationPackages/PublicationPackages.tsx +++ b/src/components/Publications/PublicationPackages/PublicationPackages.tsx @@ -76,6 +76,7 @@ const PublicationPackages = ({ {environment?.Can_Validate && ( { const setActiveModal = useModalStore(state => state.setActiveModal) const { downloadPackage } = useActions({ + publicationType, publicationUUID, versionUUID, + announcementUUID, packageUUID: UUID, }) @@ -116,7 +123,11 @@ const Package = ({ onPress={() => setActiveModal( 'publicationPackageReportUpload', - { packageUUID: UUID } + { + packageUUID: UUID, + publicationType, + publicationUUID, + } ) }> ['createPackage'] + announcementUUID?: string inline?: boolean packageType: PackageType isLocked?: boolean @@ -15,6 +16,7 @@ interface PackageCreateProps { const PackageCreate = ({ createPackage, + announcementUUID, inline, packageType, isLocked, @@ -22,8 +24,9 @@ const PackageCreate = ({ const { versionUUID } = useParams() const handleAction = () => - createPackage.mutate({ + createPackage.mutateAsync({ versionUuid: String(versionUUID), + announcementUuid: String(announcementUUID), data: { Package_Type: packageType }, }) diff --git a/src/components/Publications/PublicationPackages/components/Packages.tsx b/src/components/Publications/PublicationPackages/components/Packages.tsx index 0a86e0e7..36f7df48 100644 --- a/src/components/Publications/PublicationPackages/components/Packages.tsx +++ b/src/components/Publications/PublicationPackages/components/Packages.tsx @@ -7,6 +7,7 @@ import { } from '@/api/fetchers' import { PackageType, + PublicationAnnouncementShort, PublicationPackage, PublicationShort, PublicationVersion, @@ -15,6 +16,7 @@ import { import { LoaderCard } from '@/components/Loader' import useModalStore from '@/store/modalStore' +import { PublicationType } from '../../types' import { useActions } from './actions' import Package from './Package' import PackageCreate from './PackageCreate' @@ -29,9 +31,11 @@ const config = { } interface PackagesProps { + publicationType: PublicationType data?: PublicationPackage[] isFetching?: boolean version: PublicationVersion + announcement?: PublicationAnnouncementShort publication?: PublicationShort packageType: PackageType validPublicationPackage?: PublicationPackage @@ -41,9 +45,11 @@ interface PackagesProps { } const Packages = ({ + publicationType, data, isFetching, version, + announcement, publication, packageType, customLabel, @@ -53,7 +59,9 @@ const Packages = ({ const setActiveModal = useModalStore(state => state.setActiveModal) const { createPackage } = useActions({ + publicationType, versionUUID: version.UUID, + announcementUUID: announcement?.UUID, publicationUUID: String(publication?.UUID), }) @@ -82,6 +90,7 @@ const Packages = ({ ) : !!!data?.length ? ( @@ -90,9 +99,11 @@ const Packages = ({ {data.map(item => ( @@ -100,6 +111,7 @@ const Packages = ({ {!version.Is_Locked && ( @@ -247,6 +259,7 @@ export const AnnouncementPackages = ({ data={data} isFetching={isFetching} version={version} + announcement={announcement} packageType={packageType} isLocked={!!validPublicationPackage && !!validAnnouncementPackage} {...rest} diff --git a/src/components/Publications/PublicationPackages/components/actions.ts b/src/components/Publications/PublicationPackages/components/actions.ts index 6dde1bf5..a76eb127 100644 --- a/src/components/Publications/PublicationPackages/components/actions.ts +++ b/src/components/Publications/PublicationPackages/components/actions.ts @@ -4,33 +4,58 @@ import { AxiosError } from 'axios' import { getPublicationActPackagesActPackageUuidDownloadGetQueryKey, getPublicationActPackagesGetQueryKey, + getPublicationAnnouncementPackagesAnnouncementPackageUuidDownloadGetQueryKey, + getPublicationAnnouncementPackagesGetQueryKey, getPublicationsPublicationUuidVersionsGetQueryKey, + usePublicationActPackagesActPackageUuidReportPost, + usePublicationAnnouncementPackagesAnnouncementPackageUuidReportPost, + usePublicationAnnouncementsAnnouncementUuidPackagesPost, usePublicationVersionsVersionUuidPackagesPost, } from '@/api/fetchers' import { HTTPValidationError } from '@/api/fetchers.schemas' import { downloadFile } from '@/utils/file' +import { PublicationType } from '../../types' + interface ActionsProps { + publicationType: PublicationType versionUUID?: string + announcementUUID?: string publicationUUID: string packageUUID?: string } export const useActions = ({ + publicationType, versionUUID, + announcementUUID, publicationUUID, packageUUID, }: ActionsProps) => { const queryClient = useQueryClient() - const createPackage = usePublicationVersionsVersionUuidPackagesPost({ + const createPackage = ( + publicationType === 'act' + ? usePublicationVersionsVersionUuidPackagesPost + : usePublicationAnnouncementsAnnouncementUuidPackagesPost + )({ mutation: { onSuccess: () => { - queryClient.invalidateQueries({ - queryKey: getPublicationActPackagesGetQueryKey({ - version_uuid: versionUUID, - }), - }) + if (publicationType === 'act') { + queryClient.invalidateQueries({ + queryKey: getPublicationActPackagesGetQueryKey({ + version_uuid: versionUUID, + }), + }) + } else { + queryClient.invalidateQueries({ + queryKey: getPublicationAnnouncementPackagesGetQueryKey( + { + announcement_uuid: announcementUUID, + } + ), + }) + } queryClient.invalidateQueries({ queryKey: getPublicationsPublicationUuidVersionsGetQueryKey( @@ -59,18 +84,60 @@ export const useActions = ({ queryKey: ['downloadPackage', packageUUID, versionUUID], queryFn: async () => downloadFile( - getPublicationActPackagesActPackageUuidDownloadGetQueryKey( + (publicationType === 'act' + ? getPublicationActPackagesActPackageUuidDownloadGetQueryKey + : getPublicationAnnouncementPackagesAnnouncementPackageUuidDownloadGetQueryKey)( String(packageUUID) )[0] ).finally(() => queryClient.invalidateQueries({ - queryKey: getPublicationActPackagesGetQueryKey({ - version_uuid: versionUUID, - }), + queryKey: + publicationType === 'act' + ? getPublicationActPackagesGetQueryKey({ + version_uuid: versionUUID, + }) + : getPublicationAnnouncementPackagesGetQueryKey({ + announcement_uuid: announcementUUID, + }), }) ), enabled: false, }) - return { createPackage, downloadPackage } + const uploadReports = ( + publicationType === 'act' + ? usePublicationActPackagesActPackageUuidReportPost + : usePublicationAnnouncementPackagesAnnouncementPackageUuidReportPost + )({ + mutation: { + onSuccess: data => { + if (publicationType === 'act') { + queryClient.invalidateQueries({ + queryKey: getPublicationActPackagesGetQueryKey({ + version_uuid: versionUUID, + }), + }) + } else { + queryClient.invalidateQueries({ + queryKey: getPublicationAnnouncementPackagesGetQueryKey( + { + announcement_uuid: announcementUUID, + } + ), + }) + } + + if (data.Status === 'valid') { + queryClient.invalidateQueries({ + queryKey: + getPublicationsPublicationUuidVersionsGetQueryKey( + publicationUUID + ), + }) + } + }, + }, + }) + + return { createPackage, downloadPackage, uploadReports } } diff --git a/yarn.lock b/yarn.lock index c14f46ce..244ae04f 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3140,9 +3140,9 @@ __metadata: languageName: node linkType: hard -"@pzh-ui/components@npm:^0.0.570": - version: 0.0.570 - resolution: "@pzh-ui/components@npm:0.0.570" +"@pzh-ui/components@npm:^0.0.575": + version: 0.0.575 + resolution: "@pzh-ui/components@npm:0.0.575" dependencies: "@floating-ui/react": "npm:^0.24.8" "@headlessui/react": "npm:^1.5.0" @@ -3194,7 +3194,7 @@ __metadata: react-stately: "npm:^3.30.1" react-toastify: "npm:^9.1.2" tailwind-merge: "npm:^2.2.2" - checksum: a25fb1f3fc67e4cbd64a90632756982ad22034349c3d60149019876d6abf329715d87d986378a8169f3ab6eb612d1ed3684ad7a4ea76ce6f89d8831ccf11a855 + checksum: 45f84cd35aa8085fa6868c089af32650bf14b2cbff9520d162168ff226c2c54afd39f9e6fc67ef2d1361eab3932802264ca9f3260b6b6f7cdbb547d2c14092e8 languageName: node linkType: hard @@ -13436,7 +13436,7 @@ __metadata: "@axe-core/react": "npm:^4.10.0" "@faker-js/faker": "npm:^8.3.1" "@headlessui/react": "npm:^1.7.17" - "@pzh-ui/components": "npm:^0.0.570" + "@pzh-ui/components": "npm:^0.0.575" "@pzh-ui/config": "npm:^0.0.70" "@pzh-ui/css": "npm:^0.0.100" "@pzh-ui/icons": "npm:^0.0.69" From e4001bfe96b6e1546ee140383bae9c8b7bc55d85 Mon Sep 17 00:00:00 2001 From: Stef Winterswijk Date: Mon, 21 Oct 2024 09:48:24 +0200 Subject: [PATCH 4/4] 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', + } + } +}