Skip to content

Commit f60faec

Browse files
committed
check if correct invite id was provided
1 parent f644567 commit f60faec

File tree

3 files changed

+76
-78
lines changed

3 files changed

+76
-78
lines changed

www/src/components/Invite.tsx

Lines changed: 43 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
useInviteQuery,
1212
useRealizeInviteMutation,
1313
useSignupInviteMutation,
14+
InviteFragment,
1415
} from '../generated/graphql'
1516
import { setToken } from '../helpers/authentication'
1617

@@ -19,28 +20,13 @@ import { LoginPortal } from './users/LoginPortal'
1920
import { validatePassword } from './users/PasswordValidation'
2021
import { ConfirmPasswordField, SetPasswordField } from './users/Signup'
2122
import { WelcomeHeader } from './utils/WelcomeHeader'
22-
23-
function InvalidInvite() {
24-
return (
25-
<Flex
26-
width="100vw"
27-
height="100vh"
28-
justifyContent="center"
29-
alignItems="center"
30-
>
31-
This invite code is no longer valid
32-
</Flex>
33-
)
34-
}
23+
import { ApolloError } from '@apollo/client/errors'
24+
import LoadingIndicator from './utils/LoadingIndicator'
3525

3626
function ExistingInvite({
37-
invite: { account },
38-
id,
39-
user,
27+
invite: { id, account, user },
4028
}: {
41-
invite: InviteT
42-
id: any
43-
user: User
29+
invite: InviteFragment
4430
}) {
4531
const [mutation, { loading, error }] = useRealizeInviteMutation({
4632
variables: { id },
@@ -87,26 +73,54 @@ export default function Invite() {
8773
const [name, setName] = useState('')
8874
const [password, setPassword] = useState('')
8975
const [confirm, setConfirm] = useState('')
76+
9077
const [mutation, { loading, error }] = useSignupInviteMutation({
9178
variables: {
9279
inviteId: inviteId ?? '',
93-
attributes: {
94-
name,
95-
password,
96-
},
80+
attributes: { name, password },
9781
},
9882
onCompleted: ({ signup }) => {
9983
setToken(signup?.jwt)
10084
;(window as Window).location = '/'
10185
},
10286
})
10387

104-
const { data, error: inviteError } = useInviteQuery({
88+
const {
89+
data,
90+
loading: inviteLoading,
91+
error: inviteError,
92+
} = useInviteQuery({
10593
variables: { id: inviteId ?? '' },
10694
})
10795

108-
if (inviteError) return <InvalidInvite />
109-
if (!data) return null
96+
const invite = data?.invite
97+
98+
if (!data && inviteLoading) return <LoadingIndicator />
99+
100+
if (inviteError)
101+
return (
102+
<Flex
103+
grow={1}
104+
alignItems="center"
105+
justifyContent="center"
106+
>
107+
<GqlError
108+
error={error}
109+
header="Could not load invite"
110+
/>
111+
</Flex>
112+
)
113+
114+
if (!invite)
115+
return (
116+
<Flex
117+
grow={1}
118+
alignItems="center"
119+
justifyContent="center"
120+
>
121+
This invite code does not exist or is no longer valid
122+
</Flex>
123+
)
110124

111125
const { disabled: passwordDisabled, error: passwordError } = validatePassword(
112126
password,
@@ -116,15 +130,7 @@ export default function Invite() {
116130
const isNameValid = name.length > 0
117131
const submitEnabled = isNameValid && !passwordDisabled
118132

119-
if (data?.invite?.user) {
120-
return (
121-
<ExistingInvite
122-
invite={data?.invite as InviteT}
123-
id={inviteId}
124-
user={data?.invite?.user as User}
125-
/>
126-
)
127-
}
133+
if (invite?.user) return <ExistingInvite invite={invite} />
128134

129135
const onSubmit = (e) => {
130136
e.preventDefault()
@@ -145,7 +151,7 @@ export default function Invite() {
145151
body1
146152
color="text-xlight"
147153
>
148-
{data.invite?.account?.name} invited you to join their Plural account.
154+
{invite.account?.name} invited you to join their Plural account.
149155
Create an account to join.
150156
</P>
151157
</Div>
@@ -165,7 +171,7 @@ export default function Invite() {
165171
>
166172
<LabelledInput
167173
label="Email"
168-
value={data?.invite?.email}
174+
value={invite.email}
169175
disabled
170176
/>
171177
<LabelledInput

www/src/generated/graphql.ts

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5646,21 +5646,21 @@ export type CreateOauthIntegrationMutationVariables = Exact<{
56465646

56475647
export type CreateOauthIntegrationMutation = { __typename?: 'RootMutationType', createOauthIntegration?: { __typename?: 'OauthIntegration', id: string, service: OauthService, insertedAt?: Date | null } | null };
56485648

5649-
export type InviteFragment = { __typename?: 'Invite', id: string, secureId?: string | null, email?: string | null, insertedAt?: Date | null, user?: { __typename?: 'User', id: string, name: string, email: string, avatar?: string | null, provider?: Provider | null, demoed?: boolean | null, onboarding?: OnboardingState | null, emailConfirmed?: boolean | null, emailConfirmBy?: Date | null, backgroundColor?: string | null, serviceAccount?: boolean | null, hasInstallations?: boolean | null, hasShell?: boolean | null, onboardingChecklist?: { __typename?: 'OnboardingChecklist', dismissed?: boolean | null, status?: OnboardingChecklistState | null } | null, invites?: Array<{ __typename?: 'Invite', id: string, email?: string | null } | null> | null, roles?: { __typename?: 'Roles', admin?: boolean | null } | null, groups?: Array<{ __typename?: 'Group', id: string, name: string, global?: boolean | null, description?: string | null } | null> | null, impersonationPolicy?: { __typename?: 'ImpersonationPolicy', id: string, bindings?: Array<{ __typename?: 'ImpersonationPolicyBinding', id: string, group?: { __typename?: 'Group', id: string, name: string } | null, user?: { __typename?: 'User', id: string, name: string, email: string } | null } | null> | null } | null } | null };
5649+
export type InviteFragment = { __typename?: 'Invite', id: string, secureId?: string | null, email?: string | null, existing: boolean, insertedAt?: Date | null, account?: { __typename?: 'Account', id: string, name?: string | null, billingCustomerId?: string | null, backgroundColor?: string | null, userCount?: string | null, trialed?: boolean | null } | null, user?: { __typename?: 'User', id: string, name: string, email: string, avatar?: string | null, provider?: Provider | null, demoed?: boolean | null, onboarding?: OnboardingState | null, emailConfirmed?: boolean | null, emailConfirmBy?: Date | null, backgroundColor?: string | null, serviceAccount?: boolean | null, hasInstallations?: boolean | null, hasShell?: boolean | null, account: { __typename?: 'Account', id: string, name?: string | null, billingCustomerId?: string | null, backgroundColor?: string | null, userCount?: string | null, trialed?: boolean | null }, onboardingChecklist?: { __typename?: 'OnboardingChecklist', dismissed?: boolean | null, status?: OnboardingChecklistState | null } | null, invites?: Array<{ __typename?: 'Invite', id: string, email?: string | null } | null> | null, roles?: { __typename?: 'Roles', admin?: boolean | null } | null, groups?: Array<{ __typename?: 'Group', id: string, name: string, global?: boolean | null, description?: string | null } | null> | null, impersonationPolicy?: { __typename?: 'ImpersonationPolicy', id: string, bindings?: Array<{ __typename?: 'ImpersonationPolicyBinding', id: string, group?: { __typename?: 'Group', id: string, name: string } | null, user?: { __typename?: 'User', id: string, name: string, email: string } | null } | null> | null } | null } | null };
56505650

56515651
export type InviteQueryVariables = Exact<{
56525652
id: Scalars['String']['input'];
56535653
}>;
56545654

56555655

5656-
export type InviteQuery = { __typename?: 'RootQueryType', invite?: { __typename?: 'Invite', id: string, email?: string | null, existing: boolean, account?: { __typename?: 'Account', id: string, name?: string | null, billingCustomerId?: string | null, backgroundColor?: string | null, userCount?: string | null, trialed?: boolean | null } | null, user?: { __typename?: 'User', id: string, name: string, email: string, avatar?: string | null, provider?: Provider | null, demoed?: boolean | null, onboarding?: OnboardingState | null, emailConfirmed?: boolean | null, emailConfirmBy?: Date | null, backgroundColor?: string | null, serviceAccount?: boolean | null, hasInstallations?: boolean | null, hasShell?: boolean | null, account: { __typename?: 'Account', id: string, name?: string | null, billingCustomerId?: string | null, backgroundColor?: string | null, userCount?: string | null, trialed?: boolean | null }, onboardingChecklist?: { __typename?: 'OnboardingChecklist', dismissed?: boolean | null, status?: OnboardingChecklistState | null } | null, invites?: Array<{ __typename?: 'Invite', id: string, email?: string | null } | null> | null, roles?: { __typename?: 'Roles', admin?: boolean | null } | null, groups?: Array<{ __typename?: 'Group', id: string, name: string, global?: boolean | null, description?: string | null } | null> | null, impersonationPolicy?: { __typename?: 'ImpersonationPolicy', id: string, bindings?: Array<{ __typename?: 'ImpersonationPolicyBinding', id: string, group?: { __typename?: 'Group', id: string, name: string } | null, user?: { __typename?: 'User', id: string, name: string, email: string } | null } | null> | null } | null } | null } | null };
5656+
export type InviteQuery = { __typename?: 'RootQueryType', invite?: { __typename?: 'Invite', id: string, secureId?: string | null, email?: string | null, existing: boolean, insertedAt?: Date | null, account?: { __typename?: 'Account', id: string, name?: string | null, billingCustomerId?: string | null, backgroundColor?: string | null, userCount?: string | null, trialed?: boolean | null } | null, user?: { __typename?: 'User', id: string, name: string, email: string, avatar?: string | null, provider?: Provider | null, demoed?: boolean | null, onboarding?: OnboardingState | null, emailConfirmed?: boolean | null, emailConfirmBy?: Date | null, backgroundColor?: string | null, serviceAccount?: boolean | null, hasInstallations?: boolean | null, hasShell?: boolean | null, account: { __typename?: 'Account', id: string, name?: string | null, billingCustomerId?: string | null, backgroundColor?: string | null, userCount?: string | null, trialed?: boolean | null }, onboardingChecklist?: { __typename?: 'OnboardingChecklist', dismissed?: boolean | null, status?: OnboardingChecklistState | null } | null, invites?: Array<{ __typename?: 'Invite', id: string, email?: string | null } | null> | null, roles?: { __typename?: 'Roles', admin?: boolean | null } | null, groups?: Array<{ __typename?: 'Group', id: string, name: string, global?: boolean | null, description?: string | null } | null> | null, impersonationPolicy?: { __typename?: 'ImpersonationPolicy', id: string, bindings?: Array<{ __typename?: 'ImpersonationPolicyBinding', id: string, group?: { __typename?: 'Group', id: string, name: string } | null, user?: { __typename?: 'User', id: string, name: string, email: string } | null } | null> | null } | null } | null } | null };
56575657

56585658
export type CreateInviteMutationVariables = Exact<{
56595659
attributes: InviteAttributes;
56605660
}>;
56615661

56625662

5663-
export type CreateInviteMutation = { __typename?: 'RootMutationType', createInvite?: { __typename?: 'Invite', id: string, secureId?: string | null, email?: string | null, insertedAt?: Date | null, user?: { __typename?: 'User', id: string, name: string, email: string, avatar?: string | null, provider?: Provider | null, demoed?: boolean | null, onboarding?: OnboardingState | null, emailConfirmed?: boolean | null, emailConfirmBy?: Date | null, backgroundColor?: string | null, serviceAccount?: boolean | null, hasInstallations?: boolean | null, hasShell?: boolean | null, onboardingChecklist?: { __typename?: 'OnboardingChecklist', dismissed?: boolean | null, status?: OnboardingChecklistState | null } | null, invites?: Array<{ __typename?: 'Invite', id: string, email?: string | null } | null> | null, roles?: { __typename?: 'Roles', admin?: boolean | null } | null, groups?: Array<{ __typename?: 'Group', id: string, name: string, global?: boolean | null, description?: string | null } | null> | null, impersonationPolicy?: { __typename?: 'ImpersonationPolicy', id: string, bindings?: Array<{ __typename?: 'ImpersonationPolicyBinding', id: string, group?: { __typename?: 'Group', id: string, name: string } | null, user?: { __typename?: 'User', id: string, name: string, email: string } | null } | null> | null } | null } | null } | null };
5663+
export type CreateInviteMutation = { __typename?: 'RootMutationType', createInvite?: { __typename?: 'Invite', id: string, secureId?: string | null, email?: string | null, existing: boolean, insertedAt?: Date | null, account?: { __typename?: 'Account', id: string, name?: string | null, billingCustomerId?: string | null, backgroundColor?: string | null, userCount?: string | null, trialed?: boolean | null } | null, user?: { __typename?: 'User', id: string, name: string, email: string, avatar?: string | null, provider?: Provider | null, demoed?: boolean | null, onboarding?: OnboardingState | null, emailConfirmed?: boolean | null, emailConfirmBy?: Date | null, backgroundColor?: string | null, serviceAccount?: boolean | null, hasInstallations?: boolean | null, hasShell?: boolean | null, account: { __typename?: 'Account', id: string, name?: string | null, billingCustomerId?: string | null, backgroundColor?: string | null, userCount?: string | null, trialed?: boolean | null }, onboardingChecklist?: { __typename?: 'OnboardingChecklist', dismissed?: boolean | null, status?: OnboardingChecklistState | null } | null, invites?: Array<{ __typename?: 'Invite', id: string, email?: string | null } | null> | null, roles?: { __typename?: 'Roles', admin?: boolean | null } | null, groups?: Array<{ __typename?: 'Group', id: string, name: string, global?: boolean | null, description?: string | null } | null> | null, impersonationPolicy?: { __typename?: 'ImpersonationPolicy', id: string, bindings?: Array<{ __typename?: 'ImpersonationPolicyBinding', id: string, group?: { __typename?: 'Group', id: string, name: string } | null, user?: { __typename?: 'User', id: string, name: string, email: string } | null } | null> | null } | null } | null } | null };
56645664

56655665
export type SignupInviteMutationVariables = Exact<{
56665666
attributes: UserAttributes;
@@ -5682,7 +5682,7 @@ export type DeleteInviteMutationVariables = Exact<{
56825682
}>;
56835683

56845684

5685-
export type DeleteInviteMutation = { __typename?: 'RootMutationType', deleteInvite?: { __typename?: 'Invite', id: string, secureId?: string | null, email?: string | null, insertedAt?: Date | null, user?: { __typename?: 'User', id: string, name: string, email: string, avatar?: string | null, provider?: Provider | null, demoed?: boolean | null, onboarding?: OnboardingState | null, emailConfirmed?: boolean | null, emailConfirmBy?: Date | null, backgroundColor?: string | null, serviceAccount?: boolean | null, hasInstallations?: boolean | null, hasShell?: boolean | null, onboardingChecklist?: { __typename?: 'OnboardingChecklist', dismissed?: boolean | null, status?: OnboardingChecklistState | null } | null, invites?: Array<{ __typename?: 'Invite', id: string, email?: string | null } | null> | null, roles?: { __typename?: 'Roles', admin?: boolean | null } | null, groups?: Array<{ __typename?: 'Group', id: string, name: string, global?: boolean | null, description?: string | null } | null> | null, impersonationPolicy?: { __typename?: 'ImpersonationPolicy', id: string, bindings?: Array<{ __typename?: 'ImpersonationPolicyBinding', id: string, group?: { __typename?: 'Group', id: string, name: string } | null, user?: { __typename?: 'User', id: string, name: string, email: string } | null } | null> | null } | null } | null } | null };
5685+
export type DeleteInviteMutation = { __typename?: 'RootMutationType', deleteInvite?: { __typename?: 'Invite', id: string, secureId?: string | null, email?: string | null, existing: boolean, insertedAt?: Date | null, account?: { __typename?: 'Account', id: string, name?: string | null, billingCustomerId?: string | null, backgroundColor?: string | null, userCount?: string | null, trialed?: boolean | null } | null, user?: { __typename?: 'User', id: string, name: string, email: string, avatar?: string | null, provider?: Provider | null, demoed?: boolean | null, onboarding?: OnboardingState | null, emailConfirmed?: boolean | null, emailConfirmBy?: Date | null, backgroundColor?: string | null, serviceAccount?: boolean | null, hasInstallations?: boolean | null, hasShell?: boolean | null, account: { __typename?: 'Account', id: string, name?: string | null, billingCustomerId?: string | null, backgroundColor?: string | null, userCount?: string | null, trialed?: boolean | null }, onboardingChecklist?: { __typename?: 'OnboardingChecklist', dismissed?: boolean | null, status?: OnboardingChecklistState | null } | null, invites?: Array<{ __typename?: 'Invite', id: string, email?: string | null } | null> | null, roles?: { __typename?: 'Roles', admin?: boolean | null } | null, groups?: Array<{ __typename?: 'Group', id: string, name: string, global?: boolean | null, description?: string | null } | null> | null, impersonationPolicy?: { __typename?: 'ImpersonationPolicy', id: string, bindings?: Array<{ __typename?: 'ImpersonationPolicyBinding', id: string, group?: { __typename?: 'Group', id: string, name: string } | null, user?: { __typename?: 'User', id: string, name: string, email: string } | null } | null> | null } | null } | null } | null };
56865686

56875687
export type KeyBackupUserFragment = { __typename?: 'User', email: string };
56885688

@@ -7306,17 +7306,35 @@ export const ZoomMeetingFragmentDoc = gql`
73067306
password
73077307
}
73087308
`;
7309+
export const AccountFragmentDoc = gql`
7310+
fragment Account on Account {
7311+
id
7312+
name
7313+
billingCustomerId
7314+
backgroundColor
7315+
userCount
7316+
trialed
7317+
}
7318+
`;
73097319
export const InviteFragmentDoc = gql`
73107320
fragment Invite on Invite {
73117321
id
73127322
secureId
73137323
email
7324+
existing
73147325
insertedAt
7326+
account {
7327+
...Account
7328+
}
73157329
user {
73167330
...User
7331+
account {
7332+
...Account
7333+
}
73177334
}
73187335
}
7319-
${UserFragmentDoc}`;
7336+
${AccountFragmentDoc}
7337+
${UserFragmentDoc}`;
73207338
export const KeyBackupUserFragmentDoc = gql`
73217339
fragment KeyBackupUser on User {
73227340
email
@@ -7902,16 +7920,6 @@ export const DeferredUpdateFragmentDoc = gql`
79027920
insertedAt
79037921
}
79047922
`;
7905-
export const AccountFragmentDoc = gql`
7906-
fragment Account on Account {
7907-
id
7908-
name
7909-
billingCustomerId
7910-
backgroundColor
7911-
userCount
7912-
trialed
7913-
}
7914-
`;
79157923
export const GroupMemberFragmentDoc = gql`
79167924
fragment GroupMember on GroupMember {
79177925
id
@@ -9203,22 +9211,10 @@ export type CreateOauthIntegrationMutationOptions = Apollo.BaseMutationOptions<C
92039211
export const InviteDocument = gql`
92049212
query Invite($id: String!) {
92059213
invite(id: $id) {
9206-
id
9207-
email
9208-
existing
9209-
account {
9210-
...Account
9211-
}
9212-
user {
9213-
...User
9214-
account {
9215-
...Account
9216-
}
9217-
}
9214+
...Invite
92189215
}
92199216
}
9220-
${AccountFragmentDoc}
9221-
${UserFragmentDoc}`;
9217+
${InviteFragmentDoc}`;
92229218

92239219
/**
92249220
* __useInviteQuery__

www/src/graph/invite.graphql

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,22 @@ fragment Invite on Invite {
22
id
33
secureId
44
email
5+
existing
56
insertedAt
7+
account {
8+
...Account
9+
}
610
user {
711
...User
12+
account {
13+
...Account
14+
}
815
}
916
}
1017

1118
query Invite($id: String!) {
1219
invite(id: $id) {
13-
id
14-
email
15-
existing
16-
account {
17-
...Account
18-
}
19-
user {
20-
...User
21-
account {
22-
...Account
23-
}
24-
}
20+
...Invite
2521
}
2622
}
2723

0 commit comments

Comments
 (0)