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

PN-13920 - Refactor redux and utility to handle new notification payments #1471

Merged
merged 9 commits into from
Feb 17, 2025
90 changes: 48 additions & 42 deletions packages/pn-pa-webapp/src/__mocks__/NewNotification.mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
NewNotificationDocument,
NewNotificationRecipient,
NotificationFeePolicy,
PaymentModel,
} from '../models/NewNotification';
import { UserGroup } from '../models/user';
import { newNotificationMapper } from '../utility/notification.utility';
Expand All @@ -35,6 +34,42 @@ export const newNotificationGroups: Array<UserGroup> = [
},
];

const newNotificationPagoPa: NewNotificationDocument = {
id: 'mocked-pagopa-id',
idx: 0,
name: 'mocked-name',
contentType: 'application/pdf',
file: {
data: new File([''], 'mocked-name', { type: 'application/pdf' }),
sha256: {
hashBase64: 'mocked-pa-sha256',
hashHex: '',
},
},
ref: {
key: '',
versionToken: '',
},
};

const newNotificationF24Standard: NewNotificationDocument = {
id: 'mocked-f24standard-id',
idx: 0,
name: 'mocked-name',
contentType: 'application/pdf',
file: {
data: new File([''], 'mocked-name', { type: 'application/pdf' }),
sha256: {
hashBase64: 'mocked-f24standard-sha256',
hashHex: '',
},
},
ref: {
key: '',
versionToken: '',
},
};

