import { zodResolver } from '@hookform/resolvers/zod' import { useForm } from 'react-hook-form' import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, cn, FormControl_Shadcn_, FormDescription_Shadcn_, FormField_Shadcn_, FormItem_Shadcn_, FormLabel_Shadcn_, Form_Shadcn_, IconClock, Switch, } from 'ui' import * as z from 'zod' import { ScaffoldDivider } from 'components/layouts/Scaffold' import { Integration, IntegrationProjectConnection } from 'data/integrations/integrations.types' import { useVercelConnectionUpdateMutation } from 'data/integrations/vercel-connection-update-mutate' import { useFlag, useStore } from 'hooks' const VercelIntegrationConnectionForm = ({ connection, integration, }: { connection: IntegrationProjectConnection integration: Integration }) => { const enableVercelConnectionsConfig = useFlag('enableVercelConnectionsConfig') const { ui } = useStore() const config = connection.metadata.supabaseConfig const FormSchema = z.object({ environmentVariablesProduction: z .boolean() .default(config?.environmentVariables?.production ?? true), authRedirectUrisProduction: z.boolean().default(config?.authRedirectUris?.production ?? true), environmentVariablesPreview: z.boolean().default(config?.environmentVariables?.preview ?? true), authRedirectUrisPreview: z.boolean().default(config?.authRedirectUris?.preview ?? true), }) const form = useForm>({ resolver: zodResolver(FormSchema), defaultValues: { environmentVariablesProduction: config?.environmentVariables?.production ?? true, environmentVariablesPreview: config?.environmentVariables?.preview ?? true, authRedirectUrisProduction: config?.authRedirectUris?.production ?? true, authRedirectUrisPreview: config?.authRedirectUris?.preview ?? true, }, }) const { mutate: updateVercelConnection, isLoading: isUpdatingVercelConnection } = useVercelConnectionUpdateMutation({ onSuccess: (data) => { ui.setNotification({ category: 'success', message: `Updated Supabase directory`, }) }, }) function onSubmit(data: z.infer) { /** * remove this hardcoded if statement when we are ready to enable this feature */ if (!enableVercelConnectionsConfig) return const metadata = { ...connection.metadata, } metadata.supabaseConfig = { environmentVariables: { production: data.environmentVariablesProduction, preview: data.environmentVariablesPreview, }, authRedirectUris: { production: data.authRedirectUrisProduction, preview: data.authRedirectUrisPreview, }, } updateVercelConnection({ id: connection.id, metadata, organizationIntegrationId: integration.id, }) } return (
Vercel Connection configuration coming soon This configuration will allow you to control the environment variables and auth redirects for production and preview deployments.
{/* {isUpdatingVercelConnection && 'isUpdatingVercelConnection'} */}
Vercel Production deployments
(
Sync environment variables for Vercel Production deployments Deploy Edge Functions when merged into Production Branch
{ field.onChange(e) form.handleSubmit(onSubmit)() }} />
)} /> {/* */} (
Auto update Auth Redirect URIs for Vercel Production Deployments Deploy Edge Functions when merged into Production Branch
{ field.onChange(e) form.handleSubmit(onSubmit)() }} />
)} />
Vercel Preview deployments
(
Sync environment variables for Vercel Preview Deployments Preview deployments will be able to connect to Supabase Database Preview branches
{ field.onChange(e) form.handleSubmit(onSubmit)() }} />
)} /> (
Auto update Auth Redirect URIs for Vercel Preview Deployments Deploy Edge Functions when merged into Production Branch
{ field.onChange(e) form.handleSubmit(onSubmit)() }} />
)} />
{/* */}
) } export default VercelIntegrationConnectionForm