Skip to content

Commit 7f71765

Browse files
committed
fix: amplitude connect step matches destination workflow without URL
1 parent 29fbf47 commit 7f71765

2 files changed

Lines changed: 42 additions & 23 deletions

File tree

frontend/web/components/modals/ConnectCohortProviderModal/ConnectCohortProviderModal.tsx

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const ConnectCohortProviderModal: FC<ConnectCohortProviderModalProps> = ({
2626
provider,
2727
}) => {
2828
const config = COHORT_PROVIDERS[provider]
29+
const endpointUrl = getCohortProviderEndpoint(provider)
2930
const [selectedEnvironment, setSelectedEnvironment] = useState('')
3031

3132
const { data: environments, isLoading } = useGetEnvironmentsQuery({
@@ -76,12 +77,19 @@ const ConnectCohortProviderModal: FC<ConnectCohortProviderModalProps> = ({
7677
index={2}
7778
title={config.endpointStepTitle}
7879
>
79-
<CopyField
80-
title={config.endpointFieldTitle}
81-
value={getCohortProviderEndpoint(provider)}
82-
className='font-monospace'
83-
data-test='connect-provider-url'
84-
/>
80+
{!!config.endpointStepBody && (
81+
<p className='fs-small text-secondary lh-sm mb-0'>
82+
{config.endpointStepBody}
83+
</p>
84+
)}
85+
{!!endpointUrl && (
86+
<CopyField
87+
title={config.endpoint?.fieldTitle}
88+
value={endpointUrl}
89+
className='font-monospace'
90+
data-test='connect-provider-url'
91+
/>
92+
)}
8593
<div className='d-flex flex-column mx-0 gap-1 mt-3'>
8694
{config.authRows.map((row) => (
8795
<div
@@ -101,10 +109,12 @@ const ConnectCohortProviderModal: FC<ConnectCohortProviderModalProps> = ({
101109
</div>
102110
))}
103111
</div>
104-
<div className='fs-small text-secondary mt-3'>
105-
This URL is the same for every environment — your key decides
106-
where cohort members land.
107-
</div>
112+
{!!endpointUrl && (
113+
<div className='fs-small text-secondary mt-3'>
114+
This URL is the same for every environment — your key decides
115+
where cohort members land.
116+
</div>
117+
)}
108118
</ConnectCohortProviderStep>
109119
<ConnectCohortProviderStep index={3} title={config.exportStepTitle}>
110120
<p className='fs-small text-secondary lh-sm mb-0'>

frontend/web/components/modals/ConnectCohortProviderModal/providers.ts

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ export type CohortProviderAuthRow = {
1111
export type CohortProviderConfig = {
1212
label: string
1313
authRows: CohortProviderAuthRow[]
14-
endpointFieldTitle: string
15-
endpointPath: string
14+
// Providers where the user pastes a URL themselves carry an endpoint;
15+
// Amplitude calls Flagsmith's portal-registered endpoints instead.
16+
endpoint?: {
17+
fieldTitle: string
18+
path: string
19+
}
1620
endpointStepTitle: string
21+
endpointStepBody?: string
1722
exportStepTitle: string
1823
exportStepBody: string
1924
}
@@ -22,13 +27,10 @@ export const COHORT_PROVIDERS: Record<CohortProviderKey, CohortProviderConfig> =
2227
{
2328
amplitude: {
2429
authRows: [
25-
{ label: 'Authentication', value: 'Bearer token' },
26-
{ label: 'Token', mono: true, value: '{YOUR_SYNCHRONISATION_KEY}' },
30+
{ label: 'API key', mono: true, value: '{YOUR_SYNCHRONISATION_KEY}' },
2731
],
28-
// Amplitude posts cohort list creation here, then adds and removes
29-
// members under `lists/{list_id}/add` and `lists/{list_id}/remove`.
30-
endpointFieldTitle: 'List endpoint URL',
31-
endpointPath: 'cohort-sync/amplitude/lists/',
32+
endpointStepBody:
33+
'In Amplitude, open Data → Destinations and add Flagsmith as a cohort destination. Paste your synchronisation key when asked for the API key.',
3234
endpointStepTitle: 'Add Flagsmith as a destination in Amplitude',
3335
exportStepBody:
3436
'In Amplitude, open the cohort you want to target and synchronise it to the Flagsmith destination. Flagsmith creates the managed segment automatically on the first synchronisation, then keeps its members up to date as people enter and leave the cohort.',
@@ -41,8 +43,10 @@ export const COHORT_PROVIDERS: Record<CohortProviderKey, CohortProviderConfig> =
4143
{ label: 'Username', value: 'Any value' },
4244
{ label: 'Password', mono: true, value: '{YOUR_SYNCHRONISATION_KEY}' },
4345
],
44-
endpointFieldTitle: 'Webhook URL',
45-
endpointPath: 'cohort-sync/mixpanel/webhook/',
46+
endpoint: {
47+
fieldTitle: 'Webhook URL',
48+
path: 'cohort-sync/mixpanel/webhook/',
49+
},
4650
endpointStepTitle: 'Create a webhook in Mixpanel',
4751
exportStepBody:
4852
'In Mixpanel, open the cohort you want to target and export it to the webhook you just created. Flagsmith creates the managed segment automatically on the first synchronisation, then keeps its members up to date as people enter and leave the cohort.',
@@ -55,8 +59,13 @@ export const COHORT_PROVIDERS: Record<CohortProviderKey, CohortProviderConfig> =
5559
// providers need an absolute callback URL, so resolve against the page origin.
5660
export const getCohortProviderEndpoint = (
5761
provider: CohortProviderKey,
58-
): string =>
59-
new URL(
60-
COHORT_PROVIDERS[provider].endpointPath,
62+
): string | null => {
63+
const endpoint = COHORT_PROVIDERS[provider].endpoint
64+
if (!endpoint) {
65+
return null
66+
}
67+
return new URL(
68+
endpoint.path,
6169
new URL(Project.api, window.location.origin),
6270
).toString()
71+
}

0 commit comments

Comments
 (0)