mirror of
https://github.com/supabase/supabase.git
synced 2026-10-12 04:45:08 +03:00
* add initial installation flow of stripe sync engine * update docs link * Add supabase_vault extension dep * Add stripe logo to sync engine integration * Move overview content to bottom of integration pages * Add sync state to stripe sync page * only check sync state if stripe integration is installed * Use proper stripe-sync package and setup flows * Improve sync engine installation ux * Remove unused hardcoded dep * Add alpha status to stripe sync engine integration * fix typo * run format * fix types * Rename the stripe-sync path to remove the 'integration". The path needs to have BASE_PATH to work on prod. * Design tidy up (#41337) UI tidy up * update to latest sync engine package * Add stripe key verification * Remove noop try/catch * Add integration isntallation telelemtry * Add basic settings page * Address coderabbit comments * remove unused dep * Remove state setting on render * s/description/comment * Cleanup settings screen UI * Improve settings screen design * update schema test snapshot * Use latest stripe-sync-engine package * Update repo url to new official location * revert marketing change * Update stripe sync engine package * Add link to table from overview page * Add feature flag and improve telemetry * Fix missing useMemo dep * add uninstall telemetry note --------- Co-authored-by: Ivan Vasilov <vasilov.ivan@gmail.com> Co-authored-by: Saxon Fletcher <saxonafletcher@gmail.com>
92 lines
2.5 KiB
TypeScript
92 lines
2.5 KiB
TypeScript
import { useMutation, UseMutationOptions, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { getAccessToken } from 'common'
|
|
import { databaseKeys } from 'data/database/keys'
|
|
import { BASE_PATH } from 'lib/constants'
|
|
import { useTrack } from 'lib/telemetry/track'
|
|
import type { ResponseError } from 'types'
|
|
import { stripeSyncKeys } from './keys'
|
|
|
|
export type StripeSyncInstallVariables = {
|
|
projectRef: string
|
|
stripeSecretKey: string
|
|
}
|
|
|
|
export type StripeSyncInstallResponse = {
|
|
data: { message: string } | null
|
|
error: { message: string } | null
|
|
}
|
|
|
|
export async function installStripeSync({
|
|
projectRef,
|
|
stripeSecretKey,
|
|
}: StripeSyncInstallVariables): Promise<StripeSyncInstallResponse> {
|
|
const accessToken = await getAccessToken()
|
|
|
|
const response = await fetch(`${BASE_PATH}/api/integrations/stripe-sync`, {
|
|
method: 'POST',
|
|
headers: {
|
|
'Content-Type': 'application/json',
|
|
Authorization: `Bearer ${accessToken}`,
|
|
},
|
|
body: JSON.stringify({
|
|
projectRef,
|
|
stripeSecretKey,
|
|
}),
|
|
})
|
|
|
|
const result = await response.json()
|
|
|
|
if (!response.ok) {
|
|
throw new Error(result.error?.message || 'Failed to install Stripe Sync')
|
|
}
|
|
|
|
return result
|
|
}
|
|
|
|
type StripeSyncInstallData = Awaited<ReturnType<typeof installStripeSync>>
|
|
|
|
export const useStripeSyncInstallMutation = ({
|
|
onSuccess,
|
|
onError,
|
|
...options
|
|
}: Omit<
|
|
UseMutationOptions<StripeSyncInstallData, ResponseError, StripeSyncInstallVariables>,
|
|
'mutationFn'
|
|
> = {}) => {
|
|
const queryClient = useQueryClient()
|
|
const track = useTrack()
|
|
|
|
return useMutation<StripeSyncInstallData, ResponseError, StripeSyncInstallVariables>({
|
|
mutationFn: (vars) => installStripeSync(vars),
|
|
async onSuccess(data, variables, context) {
|
|
const { projectRef } = variables
|
|
|
|
track('integration_install_started', {
|
|
integrationName: 'stripe_sync_engine',
|
|
})
|
|
|
|
// Invalidate schemas query to refresh installation status
|
|
await queryClient.invalidateQueries({
|
|
queryKey: databaseKeys.schemas(projectRef),
|
|
})
|
|
|
|
// Also invalidate any stripe sync related queries
|
|
await queryClient.invalidateQueries({
|
|
queryKey: stripeSyncKeys.all,
|
|
})
|
|
|
|
await onSuccess?.(data, variables, context)
|
|
},
|
|
async onError(data, variables, context) {
|
|
if (onError === undefined) {
|
|
toast.error(`Failed to install Stripe Sync: ${data.message}`)
|
|
} else {
|
|
onError(data, variables, context)
|
|
}
|
|
},
|
|
...options,
|
|
})
|
|
}
|