From 32a45f2fa01749f2a8a7d55bc8db757989a3c50d Mon Sep 17 00:00:00 2001 From: Sarah Donvito Date: Thu, 11 Apr 2024 16:26:15 +0200 Subject: [PATCH 01/14] feat(PN-10623): wip on new field for senderDenomination --- .../PreliminaryInformations.tsx | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx index 8420e946d6..a2f61f45c1 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx @@ -53,6 +53,13 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { const hasGroups = useAppSelector( (state: RootState) => state.userState.user.organization.hasGroups ); + const senderDenomination = useAppSelector((state: RootState) => + state.userState.user.organization.parentDescription + ? state.userState.user.organization.parentDescription + + ' - ' + + state.userState.user.organization.name + : state.userState.user.organization.name + ); const { t } = useTranslation(['notifiche'], { keyPrefix: 'new-notification.steps.preliminary-informations', @@ -64,6 +71,7 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { () => ({ paProtocolNumber: notification.paProtocolNumber || '', subject: notification.subject || '', + senderDenomination, abstract: notification.abstract ?? '', group: notification.group ?? '', taxonomyCode: notification.taxonomyCode || '', @@ -76,6 +84,7 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { const validationSchema = yup.object({ paProtocolNumber: requiredStringFieldValidation(tc, 256), subject: requiredStringFieldValidation(tc, 134, 10), + senderDenomination: requiredStringFieldValidation(tc, 80), abstract: yup .string() .max(1024, tc('too-long-field-error', { maxLength: 1024 })) @@ -158,6 +167,19 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { size="small" margin="normal" /> + 80} + disabled={senderDenomination.length < 80} + helperText={formik.touched.subject && formik.errors.subject} + size="small" + margin="normal" + /> Date: Fri, 12 Apr 2024 13:33:07 +0200 Subject: [PATCH 02/14] feat(PN-10623): wip on senderDenomination field for PA --- .../public/locales/it/notifiche.json | 1 + .../NewNotification/PreliminaryInformations.tsx | 16 +++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/pn-pa-webapp/public/locales/it/notifiche.json b/packages/pn-pa-webapp/public/locales/it/notifiche.json index 182610665a..6309eed9ea 100644 --- a/packages/pn-pa-webapp/public/locales/it/notifiche.json +++ b/packages/pn-pa-webapp/public/locales/it/notifiche.json @@ -386,6 +386,7 @@ "title": "Informazioni preliminari", "protocol-number": "Numero di protocollo", "subject": "Oggetto della notifica", + "sender-denomination": "Ente mittente", "abstract": "Descrizione", "group": "Gruppo", "no-groups": "Non ci sono gruppi per questo prodotto", diff --git a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx index a2f61f45c1..3cad94ba52 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx @@ -169,14 +169,20 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { /> 80} - disabled={senderDenomination.length < 80} - helperText={formik.touched.subject && formik.errors.subject} + error={ + formik.values.senderDenomination.length > 80 && + Boolean(formik.errors.senderDenomination) + } + disabled={formik.values.senderDenomination.length < 80} + helperText={ + (formik.touched.senderDenomination && formik.errors.senderDenomination) || + (formik.values.senderDenomination.length > 80 && formik.errors.senderDenomination) + } size="small" margin="normal" /> From 55059e06a833eaf9cec30eccc1bf49093ff11b3f Mon Sep 17 00:00:00 2001 From: Sarah Donvito Date: Wed, 17 Apr 2024 12:41:38 +0200 Subject: [PATCH 03/14] feat(PN-10623): wip on senderDenomination field --- .../PreliminaryInformations.tsx | 17 ++++-- .../pn-pa-webapp/src/redux/auth/reducers.ts | 2 + yarn.lock | 61 +++---------------- 3 files changed, 24 insertions(+), 56 deletions(-) diff --git a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx index 3cad94ba52..b7bc2c420d 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx @@ -53,6 +53,7 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { const hasGroups = useAppSelector( (state: RootState) => state.userState.user.organization.hasGroups ); + const senderDenomination = useAppSelector((state: RootState) => state.userState.user.organization.parentDescription ? state.userState.user.organization.parentDescription + @@ -134,6 +135,13 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { fetchGroups(); }, [fetchGroups]); + const checkIsLessThan80Chars = (field: string | undefined) => { + if (field) { + return field.length < 80; + } else { + return false; + } + }; return ( { value={formik.values.senderDenomination} onChange={handleChangeTouched} error={ - formik.values.senderDenomination.length > 80 && + checkIsLessThan80Chars(formik.values.senderDenomination) && Boolean(formik.errors.senderDenomination) } - disabled={formik.values.senderDenomination.length < 80} + disabled={checkIsLessThan80Chars(formik.values.senderDenomination)} helperText={ - (formik.touched.senderDenomination && formik.errors.senderDenomination) || - (formik.values.senderDenomination.length > 80 && formik.errors.senderDenomination) + (!checkIsLessThan80Chars(formik.values.senderDenomination) && + formik.errors.senderDenomination) || + (formik.touched.senderDenomination && formik.errors.senderDenomination) } size="small" margin="normal" diff --git a/packages/pn-pa-webapp/src/redux/auth/reducers.ts b/packages/pn-pa-webapp/src/redux/auth/reducers.ts index 762c67ac2e..f64d89d528 100644 --- a/packages/pn-pa-webapp/src/redux/auth/reducers.ts +++ b/packages/pn-pa-webapp/src/redux/auth/reducers.ts @@ -106,6 +106,8 @@ const userSlice = createSlice({ userDataMatcher.validateSync(user, { stripUnknown: false }); sessionStorage.setItem('user', JSON.stringify(user)); state.user = action.payload; + state.user.organization.parentDescription = + 'Commissario Straordinario del Governo ZES Sicilia Occidentale'; } catch (e) { state.isUnauthorizedUser = true; state.messageUnauthorizedUser = emptyUnauthorizedMessage; diff --git a/yarn.lock b/yarn.lock index 4af123b476..022ae48031 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2852,7 +2852,7 @@ "@types/react" "*" hoist-non-react-statics "^3.3.0" -"@types/istanbul-lib-coverage@^2.0.0": +"@types/istanbul-lib-coverage@*", "@types/istanbul-lib-coverage@^2.0.0": version "2.0.6" resolved "https://registry.yarnpkg.com/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.6.tgz#7739c232a1fee9b4d3ce8985f314c0c6d33549d7" integrity sha512-2QF/t/auWm0lsy8XtKVPG19v3sSOQlJe/YHZgfjb/KBBHOGSV+J2q/S671rcq9uTBrLAXmZpqJiaQbMT+zNU1w== @@ -2862,6 +2862,13 @@ resolved "https://registry.npmjs.org/@types/istanbul-lib-coverage/-/istanbul-lib-coverage-2.0.4.tgz" integrity sha512-z/QT1XN4K4KYuslS23k62yDIDLwLFkzxOuMplDtObz0+y7VqJCaO2o+SPwHCvLFZh7xazvvoor2tA/hPz9ee7g== +"@types/istanbul-lib-report@*": + version "3.0.3" + resolved "https://registry.yarnpkg.com/@types/istanbul-lib-report/-/istanbul-lib-report-3.0.3.tgz#53047614ae72e19fc0401d872de3ae2b4ce350bf" + integrity sha512-NQn7AHQnk/RSLOxrBbGyJM/aVQ+pjj5HCgasFxc0K/KhoATfQ/47AyUl15I2yBUpihjmas+a+VJBOqecrFH+uA== + dependencies: + "@types/istanbul-lib-coverage" "*" + "@types/istanbul-reports@^3.0.0": version "3.0.4" resolved "https://registry.yarnpkg.com/@types/istanbul-reports/-/istanbul-reports-3.0.4.tgz#0f03e3d2f670fbdac586e34b433783070cc16f54" @@ -3541,11 +3548,6 @@ available-typed-arrays@^1.0.5: resolved "https://registry.yarnpkg.com/available-typed-arrays/-/available-typed-arrays-1.0.5.tgz#92f95616501069d07d10edb2fc37d3e1c65123b7" integrity sha512-DMD0KiN46eipeziST1LPP/STfDU0sufISXmjSgvVsoU2tqxctQeASejWcfNtxYKqETM1UxQ8sp2OrSBWpHY6sw== -axe-core@4.4.1: - version "4.4.1" - resolved "https://registry.yarnpkg.com/axe-core/-/axe-core-4.4.1.tgz#7dbdc25989298f9ad006645cd396782443757413" - integrity sha512-gd1kmb21kwNuWr6BQz8fv6GNECPBnUasepcoLbekws23NVBLODdsClRZ+bQ8+9Uomf3Sm3+Vwn0oYG9NvwnJCw== - axios-mock-adapter@^1.22.0: version "1.22.0" resolved "https://registry.yarnpkg.com/axios-mock-adapter/-/axios-mock-adapter-1.22.0.tgz#0f3e6be0fc9b55baab06f2d49c0b71157e7c053d" @@ -4438,11 +4440,6 @@ detect-indent@^5.0.0: resolved "https://registry.npmjs.org/detect-indent/-/detect-indent-5.0.0.tgz" integrity sha1-OHHMCmoALow+Wzz38zYmRnXwa50= -diff-sequences@^27.5.1: - version "27.5.1" - resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-27.5.1.tgz#eaecc0d327fd68c8d9672a1e64ab8dccb2ef5327" - integrity sha512-k1gCAXAsNgLwEL+Y8Wvl+M6oEFj5bgazfZULpS5CneoPPXRaCCW7dm+q21Ky2VEE5X+VeRDBVg1Pcvvsr4TtNQ== - diff-sequences@^29.6.3: version "29.6.3" resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-29.6.3.tgz#4deaf894d11407c51efc8418012f9e70b84ea921" @@ -6259,26 +6256,6 @@ javascript-natural-sort@0.7.1: resolved "https://registry.yarnpkg.com/javascript-natural-sort/-/javascript-natural-sort-0.7.1.tgz#f9e2303d4507f6d74355a73664d1440fb5a0ef59" integrity sha512-nO6jcEfZWQXDhOiBtG2KvKyEptz7RVbpGP4vTD2hLBdmNQSsCiicO2Ioinv6UI4y9ukqnBpy+XZ9H6uLNgJTlw== -jest-axe@^6.0.0: - version "6.0.1" - resolved "https://registry.yarnpkg.com/jest-axe/-/jest-axe-6.0.1.tgz#54a8b7dc09afd6190b21f38b51b8bddc2d923834" - integrity sha512-+KcRAdZeKXBbtHTmMkokRq5/hXHaVFpX+WS2o3uvhkmF3szdr4+TYAz+QuOTeM0B1d4YPoNmQWhGzSzxHJNZrA== - dependencies: - axe-core "4.4.1" - chalk "4.1.0" - jest-matcher-utils "27.0.2" - lodash.merge "4.6.2" - -jest-diff@^27.0.0, jest-diff@^27.0.2: - version "27.5.1" - resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-27.5.1.tgz#a07f5011ac9e6643cf8a95a462b7b1ecf6680def" - integrity sha512-m0NvkX55LDt9T4mctTEgnZk3fmEg3NRYutvMPWM/0iPnkFj2wIeF45O1718cMSOFO1vINkqmxqD8vE37uTEbqw== - dependencies: - chalk "^4.0.0" - diff-sequences "^27.5.1" - jest-get-type "^27.5.1" - pretty-format "^27.5.1" - jest-diff@^29.7.0: version "29.7.0" resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-29.7.0.tgz#017934a66ebb7ecf6f205e84699be10afd70458a" @@ -6289,26 +6266,11 @@ jest-diff@^29.7.0: jest-get-type "^29.6.3" pretty-format "^29.7.0" -jest-get-type@^27.0.1, jest-get-type@^27.5.1: - version "27.5.1" - resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-27.5.1.tgz#3cd613c507b0f7ace013df407a1c1cd578bcb4f1" - integrity sha512-2KY95ksYSaK7DMBWQn6dQz3kqAf3BB64y2udeG+hv4KfSOb9qwcYQstTJc1KCbsix+wLZWZYN8t7nwX3GOBLRw== - jest-get-type@^29.6.3: version "29.6.3" resolved "https://registry.yarnpkg.com/jest-get-type/-/jest-get-type-29.6.3.tgz#36f499fdcea197c1045a127319c0481723908fd1" integrity sha512-zrteXnqYxfQh7l5FHyL38jL39di8H8rHoecLH3JNxH3BwOrBsNeabdap5e0I23lD4HHI8W5VFBZqG4Eaq5LNcw== -jest-matcher-utils@27.0.2: - version "27.0.2" - resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-27.0.2.tgz#f14c060605a95a466cdc759acc546c6f4cbfc4f0" - integrity sha512-Qczi5xnTNjkhcIB0Yy75Txt+Ez51xdhOxsukN7awzq2auZQGPHcQrJ623PZj0ECDEMOk2soxWx05EXdXGd1CbA== - dependencies: - chalk "^4.0.0" - jest-diff "^27.0.2" - jest-get-type "^27.0.1" - pretty-format "^27.0.2" - jest-matcher-utils@^29.7.0: version "29.7.0" resolved "https://registry.yarnpkg.com/jest-matcher-utils/-/jest-matcher-utils-29.7.0.tgz#ae8fec79ff249fd592ce80e3ee474e83a6c44f12" @@ -6686,11 +6648,6 @@ lodash.ismatch@^4.4.0: resolved "https://registry.npmjs.org/lodash.ismatch/-/lodash.ismatch-4.4.0.tgz" integrity sha1-dWy1FQyjum8RCFp4hJZF8Yj4Xzc= -lodash.merge@4.6.2: - version "4.6.2" - resolved "https://registry.yarnpkg.com/lodash.merge/-/lodash.merge-4.6.2.tgz#558aa53b43b661e1925a0afdfa36a9a1085fe57a" - integrity sha512-0KpjqXRVvrYyCsX1swR/XTK0va6VQkQM6MNo7PqW77ByjAhoARA8EfrP1N4+KlKj8YS0ZUCtRT/YUuhyYDujIQ== - lodash@^4.17.14, lodash@^4.17.15, lodash@^4.17.19, lodash@^4.17.21: version "4.17.21" resolved "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz" @@ -7991,7 +7948,7 @@ pretty-format@29.4.3: ansi-styles "^5.0.0" react-is "^18.0.0" -pretty-format@^27.0.0, pretty-format@^27.0.2, pretty-format@^27.5.1: +pretty-format@^27.0.2: version "27.5.1" resolved "https://registry.npmjs.org/pretty-format/-/pretty-format-27.5.1.tgz" integrity sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ== From 10d477c8501b89db35068b1bec5e6d9cb71767fa Mon Sep 17 00:00:00 2001 From: Sarah Donvito Date: Wed, 17 Apr 2024 13:36:08 +0200 Subject: [PATCH 04/14] feat(PN-10623): fix field for senderDenomination --- .../NewNotification/PreliminaryInformations.tsx | 10 +++++----- packages/pn-pa-webapp/src/redux/auth/reducers.ts | 2 -- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx index b7bc2c420d..0ee0717536 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx @@ -135,7 +135,7 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { fetchGroups(); }, [fetchGroups]); - const checkIsLessThan80Chars = (field: string | undefined) => { + const isLessThan80Chars = (field: string | undefined) => { if (field) { return field.length < 80; } else { @@ -177,18 +177,18 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { /> Date: Wed, 17 Apr 2024 13:56:00 +0200 Subject: [PATCH 05/14] feat(PN-10623): fix on tests --- packages/pn-pa-webapp/src/__mocks__/NewNotification.mock.ts | 1 + .../NewNotification/__test__/PreliminaryInformations.test.tsx | 3 +++ packages/pn-pa-webapp/src/models/NewNotification.ts | 4 ++-- packages/pn-pa-webapp/src/redux/newNotification/reducers.ts | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/pn-pa-webapp/src/__mocks__/NewNotification.mock.ts b/packages/pn-pa-webapp/src/__mocks__/NewNotification.mock.ts index a15b03d606..d1c3f79016 100644 --- a/packages/pn-pa-webapp/src/__mocks__/NewNotification.mock.ts +++ b/packages/pn-pa-webapp/src/__mocks__/NewNotification.mock.ts @@ -204,6 +204,7 @@ export const newNotificationEmpty: NewNotification = { group: '', taxonomyCode: '', notificationFeePolicy: '' as NotificationFeePolicy, + senderDenomination: '', }; export const newNotificationDTO: NewNotificationDTO = newNotificationMapper(newNotification); diff --git a/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformations.test.tsx b/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformations.test.tsx index bdb2e72dcd..9f85a9cee0 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformations.test.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformations.test.tsx @@ -59,6 +59,7 @@ const populateForm = async (form: HTMLFormElement, hasPayment: boolean) => { await testInput(form, 'paProtocolNumber', newNotification.paProtocolNumber); await testInput(form, 'subject', newNotification.subject); await testInput(form, 'taxonomyCode', newNotification.taxonomyCode); + await testInput(form, 'senderDenomination', newNotification.senderDenomination); await testSelect( form, 'group', @@ -196,6 +197,7 @@ describe('PreliminaryInformations component with payment enabled', async () => { recipients: [], physicalCommunicationType: PhysicalCommunicationType.AR_REGISTERED_LETTER, paymentMode: PaymentModel.PAGO_PA_NOTICE_F24_FLATRATE, + senderDenomination: newNotification.senderDenomination, }); }); expect(confirmHandlerMk).toBeCalledTimes(1); @@ -420,6 +422,7 @@ describe('PreliminaryInformations Component with payment disabled', async () => recipients: [], physicalCommunicationType: PhysicalCommunicationType.AR_REGISTERED_LETTER, paymentMode: PaymentModel.NOTHING, + senderDenomination: newNotification.senderDenomination, }); }); expect(confirmHandlerMk).toBeCalledTimes(1); diff --git a/packages/pn-pa-webapp/src/models/NewNotification.ts b/packages/pn-pa-webapp/src/models/NewNotification.ts index ac36869f78..8202e02e0b 100644 --- a/packages/pn-pa-webapp/src/models/NewNotification.ts +++ b/packages/pn-pa-webapp/src/models/NewNotification.ts @@ -1,10 +1,10 @@ import { DigitalDomicileType, + NotificationDetailDocument, NotificationDetailRecipient, NotificationFeePolicy, PhysicalCommunicationType, RecipientType, - NotificationDetailDocument, } from '@pagopa-pn/pn-commons'; export enum PaymentModel { @@ -22,7 +22,7 @@ interface BaseNewNotification { abstract?: string; cancelledIun?: string; physicalCommunicationType: PhysicalCommunicationType; - senderDenomination?: string; + senderDenomination: string; senderTaxId?: string; group?: string; taxonomyCode: string; diff --git a/packages/pn-pa-webapp/src/redux/newNotification/reducers.ts b/packages/pn-pa-webapp/src/redux/newNotification/reducers.ts index 54536893ab..8a4a59cd04 100644 --- a/packages/pn-pa-webapp/src/redux/newNotification/reducers.ts +++ b/packages/pn-pa-webapp/src/redux/newNotification/reducers.ts @@ -31,6 +31,7 @@ const initialState = { taxonomyCode: '', paymentMode: '' as PaymentModel, notificationFeePolicy: '' as NotificationFeePolicy, + senderDenomination: '', } as NewNotification, groups: [] as Array, isCompleted: false, From f62d712964a81832d6321a96f5a1592694f91a42 Mon Sep 17 00:00:00 2001 From: Sarah Donvito Date: Wed, 17 Apr 2024 14:19:42 +0200 Subject: [PATCH 06/14] feat(PN-10263): fix on tests --- .../src/redux/newNotification/__test__/reducers.test.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/pn-pa-webapp/src/redux/newNotification/__test__/reducers.test.ts b/packages/pn-pa-webapp/src/redux/newNotification/__test__/reducers.test.ts index fc0f5dbd8c..afd9fb4d9f 100644 --- a/packages/pn-pa-webapp/src/redux/newNotification/__test__/reducers.test.ts +++ b/packages/pn-pa-webapp/src/redux/newNotification/__test__/reducers.test.ts @@ -44,6 +44,7 @@ const initialState = { group: '', taxonomyCode: '', notificationFeePolicy: '', + senderDenomination: '', }, groups: [], isCompleted: false, From 98a72304560aea94496bf6658d6935fdf56e1484 Mon Sep 17 00:00:00 2001 From: Sarah Donvito Date: Wed, 17 Apr 2024 16:47:07 +0200 Subject: [PATCH 07/14] feat(PN-10623): change request --- .../NewNotification/PreliminaryInformations.tsx | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx index 0ee0717536..0fdad46202 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx @@ -135,13 +135,7 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { fetchGroups(); }, [fetchGroups]); - const isLessThan80Chars = (field: string | undefined) => { - if (field) { - return field.length < 80; - } else { - return false; - } - }; + const isLessThan80Chars = (field: string) => field && field.length < 80; return ( Date: Wed, 17 Apr 2024 19:15:21 +0200 Subject: [PATCH 08/14] feat(PN-10263): wip on tests --- .../src/__mocks__/NewNotification.mock.ts | 2 +- .../PreliminaryInformations.tsx | 8 ++- .../__test__/PreliminaryInformations.test.tsx | 50 ++++++++++++++++++- 3 files changed, 56 insertions(+), 4 deletions(-) diff --git a/packages/pn-pa-webapp/src/__mocks__/NewNotification.mock.ts b/packages/pn-pa-webapp/src/__mocks__/NewNotification.mock.ts index d1c3f79016..871150c1f2 100644 --- a/packages/pn-pa-webapp/src/__mocks__/NewNotification.mock.ts +++ b/packages/pn-pa-webapp/src/__mocks__/NewNotification.mock.ts @@ -204,7 +204,7 @@ export const newNotificationEmpty: NewNotification = { group: '', taxonomyCode: '', notificationFeePolicy: '' as NotificationFeePolicy, - senderDenomination: '', + senderDenomination: userResponse.organization.name, }; export const newNotificationDTO: NewNotificationDTO = newNotificationMapper(newNotification); diff --git a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx index 0fdad46202..e74105ae13 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx @@ -85,7 +85,11 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { const validationSchema = yup.object({ paProtocolNumber: requiredStringFieldValidation(tc, 256), subject: requiredStringFieldValidation(tc, 134, 10), - senderDenomination: requiredStringFieldValidation(tc, 80), + // senderDenomination: requiredStringFieldValidation(tc, 80), + senderDenomination: yup + .string() + .required(`${t('sender-denomination')} ${tc('required')}`) + .max(80, tc('too-long-field-error', { maxLength: 80 })), abstract: yup .string() .max(1024, tc('too-long-field-error', { maxLength: 1024 })) @@ -135,7 +139,7 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { fetchGroups(); }, [fetchGroups]); - const isLessThan80Chars = (field: string) => field && field.length < 80; + const isLessThan80Chars = (field: string): boolean => (field ? field.length < 80 : false); return ( { await testInput(form, 'paProtocolNumber', newNotification.paProtocolNumber); await testInput(form, 'subject', newNotification.subject); await testInput(form, 'taxonomyCode', newNotification.taxonomyCode); - await testInput(form, 'senderDenomination', newNotification.senderDenomination); + await testInput(form, 'senderDenomination', userResponse.organization.name); await testSelect( form, 'group', @@ -120,6 +121,7 @@ describe('PreliminaryInformations component with payment enabled', async () => { testFormElements(form, 'abstract', 'abstract'); testFormElements(form, 'group', 'group'); testFormElements(form, 'taxonomyCode', 'taxonomy-id*'); + testFormElements(form, 'senderDenomination', 'sender-denomination*'); testRadio(form, 'comunicationTypeRadio', ['registered-letter-890', 'simple-registered-letter']); testRadio(form, 'paymentMethodRadio', [ 'pagopa-notice', @@ -170,6 +172,7 @@ describe('PreliminaryInformations component with payment enabled', async () => { user: { organization: { hasGroup: true, + name: 'Comune di Milano', }, }, }, @@ -257,6 +260,16 @@ describe('PreliminaryInformations component with payment enabled', async () => { expect(taxonomyCodeError).toHaveTextContent('taxonomy-id required'); await testInput(form, 'taxonomyCode', randomString(4)); expect(taxonomyCodeError).toHaveTextContent('taxonomy-id invalid'); + // senderDenomination + await testInput(form, 'senderDenomination', ''); + const senderDenominationError = form.querySelector('#senderDenomination-helper-text'); + expect(senderDenominationError).toHaveTextContent('sender-denomination required'); + await testInput( + form, + 'senderDenomination', + 'Comune di Palermo - Commissario Straordinario del Governo ZES Sicilia Occidentale' + ); + expect(senderDenominationError).toHaveTextContent('too-long-field-error'); // check submit button state const button = within(form).getByTestId('step-submit'); expect(button).toBeDisabled(); @@ -273,6 +286,7 @@ describe('PreliminaryInformations component with payment enabled', async () => { user: { organization: { hasGroup: true, + name: 'Comune di Palermo', }, }, }, @@ -291,6 +305,12 @@ describe('PreliminaryInformations component with payment enabled', async () => { testFormElements(form, 'abstract', 'abstract', newNotification.abstract); testFormElements(form, 'group', 'group', newNotification.group); testFormElements(form, 'taxonomyCode', 'taxonomy-id*', newNotification.taxonomyCode); + testFormElements( + form, + 'senderDenomination', + 'sender-denomination*', + userResponse.organization.name + ); const physicalCommunicationType = form.querySelector( `input[name="physicalCommunicationType"][value="${newNotification.physicalCommunicationType}"]` ); @@ -427,4 +447,32 @@ describe('PreliminaryInformations Component with payment disabled', async () => }); expect(confirmHandlerMk).toBeCalledTimes(1); }); + + it('set senderDenomination longer than 80 characters', async () => { + mock.onGet(GET_USER_GROUPS(GroupStatus.ACTIVE)).reply(200, newNotificationGroups); + await act(async () => { + result = render( + , + { + preloadedState: { + userState: { + user: { + organization: { + hasGroup: true, + name: 'Comune di Palermo - Commissario Straordinario del Governo ZES Sicilia Occidentale', + }, + }, + }, + }, + } + ); + }); + const form = result.getByTestId('preliminaryInformationsForm') as HTMLFormElement; + const button = within(form).getByTestId('step-submit'); + await populateForm(form, true); + expect(button).toBeDisabled(); + }); }); From 0810853bb489ab5afb6e588f8d5577730dcec381 Mon Sep 17 00:00:00 2001 From: Sarah Donvito Date: Thu, 18 Apr 2024 16:34:14 +0200 Subject: [PATCH 09/14] feat(PN-10623): fix on tests --- .../pn-pa-webapp/src/__mocks__/Auth.mock.ts | 21 ++++++++++ .../__test__/PreliminaryInformations.test.tsx | 41 ++++++++----------- 2 files changed, 37 insertions(+), 25 deletions(-) diff --git a/packages/pn-pa-webapp/src/__mocks__/Auth.mock.ts b/packages/pn-pa-webapp/src/__mocks__/Auth.mock.ts index 9cf6f3973c..9381f01fea 100644 --- a/packages/pn-pa-webapp/src/__mocks__/Auth.mock.ts +++ b/packages/pn-pa-webapp/src/__mocks__/Auth.mock.ts @@ -68,3 +68,24 @@ export const userResponse: User = { }, desired_exp: calcExpirationDate(), }; +export const longOrganizationNameUserResponse: User = { + sessionToken: 'mocked-session-token', + name: 'giuseppe', + family_name: 'rossini', + fiscal_number: 'RSSGPP80B02G273H', + email: 'giuseppe.rossini@gmail.com', + uid: '00000000-0000-0000-0000-000000000000', + organization: { + id: '5b994d4a-0fa8-47ac-9c7b-354f1d44a1ce', + name: 'Comune di Palermo - Commissario Straordinario del Governo ZES Sicilia Occidentale', + roles: [ + { + partyRole: PartyRole.MANAGER, + role: PNRole.ADMIN, + }, + ], + fiscal_code: '80016350821', + hasGroups: false, + }, + desired_exp: calcExpirationDate(), +}; diff --git a/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformations.test.tsx b/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformations.test.tsx index df244104bc..7620ed4356 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformations.test.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/__test__/PreliminaryInformations.test.tsx @@ -14,7 +14,7 @@ import { testSelect, } from '@pagopa-pn/pn-commons/src/test-utils'; -import { userResponse } from '../../../__mocks__/Auth.mock'; +import { longOrganizationNameUserResponse, userResponse } from '../../../__mocks__/Auth.mock'; import { newNotification, newNotificationEmpty, @@ -56,11 +56,15 @@ vi.mock('../../../services/configuration.service', async () => { }; }); -const populateForm = async (form: HTMLFormElement, hasPayment: boolean) => { +const populateForm = async ( + form: HTMLFormElement, + hasPayment: boolean, + organizationName: string = userResponse.organization.name +) => { await testInput(form, 'paProtocolNumber', newNotification.paProtocolNumber); await testInput(form, 'subject', newNotification.subject); await testInput(form, 'taxonomyCode', newNotification.taxonomyCode); - await testInput(form, 'senderDenomination', userResponse.organization.name); + await testInput(form, 'senderDenomination', organizationName); await testSelect( form, 'group', @@ -172,7 +176,6 @@ describe('PreliminaryInformations component with payment enabled', async () => { user: { organization: { hasGroup: true, - name: 'Comune di Milano', }, }, }, @@ -232,12 +235,12 @@ describe('PreliminaryInformations component with payment enabled', async () => { // set invalid values // paProtocolNumber await testInput(form, 'paProtocolNumber', ''); - const potrocolNumberError = form.querySelector('#paProtocolNumber-helper-text'); - expect(potrocolNumberError).toHaveTextContent('required-field'); + const protocolNumberError = form.querySelector('#paProtocolNumber-helper-text'); + expect(protocolNumberError).toHaveTextContent('required-field'); await testInput(form, 'paProtocolNumber', ' text-with-spaces '); - expect(potrocolNumberError).toHaveTextContent('no-spaces-at-edges'); + expect(protocolNumberError).toHaveTextContent('no-spaces-at-edges'); await testInput(form, 'paProtocolNumber', randomString(257)); - expect(potrocolNumberError).toHaveTextContent('too-long-field-error'); + expect(protocolNumberError).toHaveTextContent('too-long-field-error'); // subject await testInput(form, 'subject', ''); const subjectError = form.querySelector('#subject-helper-text'); @@ -452,27 +455,15 @@ describe('PreliminaryInformations Component with payment disabled', async () => mock.onGet(GET_USER_GROUPS(GroupStatus.ACTIVE)).reply(200, newNotificationGroups); await act(async () => { result = render( - , - { - preloadedState: { - userState: { - user: { - organization: { - hasGroup: true, - name: 'Comune di Palermo - Commissario Straordinario del Governo ZES Sicilia Occidentale', - }, - }, - }, - }, - } + ); }); const form = result.getByTestId('preliminaryInformationsForm') as HTMLFormElement; + await testInput(form, 'senderDenomination', longOrganizationNameUserResponse.organization.name); + const senderDenominationError = form.querySelector('#senderDenomination-helper-text'); + expect(senderDenominationError).toHaveTextContent('too-long-field-error'); const button = within(form).getByTestId('step-submit'); - await populateForm(form, true); + // check submit button state expect(button).toBeDisabled(); }); }); From 2b2aaba838b7009e1345d20a51424e4223e9c3c2 Mon Sep 17 00:00:00 2001 From: Sarah Donvito Date: Thu, 18 Apr 2024 18:57:52 +0200 Subject: [PATCH 10/14] feat(PN-10623): wip on senderDenomination field --- packages/pn-pa-webapp/src/redux/auth/reducers.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/pn-pa-webapp/src/redux/auth/reducers.ts b/packages/pn-pa-webapp/src/redux/auth/reducers.ts index 762c67ac2e..a7794bb095 100644 --- a/packages/pn-pa-webapp/src/redux/auth/reducers.ts +++ b/packages/pn-pa-webapp/src/redux/auth/reducers.ts @@ -161,6 +161,10 @@ const userSlice = createSlice({ }); builder.addCase(getInstitutions.fulfilled, (state, action) => { state.institutions = action.payload; + const currentInstitutionParentName = state.institutions.find( + (e) => e.id === state.user.organization.id + )?.parentName; + state.user.organization.parentDescription = currentInstitutionParentName; }); builder.addCase(getProductsOfInstitution.fulfilled, (state, action) => { state.productsOfInstitution = action.payload; From a4f6182ac45136154196f675764973cbbad8c273 Mon Sep 17 00:00:00 2001 From: Sarah Donvito Date: Fri, 19 Apr 2024 12:54:16 +0200 Subject: [PATCH 11/14] feat(PN-10623): use rootParent in senderDenomination --- .../NewNotification/PreliminaryInformations.tsx | 7 +++---- packages/pn-pa-webapp/src/redux/auth/reducers.ts | 8 ++++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx index e74105ae13..275cbd666f 100644 --- a/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx +++ b/packages/pn-pa-webapp/src/components/NewNotification/PreliminaryInformations.tsx @@ -55,8 +55,8 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { ); const senderDenomination = useAppSelector((state: RootState) => - state.userState.user.organization.parentDescription - ? state.userState.user.organization.parentDescription + + state.userState.user.organization.rootParent?.description + ? state.userState.user.organization.rootParent?.description + ' - ' + state.userState.user.organization.name : state.userState.user.organization.name @@ -85,7 +85,6 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { const validationSchema = yup.object({ paProtocolNumber: requiredStringFieldValidation(tc, 256), subject: requiredStringFieldValidation(tc, 134, 10), - // senderDenomination: requiredStringFieldValidation(tc, 80), senderDenomination: yup .string() .required(`${t('sender-denomination')} ${tc('required')}`) @@ -184,7 +183,7 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => { !isLessThan80Chars(formik.values.senderDenomination) && Boolean(formik.errors.senderDenomination) } - disabled={isLessThan80Chars(notification.senderDenomination)} + disabled={isLessThan80Chars(senderDenomination)} helperText={ (!isLessThan80Chars(formik.values.senderDenomination) && formik.errors.senderDenomination) || diff --git a/packages/pn-pa-webapp/src/redux/auth/reducers.ts b/packages/pn-pa-webapp/src/redux/auth/reducers.ts index a7794bb095..eb7a536125 100644 --- a/packages/pn-pa-webapp/src/redux/auth/reducers.ts +++ b/packages/pn-pa-webapp/src/redux/auth/reducers.ts @@ -161,10 +161,10 @@ const userSlice = createSlice({ }); builder.addCase(getInstitutions.fulfilled, (state, action) => { state.institutions = action.payload; - const currentInstitutionParentName = state.institutions.find( - (e) => e.id === state.user.organization.id - )?.parentName; - state.user.organization.parentDescription = currentInstitutionParentName; + // const currentInstitutionParentName = state.institutions.find( + // (e) => e.id === state.user.organization.id + // )?.parentName; + // state.user.organization.parentDescription = currentInstitutionParentName; }); builder.addCase(getProductsOfInstitution.fulfilled, (state, action) => { state.productsOfInstitution = action.payload; From a66910362691de206cd67d7dcee309b79dcaedf3 Mon Sep 17 00:00:00 2001 From: Sarah Donvito Date: Fri, 19 Apr 2024 13:11:59 +0200 Subject: [PATCH 12/14] feat(PN-10623): remove useless comment --- packages/pn-pa-webapp/src/redux/auth/reducers.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/packages/pn-pa-webapp/src/redux/auth/reducers.ts b/packages/pn-pa-webapp/src/redux/auth/reducers.ts index eb7a536125..762c67ac2e 100644 --- a/packages/pn-pa-webapp/src/redux/auth/reducers.ts +++ b/packages/pn-pa-webapp/src/redux/auth/reducers.ts @@ -161,10 +161,6 @@ const userSlice = createSlice({ }); builder.addCase(getInstitutions.fulfilled, (state, action) => { state.institutions = action.payload; - // const currentInstitutionParentName = state.institutions.find( - // (e) => e.id === state.user.organization.id - // )?.parentName; - // state.user.organization.parentDescription = currentInstitutionParentName; }); builder.addCase(getProductsOfInstitution.fulfilled, (state, action) => { state.productsOfInstitution = action.payload; From 1c99c0992dfab66f06c3d8cc50c17ddc5f0cae67 Mon Sep 17 00:00:00 2001 From: Sarah Donvito Date: Mon, 22 Apr 2024 11:08:25 +0200 Subject: [PATCH 13/14] fix(PN-10623): update user type and organization type in PA --- packages/pn-pa-webapp/src/pages/NewNotification.page.tsx | 4 ++-- packages/pn-pa-webapp/src/redux/auth/reducers.ts | 1 - packages/pn-pa-webapp/src/redux/auth/types.ts | 1 - 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/packages/pn-pa-webapp/src/pages/NewNotification.page.tsx b/packages/pn-pa-webapp/src/pages/NewNotification.page.tsx index 475fb0debc..69b8cc2406 100644 --- a/packages/pn-pa-webapp/src/pages/NewNotification.page.tsx +++ b/packages/pn-pa-webapp/src/pages/NewNotification.page.tsx @@ -91,8 +91,8 @@ const NewNotification = () => { useEffect(() => { dispatch( setSenderInfos({ - senderDenomination: organization.parentDescription - ? organization.parentDescription + ' - ' + organization.name + senderDenomination: organization.rootParent?.description + ? organization.rootParent?.description + ' - ' + organization.name : organization.name, senderTaxId: organization.fiscal_code, }) diff --git a/packages/pn-pa-webapp/src/redux/auth/reducers.ts b/packages/pn-pa-webapp/src/redux/auth/reducers.ts index 762c67ac2e..042345f96e 100644 --- a/packages/pn-pa-webapp/src/redux/auth/reducers.ts +++ b/packages/pn-pa-webapp/src/redux/auth/reducers.ts @@ -35,7 +35,6 @@ const organizationMatcher: yup.SchemaOf = yup.object({ groups: yup.array().of(yup.string()).notRequired(), name: yup.string().required(), hasGroups: yup.boolean(), - parentDescription: yup.string().notRequired(), aooParent: yup.string().notRequired(), subUnitCode: yup.string().notRequired(), subUnitType: yup.string().notRequired(), diff --git a/packages/pn-pa-webapp/src/redux/auth/types.ts b/packages/pn-pa-webapp/src/redux/auth/types.ts index 81e442a0e6..e484d52836 100644 --- a/packages/pn-pa-webapp/src/redux/auth/types.ts +++ b/packages/pn-pa-webapp/src/redux/auth/types.ts @@ -8,7 +8,6 @@ export interface User extends BasicUser { } export interface Organization { - parentDescription?: string; id: string; roles: Array; fiscal_code: string; // organization fiscal code From b0fdacf0f12c0deb7fd4ff0f3681ea4d5fde65f9 Mon Sep 17 00:00:00 2001 From: Carlotta Dimatteo Date: Mon, 22 Apr 2024 12:08:41 +0200 Subject: [PATCH 14/14] chore: added missing properties defined in schema --- packages/pn-pa-webapp/src/redux/auth/reducers.ts | 1 + packages/pn-pa-webapp/src/redux/auth/types.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/packages/pn-pa-webapp/src/redux/auth/reducers.ts b/packages/pn-pa-webapp/src/redux/auth/reducers.ts index 042345f96e..26dc1c8438 100644 --- a/packages/pn-pa-webapp/src/redux/auth/reducers.ts +++ b/packages/pn-pa-webapp/src/redux/auth/reducers.ts @@ -44,6 +44,7 @@ const organizationMatcher: yup.SchemaOf = yup.object({ description: yup.string().notRequired(), }) .notRequired(), + ipaCode: yup.string().notRequired() }); const userDataMatcher = yup diff --git a/packages/pn-pa-webapp/src/redux/auth/types.ts b/packages/pn-pa-webapp/src/redux/auth/types.ts index e484d52836..72a7deebd7 100644 --- a/packages/pn-pa-webapp/src/redux/auth/types.ts +++ b/packages/pn-pa-webapp/src/redux/auth/types.ts @@ -17,6 +17,7 @@ export interface Organization { subUnitCode?: string; subUnitType?: string; aooParent?: string; + ipaCode?: string; rootParent?: { id?: string; description?: string;