Skip to content

Commit

Permalink
amendments
Browse files Browse the repository at this point in the history
  • Loading branch information
dr-bizz committed Sep 12, 2024
1 parent ae710d5 commit 7c1ec63
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 77 deletions.
16 changes: 6 additions & 10 deletions src/components/Tool/Appeal/Flow/ContactFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,12 @@ export const ContactFlow: React.FC<ContactFlowProps> = ({
const newStatus =
data.data?.updateAccountListPledge?.pledge.status;

const { message, snackbarOptions } =
handleReceivedSnackBarNotifications({
dbStatus: newStatus,
selectedAppealStatus: newAppealStatus,
t,
});

if (message) {
enqueueSnackbar(message, snackbarOptions);
}
handleReceivedSnackBarNotifications({
dbStatus: newStatus,
selectedAppealStatus: newAppealStatus,
t,
enqueueSnackbar,
});
},
});
} else {
Expand Down
61 changes: 27 additions & 34 deletions src/components/Tool/Appeal/Modals/PledgeModal/PledgeModal.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,33 @@ jest.mock('notistack', () => ({
},
}));

const defaultUpdateAccountListPledge = {
pledge: {
id: defaultPledge.id,
status: PledgeStatusEnum.NotReceived,
},
};
const defaultCreateAccountListPledge = {
pledge: {
id: 'abc',
status: PledgeStatusEnum.NotReceived,
amount: defaultPledge.amount,
amountCurrency: defaultPledge.amountCurrency,
},
};

interface ComponentsProps {
pledge?: AppealContactInfoFragment['pledges'][0];
selectedAppealStatus?: AppealStatusEnum;
updateAccountListPledge?: UpdateAccountListPledgeMutation;
createAccountListPledge?: CreateAccountListPledgeMutation;
updateAccountListPledge?: UpdateAccountListPledgeMutation['updateAccountListPledge'];
createAccountListPledge?: CreateAccountListPledgeMutation['createAccountListPledge'];
}

const Components = ({
pledge = undefined,
selectedAppealStatus,
updateAccountListPledge = {},
createAccountListPledge = {},
updateAccountListPledge = defaultUpdateAccountListPledge,
createAccountListPledge = defaultCreateAccountListPledge,
}: ComponentsProps) => (
<I18nextProvider i18n={i18n}>
<LocalizationProvider dateAdapter={AdapterLuxon}>
Expand All @@ -79,8 +94,8 @@ const Components = ({
}>
onCall={mutationSpy}
mocks={{
UpdateAccountListPledge: updateAccountListPledge,
CreateAccountListPledge: createAccountListPledge,
UpdateAccountListPledge: { updateAccountListPledge },
CreateAccountListPledge: { createAccountListPledge },
}}
>
<AppealsWrapper>
Expand Down Expand Up @@ -152,16 +167,6 @@ describe('PledgeModal', () => {
const { getByRole } = render(
<Components
selectedAppealStatus={AppealStatusEnum.ReceivedNotProcessed}
createAccountListPledge={{
createAccountListPledge: {
pledge: {
id: 'abc',
status: PledgeStatusEnum.NotReceived,
amount: defaultPledge.amount,
amountCurrency: defaultPledge.amountCurrency,
},
},
}}
/>,
);

Expand Down Expand Up @@ -191,14 +196,6 @@ describe('PledgeModal', () => {
<Components
pledge={defaultPledge}
selectedAppealStatus={AppealStatusEnum.ReceivedNotProcessed}
updateAccountListPledge={{
updateAccountListPledge: {
pledge: {
id: defaultPledge.id,
status: PledgeStatusEnum.NotReceived,
},
},
}}
/>,
);

Expand Down Expand Up @@ -226,11 +223,9 @@ describe('PledgeModal', () => {
pledge={defaultPledge}
selectedAppealStatus={AppealStatusEnum.NotReceived}
updateAccountListPledge={{
updateAccountListPledge: {
pledge: {
id: defaultPledge.id,
status: PledgeStatusEnum.ReceivedNotProcessed,
},
pledge: {
...defaultUpdateAccountListPledge.pledge,
status: PledgeStatusEnum.ReceivedNotProcessed,
},
}}
/>,
Expand Down Expand Up @@ -260,11 +255,9 @@ describe('PledgeModal', () => {
pledge={defaultPledge}
selectedAppealStatus={AppealStatusEnum.NotReceived}
updateAccountListPledge={{
updateAccountListPledge: {
pledge: {
id: defaultPledge.id,
status: PledgeStatusEnum.Processed,
},
pledge: {
...defaultUpdateAccountListPledge.pledge,
status: PledgeStatusEnum.Processed,
},
}}
/>,
Expand Down
47 changes: 18 additions & 29 deletions src/components/Tool/Appeal/Modals/PledgeModal/PledgeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,17 @@ export const PledgeModal: React.FC<PledgeModalProps> = ({
},
},
refetchQueries: ['Contacts', 'Appeal'],
update: (_, data) => {
const newStatus = data.data?.createAccountListPledge?.pledge.status;

onCompleted: ({ createAccountListPledge }) => {
const newStatus = createAccountListPledge?.pledge.status;
if (selectedAppealStatus) {
const { message, snackbarOptions } =
handleReceivedSnackBarNotifications({
dbStatus: newStatus,
selectedAppealStatus,
t,
});

if (message) {
enqueueSnackbar(message, snackbarOptions);
}
handleReceivedSnackBarNotifications({
dbStatus: newStatus,
selectedAppealStatus,
t,
enqueueSnackbar,
});
}
},
onCompleted: () => {

enqueueSnackbar(t('Successfully added commitment to appeal'), {
variant: 'success',
});
Expand Down Expand Up @@ -163,23 +157,18 @@ export const PledgeModal: React.FC<PledgeModalProps> = ({
},
},
refetchQueries: ['Contacts', 'Appeal'],
update: (_, data) => {
const newStatus = data.data?.updateAccountListPledge?.pledge.status;
onCompleted: ({ updateAccountListPledge }) => {
const newStatus = updateAccountListPledge?.pledge.status;

if (selectedAppealStatus) {
const { message, snackbarOptions } =
handleReceivedSnackBarNotifications({
dbStatus: newStatus,
selectedAppealStatus,
t,
});

if (message) {
enqueueSnackbar(message, snackbarOptions);
}
handleReceivedSnackBarNotifications({
dbStatus: newStatus,
selectedAppealStatus,
t,
enqueueSnackbar,
});
}
},
onCompleted: () => {

enqueueSnackbar(t('Successfully edited commitment'), {
variant: 'success',
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ interface HandleReceivedSnackBarNotificationsProps {
dbStatus: Maybe<PledgeStatusEnum> | undefined;
selectedAppealStatus: AppealStatusEnum;
t: TFunction;
enqueueSnackbar: (message: string, options?: OptionsObject) => void;
}
const handleReceivedSnackBarNotifications = ({
dbStatus,
selectedAppealStatus,
t,
enqueueSnackbar,
}: HandleReceivedSnackBarNotificationsProps) => {
let message = '';
const snackbarOptions: OptionsObject = {
Expand Down Expand Up @@ -40,10 +42,10 @@ const handleReceivedSnackBarNotifications = ({
'Unable to move contact to the "Committed" column as part of the pledge has been Received.',
);
}
return {
message,
snackbarOptions,
};

if (message) {
enqueueSnackbar(message, snackbarOptions);
}
};

export default handleReceivedSnackBarNotifications;

0 comments on commit 7c1ec63

Please sign in to comment.