diff --git a/src/components/Tool/Appeal/Flow/ContactFlow.tsx b/src/components/Tool/Appeal/Flow/ContactFlow.tsx index b68b4f98a..10319643a 100644 --- a/src/components/Tool/Appeal/Flow/ContactFlow.tsx +++ b/src/components/Tool/Appeal/Flow/ContactFlow.tsx @@ -170,16 +170,12 @@ export const ContactFlow: React.FC = ({ 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 { diff --git a/src/components/Tool/Appeal/Modals/PledgeModal/PledgeModal.test.tsx b/src/components/Tool/Appeal/Modals/PledgeModal/PledgeModal.test.tsx index 2ece5f549..4dbc19987 100644 --- a/src/components/Tool/Appeal/Modals/PledgeModal/PledgeModal.test.tsx +++ b/src/components/Tool/Appeal/Modals/PledgeModal/PledgeModal.test.tsx @@ -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) => ( @@ -79,8 +94,8 @@ const Components = ({ }> onCall={mutationSpy} mocks={{ - UpdateAccountListPledge: updateAccountListPledge, - CreateAccountListPledge: createAccountListPledge, + UpdateAccountListPledge: { updateAccountListPledge }, + CreateAccountListPledge: { createAccountListPledge }, }} > @@ -152,16 +167,6 @@ describe('PledgeModal', () => { const { getByRole } = render( , ); @@ -191,14 +196,6 @@ describe('PledgeModal', () => { , ); @@ -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, }, }} />, @@ -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, }, }} />, diff --git a/src/components/Tool/Appeal/Modals/PledgeModal/PledgeModal.tsx b/src/components/Tool/Appeal/Modals/PledgeModal/PledgeModal.tsx index 1b90b3a68..3f655858e 100644 --- a/src/components/Tool/Appeal/Modals/PledgeModal/PledgeModal.tsx +++ b/src/components/Tool/Appeal/Modals/PledgeModal/PledgeModal.tsx @@ -118,23 +118,17 @@ export const PledgeModal: React.FC = ({ }, }, 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', }); @@ -163,23 +157,18 @@ export const PledgeModal: React.FC = ({ }, }, 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', }); diff --git a/src/components/Tool/Appeal/Shared/handleReceivedSnackBarNotifications/handleReceivedSnackBarNotifications.ts b/src/components/Tool/Appeal/Shared/handleReceivedSnackBarNotifications/handleReceivedSnackBarNotifications.ts index 9aeb30ae6..7087646cb 100644 --- a/src/components/Tool/Appeal/Shared/handleReceivedSnackBarNotifications/handleReceivedSnackBarNotifications.ts +++ b/src/components/Tool/Appeal/Shared/handleReceivedSnackBarNotifications/handleReceivedSnackBarNotifications.ts @@ -7,11 +7,13 @@ interface HandleReceivedSnackBarNotificationsProps { dbStatus: Maybe | undefined; selectedAppealStatus: AppealStatusEnum; t: TFunction; + enqueueSnackbar: (message: string, options?: OptionsObject) => void; } const handleReceivedSnackBarNotifications = ({ dbStatus, selectedAppealStatus, t, + enqueueSnackbar, }: HandleReceivedSnackBarNotificationsProps) => { let message = ''; const snackbarOptions: OptionsObject = { @@ -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;