Skip to content

Commit

Permalink
ref: Update TOS to work for service less users. (#2321)
Browse files Browse the repository at this point in the history
* Update with service less requests

* Make sure hook supports service less

* feat: Add Flag MultiSelect to CommitPageTabs (#2303)

Add a feature flagged multi select to the CommitPageTabs component.

GH codecov/engineering-team#344

* Add patch column to pulls table (#2308)

* feat: add patch column to the pulls list page

* uncomment development settings

* feat: Create Team Plan Table for the Files Changed Table on the Commit Detail Page (#2309)

Create new commit fetching hooks for the team plan, as well as creating a new table for files changed tab on the
commit detail page for the new team plan.

GH codecov/engineering-team#633

* Setup pull request page to pass around selected flags (#2282)

* feat: setup pull request page to pass around selected flags in links

* Feedback, fix passing links to files+folders, additional testing

* fix file explorer test failing on href match due to new query param pass through

* airplane commit, cant check local dev server: Resolve merge issues / tests + unify codebases missed of commitSHA and commitSha to just commitSha

* Prevent multislect from collapsing + wire up PR details page to pass through flags links

* Fix accidental removal of ref on usePrefetchPullFileEntry

* Add patch column to pulls table (#2308)

* feat: add patch column to the pulls list page

* uncomment development settings

* feat: Create Team Plan Table for the Files Changed Table on the Commit Detail Page (#2309)

Create new commit fetching hooks for the team plan, as well as creating a new table for files changed tab on the
commit detail page for the new team plan.

GH codecov/engineering-team#633

---------

Co-authored-by: Adrian <[email protected]>
Co-authored-by: nicholas-codecov <[email protected]>

* chore: Remove segment from frontend (#2314)

* Update with tests

* test with support service less

* adjust logic to handle original route

* it's fine it works with no providers

---------

Co-authored-by: nicholas-codecov <[email protected]>
Co-authored-by: Adrian <[email protected]>
Co-authored-by: Terry <[email protected]>
  • Loading branch information
4 people committed Oct 31, 2023
1 parent bd0277c commit f79c32e
Show file tree
Hide file tree
Showing 10 changed files with 175 additions and 133 deletions.
1 change: 1 addition & 0 deletions src/layouts/BaseLayout/BaseLayout.spec.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ const internalUserHasSyncedProviders = {
service: 'github',
},
],
termsAgreement: false,
}

const queryClient = new QueryClient({
Expand Down
9 changes: 2 additions & 7 deletions src/layouts/BaseLayout/hooks/useUserAccessGate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
28 changes: 26 additions & 2 deletions src/layouts/BaseLayout/hooks/useUserAccessGate.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -249,7 +273,7 @@ describe('useUserAccessGate', () => {
'signed TOS',
{
user: loggedInUser,
internalUser: internalUserHasSyncedProviders,
internalUser: internalUserWithSignedTOS,
termsOfServicePage: true,
isSelfHosted: false,
defaultOrgSelectorPage: false,
Expand Down Expand Up @@ -361,7 +385,7 @@ describe('useUserAccessGate', () => {
'unsigned TOS',
{
user: loggedInUnsignedUser,
internalUser: internalUserHasSyncedProviders,
internalUser: internalUserWithUnsignedTOS,
termsOfServicePage: true,
isSelfHosted: false,
defaultOrgSelectorPage: false,
Expand Down
13 changes: 7 additions & 6 deletions src/pages/TermsOfService/TermsOfService.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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 }) {
Expand Down Expand Up @@ -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)
Expand All @@ -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,
})
}

Expand Down Expand Up @@ -177,7 +178,7 @@ export default function TermsOfService() {
)}
<div className="mt-3 flex justify-end">
<Button
disabled={isDisabled(formState)}
disabled={isDisabled(formState, isMutationLoading)}
type="submit"
hook="user signed tos"
>
Expand Down
Loading

0 comments on commit f79c32e

Please sign in to comment.