Skip to content

Commit

Permalink
client: remove deprecated authenticatedUser.email
Browse files Browse the repository at this point in the history
  • Loading branch information
bobheadxi committed Jan 6, 2023
1 parent 7a6dc29 commit 6b80bb1
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 17 deletions.
2 changes: 1 addition & 1 deletion client/shared/src/auth.ts
Expand Up @@ -10,7 +10,6 @@ export const currentAuthStateQuery = gql`
databaseID
username
avatarURL
email
displayName
siteAdmin
tags
Expand All @@ -36,6 +35,7 @@ export const currentAuthStateQuery = gql`
emails {
email
verified
isPrimary
}
latestSettings {
id
Expand Down
7 changes: 4 additions & 3 deletions client/shared/src/util/url.ts
Expand Up @@ -594,16 +594,17 @@ export function buildGetStartedURL(cloudSignup?: boolean, authenticatedUser?: Au
* @returns signup UR string with relevant params attached
*/
export const buildCloudTrialURL = (
authenticatedUser: Pick<AuthenticatedUser, 'displayName' | 'email'> | null | undefined,
authenticatedUser: Pick<AuthenticatedUser, 'displayName' | 'emails'> | null | undefined,
product?: string
): string => {
const url = new URL('https://signup.sourcegraph.com/')

if (product) {
url.searchParams.append('p', product)
}
if (authenticatedUser?.email) {
url.searchParams.append('email', authenticatedUser.email)
const primaryEmail = authenticatedUser?.emails.find(email => email.isPrimary)
if (primaryEmail) {
url.searchParams.append('email', primaryEmail.email)
}
if (authenticatedUser?.displayName) {
url.searchParams.append('name', authenticatedUser.displayName)
Expand Down
Expand Up @@ -54,7 +54,6 @@ const PLATFORM_CONTEXT: CommunitySearchContextPageProps['platformContext'] = {
const authUser: AuthenticatedUser = {
__typename: 'User',
id: '0',
email: 'alice@sourcegraph.com',
username: 'alice',
avatarURL: null,
session: { canSignOut: true },
Expand All @@ -73,7 +72,13 @@ const authUser: AuthenticatedUser = {
databaseID: 0,
tosAccepted: true,
searchable: true,
emails: [],
emails: [
{
email: 'alice@sourcegraph.com',
isPrimary: true,
verified: true,
},
],
latestSettings: null,
}

Expand Down
Expand Up @@ -25,7 +25,7 @@ import { BatchSpecInfoByline } from './BatchSpecInfoByline'
import { CreateUpdateBatchChangeAlert } from './CreateUpdateBatchChangeAlert'
import { PreviewList } from './list/PreviewList'

export type PreviewPageAuthenticatedUser = Pick<AuthenticatedUser, 'url' | 'displayName' | 'username' | 'email'>
export type PreviewPageAuthenticatedUser = Pick<AuthenticatedUser, 'url' | 'displayName' | 'username' | 'emails'>

export interface BatchChangePreviewPageProps extends BatchChangePreviewProps {
/** Used for testing. */
Expand Down
Expand Up @@ -384,7 +384,8 @@ const ExpandedSection: React.FunctionComponent<
node.targets.changeset.author
? node.targets.changeset.author
: {
email: authenticatedUser.email,
email:
authenticatedUser.emails.find(email => email.isPrimary)?.email || '',
displayName: authenticatedUser.displayName || authenticatedUser.username,
user: authenticatedUser,
}
Expand Down
Expand Up @@ -94,6 +94,8 @@ export const EmailAction: React.FunctionComponent<React.PropsWithChildren<Action
const testState = loading ? 'loading' : called && !error ? 'called' : error || undefined

const emailConfigured = window.context.emailEnabled
const userPrimaryEmail = authenticatedUser.emails.find(email => email.isPrimary)

const emailNotConfiguredMessage = !emailConfigured ? (
!action ? (
<>
Expand All @@ -116,7 +118,7 @@ export const EmailAction: React.FunctionComponent<React.PropsWithChildren<Action
idName="email"
disabled={disabledBasedOnEmailConfig}
completed={!!action}
completedSubtitle={authenticatedUser.email}
completedSubtitle={userPrimaryEmail?.email || ''}
actionEnabled={enabled}
toggleActionEnabled={toggleEmailNotificationEnabled}
includeResults={includeResults}
Expand All @@ -138,7 +140,7 @@ export const EmailAction: React.FunctionComponent<React.PropsWithChildren<Action
id="code-monitoring-form-actions-recipients"
className="mb-2"
label="Recipients"
value={`${authenticatedUser.email || ''} (you)`}
value={`${userPrimaryEmail?.email || ''} (you)`}
disabled={true}
autoFocus={true}
required={true}
Expand Down
17 changes: 14 additions & 3 deletions client/web/src/enterprise/code-monitoring/testing/util.ts
Expand Up @@ -10,7 +10,6 @@ export const mockUser: AuthenticatedUser = {
__typename: 'User',
id: 'userID',
username: 'username',
email: 'user@me.com',
siteAdmin: true,
databaseID: 0,
tags: [],
Expand All @@ -26,7 +25,13 @@ export const mockUser: AuthenticatedUser = {
session: { __typename: 'Session', canSignOut: true },
tosAccepted: true,
searchable: true,
emails: [],
emails: [
{
email: 'user@me.com',
isPrimary: true,
verified: true,
},
],
latestSettings: null,
}

Expand Down Expand Up @@ -304,7 +309,13 @@ export const mockCodeMonitorNodes: ListCodeMonitors['nodes'] = [
export const mockAuthenticatedUser: AuthenticatedUser = {
id: 'userID',
username: 'username',
email: 'user@me.com',
emails: [
{
email: 'user@me.com',
isPrimary: true,
verified: true,
},
],
siteAdmin: true,
} as AuthenticatedUser

Expand Down
Expand Up @@ -68,7 +68,6 @@ const searchContextToEdit: SearchContextFields = {
const authUser: AuthenticatedUser = {
__typename: 'User',
id: '0',
email: 'alice@sourcegraph.com',
username: 'alice',
avatarURL: null,
session: { canSignOut: true },
Expand All @@ -87,7 +86,13 @@ const authUser: AuthenticatedUser = {
databaseID: 0,
tosAccepted: true,
searchable: true,
emails: [],
emails: [
{
email: 'alice@sourcegraph.com',
isPrimary: true,
verified: true,
},
],
latestSettings: null,
}

Expand Down
7 changes: 5 additions & 2 deletions client/web/src/user/settings/research/ProductResearch.tsx
Expand Up @@ -10,7 +10,7 @@ import { PageTitle } from '../../../components/PageTitle'

interface Props {
telemetryService: TelemetryService
authenticatedUser: Pick<AuthenticatedUser, 'email'>
authenticatedUser: Pick<AuthenticatedUser, 'emails'>
}

const SIGN_UP_FORM_URL = 'https://info.sourcegraph.com/product-research'
Expand All @@ -24,7 +24,10 @@ export const ProductResearchPage: React.FunctionComponent<React.PropsWithChildre
}, [telemetryService])

const signUpForm = new URL(SIGN_UP_FORM_URL)
signUpForm.searchParams.set('email', authenticatedUser.email)
const primaryEmail = authenticatedUser.emails.find(email => email.isPrimary)
if (primaryEmail) {
signUpForm.searchParams.set('email', primaryEmail.email)
}

return (
<>
Expand Down

0 comments on commit 6b80bb1

Please sign in to comment.