const newNotificationRecipients: Array<NewNotificationRecipient> = [
{
id: 'recipient.0',
Expand All @@ -53,6 +88,11 @@ const newNotificationRecipients: Array<NewNotificationRecipient> = [
municipalityDetails: '',
province: 'Roma',
foreignState: 'Italia',
payments: [
{
pagoPA: { ...newNotificationPagoPa },
},
],
},
{
id: 'recipient.1',
Expand All @@ -71,6 +111,12 @@ const newNotificationRecipients: Array<NewNotificationRecipient> = [
municipalityDetails: '',
province: 'Roma',
foreignState: 'Italia',
payments: [
{
pagoPA: { ...newNotificationPagoPa },
f24: { ...newNotificationF24Standard },
},
],
},
];

Expand Down Expand Up @@ -115,42 +161,6 @@ const newNotificationDocuments: Array<NewNotificationDocument> = [
},
];

const newNotificationPagoPa: NewNotificationDocument = {
id: 'mocked-pagopa-id',
idx: 0,
name: 'mocked-name',
contentType: 'application/pdf',
file: {
data: new File([''], 'mocked-name', { type: 'application/pdf' }),
sha256: {
hashBase64: 'mocked-pa-sha256',
hashHex: '',
},
},
ref: {
key: '',
versionToken: '',
},
};

const newNotificationF24Standard: NewNotificationDocument = {
id: 'mocked-f24standard-id',
idx: 0,
name: 'mocked-name',
contentType: 'application/pdf',
file: {
data: new File([''], 'mocked-name', { type: 'application/pdf' }),
sha256: {
hashBase64: 'mocked-f24standard-sha256',
hashHex: '',
},
},
ref: {
key: '',
versionToken: '',
},
};

export const payments = {
[newNotificationRecipients[0].taxId]: {
pagoPa: { ...newNotificationPagoPa },
Expand All @@ -168,7 +178,6 @@ export const newNotification: NewNotification = {
recipients: newNotificationRecipients,
documents: newNotificationDocuments,
physicalCommunicationType: PhysicalCommunicationType.REGISTERED_LETTER_890,
paymentMode: PaymentModel.NOTHING,
group: newNotificationGroups[2].id,
taxonomyCode: '010801N',
notificationFeePolicy: NotificationFeePolicy.FLAT_RATE,
Expand All @@ -185,12 +194,9 @@ export const newNotificationEmpty: NewNotification = {
subject: '',
recipients: [],
documents: [],
payment: {},
physicalCommunicationType: '' as PhysicalCommunicationType,
paymentMode: '' as PaymentModel,
physicalCommunicationType: PhysicalCommunicationType.REGISTERED_LETTER_890,
group: '',
taxonomyCode: '',
notificationFeePolicy: '' as NotificationFeePolicy,
senderDenomination: userResponse.organization.name,
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ const PaymentMethods: React.FC<Props> = ({

const handlePreviousStep = () => {
if (onPreviousStep) {
dispatch(setPaymentDocuments({ paymentDocuments: formatPaymentDocuments() }));
dispatch(setPaymentDocuments({ recipients: notification.recipients }));
onPreviousStep();
}
};
Expand Down Expand Up @@ -221,7 +221,7 @@ const PaymentMethods: React.FC<Props> = ({
// Maybe now the form is empty, but in the previous time the user went back
// from the payments step the form wasn't empty.
// Just in case, we clean the payment info from the Redux store
dispatch(setPaymentDocuments({ paymentDocuments: {} }));
// dispatch(setPaymentDocuments({ paymentDocuments: {} }));
dispatch(setIsCompleted());
} else {
// Beware! -
Expand Down Expand Up @@ -283,10 +283,10 @@ const PaymentMethods: React.FC<Props> = ({

useImperativeHandle(forwardedRef, () => ({
confirm() {
dispatch(setPaymentDocuments({ paymentDocuments: formatPaymentDocuments() }));
dispatch(setPaymentDocuments({ recipients: notification.recipients }));
},
}));

return (
<form onSubmit={formik.handleSubmit} data-testid="paymentMethodForm">
<NewNotificationCard
Expand Down
19 changes: 16 additions & 3 deletions packages/pn-pa-webapp/src/models/NewNotification.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,14 @@ export enum NotificationFeePolicy {
DELIVERY_MODE = 'DELIVERY_MODE',
}

enum PagoPaIntegrationMode {
NONE = 'NONE',
SYNC = 'SYNC',
ASYNC = 'ASYNC',
}

interface BaseNewNotification {
notificationFeePolicy: NotificationFeePolicy;
notificationFeePolicy?: NotificationFeePolicy;
idempotenceToken?: string;
paProtocolNumber: string;
subject: string;
Expand All @@ -38,6 +44,11 @@ export interface NewNotificationDTO extends BaseNewNotification {
additionalLanguages?: Array<string>;
}

export interface NewNotificationPayment {
pagoPA?: NewNotificationDocument;
f24?: NewNotificationDocument;
}

// New Notification
export interface NewNotificationRecipient {
id: string;
Expand All @@ -56,6 +67,7 @@ export interface NewNotificationRecipient {
municipalityDetails?: string;
province: string;
foreignState: string;
payments?: Array<NewNotificationPayment>;
}

export interface NewNotificationDocument {
Expand All @@ -77,10 +89,11 @@ export interface NewNotificationDocument {
}

export interface NewNotification extends BaseNewNotification, NewNotificationBilingualism {
paymentMode?: PaymentModel;
recipients: Array<NewNotificationRecipient>;
documents: Array<NewNotificationDocument>;
payment?: { [key: string]: PaymentObject };
paFee?: number;
vat?: number;
pagoPaIntMode?: PagoPaIntegrationMode;
}

export interface NewNotificationBilingualism {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ const initialState = {
subject: '',
recipients: [],
documents: [],
payment: {},
physicalCommunicationType: '',
paymentMode: '',
physicalCommunicationType: 'REGISTERED_LETTER_890',
group: '',
taxonomyCode: '',
notificationFeePolicy: '',
senderDenomination: '',
},
groups: [],
Expand Down Expand Up @@ -173,9 +170,9 @@ describe('New notification redux state tests', () => {
});

it('Should be able to save payment documents', () => {
const action = store.dispatch(setPaymentDocuments({ paymentDocuments: payments }));
const action = store.dispatch(setPaymentDocuments({ recipients: newNotification.recipients }));
expect(action.type).toBe('newNotificationSlice/setPaymentDocuments');
expect(action.payload).toEqual({ paymentDocuments: payments });
expect(action.payload).toEqual({ recipients: newNotification.recipients });
});

it('Should be able to upload payment document', async () => {
Expand Down Expand Up @@ -272,6 +269,7 @@ describe('New notification redux state tests', () => {
idempotenceToken: 'mocked-idempotenceToken',
};
const mappedNotification = newNotificationMapper(newNotification);

mock.onPost('/bff/v1/notifications/sent', mappedNotification).reply(200, mockResponse);
const action = await store.dispatch(createNewNotification(newNotification));
expect(action.type).toBe('createNewNotification/fulfilled');
Expand Down
35 changes: 13 additions & 22 deletions packages/pn-pa-webapp/src/redux/newNotification/reducers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import {
NewNotification,
NewNotificationDocument,
NewNotificationRecipient,
NotificationFeePolicy,
PaymentModel,
PaymentObject,
} from '../../models/NewNotification';
import { UserGroup } from '../../models/user';
import { getConfiguration } from '../../services/configuration.service';
Expand All @@ -19,22 +16,26 @@ import {
} from './actions';
import { PreliminaryInformationsPayload } from './types';

const initialState = {
type NewNotificationInitialState = {
loading: boolean;
notification: NewNotification;
groups: Array<UserGroup>;
isCompleted: boolean;
};

const initialState: NewNotificationInitialState = {
loading: false,
notification: {
paProtocolNumber: '',
subject: '',
recipients: [],
documents: [],
payment: {},
physicalCommunicationType: '' as PhysicalCommunicationType,
physicalCommunicationType: PhysicalCommunicationType.REGISTERED_LETTER_890,
group: '',
taxonomyCode: '',
paymentMode: '' as PaymentModel,
notificationFeePolicy: '' as NotificationFeePolicy,
senderDenomination: '',
} as NewNotification,
groups: [] as Array<UserGroup>,
},
groups: [],
isCompleted: false,
};

Expand All @@ -54,19 +55,9 @@ const newNotificationSlice = createSlice({
state.notification.senderTaxId = action.payload.senderTaxId;
},
setPreliminaryInformations: (state, action: PayloadAction<PreliminaryInformationsPayload>) => {
// TODO: capire la logica di set della fee policy sia corretta
state.notification = {
...state.notification,
...action.payload,
// PN-1835
// in questa fase la notificationFeePolicy viene assegnata di default a FLAT_RATE
// Carlotta Dimatteo 10/08/2022
notificationFeePolicy: NotificationFeePolicy.FLAT_RATE,
// reset payment data if payment mode has changed
payment:
state.notification.paymentMode !== action.payload.paymentMode
? {}
: state.notification.payment,
};
},
saveRecipients: (
Expand All @@ -86,11 +77,11 @@ const newNotificationSlice = createSlice({
},
setPaymentDocuments: (
state,
action: PayloadAction<{ paymentDocuments: { [key: string]: PaymentObject } }>
action: PayloadAction<{ recipients: Array<NewNotificationRecipient> }>
) => {
state.notification = {
...state.notification,
payment: action.payload.paymentDocuments,
recipients: action.payload.recipients,
};
},
setIsCompleted: (state) => {
Expand Down
Loading