-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(data-warehouse): hubspot integration (#19529)
* initial api * urls * refactor source selector frontend * refactor source selector frontend * field config * http working * add hubspot dlt helpers * remove products endpoint and add token refresh * reformat * add limiting * Update UI snapshots for `chromium` (1) * Update UI snapshots for `chromium` (1) * typing and migration * typing * update latest migration * add hubspot logo * Update UI snapshots for `chromium` (1) * add prefix flow --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
- Loading branch information
1 parent
b8b90c1
commit 1d6ba3c
Showing
27 changed files
with
915 additions
and
117 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
frontend/src/scenes/data-warehouse/external/sourceFormLogic.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
import { lemonToast } from '@posthog/lemon-ui' | ||
import { actions, connect, kea, listeners, path, props } from 'kea' | ||
import { forms } from 'kea-forms' | ||
import { router, urlToAction } from 'kea-router' | ||
import api from 'lib/api' | ||
import { urls } from 'scenes/urls' | ||
|
||
import { ExternalDataSourceCreatePayload, ExternalDataSourceType } from '~/types' | ||
|
||
import type { sourceFormLogicType } from './sourceFormLogicType' | ||
import { getHubspotRedirectUri, sourceModalLogic } from './sourceModalLogic' | ||
|
||
export interface SourceFormProps { | ||
sourceType: ExternalDataSourceType | ||
} | ||
|
||
interface SourceConfig { | ||
name: string | ||
caption: string | ||
fields: FieldConfig[] | ||
} | ||
interface FieldConfig { | ||
name: string | ||
label: string | ||
type: string | ||
required: boolean | ||
} | ||
|
||
export const SOURCE_DETAILS: Record<string, SourceConfig> = { | ||
Stripe: { | ||
name: 'Stripe', | ||
caption: 'Enter your Stripe credentials to link your Stripe to PostHog', | ||
fields: [ | ||
{ | ||
name: 'account_id', | ||
label: 'Account ID', | ||
type: 'text', | ||
required: true, | ||
}, | ||
{ | ||
name: 'client_secret', | ||
label: 'Client Secret', | ||
type: 'text', | ||
required: true, | ||
}, | ||
], | ||
}, | ||
} | ||
|
||
const getPayloadDefaults = (sourceType: string): Record<string, any> => { | ||
switch (sourceType) { | ||
case 'Stripe': | ||
return { | ||
account_id: '', | ||
client_secret: '', | ||
} | ||
default: | ||
return {} | ||
} | ||
} | ||
|
||
const getErrorsDefaults = (sourceType: string): ((args: Record<string, any>) => Record<string, any>) => { | ||
switch (sourceType) { | ||
case 'Stripe': | ||
return ({ payload }) => ({ | ||
payload: { | ||
account_id: !payload.account_id && 'Please enter an account id.', | ||
client_secret: !payload.client_secret && 'Please enter a client secret.', | ||
}, | ||
}) | ||
default: | ||
return () => ({}) | ||
} | ||
} | ||
|
||
export const sourceFormLogic = kea<sourceFormLogicType>([ | ||
path(['scenes', 'data-warehouse', 'external', 'sourceFormLogic']), | ||
props({} as SourceFormProps), | ||
connect({ | ||
actions: [sourceModalLogic, ['onClear', 'toggleSourceModal', 'loadSources']], | ||
}), | ||
actions({ | ||
onBack: true, | ||
handleRedirect: (kind: string, searchParams: any) => ({ kind, searchParams }), | ||
}), | ||
listeners(({ actions }) => ({ | ||
onBack: () => { | ||
actions.resetExternalDataSource() | ||
actions.onClear() | ||
}, | ||
submitExternalDataSourceSuccess: () => { | ||
lemonToast.success('New Data Resource Created') | ||
actions.toggleSourceModal(false) | ||
actions.resetExternalDataSource() | ||
actions.loadSources() | ||
router.actions.push(urls.dataWarehouseSettings()) | ||
}, | ||
submitExternalDataSourceFailure: ({ error }) => { | ||
lemonToast.error(error?.message || 'Something went wrong') | ||
}, | ||
handleRedirect: async ({ kind, searchParams }) => { | ||
switch (kind) { | ||
case 'hubspot': { | ||
actions.setExternalDataSourceValue('payload', { | ||
code: searchParams.code, | ||
redirect_uri: getHubspotRedirectUri(), | ||
}) | ||
actions.setExternalDataSourceValue('source_type', 'Hubspot') | ||
return | ||
} | ||
default: | ||
lemonToast.error(`Something went wrong.`) | ||
} | ||
}, | ||
})), | ||
urlToAction(({ actions }) => ({ | ||
'/data-warehouse/:kind/redirect': ({ kind = '' }, searchParams) => { | ||
actions.handleRedirect(kind, searchParams) | ||
}, | ||
})), | ||
forms(({ props }) => ({ | ||
externalDataSource: { | ||
defaults: { | ||
prefix: '', | ||
source_type: props.sourceType, | ||
payload: getPayloadDefaults(props.sourceType), | ||
} as ExternalDataSourceCreatePayload, | ||
errors: getErrorsDefaults(props.sourceType), | ||
submit: async (payload: ExternalDataSourceCreatePayload) => { | ||
const newResource = await api.externalDataSources.create(payload) | ||
return newResource | ||
}, | ||
}, | ||
})), | ||
]) |
Oops, something went wrong.