-
Notifications
You must be signed in to change notification settings - Fork 8.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: Correctly prefill username in case of non-org email invite in an org #12854
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -73,13 +73,15 @@ | |
setPremium, | ||
premium, | ||
setUsernameTaken, | ||
orgSlug, | ||
usernameTaken, | ||
...props | ||
}: React.ComponentProps<typeof TextField> & { | ||
username: string; | ||
setPremium: (value: boolean) => void; | ||
premium: boolean; | ||
usernameTaken: boolean; | ||
orgSlug?: string; | ||
setUsernameTaken: (value: boolean) => void; | ||
}) { | ||
const { t } = useLocale(); | ||
|
@@ -95,13 +97,13 @@ | |
setUsernameTaken(false); | ||
return; | ||
} | ||
fetchUsername(debouncedUsername).then(({ data }) => { | ||
fetchUsername(debouncedUsername, orgSlug ?? null).then(({ data }) => { | ||
setPremium(data.premium); | ||
setUsernameTaken(!data.available); | ||
}); | ||
} | ||
checkUsername(); | ||
}, [debouncedUsername, setPremium, setUsernameTaken, formState.isSubmitting, formState.isSubmitSuccessful]); | ||
Check warning on line 106 in apps/web/pages/signup.tsx GitHub Actions / ESLint Report Analysisapps/web/pages/signup.tsx#L106
|
||
|
||
return ( | ||
<div> | ||
|
@@ -276,6 +278,7 @@ | |
{/* Username */} | ||
{!isOrgInviteByLink ? ( | ||
<UsernameField | ||
orgSlug={orgSlug} | ||
label={t("username")} | ||
username={watch("username") || ""} | ||
premium={premiumUsername} | ||
|
@@ -610,23 +613,25 @@ | |
metadata: teamMetadataSchema.parse(verificationToken?.team?.metadata), | ||
}; | ||
|
||
const isATeamInOrganization = tokenTeam?.parentId !== null; | ||
const isOrganization = tokenTeam.metadata?.isOrganization; | ||
// Detect if the team is an org by either the metadata flag or if it has a parent team | ||
const isOrganization = tokenTeam.metadata?.isOrganization || tokenTeam?.parentId !== null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Better naming |
||
const isOrganizationOrATeamInOrganization = isOrganization || isATeamInOrganization; | ||
// If we are dealing with an org, the slug may come from the team itself or its parent | ||
const orgSlug = isOrganization | ||
const orgSlug = isOrganizationOrATeamInOrganization | ||
? tokenTeam.metadata?.requestedSlug || tokenTeam.parent?.slug || tokenTeam.slug | ||
: null; | ||
|
||
// Org context shouldn't check if a username is premium | ||
if (!IS_SELF_HOSTED && !isOrganization) { | ||
if (!IS_SELF_HOSTED && !isOrganizationOrATeamInOrganization) { | ||
// Im not sure we actually hit this because of next redirects signup to website repo - but just in case this is pretty cool :) | ||
const { available, suggestion } = await checkPremiumUsername(username); | ||
|
||
username = available ? username : suggestion || username; | ||
} | ||
|
||
const isValidEmail = checkValidEmail(verificationToken.identifier); | ||
const isOrgInviteByLink = isOrganization && !isValidEmail; | ||
const isOrgInviteByLink = isOrganizationOrATeamInOrganization && !isValidEmail; | ||
const parentMetaDataForSubteam = tokenTeam?.parent?.metadata | ||
? teamMetadataSchema.parse(tokenTeam.parent.metadata) | ||
: null; | ||
|
@@ -638,7 +643,14 @@ | |
prepopulateFormValues: !isOrgInviteByLink | ||
? { | ||
email: verificationToken.identifier, | ||
username: slugify(username), | ||
username: isOrganizationOrATeamInOrganization | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It fixes the prefilling issue. |
||
? getOrgUsernameFromEmail( | ||
verificationToken.identifier, | ||
(isOrganization | ||
? tokenTeam.metadata?.orgAutoAcceptEmail | ||
: parentMetaDataForSubteam?.orgAutoAcceptEmail) || "" | ||
) | ||
: slugify(username), | ||
} | ||
: null, | ||
orgSlug, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should read the orgSlug here from the correct place and pass that on.