Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(PN-10623): implement field for senderDenomination #1186

Merged
merged 19 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
32a45f2
feat(PN-10623): wip on new field for senderDenomination
SarahDonvito Apr 11, 2024
7821559
feat(PN-10623): wip on senderDenomination field for PA
SarahDonvito Apr 12, 2024
134e8e5
Merge branch 'develop' of github.com:pagopa/pn-frontend into fix/PN-1…
SarahDonvito Apr 16, 2024
272912a
Merge branch 'develop' of github.com:pagopa/pn-frontend into fix/PN-1…
SarahDonvito Apr 17, 2024
55059e0
feat(PN-10623): wip on senderDenomination field
SarahDonvito Apr 17, 2024
f062e78
Merge branch 'develop' of github.com:pagopa/pn-frontend into fix/PN-1…
SarahDonvito Apr 17, 2024
10d477c
feat(PN-10623): fix field for senderDenomination
SarahDonvito Apr 17, 2024
dc79735
feat(PN-10623): fix on tests
SarahDonvito Apr 17, 2024
f62d712
feat(PN-10263): fix on tests
SarahDonvito Apr 17, 2024
2e80c99
Merge branch 'develop' of github.com:pagopa/pn-frontend into fix/PN-1…
SarahDonvito Apr 17, 2024
98a7230
feat(PN-10623): change request
SarahDonvito Apr 17, 2024
0801c40
feat(PN-10263): wip on tests
SarahDonvito Apr 17, 2024
e3dd060
Merge branch 'develop' of github.com:pagopa/pn-frontend into fix/PN-1…
SarahDonvito Apr 17, 2024
0810853
feat(PN-10623): fix on tests
SarahDonvito Apr 18, 2024
2b2aaba
feat(PN-10623): wip on senderDenomination field
SarahDonvito Apr 18, 2024
a4f6182
feat(PN-10623): use rootParent in senderDenomination
SarahDonvito Apr 19, 2024
a669103
feat(PN-10623): remove useless comment
SarahDonvito Apr 19, 2024
1c99c09
fix(PN-10623): update user type and organization type in PA
SarahDonvito Apr 22, 2024
b0fdacf
chore: added missing properties defined in schema
ZorbaDimatteo Apr 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/pn-pa-webapp/public/locales/it/notifiche.json
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,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",
Expand Down
21 changes: 21 additions & 0 deletions packages/pn-pa-webapp/src/__mocks__/Auth.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: '[email protected]',
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(),
};
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ export const newNotificationEmpty: NewNotification = {
group: '',
taxonomyCode: '',
notificationFeePolicy: '' as NotificationFeePolicy,
senderDenomination: userResponse.organization.name,
};

export const newNotificationDTO: NewNotificationDTO = newNotificationMapper(newNotification);
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => {
(state: RootState) => state.userState.user.organization.hasGroups
);

const senderDenomination = useAppSelector((state: RootState) =>
state.userState.user.organization.rootParent?.description
? state.userState.user.organization.rootParent?.description +
' - ' +
state.userState.user.organization.name
: state.userState.user.organization.name
);

