Skip to content

Commit

Permalink
fix: refactor interceptDispatch and add remaining profile properties
Browse files Browse the repository at this point in the history
  • Loading branch information
alessandrogelmi committed Mar 28, 2024
1 parent cc52eb5 commit b683cec
Show file tree
Hide file tree
Showing 30 changed files with 748 additions and 272 deletions.
7 changes: 4 additions & 3 deletions packages/pn-commons/src/services/tracking.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ function callMixpanelTrackingMethod(
mixpanel.track(event_name, properties);
break;
case EventPropertyType.PROFILE:
mixpanel.people.set({ event_name: properties });
mixpanel.people.set(properties);
break;
case EventPropertyType.INCREMENTAL:
const hasProperties =
Expand All @@ -33,7 +33,7 @@ function callMixpanelTrackingMethod(
mixpanel.people.increment(hasProperties ? { event_name: properties } : event_name);
break;
case EventPropertyType.SUPER_PROPERTY:
mixpanel.register({ event_name: properties });
mixpanel.register(properties);
break;
default:
mixpanel.track(event_name, properties);
Expand Down Expand Up @@ -77,7 +77,8 @@ export const interceptDispatch =
(action: PayloadAction<any, string, any>): void | PayloadAction<any, string, any> => {
if (eventsActionsMap[action.type]) {
const eventName = eventsActionsMap[action.type];
eventStrategyFactory.triggerEvent(eventName, action.payload);
const data = { payload: action.payload, params: action.meta?.arg };
eventStrategyFactory.triggerEvent(eventName, data);
}
return next(action);
};
21 changes: 20 additions & 1 deletion packages/pn-personafisica-webapp/src/models/PFEventsType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,30 @@ export enum PFEventsType {
SEND_HAS_MANDATE = 'SEND_HAS_MANDATE',
SEND_MANDATE_GIVEN = 'SEND_MANDATE_GIVEN',
SEND_HAS_ADDRESSES = 'SEND_HAS_ADDRESSES',
SEND_HAS_MANDATE_LOGIN = 'SEND_HAS_MANDATE_LOGIN',
SEND_ENABLE_IO = 'SEND_ENABLE_IO',
SEND_DISABLE_IO = 'SEND_DISABLE_IO',
SEND_ACCEPT_DELEGATION = 'SEND_ACCEPT_DELEGATION',
SEND_ADD_LEGAL_ADDRESS = 'SEND_ADD_LEGAL_ADDRESS',
SEND_REMOVE_LEGAL_ADDRESS = 'SEND_REMOVE_LEGAL_ADDRESS',
SEND_REMOVE_COURTESY_ADDRESS = 'SEND_REMOVE_COURTESY_ADDRESS',
SEND_ADD_COURTESY_ADDRESS = 'SEND_ADD_COURTESY_ADDRESS',
}

export const eventsActionsMap: Record<string, PFEventsType> = {
'getReceivedNotificationOtherDocument/fulfilled': PFEventsType.SEND_DOWNLOAD_RESPONSE,
'getReceivedNotificationLegalfact/fulfilled': PFEventsType.SEND_DOWNLOAD_RESPONSE,
'exchangeToken/fulfilled': PFEventsType.SEND_AUTH_SUCCESS,
'getDigitalAddresses/fulfilled': PFEventsType.SEND_HAS_ADDRESSES,

// --- PROFILE_PROPERTY
'getDomicileInfo/fulfilled': PFEventsType.SEND_HAS_ADDRESSES,
'getSidemenuInformation/fulfilled': PFEventsType.SEND_HAS_MANDATE_LOGIN,
'getDelegates/fulfilled': PFEventsType.SEND_MANDATE_GIVEN,
'enableIOAddress/fulfilled': PFEventsType.SEND_ENABLE_IO,
'disableIOAddress/fulfilled': PFEventsType.SEND_DISABLE_IO,
'acceptDelegation/fulfilled': PFEventsType.SEND_ACCEPT_DELEGATION,
'createOrUpdateLegalAddress/fulfilled': PFEventsType.SEND_ADD_LEGAL_ADDRESS,
'deleteLegalAddress/fulfilled': PFEventsType.SEND_REMOVE_LEGAL_ADDRESS,
'deleteCourtesyAddress/fulfilled': PFEventsType.SEND_REMOVE_COURTESY_ADDRESS,
'createOrUpdateCourtesyAddress/fulfilled': PFEventsType.SEND_ADD_COURTESY_ADDRESS,
};
25 changes: 4 additions & 21 deletions packages/pn-personafisica-webapp/src/redux/sidemenu/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,26 +34,9 @@ export const getDomicileInfo = createAsyncThunk<Array<DigitalAddress>>(
address.value !== IOAllowedValues.DISABLED);
const allAddresses = await ContactsApi.getDigitalAddresses();

const legalAddresses = allAddresses.legal.filter(isDefaultAddress);
const courtesyAddresses = allAddresses.courtesy.filter(isDefaultAddress);

// PFEventStrategyFactory.triggerEvent(PFEventsType.SEND_HAS_PEC, { legalAddresses }, [
// EventPropertyType.PROFILE,
// EventPropertyType.SUPER_PROPERTY,
// ]);
// PFEventStrategyFactory.triggerEvent(PFEventsType.SEND_HAS_SMS, courtesyAddresses, [
// EventPropertyType.PROFILE,
// EventPropertyType.SUPER_PROPERTY,
// ]);
// PFEventStrategyFactory.triggerEvent(PFEventsType.SEND_HAS_EMAIL, courtesyAddresses, [
// EventPropertyType.PROFILE,
// EventPropertyType.SUPER_PROPERTY,
// ]);
// PFEventStrategyFactory.triggerEvent(PFEventsType.SEND_HAS_IO, courtesyAddresses, [
// EventPropertyType.PROFILE,
// EventPropertyType.SUPER_PROPERTY,
// ]);

return [...legalAddresses, ...courtesyAddresses];
return [
...allAddresses.legal.filter(isDefaultAddress),
...allAddresses.courtesy.filter(isDefaultAddress),
];
})
);
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import { EventStrategy, EventStrategyFactory } from '@pagopa-pn/pn-commons';

