diff --git a/src/layouts/BaseLayout/BaseLayout.spec.jsx b/src/layouts/BaseLayout/BaseLayout.spec.jsx index ee55dabbc0..3221d75457 100644 --- a/src/layouts/BaseLayout/BaseLayout.spec.jsx +++ b/src/layouts/BaseLayout/BaseLayout.spec.jsx @@ -78,6 +78,7 @@ const internalUserHasSyncedProviders = { service: 'github', }, ], + termsAgreement: false, } const queryClient = new QueryClient({ diff --git a/src/layouts/BaseLayout/hooks/useUserAccessGate.js b/src/layouts/BaseLayout/hooks/useUserAccessGate.js index 08bdfdf1d0..c2bd947465 100644 --- a/src/layouts/BaseLayout/hooks/useUserAccessGate.js +++ b/src/layouts/BaseLayout/hooks/useUserAccessGate.js @@ -73,13 +73,8 @@ const useUserAccessGate = () => { // the undefined provider check can be removed when the ToS has // been refactored to no longer use a provider - if ( - termsOfServicePage && - !isUndefined(provider) && - !isGuest && - !config.IS_SELF_HOSTED - ) { - showAgreeToTerms = userData?.termsAgreement === false + if (termsOfServicePage && !isGuest && !config.IS_SELF_HOSTED) { + showAgreeToTerms = internalUser?.termsAgreement === false } const onSyncPage = currentRoute.path === '/sync' diff --git a/src/layouts/BaseLayout/hooks/useUserAccessGate.spec.tsx b/src/layouts/BaseLayout/hooks/useUserAccessGate.spec.tsx index 3f350f6cb5..b8f59be8d1 100644 --- a/src/layouts/BaseLayout/hooks/useUserAccessGate.spec.tsx +++ b/src/layouts/BaseLayout/hooks/useUserAccessGate.spec.tsx @@ -160,6 +160,30 @@ const internalUserHasSyncedProviders = { ], } +const internalUserWithSignedTOS = { + email: userSignedInIdentity.email, + name: userSignedInIdentity.name, + externalId: '123', + owners: [ + { + service: 'github', + }, + ], + termsAgreement: true, +} + +const internalUserWithUnsignedTOS = { + email: userSignedInIdentity.email, + name: userSignedInIdentity.name, + externalId: '123', + owners: [ + { + service: 'github', + }, + ], + termsAgreement: false, +} + type InternalUser = | typeof internalUserNoSyncedProviders | typeof internalUserHasSyncedProviders @@ -249,7 +273,7 @@ describe('useUserAccessGate', () => { 'signed TOS', { user: loggedInUser, - internalUser: internalUserHasSyncedProviders, + internalUser: internalUserWithSignedTOS, termsOfServicePage: true, isSelfHosted: false, defaultOrgSelectorPage: false, @@ -361,7 +385,7 @@ describe('useUserAccessGate', () => { 'unsigned TOS', { user: loggedInUnsignedUser, - internalUser: internalUserHasSyncedProviders, + internalUser: internalUserWithUnsignedTOS, termsOfServicePage: true, isSelfHosted: false, defaultOrgSelectorPage: false, diff --git a/src/pages/TermsOfService/TermsOfService.jsx b/src/pages/TermsOfService/TermsOfService.jsx index 1aacdc2f6d..9ac09789e4 100644 --- a/src/pages/TermsOfService/TermsOfService.jsx +++ b/src/pages/TermsOfService/TermsOfService.jsx @@ -5,7 +5,7 @@ import { useForm } from 'react-hook-form' import { z } from 'zod' import umbrellaSvg from 'assets/svg/umbrella.svg' -import { useUser } from 'services/user' +import { useInternalUser } from 'services/user' import A from 'ui/A' import Button from 'ui/Button' import TextInput from 'ui/TextInput' @@ -18,8 +18,8 @@ const FormSchema = z.object({ tos: z.literal(true), }) -function isDisabled({ isValid, isDirty }) { - return (!isValid && isDirty) || !isDirty +function isDisabled({ isValid, isDirty, isMutationLoading }) { + return (!isValid && isDirty) || !isDirty || isMutationLoading } function EmailInput({ register, marketingEmailMessage, showEmailRequired }) { @@ -61,7 +61,7 @@ export default function TermsOfService() { resolver: zodResolver(FormSchema), mode: 'onChange', }) - const { mutate } = useSaveTermsAgreement({ + const { mutate, isLoading: isMutationLoading } = useSaveTermsAgreement({ onSuccess: ({ data }) => { if (data?.saveTermsAgreement?.error) { setError('apiError', data?.saveTermsAgreement?.error) @@ -70,12 +70,13 @@ export default function TermsOfService() { }, onError: (error) => setError('apiError', error), }) - const { data: currentUser, isLoading: userIsLoading } = useUser() + const { data: currentUser, isLoading: userIsLoading } = useInternalUser() const onSubmit = (data) => { mutate({ businessEmail: data?.marketingEmail || currentUser?.email, termsAgreement: true, + marketingConsent: data?.marketingConsent, }) } @@ -177,7 +178,7 @@ export default function TermsOfService() { )}