Make SSC base url dynamic (#62790)

* Add config item, get it to the front end
* Use config on the front end
* Send team=1 if the team button is clicked
* Unrelated: Event logging cleanup
This commit is contained in:
David Veszelovszki 2024-05-21 11:58:08 +02:00 committed by GitHub
parent e2a0fd6113
commit 376a737d61
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 21 additions and 13 deletions

View File

@ -6,7 +6,6 @@ import { useNavigate } from 'react-router-dom'
import { useQuery } from '@sourcegraph/http-client'
import type { TelemetryV2Props } from '@sourcegraph/shared/src/telemetry'
import { EVENT_LOGGER } from '@sourcegraph/shared/src/telemetry/web/eventLogger'
import {
Badge,
Button,
@ -26,10 +25,9 @@ import { Page } from '../../components/Page'
import { PageTitle } from '../../components/PageTitle'
import { CodySubscriptionPlan } from '../../graphql-operations'
import type { UserCodyPlanResult, UserCodyPlanVariables } from '../../graphql-operations'
import { EventName } from '../../util/constants'
import { CodyColorIcon } from '../chat/CodyPageIcon'
import { isCodyEnabled } from '../isCodyEnabled'
import { manageSubscriptionRedirectURL, isEmbeddedCodyProUIEnabled } from '../util'
import { isEmbeddedCodyProUIEnabled, manageSubscriptionRedirectURL } from '../util'
import { USER_CODY_PLAN } from './queries'
@ -49,7 +47,6 @@ export const CodySubscriptionPage: React.FunctionComponent<CodySubscriptionPageP
const utm_source = parameters.get('utm_source')
useEffect(() => {
EVENT_LOGGER.log(EventName.CODY_SUBSCRIPTION_PAGE_VIEWED, { utm_source }, { utm_source })
telemetryRecorder.recordEvent('cody.planSelection', 'view')
}, [utm_source, telemetryRecorder])
@ -85,7 +82,9 @@ export const CodySubscriptionPage: React.FunctionComponent<CodySubscriptionPageP
<Button
variant="primary"
onClick={() => {
EVENT_LOGGER.log(EventName.CODY_MANAGE_SUBSCRIPTION_CLICKED)
telemetryRecorder.recordEvent('cody.manageSubscription', 'click', {
metadata: { tier: 1 },
})
window.location.href = manageSubscriptionRedirectURL
}}
>
@ -209,7 +208,6 @@ export const CodySubscriptionPage: React.FunctionComponent<CodySubscriptionPageP
className="mb-0 text-muted d-inline cursor-pointer"
size="small"
onClick={() => {
EVENT_LOGGER.log(EventName.CODY_MANAGE_SUBSCRIPTION_CLICKED)
telemetryRecorder.recordEvent('cody.planSelection', 'click', {
metadata: { tier: 0 },
})
@ -227,7 +225,12 @@ export const CodySubscriptionPage: React.FunctionComponent<CodySubscriptionPageP
telemetryRecorder.recordEvent('cody.planSelection', 'click', {
metadata: { tier: 1, team: 1 },
})
window.location.href = manageSubscriptionRedirectURL // TODO: Use team link or argument
// We add ?team=1 to the URL to indicate that the user is creating a team.
// We can use this info to initialize the UI differently,
// or even display an entirely different UI.
const url = new URL(manageSubscriptionRedirectURL)
url.searchParams.append('team', '1')
window.location.href = url.toString()
}}
>
<span className={classNames(styles.proBadge, 'mr-1')} />
@ -364,11 +367,6 @@ export const CodySubscriptionPage: React.FunctionComponent<CodySubscriptionPageP
to="https://sourcegraph.com/contact/request-info?utm_source=cody_subscription_page"
target="_blank"
onClick={() => {
EVENT_LOGGER.log(
EventName.CODY_SUBSCRIPTION_PLAN_CLICKED,
{ tier: 'enterprise' },
{ tier: 'enterprise' }
)
telemetryRecorder.recordEvent('cody.planSelection', 'click', {
metadata: { tier: 2 },
})

View File

@ -1,7 +1,7 @@
// The URL to direct users in order to manage their Cody Pro subscription.
import { useState, useEffect } from 'react'
export const manageSubscriptionRedirectURL = 'https://accounts.sourcegraph.com/cody/subscription'
export const manageSubscriptionRedirectURL = `${window.context.frontendCodyProConfig?.sscBaseUrl}/subscription`
/**
* useEmbeddedCodyProUi returns if we expect the Cody Pro UI to be served from sourcegraph.com. Meaning

View File

@ -306,6 +306,7 @@ export interface SourcegraphContext extends Pick<Required<SiteConfiguration>, 'e
/** Configuration for Cody Pro-tier functionality, if applicable. */
frontendCodyProConfig?: {
stripePublishableKey: string
sscBaseUrl: string
}
}

View File

@ -152,6 +152,7 @@ type LicenseInfo struct {
// to the frontend.
type FrontendCodyProConfig struct {
StripePublishableKey string `json:"stripePublishableKey"`
SscBaseUrl string `json:"sscBaseUrl"`
}
// JSContext is made available to JavaScript code via the
@ -708,5 +709,6 @@ func makeFrontendCodyProConfig(config *schema.CodyProConfig) *FrontendCodyProCon
}
return &FrontendCodyProConfig{
StripePublishableKey: config.StripePublishableKey,
SscBaseUrl: config.SscBaseUrl,
}
}

View File

@ -652,6 +652,8 @@ type CodyProConfig struct {
SamsBackendOrigin string `json:"samsBackendOrigin,omitempty"`
// SscBackendOrigin description: Origin of the Self-serve Cody backend.
SscBackendOrigin string `json:"sscBackendOrigin,omitempty"`
// SscBaseUrl description: The base URL of the Self-Serve Cody site.
SscBaseUrl string `json:"sscBaseUrl,omitempty"`
// StripePublishableKey description: Stripe Publishable Key for use in Stripe Checkout, Stripe Elements. This is not considered a secret.
StripePublishableKey string `json:"stripePublishableKey,omitempty"`
}

View File

@ -2277,6 +2277,11 @@
"default": "",
"description": "Origin of the Self-serve Cody backend.",
"examples": ["https://accounts.sourcegraph.com"]
},
"sscBaseUrl": {
"type": "string",
"default": "https://accounts.sourcegraph.com/cody",
"description": "The base URL of the Self-Serve Cody site."
}
}
}