import { PFEventsType } from '../../models/PFEventsType';
import { SendAcceptDelegationStrategy } from './Strategies/SendAcceptDelegationStrategy';
import { SendAddContactActionStrategy } from './Strategies/SendAddContactActionStrategy';
import { SendAddContactScreenViewStrategy } from './Strategies/SendAddContactScreenViewStrategy';
import { SendAddCourtesyAddressStrategy } from './Strategies/SendAddCourtesyAddressStrategy';
import { SendAddLegalAddressStrategy } from './Strategies/SendAddLegalAddressStrategy';
import { SendAddMandateUXConversionStrategy } from './Strategies/SendAddMandateUXConversionStrategy';
import { SendAddMandateUXSuccessStrategy } from './Strategies/SendAddMandateUXSuccessStrategy';
import { SendDisableIOStrategy } from './Strategies/SendDisableIOStrategy';
import { SendDownloadCertificateOpposable } from './Strategies/SendDownloadCertificateOpposable';
import { SendDownloadResponseStrategy } from './Strategies/SendDownloadResponse';
import { SendEnableIOStrategy } from './Strategies/SendEnableIOStrategy';
import { SendGenericErrorStrategy } from './Strategies/SendGenericErrorStrategy';
import { SendHasAddressesStrategy } from './Strategies/SendHasAddressesStrategy';
import { SendHasMandateGivenStrategy } from './Strategies/SendHasMandateGivensStrategy';
import { SendHasMandateLoginStrategy } from './Strategies/SendHasMandateLoginStrategy';
import { SendHasMandateStrategy } from './Strategies/SendHasMandateStrategy';
import { SendMandateGivenStrategy } from './Strategies/SendMandateGivenStrategy';
import { SendNotificationCountStrategy } from './Strategies/SendNotificationCount';
import { SendNotificationDetailStrategy } from './Strategies/SendNotificationDetailStrategy';
import { SendNotificationStatusDetailStrategy } from './Strategies/SendNotificationStatusDetail';
Expand All @@ -20,6 +26,8 @@ import { SendPaymentStatusStrategy } from './Strategies/SendPaymentStatusStrateg
import { SendPaymentsCountStrategy } from './Strategies/SendPaymentsCountStrategy';
import { SendRefreshPageStrategy } from './Strategies/SendRefreshPageStrategy';
import { SendRemoveContactSuccessStrategy } from './Strategies/SendRemoveContactSuccess';
import { SendRemoveCourtesyAddressStrategy } from './Strategies/SendRemoveCourtesyAddress';
import { SendRemoveLegalAddressStrategy } from './Strategies/SendRemoveLegalAddress';
import { SendServiceStatusStrategy } from './Strategies/SendServiceStatusStrategy';
import { SendToastErrorStrategy } from './Strategies/SendToastErrorStrategy';
import { SendViewContactDetailsStrategy } from './Strategies/SendViewContactDetailsStrategy';
Expand Down Expand Up @@ -139,14 +147,30 @@ class PFEventStrategyFactory extends EventStrategyFactory<PFEventsType> {

case PFEventsType.SEND_HAS_ADDRESSES:
return new SendHasAddressesStrategy();
case PFEventsType.SEND_HAS_MANDATE_LOGIN:
return new SendHasMandateLoginStrategy();
case PFEventsType.SEND_MANDATE_GIVEN:
return new SendHasMandateGivenStrategy();
case PFEventsType.SEND_HAS_MANDATE:
return new SendHasMandateStrategy();
case PFEventsType.SEND_DISABLE_IO:
return new SendDisableIOStrategy();
case PFEventsType.SEND_ENABLE_IO:
return new SendEnableIOStrategy();
case PFEventsType.SEND_ACCEPT_DELEGATION:
return new SendAcceptDelegationStrategy();
case PFEventsType.SEND_REMOVE_LEGAL_ADDRESS:
return new SendRemoveLegalAddressStrategy();
case PFEventsType.SEND_ADD_LEGAL_ADDRESS:
return new SendAddLegalAddressStrategy();
case PFEventsType.SEND_NOTIFICATIONS_COUNT:
return new SendNotificationCountStrategy();
case PFEventsType.SEND_PAYMENTS_COUNT:
return new SendPaymentsCountStrategy();
case PFEventsType.SEND_HAS_MANDATE:
return new SendHasMandateStrategy();
case PFEventsType.SEND_MANDATE_GIVEN:
return new SendMandateGivenStrategy();
case PFEventsType.SEND_REMOVE_COURTESY_ADDRESS:
return new SendRemoveCourtesyAddressStrategy();
case PFEventsType.SEND_ADD_COURTESY_ADDRESS:
return new SendAddCourtesyAddressStrategy();
default:
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { EventPropertyType, EventStrategy, TrackedEvent } from '@pagopa-pn/pn-commons';

type SendAcceptDelegation = {
SEND_HAS_MANDATE: 'yes';
};

export class SendAcceptDelegationStrategy implements EventStrategy {
performComputations(): TrackedEvent<SendAcceptDelegation> {
return {
[EventPropertyType.PROFILE]: {
SEND_HAS_MANDATE: 'yes',
},
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import { EventPropertyType, EventStrategy, TrackedEvent } from '@pagopa-pn/pn-commons';

import { CourtesyChannelType, DigitalAddress } from '../../../models/contacts';
import { SaveDigitalAddressParams } from '../../../redux/contact/types';

type SendAddCourtesyAddressReturn =
| {
SEND_HAS_EMAIL: 'yes';
}
| {
SEND_HAS_SMS: 'yes';
};

type SendAddCourtesyAddressData = {
payload: DigitalAddress | void;
params: SaveDigitalAddressParams;
};

export class SendAddCourtesyAddressStrategy implements EventStrategy {
performComputations({
payload,
params,
}: SendAddCourtesyAddressData): TrackedEvent<SendAddCourtesyAddressReturn> {
// Check payload to distinguish between the action called before PIN validation and after
// We have to track only the action after the PIN validation
if (!payload) {
return {};
}

if (params.channelType === CourtesyChannelType.EMAIL) {
return {
[EventPropertyType.PROFILE]: {
SEND_HAS_EMAIL: 'yes',
},
};
}

return {
[EventPropertyType.PROFILE]: {
SEND_HAS_SMS: 'yes',
},
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { EventPropertyType, EventStrategy, TrackedEvent } from '@pagopa-pn/pn-commons';

import { DigitalAddress } from '../../../models/contacts';

type SendAddLegalAddress = {
SEND_HAS_PEC: 'yes';
};

type SendAddLegalAddressData = {
payload: DigitalAddress | void;
};

export class SendAddLegalAddressStrategy implements EventStrategy {
performComputations({ payload }: SendAddLegalAddressData): TrackedEvent<SendAddLegalAddress> {
if (!(payload && payload.pecValid)) {
return {};
}

return {
[EventPropertyType.PROFILE]: { SEND_HAS_PEC: 'yes' },
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { EventPropertyType, EventStrategy, TrackedEvent } from '@pagopa-pn/pn-commons';

type SendDisableIO = {
SEND_APPIO_STATUS: 'deactivated';
};

export class SendDisableIOStrategy implements EventStrategy {
performComputations(): TrackedEvent<SendDisableIO> {
return {
[EventPropertyType.PROFILE]: {
SEND_APPIO_STATUS: 'deactivated',
},
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import {
} from '@pagopa-pn/pn-commons';

type SendDownloadResponse = {
url?: string;
docType?: string;
payload: {
url?: string;
docType?: string;
};
};

type SendDownloadResponseReturn = {
Expand All @@ -18,8 +20,7 @@ type SendDownloadResponseReturn = {

export class SendDownloadResponseStrategy implements EventStrategy {
performComputations({
url,
docType,
payload: { url, docType },
}: SendDownloadResponse): TrackedEvent<SendDownloadResponseReturn> {
return {
[EventPropertyType.TRACK]: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { EventPropertyType, EventStrategy, TrackedEvent } from '@pagopa-pn/pn-commons';

type SendEnableIO = {
SEND_APPIO_STATUS: 'activated';
};

export class SendEnableIOStrategy implements EventStrategy {
performComputations(): TrackedEvent<SendEnableIO> {
return {
[EventPropertyType.PROFILE]: {
SEND_APPIO_STATUS: 'activated',
},
};
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { EventPropertyType, EventStrategy, TrackedEvent } from '@pagopa-pn/pn-commons';

import { CourtesyChannelType, DigitalAddresses, IOAllowedValues } from '../../../models/contacts';
import {
CourtesyChannelType,
DigitalAddress,
IOAllowedValues,
LegalChannelType,
} from '../../../models/contacts';

type SendHasAddresses = {
SEND_HAS_PEC: 'yes' | 'no';
Expand All @@ -9,18 +14,19 @@ type SendHasAddresses = {
SEND_APPIO_STATUS: 'nd' | 'deactivated' | 'activated';
};

type SendHasAddressesData = {
payload: Array<DigitalAddress>;
};

export class SendHasAddressesStrategy implements EventStrategy {
performComputations(payload: DigitalAddresses): TrackedEvent<SendHasAddresses> {
const hasLegalAddresses = payload?.legal?.length > 0;
performComputations({ payload }: SendHasAddressesData): TrackedEvent<SendHasAddresses> {
const hasLegalAddresses =
payload.filter((address) => address.channelType === LegalChannelType.PEC).length > 0;
const hasCourtesyEmailAddresses =
payload?.courtesy?.filter((address) => address.channelType === CourtesyChannelType.EMAIL)
.length > 0;
payload.filter((address) => address.channelType === CourtesyChannelType.EMAIL).length > 0;
const hasCourtesySmsAddresses =
payload?.courtesy?.filter((address) => address.channelType === CourtesyChannelType.SMS)
.length > 0;
const contactIO = payload?.courtesy?.find(
(address) => address.channelType === CourtesyChannelType.IOMSG
);
payload?.filter((address) => address.channelType === CourtesyChannelType.SMS).length > 0;
const contactIO = payload?.find((address) => address.channelType === CourtesyChannelType.IOMSG);

// eslint-disable-next-line functional/no-let
let ioStatus: 'nd' | 'deactivated' | 'activated';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { EventPropertyType, EventStrategy, TrackedEvent } from '@pagopa-pn/pn-commons';

import { Delegation } from '../../../redux/delegation/types';
import { DelegationStatus } from '../../status.utility';

type SendHasMandateGiven = {
SEND_MANDATE_GIVEN: 'yes' | 'no';
};

type SendHasMandateGivenData = {
payload: Array<Delegation>;
};

export class SendHasMandateGivenStrategy implements EventStrategy {
performComputations({ payload }: SendHasMandateGivenData): TrackedEvent<SendHasMandateGiven> {
const hasDelegates = payload?.filter(
(delegation) => delegation.status === DelegationStatus.ACTIVE
);

return {
[EventPropertyType.PROFILE]: {
SEND_MANDATE_GIVEN: hasDelegates?.length > 0 ? 'yes' : 'no',
},
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { EventPropertyType, EventStrategy, TrackedEvent } from '@pagopa-pn/pn-commons';

import { Delegator } from '../../../redux/delegation/types';

type SendHasMandateLogin = {
SEND_HAS_MANDATE: 'yes' | 'no';
};

type SendHasMandateLoginData = {
payload: Array<Delegator>;
};

export class SendHasMandateLoginStrategy implements EventStrategy {
performComputations({ payload }: SendHasMandateLoginData): TrackedEvent<SendHasMandateLogin> {
return {
[EventPropertyType.PROFILE]: {
SEND_HAS_MANDATE: payload.length > 0 ? 'yes' : 'no',
},
};
}
}
Loading

0 comments on commit b683cec

Please sign in to comment.