Skip to content

Commit

Permalink
Reuse existing mutation
Browse files Browse the repository at this point in the history
  • Loading branch information
canac committed Sep 4, 2024
1 parent 1c3d794 commit 671879b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 26 deletions.
16 changes: 0 additions & 16 deletions pages/accountLists/[accountListId]/setup/Finish.graphql

This file was deleted.

15 changes: 9 additions & 6 deletions pages/accountLists/[accountListId]/setup/finish.page.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ describe('Finish account page', () => {
render(<TestComponent />);

await waitFor(() =>
expect(mutationSpy).toHaveGraphqlOperation('UpdateSetupPosition', {
setupPosition: 'finish',
expect(mutationSpy).toHaveGraphqlOperation('UpdateUserOptions', {
key: 'setup_position',
value: 'finish',
}),
);
});
Expand All @@ -42,8 +43,9 @@ describe('Finish account page', () => {
userEvent.click(getByRole('button', { name: /Yes/ }));

await waitFor(() =>
expect(mutationSpy).toHaveGraphqlOperation('UpdateSetupPosition', {
setupPosition: '',
expect(mutationSpy).toHaveGraphqlOperation('UpdateUserOptions', {
key: 'setup_position',
value: '',
}),
);
expect(push).toHaveBeenCalledWith(
Expand All @@ -57,8 +59,9 @@ describe('Finish account page', () => {
userEvent.click(getByRole('button', { name: /Nope/ }));

await waitFor(() =>
expect(mutationSpy).toHaveGraphqlOperation('UpdateSetupPosition', {
setupPosition: '',
expect(mutationSpy).toHaveGraphqlOperation('UpdateUserOptions', {
key: 'setup_position',
value: '',
}),
);
expect(push).toHaveBeenCalledWith(`/accountLists/${accountListId}`);
Expand Down
9 changes: 5 additions & 4 deletions pages/accountLists/[accountListId]/setup/finish.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import React, { useEffect } from 'react';
import { Button } from '@mui/material';
import { Trans, useTranslation } from 'react-i18next';
import { loadSession } from 'pages/api/utils/pagePropsHelpers';
import { useUpdateUserOptionsMutation } from 'src/components/Contacts/ContactFlow/ContactFlowSetup/UpdateUserOptions.generated';
import { SetupPage } from 'src/components/Setup/SetupPage';
import { LargeButton } from 'src/components/Setup/styledComponents';
import { useAccountListId } from 'src/hooks/useAccountListId';
import useGetAppSettings from 'src/hooks/useGetAppSettings';
import { useUpdateSetupPositionMutation } from './Finish.generated';

// This is the last page of the tour, and it lets users choose to go to the
// tools page. It is always shown.
Expand All @@ -17,12 +17,13 @@ const FinishPage: React.FC = () => {
const { appName } = useGetAppSettings();
const accountListId = useAccountListId();
const { push } = useRouter();
const [updateSetupPosition] = useUpdateSetupPositionMutation();
const [updateUserOptions] = useUpdateUserOptionsMutation();

const setSetupPosition = (setupPosition: string) =>
updateSetupPosition({
updateUserOptions({
variables: {
setupPosition,
key: 'setup_position',
value: setupPosition,
},
});

Expand Down

0 comments on commit 671879b

Please sign in to comment.