const { t } = useTranslation(['notifiche'], {
keyPrefix: 'new-notification.steps.preliminary-informations',
});
Expand All @@ -64,6 +72,7 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => {
() => ({
paProtocolNumber: notification.paProtocolNumber || '',
subject: notification.subject || '',
senderDenomination,
abstract: notification.abstract ?? '',
group: notification.group ?? '',
taxonomyCode: notification.taxonomyCode || '',
Expand All @@ -76,6 +85,10 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => {
const validationSchema = yup.object({
paProtocolNumber: requiredStringFieldValidation(tc, 256),
subject: requiredStringFieldValidation(tc, 134, 10),
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 }))
Expand Down Expand Up @@ -125,6 +138,7 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => {
fetchGroups();
}, [fetchGroups]);

const isLessThan80Chars = (field: string): boolean => (field ? field.length < 80 : false);
return (
<ApiErrorWrapper
apiId={NEW_NOTIFICATION_ACTIONS.GET_USER_GROUPS}
Expand Down Expand Up @@ -158,6 +172,26 @@ const PreliminaryInformations = ({ notification, onConfirm }: Props) => {
size="small"
margin="normal"
/>
<TextField
id="senderDenomination"
label={`${t('sender-denomination')}*`}
fullWidth
name="senderDenomination"
value={formik.values.senderDenomination}
onChange={handleChangeTouched}
error={
!isLessThan80Chars(formik.values.senderDenomination) &&
Boolean(formik.errors.senderDenomination)
}
disabled={isLessThan80Chars(senderDenomination)}
helperText={
(!isLessThan80Chars(formik.values.senderDenomination) &&
formik.errors.senderDenomination) ||
(formik.touched.senderDenomination && formik.errors.senderDenomination)
}
size="small"
margin="normal"
/>
<TextField
id="abstract"
label={t('abstract')}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
testSelect,
} from '@pagopa-pn/pn-commons/src/test-utils';

import { longOrganizationNameUserResponse, userResponse } from '../../../__mocks__/Auth.mock';
import {
newNotification,
newNotificationEmpty,
Expand Down Expand Up @@ -55,10 +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', organizationName);
await testSelect(
form,
'group',
Expand Down Expand Up @@ -119,6 +125,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',
Expand Down Expand Up @@ -196,6 +203,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);
Expand Down Expand Up @@ -227,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');
Expand All @@ -255,6 +263,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();
Expand All @@ -271,6 +289,7 @@ describe('PreliminaryInformations component with payment enabled', async () => {
user: {
organization: {
hasGroup: true,
name: 'Comune di Palermo',
},
},
},
Expand All @@ -289,6 +308,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}"]`
);
Expand Down Expand Up @@ -420,8 +445,25 @@ describe('PreliminaryInformations Component with payment disabled', async () =>
recipients: [],
physicalCommunicationType: PhysicalCommunicationType.AR_REGISTERED_LETTER,
paymentMode: PaymentModel.NOTHING,
senderDenomination: newNotification.senderDenomination,
});
});
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(
<PreliminaryInformations notification={newNotificationEmpty} onConfirm={confirmHandlerMk} />
);
});
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');
// check submit button state
expect(button).toBeDisabled();
});
});
4 changes: 2 additions & 2 deletions packages/pn-pa-webapp/src/models/NewNotification.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
DigitalDomicileType,
NotificationDetailDocument,
NotificationDetailRecipient,
NotificationFeePolicy,
PhysicalCommunicationType,
RecipientType,
NotificationDetailDocument,
} from '@pagopa-pn/pn-commons';

export enum PaymentModel {
Expand All @@ -22,7 +22,7 @@ interface BaseNewNotification {
abstract?: string;
cancelledIun?: string;
physicalCommunicationType: PhysicalCommunicationType;
senderDenomination?: string;
senderDenomination: string;
senderTaxId?: string;
group?: string;
taxonomyCode: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/pn-pa-webapp/src/pages/NewNotification.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
Expand Down
2 changes: 1 addition & 1 deletion packages/pn-pa-webapp/src/redux/auth/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const organizationMatcher: yup.SchemaOf<Organization> = 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(),
Expand All @@ -45,6 +44,7 @@ const organizationMatcher: yup.SchemaOf<Organization> = yup.object({
description: yup.string().notRequired(),
})
.notRequired(),
ipaCode: yup.string().notRequired()
});

const userDataMatcher = yup
Expand Down
2 changes: 1 addition & 1 deletion packages/pn-pa-webapp/src/redux/auth/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ export interface User extends BasicUser {
}

export interface Organization {
parentDescription?: string;
id: string;
roles: Array<Role>;
fiscal_code: string; // organization fiscal code
Expand All @@ -18,6 +17,7 @@ export interface Organization {
subUnitCode?: string;
subUnitType?: string;
aooParent?: string;
ipaCode?: string;
rootParent?: {
id?: string;
description?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const initialState = {
group: '',
taxonomyCode: '',
notificationFeePolicy: '',
senderDenomination: '',
},
groups: [],
isCompleted: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const initialState = {
taxonomyCode: '',
paymentMode: '' as PaymentModel,
notificationFeePolicy: '' as NotificationFeePolicy,
senderDenomination: '',
} as NewNotification,
groups: [] as Array<UserGroup>,
isCompleted: false,
Expand Down