Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

show Vercel connection errors inline (#48473)

Danny White9b3e0a906085
diff --git a/apps/studio/components/interfaces/Integrations/VercelGithub/ProjectLinker.tsx b/apps/studio/components/interfaces/Integrations/VercelGithub/ProjectLinker.tsx
index 2a491957170..8a4e66b84a5 100644
--- a/apps/studio/components/interfaces/Integrations/VercelGithub/ProjectLinker.tsx
+++ b/apps/studio/components/interfaces/Integrations/VercelGithub/ProjectLinker.tsx
@@ -8,6 +8,7 @@ import {
SupabaseProjectSelector,
} from './ProjectLinkerComponents'
import { Project, ProjectLinkerProps } from './VercelGithub.types'
+import { InterstitialActionError } from '@/components/layouts/InterstitialLayout'
import ShimmerLine from '@/components/ui/ShimmerLine'
import { useOrgProjectsInfiniteQuery } from '@/data/projects/org-projects-infinite-query'
import { useSelectedOrganizationQuery } from '@/hooks/misc/useSelectedOrganization'
@@ -31,6 +32,8 @@ export const ProjectLinker = ({
defaultForeignProjectId,
mode,
variant = 'default',
+ actionError,
+ onSelectionChange,
}: ProjectLinkerProps) => {
const [openProjectsDropdown, setOpenProjectsDropdown] = useState(false)
const [openForeignProjectsComboBox, setOpenForeignProjectsComboBox] = useState(false)
@@ -38,6 +41,7 @@ export const ProjectLinker = ({
defaultForeignProjectId
)
const [selectedSupabaseProject, setSelectedSupabaseProject] = useState<Project>()
+ const [validationError, setValidationError] = useState<string>()
const { data: selectedOrganization } = useSelectedOrganizationQuery()
const { data: orgProjects, isPending: loadingSupabaseProjects } = useOrgProjectsInfiniteQuery({
@@ -60,11 +64,15 @@ export const ProjectLinker = ({
const alreadyInstalled = flatInstalledConnectionsIds.has(foreignProjectId ?? '')
if (alreadyInstalled) {
- return toast.error(
- `Unable to connect to ${selectedForeignProject.name}: Selected repository already has an installed connection to a project`
- )
+ const message = `Unable to connect to ${selectedForeignProject.name}: Selected repository already has an installed connection to a project`
+ if (variant === 'interstitial') {
+ setValidationError(message)
+ return
+ }
+ return toast.error(message)
}
+ setValidationError(undefined)
_onCreateConnections({
organizationIntegrationId: organizationIntegrationId!,
connection: {
@@ -95,6 +103,17 @@ export const ProjectLinker = ({
isLoading ||
!selectedSupabaseProject ||
!selectedForeignProject
+ const displayedActionError = actionError ?? validationError
+ const setForeignProjectSelection: typeof setForeignProjectId = (value) => {
+ setForeignProjectId(value)
+ setValidationError(undefined)
+ onSelectionChange?.()
+ }
+ const setSupabaseProjectSelection: typeof setSelectedSupabaseProject = (value) => {
+ setSelectedSupabaseProject(value)
+ setValidationError(undefined)
+ onSelectionChange?.()
+ }
useEffect(() => {
if (defaultSupabaseProject !== undefined && selectedSupabaseProject === undefined)
@@ -134,7 +153,7 @@ export const ProjectLinker = ({
selectedSupabaseProject={selectedSupabaseProject}
loadingSupabaseProjects={loadingSupabaseProjects}
setOpen={setOpenProjectsDropdown}
- setSelectedSupabaseProject={setSelectedSupabaseProject}
+ setSelectedSupabaseProject={setSupabaseProjectSelection}
/>
</section>
@@ -151,7 +170,7 @@ export const ProjectLinker = ({
loadingForeignProjects={loadingForeignProjects}
foreignProjects={foreignProjects}
integrationIcon={integrationIcon}
- setForeignProjectId={setForeignProjectId}
+ setForeignProjectId={setForeignProjectSelection}
onOpenChange={setOpenForeignProjectsComboBox}
getForeignProjectIcon={getForeignProjectIcon}
/>
@@ -159,17 +178,20 @@ export const ProjectLinker = ({
</>
)}
- <ActionButtons
- slug={slug}
- mode={mode}
- variant={variant}
- showCreateProject={showNoEntitiesState && noSupabaseProjects}
- connectDisabled={connectDisabled}
- foreignProjectId={foreignProjectId}
- isLoading={isLoading}
- onCreateConnections={onCreateConnections}
- onSkip={onSkip}
- />
+ <div className="flex flex-col gap-2">
+ <ActionButtons
+ slug={slug}
+ mode={mode}
+ variant={variant}
+ showCreateProject={showNoEntitiesState && noSupabaseProjects}
+ connectDisabled={connectDisabled}
+ foreignProjectId={foreignProjectId}
+ isLoading={isLoading}
+ onCreateConnections={onCreateConnections}
+ onSkip={onSkip}
+ />
+ <InterstitialActionError error={displayedActionError} />
+ </div>
</div>
)
}
@@ -216,7 +238,7 @@ export const ProjectLinker = ({
selectedSupabaseProject={selectedSupabaseProject}
loadingSupabaseProjects={loadingSupabaseProjects}
setOpen={setOpenProjectsDropdown}
- setSelectedSupabaseProject={setSelectedSupabaseProject}
+ setSelectedSupabaseProject={setSupabaseProjectSelection}
/>
</Panel>
@@ -236,7 +258,7 @@ export const ProjectLinker = ({
loadingForeignProjects={loadingForeignProjects}
foreignProjects={foreignProjects}
integrationIcon={integrationIcon}
- setForeignProjectId={setForeignProjectId}
+ setForeignProjectId={setForeignProjectSelection}
onOpenChange={setOpenForeignProjectsComboBox}
getForeignProjectIcon={getForeignProjectIcon}
/>
diff --git a/apps/studio/components/interfaces/Integrations/VercelGithub/VercelGithub.types.ts b/apps/studio/components/interfaces/Integrations/VercelGithub/VercelGithub.types.ts
index aa745b4d43b..ced750b9887 100644
--- a/apps/studio/components/interfaces/Integrations/VercelGithub/VercelGithub.types.ts
+++ b/apps/studio/components/interfaces/Integrations/VercelGithub/VercelGithub.types.ts
@@ -33,4 +33,6 @@ export interface ProjectLinkerProps {
defaultForeignProjectId?: string
mode: 'Vercel' | 'GitHub'
variant?: 'default' | 'interstitial'
+ actionError?: string
+ onSelectionChange?: () => void
}
diff --git a/apps/studio/components/interfaces/Organization/IntegrationSettings/SidePanelVercelProjectLinker.tsx b/apps/studio/components/interfaces/Organization/IntegrationSettings/SidePanelVercelProjectLinker.tsx
index 774ee1f63d7..d765fa85c95 100644
--- a/apps/studio/components/interfaces/Organization/IntegrationSettings/SidePanelVercelProjectLinker.tsx
+++ b/apps/studio/components/interfaces/Organization/IntegrationSettings/SidePanelVercelProjectLinker.tsx
@@ -16,6 +16,7 @@ import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { BASE_PATH } from '@/lib/constants'
import { EMPTY_ARR } from '@/lib/void'
import { useSidePanelsStateSnapshot } from '@/state/side-panels'
+import type { ResponseError } from '@/types'
const VERCEL_ICON = (
<svg xmlns="http://www.w3.org/2000/svg" fill="white" viewBox="0 0 512 512" className="w-6">
@@ -82,6 +83,9 @@ export const SidePanelVercelProjectLinker = () => {
sidePanelStateSnapshot.setVercelConnectionsOpen(false)
},
+ onError(error: ResponseError) {
+ toast.error(`Failed to create connection: ${error.message}`)
+ },
})
const onCreateConnections = useCallback(
diff --git a/apps/studio/data/integrations/integrations-vercel-connections-create-mutation.ts b/apps/studio/data/integrations/integrations-vercel-connections-create-mutation.ts
index 51238c1daae..88cb907238a 100644
--- a/apps/studio/data/integrations/integrations-vercel-connections-create-mutation.ts
+++ b/apps/studio/data/integrations/integrations-vercel-connections-create-mutation.ts
@@ -1,5 +1,4 @@
import { useMutation, useQueryClient } from '@tanstack/react-query'
-import { toast } from 'sonner'
import type { IntegrationConnectionsCreateVariables } from './integrations.types'
import { integrationKeys } from './keys'
@@ -67,11 +66,7 @@ export const useIntegrationVercelConnectionsCreateMutation = ({
},
async onError(data, variables, context) {
snapshot.setLoading(false)
- if (onError === undefined) {
- toast.error(`Failed to create connection: ${data.message}`)
- } else {
- onError(data, variables, context)
- }
+ await onError?.(data, variables, context)
},
...options,
})
diff --git a/apps/studio/data/integrations/vercel-integration-create-mutation.ts b/apps/studio/data/integrations/vercel-integration-create-mutation.ts
index 35603b759b5..dc60e11bdc6 100644
--- a/apps/studio/data/integrations/vercel-integration-create-mutation.ts
+++ b/apps/studio/data/integrations/vercel-integration-create-mutation.ts
@@ -1,5 +1,4 @@
import { useMutation, useQueryClient } from '@tanstack/react-query'
-import { toast } from 'sonner'
import { integrationKeys } from './keys'
import { handleError, post } from '@/data/fetchers'
@@ -69,11 +68,7 @@ export const useVercelIntegrationCreateMutation = ({
await onSuccess?.(data, variables, context)
},
async onError(data, variables, context) {
- if (onError === undefined) {
- toast.error(`Failed to create Vercel integration: ${data.message}`)
- } else {
- onError(data, variables, context)
- }
+ await onError?.(data, variables, context)
},
...options,
})
diff --git a/apps/studio/pages/integrations/vercel/[slug]/deploy-button/new-project.tsx b/apps/studio/pages/integrations/vercel/[slug]/deploy-button/new-project.tsx
index 02e1c050ab2..5092e50ec87 100644
--- a/apps/studio/pages/integrations/vercel/[slug]/deploy-button/new-project.tsx
+++ b/apps/studio/pages/integrations/vercel/[slug]/deploy-button/new-project.tsx
@@ -1,6 +1,7 @@
import { useParams } from 'common'
import Head from 'next/head'
import { useEffect, useState } from 'react'
+import { toast } from 'sonner'
import { isVercelUrl } from '@/components/interfaces/Integrations/Vercel/VercelIntegration.utils'
import {
@@ -54,7 +55,11 @@ const VercelIntegration: NextPageWithLayout = () => {
}
)
- const { mutateAsync: createConnections } = useIntegrationVercelConnectionsCreateMutation()
+ const { mutateAsync: createConnections } = useIntegrationVercelConnectionsCreateMutation({
+ onError(error) {
+ toast.error(`Failed to create connection: ${error.message}`)
+ },
+ })
useEffect(() => {
if (!isSuccess) return
diff --git a/apps/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx b/apps/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx
index 7febfc533af..ccd04468424 100644
--- a/apps/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx
+++ b/apps/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx
@@ -2,7 +2,6 @@ import { useParams } from 'common'
import { keyBy } from 'lodash'
import Head from 'next/head'
import { useCallback, useMemo } from 'react'
-import { toast } from 'sonner'
import { Card, CardContent } from 'ui'
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
@@ -101,25 +100,29 @@ const VercelChooseProjectPage: NextPageWithLayout = () => {
const snapshot = useIntegrationInstallationSnapshot()
- const { mutate: createConnections, isPending: isCreatingConnection } =
- useIntegrationVercelConnectionsCreateMutation({
- onSuccess() {
- if (next && isVercelUrl(next)) {
- snapshot.setLoading(false)
- window.location.href = next
- }
- },
- onMutate() {
- snapshot.setLoading(true)
- },
- onError(error) {
+ const {
+ mutate: createConnections,
+ isPending: isCreatingConnection,
+ error: createConnectionsError,
+ reset: resetCreateConnectionsError,
+ } = useIntegrationVercelConnectionsCreateMutation({
+ onSuccess() {
+ if (next && isVercelUrl(next)) {
snapshot.setLoading(false)
- toast.error(`Creating connection failed: ${error.message}`)
- },
- })
+ window.location.href = next
+ }
+ },
+ onMutate() {
+ snapshot.setLoading(true)
+ },
+ })
+ const actionError = createConnectionsError
+ ? `Creating connection failed: ${createConnectionsError.message}`
+ : undefined
const onCreateConnections = useCallback(
(vars: Parameters<typeof createConnections>[0]) => {
+ resetCreateConnectionsError()
createConnections({
...vars,
connection: {
@@ -135,7 +138,7 @@ const VercelChooseProjectPage: NextPageWithLayout = () => {
},
})
},
- [createConnections]
+ [createConnections, resetCreateConnectionsError]
)
const showLoadingState =
@@ -212,6 +215,8 @@ const VercelChooseProjectPage: NextPageWithLayout = () => {
}
loadingForeignProjects={isLoadingVercelProjectsData}
mode="Vercel"
+ actionError={actionError}
+ onSelectionChange={resetCreateConnectionsError}
/>
</div>
)}
diff --git a/apps/studio/pages/integrations/vercel/install.tsx b/apps/studio/pages/integrations/vercel/install.tsx
index fb2365a9730..9236e3f3359 100644
--- a/apps/studio/pages/integrations/vercel/install.tsx
+++ b/apps/studio/pages/integrations/vercel/install.tsx
@@ -3,7 +3,6 @@ import Head from 'next/head'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { useEffect, useMemo, useState } from 'react'
-import { toast } from 'sonner'
import {
Badge,
Button,
@@ -24,7 +23,11 @@ import {
VercelIntegrationLogo,
} from '@/components/interfaces/Integrations/Vercel/VercelIntegrationInterstitial'
import { getHasInstalledObject } from '@/components/layouts/IntegrationsLayout/Integrations.utils'
-import { InterstitialAccountRow, InterstitialLayout } from '@/components/layouts/InterstitialLayout'
+import {
+ InterstitialAccountRow,
+ InterstitialActionError,
+ InterstitialLayout,
+} from '@/components/layouts/InterstitialLayout'
import { useIntegrationsQuery } from '@/data/integrations/integrations-query'
import { useVercelIntegrationCreateMutation } from '@/data/integrations/vercel-integration-create-mutation'
import { useOrganizationsQuery } from '@/data/organizations/organizations-query'
@@ -62,6 +65,7 @@ const VercelIntegration: NextPageWithLayout = () => {
const { code, configurationId, currentProjectId, externalId, next, teamId, source } = useParams()
const [selectedOrg, setSelectedOrg] = useState<Organization | null>(null)
+ const [validationError, setValidationError] = useState<string>()
const { username, primaryEmail, avatarUrl } = useProfileNameAndPicture()
const displayName = primaryEmail ?? username ?? ''
@@ -146,46 +150,56 @@ const VercelIntegration: NextPageWithLayout = () => {
break
}
default:
- toast.error(
+ setValidationError(
`Unsupported Vercel installation source: ${source}. Please contact support if this error persists.`
)
}
}
- const { mutate, isPending: isLoadingVercelIntegrationCreateMutation } =
- useVercelIntegrationCreateMutation({
- onMutate() {
- snapshot.setLoading(true)
- },
- onSuccess() {
- handleRouteChange()
- snapshot.setLoading(false)
- },
- onError(error) {
- snapshot.setLoading(false)
- toast.error(`Creating Vercel integration failed: ${error.message}`)
- },
- })
+ const {
+ mutate,
+ isPending: isLoadingVercelIntegrationCreateMutation,
+ error: createIntegrationError,
+ reset: resetCreateIntegrationError,
+ } = useVercelIntegrationCreateMutation({
+ onMutate() {
+ snapshot.setLoading(true)
+ },
+ onSuccess() {
+ handleRouteChange()
+ snapshot.setLoading(false)
+ },
+ onError() {
+ snapshot.setLoading(false)
+ },
+ })
+ const actionError =
+ validationError ??
+ (createIntegrationError
+ ? `Creating Vercel integration failed: ${createIntegrationError.message}`
+ : undefined)
function onInstall() {
+ setValidationError(undefined)
+ resetCreateIntegrationError()
const orgSlug = selectedOrg?.slug
const isIntegrationInstalled = orgSlug ? installed[orgSlug] : false
if (!orgSlug) {
- return toast.error('Please select an organization')
+ return setValidationError('Please select an organization')
}
if (!code) {
- return toast.error('Vercel code missing')
+ return setValidationError('Vercel code missing')
}
if (!configurationId) {
- return toast.error('Vercel Configuration ID missing')
+ return setValidationError('Vercel configuration ID missing')
}
if (!source) {
- return toast.error('Vercel Configuration source missing')
+ return setValidationError('Vercel configuration source missing')
}
/**
@@ -271,7 +285,11 @@ const VercelIntegration: NextPageWithLayout = () => {
selectedOrg={selectedOrg}
disabled={noOrganizations || dataLoading}
installed={installed}
- onSelectedOrgChange={setSelectedOrg}
+ onSelectedOrgChange={(organization) => {
+ setSelectedOrg(organization)
+ setValidationError(undefined)
+ resetCreateIntegrationError()
+ }}
/>
{missingParams.length > 0 && (
@@ -311,6 +329,7 @@ const VercelIntegration: NextPageWithLayout = () => {
>
{selectedOrg && installed[selectedOrg.slug] ? 'Continue' : 'Install integration'}
</Button>
+ <InterstitialActionError error={actionError} />
</div>
</div>
)}