From 671879ba4a30709c6bc1acc5dea5d4883edac1ea Mon Sep 17 00:00:00 2001 From: Caleb Cox Date: Tue, 3 Sep 2024 16:45:35 -0500 Subject: [PATCH] Reuse existing mutation --- .../[accountListId]/setup/Finish.graphql | 16 ---------------- .../[accountListId]/setup/finish.page.test.tsx | 15 +++++++++------ .../[accountListId]/setup/finish.page.tsx | 9 +++++---- 3 files changed, 14 insertions(+), 26 deletions(-) delete mode 100644 pages/accountLists/[accountListId]/setup/Finish.graphql diff --git a/pages/accountLists/[accountListId]/setup/Finish.graphql b/pages/accountLists/[accountListId]/setup/Finish.graphql deleted file mode 100644 index 0e6ad29d5..000000000 --- a/pages/accountLists/[accountListId]/setup/Finish.graphql +++ /dev/null @@ -1,16 +0,0 @@ -query DefaultAccountList { - user { - id - defaultAccountList - } -} - -mutation UpdateSetupPosition($setupPosition: String!) { - createOrUpdateUserOption( - input: { key: "setup_position", value: $setupPosition } - ) { - option { - id - } - } -} diff --git a/pages/accountLists/[accountListId]/setup/finish.page.test.tsx b/pages/accountLists/[accountListId]/setup/finish.page.test.tsx index 4fd33a291..ca36862b3 100644 --- a/pages/accountLists/[accountListId]/setup/finish.page.test.tsx +++ b/pages/accountLists/[accountListId]/setup/finish.page.test.tsx @@ -30,8 +30,9 @@ describe('Finish account page', () => { render(); await waitFor(() => - expect(mutationSpy).toHaveGraphqlOperation('UpdateSetupPosition', { - setupPosition: 'finish', + expect(mutationSpy).toHaveGraphqlOperation('UpdateUserOptions', { + key: 'setup_position', + value: 'finish', }), ); }); @@ -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( @@ -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}`); diff --git a/pages/accountLists/[accountListId]/setup/finish.page.tsx b/pages/accountLists/[accountListId]/setup/finish.page.tsx index df620e842..fd0c6faac 100644 --- a/pages/accountLists/[accountListId]/setup/finish.page.tsx +++ b/pages/accountLists/[accountListId]/setup/finish.page.tsx @@ -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. @@ -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, }, });