Skip to content

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

Merge branch 'master' into feat/github-integration

Alaister Young9fbc18ca2ff2
diff --cc studio/components/interfaces/Integrations/ProjectLinker.tsx
index 1df94aed64d,e220c54f1d2..8aefbcc265e
--- a/studio/components/interfaces/Integrations/ProjectLinker.tsx
+++ b/studio/components/interfaces/Integrations/ProjectLinker.tsx
@@@ -1,69 -1,124 +1,104 @@@
- import { ReactNode, useState } from 'react'
-import { ENV_VAR_RAW_KEYS } from 'components/interfaces/Integrations/Integrations-Vercel.constants'
-import { Markdown } from 'components/interfaces/Markdown'
-import { vercelIcon } from 'components/to-be-cleaned/ListIcons'
-import { useIntegrationConnectionsCreateMutation } from 'data/integrations/integration-connections-create-mutation'
-import { useIntegrationsVercelConnectionSyncEnvsMutation } from 'data/integrations/integrations-vercel-connection-sync-envs-mutation'
-import { VercelProjectsResponse } from 'data/integrations/integrations-vercel-projects-query'
++import { ReactNode, useRef, useState } from 'react'
+
import { IntegrationProjectConnection } from 'data/integrations/integrations.types'
+import { IntegrationConnectionsCreateVariables } from 'data/integrations/types'
import { useSelectedOrganization } from 'hooks'
import { BASE_PATH } from 'lib/constants'
- import { Button, Listbox, cn } from 'ui'
-import { useRef, useState } from 'react'
-import { toast } from 'react-hot-toast'
+ import {
+ Button,
+ CommandEmpty_Shadcn_,
+ CommandGroup_Shadcn_,
+ CommandInput_Shadcn_,
+ CommandItem_Shadcn_,
+ CommandList_Shadcn_,
+ Command_Shadcn_,
+ IconChevronDown,
+ PopoverContent_Shadcn_,
+ PopoverTrigger_Shadcn_,
+ Popover_Shadcn_,
+ cn,
+ } from 'ui'
-interface Project {
+export interface Project {
id: string
name: string
ref: string
}
+export interface ForeignProject {
+ id: string
+ name: string
+}
+
export interface ProjectLinkerProps {
organizationIntegrationId: string | undefined
- foreignProjects: VercelProjectsResponse[]
+ foreignProjects: ForeignProject[]
supabaseProjects: Project[]
- onCreateConnections?: () => void
+ onCreateConnections: (variables: IntegrationConnectionsCreateVariables) => void
installedConnections: IntegrationProjectConnection[] | undefined
- setLoading?: (x: boolean) => void
- showSkip?: boolean
+ isLoading?: boolean
+ integrationIcon: ReactNode
+ getForeignProjectIcon?: (project: ForeignProject) => ReactNode
+ choosePrompt?: string
+ onSkip?: () => void
+ loadingForeignProjects?: boolean
+ loadingSupabaseProjects?: boolean
}
- const UNDEFINED_SELECT_VALUE = 'undefined'
-
const ProjectLinker = ({
organizationIntegrationId,
foreignProjects,
supabaseProjects,
onCreateConnections: _onCreateConnections,
installedConnections = [],
- setLoading,
- showSkip = false,
+ isLoading,
+ integrationIcon,
+ getForeignProjectIcon,
+ choosePrompt = 'Choose a project',
+ onSkip,
+ loadingForeignProjects,
+ loadingSupabaseProjects,
}: ProjectLinkerProps) => {
+ const [supabaseProjectsComboBoxOpen, setSupabaseProjectsComboboxOpen] = useState(false)
- const [vercelProjectsComboBoxOpen, setVercelProjectsComboboxOpen] = useState(false)
++ const [foreignProjectsComboBoxOpen, setForeignProjectsComboboxOpen] = useState(false)
+ const supabaseProjectsComboBoxRef = useRef<HTMLButtonElement>(null)
- const vercelProjectsComboBoxRef = useRef<HTMLButtonElement>(null)
++ const foreignProjectsComboBoxRef = useRef<HTMLButtonElement>(null)
+
const selectedOrganization = useSelectedOrganization()
- const [supabaseProjectRef, setSupabaseProjectRef] = useState(UNDEFINED_SELECT_VALUE)
- const [foreignProjectId, setForeignProjectId] = useState(UNDEFINED_SELECT_VALUE)
+ const [supabaseProjectRef, setSupabaseProjectRef] = useState<string | undefined>(undefined)
- const [vercelProjectId, setVercelProjectId] = useState<string | undefined>(undefined)
-
- const { mutateAsync: syncEnvs } = useIntegrationsVercelConnectionSyncEnvsMutation()
- const { mutate: createConnections, isLoading } = useIntegrationConnectionsCreateMutation({
- async onSuccess({ id }) {
- try {
- await syncEnvs({ connectionId: id })
- } catch (error: any) {
- toast.error('Failed to sync environment variables: ', error.message)
- }
-
- if (setLoading) setLoading(false)
- _onCreateConnections?.()
- },
- onError() {
- if (setLoading) setLoading(false)
- },
- })
++ const [foreignProjectId, setForeignProjectId] = useState<string | undefined>(undefined)
+
+ // create a flat array of foreign project ids. ie, ["prj_MlkO6AiLG5ofS9ojKrkS3PhhlY3f", ..]
+ const flatInstalledConnectionsIds = new Set(installedConnections.map((x) => x.foreign_project_id))
+
- // check that vercel project is not already installed
- const filteredForeignProjects: VercelProjectsResponse[] = foreignProjects.filter(
- (foreignProject) => {
- return !flatInstalledConnectionsIds.has(foreignProject.id)
- }
- )
++ // check that foreign project is not already installed
++ const filteredForeignProjects = foreignProjects.filter((foreignProject) => {
++ return !flatInstalledConnectionsIds.has(foreignProject.id)
++ })
+
+ const selectedSupabaseProject = supabaseProjectRef
+ ? supabaseProjects.find((x) => x.ref?.toLowerCase() === supabaseProjectRef?.toLowerCase())
+ : undefined
+
- const selectedVercelProject = vercelProjectId
- ? filteredForeignProjects.find((x) => x.id?.toLowerCase() === vercelProjectId?.toLowerCase())
++ const selectedForeignProject = foreignProjectId
++ ? filteredForeignProjects.find((x) => x.id?.toLowerCase() === foreignProjectId?.toLowerCase())
+ : undefined
function onCreateConnections() {
- const projectDetails = foreignProjects.filter((x) => x.id === foreignProjectId)[0]
- const projectDetails = selectedVercelProject
++ const projectDetails = selectedForeignProject
- if (!organizationIntegrationId) {
- console.error('No integration ID set')
- return
- }
+ if (!organizationIntegrationId) return console.error('No integration ID set')
- if (!selectedVercelProject?.id) return console.error('No Vercel project ID set')
++ if (!selectedForeignProject?.id) return console.error('No Foreign project ID set')
+ if (!selectedSupabaseProject?.ref) return console.error('No Supabase project ref set')
- if (setLoading) setLoading(true)
-
- createConnections({
+ _onCreateConnections({
organizationIntegrationId,
connection: {
- foreign_project_id: foreignProjectId,
- supabase_project_ref: supabaseProjectRef,
- foreign_project_id: selectedVercelProject?.id,
++ foreign_project_id: selectedForeignProject?.id,
+ supabase_project_ref: selectedSupabaseProject?.ref,
metadata: {
...projectDetails,
- supabaseConfig: {
- projectEnvVars: {
- write: true,
- },
- },
},
},
orgSlug: selectedOrganization?.slug,
@@@ -139,31 -225,96 +205,75 @@@
<div className="border border-scale-1000 h-px w-16 border-dashed self-end mb-5"></div>
<Panel>
<div className="bg-black shadow rounded p-1 w-12 h-12 flex justify-center items-center">
- {integrationIcon}
+ <svg
+ xmlns="http://www.w3.org/2000/svg"
+ fill="white"
+ viewBox="0 0 512 512"
+ className="w-6"
+ >
+ <path fillRule="evenodd" d="M256,48,496,464H16Z" />
+ </svg>
</div>
- <Listbox
- className="w-full"
- value={foreignProjectId ?? UNDEFINED_SELECT_VALUE}
- onChange={(e) => setForeignProjectId(e)}
+
+ <Popover_Shadcn_
- open={vercelProjectsComboBoxOpen}
- onOpenChange={setVercelProjectsComboboxOpen}
++ open={foreignProjectsComboBoxOpen}
++ onOpenChange={setForeignProjectsComboboxOpen}
>
- <Listbox.Option value={UNDEFINED_SELECT_VALUE} label={choosePrompt} disabled>
- {choosePrompt}
- </Listbox.Option>
- {filteredForeignProjects.map((project) => {
- return (
- <Listbox.Option
- key={project.id}
- value={project.id}
- label={project.name}
- addOnBefore={() => {
- return getForeignProjectIcon?.(project) ?? null
- }}
- >
- {project.name}
- </Listbox.Option>
- )
- })}
- </Listbox>
+ <PopoverTrigger_Shadcn_ asChild>
+ <Button
- ref={vercelProjectsComboBoxRef}
++ ref={foreignProjectsComboBoxRef}
+ type="default"
+ size="medium"
+ block
+ disabled={loadingForeignProjects}
+ loading={loadingForeignProjects}
+ className="justify-start"
+ icon={
- selectedVercelProject ? (
- selectedVercelProject?.framework ? (
- vercelIcon
- ) : (
- <img
- src={`${BASE_PATH}/img/icons/frameworks/${selectedVercelProject.framework}.svg`}
- width={21}
- height={21}
- alt={`icon`}
- />
- )
- ) : (
- <></>
- )
++ selectedForeignProject
++ ? getForeignProjectIcon?.(selectedForeignProject)
++ : integrationIcon
+ }
+ iconRight={
+ <span className="grow flex justify-end">
+ <IconChevronDown className={''} />
+ </span>
+ }
+ >
- {(selectedVercelProject && selectedVercelProject.name) ??
- 'Choose a Vercel Project'}
++ {(selectedForeignProject && selectedForeignProject.name) ?? choosePrompt}
+ </Button>
+ </PopoverTrigger_Shadcn_>
+ <PopoverContent_Shadcn_
+ className="p-0 w-full"
+ side="bottom"
+ align="center"
- style={{ width: vercelProjectsComboBoxRef.current?.offsetWidth }}
++ style={{ width: foreignProjectsComboBoxRef.current?.offsetWidth }}
+ >
+ <Command_Shadcn_>
+ <CommandInput_Shadcn_ placeholder="Search organization..." />
+ <CommandList_Shadcn_ className="!max-h-[170px]">
+ <CommandEmpty_Shadcn_>No results found.</CommandEmpty_Shadcn_>
+ <CommandGroup_Shadcn_>
+ {filteredForeignProjects.map((project) => {
+ return (
+ <CommandItem_Shadcn_
+ value={project.id}
+ key={project.id}
+ className="flex gap-2 items-center"
+ onSelect={(id) => {
- if (id) setVercelProjectId(id)
- setVercelProjectsComboboxOpen(false)
++ if (id) setForeignProjectId(id)
++ setForeignProjectsComboboxOpen(false)
+ }}
+ >
- {!project?.framework ? (
- vercelIcon
- ) : (
- <img
- src={`${BASE_PATH}/img/icons/frameworks/${project.framework}.svg`}
- width={21}
- height={21}
- alt={`icon`}
- />
- )}
++ {getForeignProjectIcon?.(project) ?? integrationIcon}
+ <span>{project.name}</span>
+ </CommandItem_Shadcn_>
+ )
+ })}
+ </CommandGroup_Shadcn_>
+ </CommandList_Shadcn_>
+ </Command_Shadcn_>
+ </PopoverContent_Shadcn_>
+ </Popover_Shadcn_>
</Panel>
</div>
</div>
@@@ -184,7 -335,15 +294,15 @@@
className="self-end"
onClick={onCreateConnections}
loading={isLoading}
- disabled={isLoading}
+ disabled={
+ // data loading states
+ loadingForeignProjects ||
+ loadingSupabaseProjects ||
+ isLoading ||
+ // check wether both project types are not undefined
+ !selectedSupabaseProject ||
- !selectedVercelProject
++ !selectedForeignProject
+ }
>
Connect project
</Button>
diff --cc studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx
index aeaa77c4995,fa67ca265bb..02228325215
--- a/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx
+++ b/studio/pages/integrations/vercel/[slug]/marketplace/choose-project.tsx
@@@ -1,32 -1,18 +1,31 @@@
-import { useMemo, useState } from 'react'
+import { keyBy } from 'lodash'
+import { useCallback, useMemo } from 'react'
++import { toast } from 'react-hot-toast'
import { useParams } from 'common'
-import ProjectLinker from 'components/interfaces/Integrations/ProjectLinker'
++import { ENV_VAR_RAW_KEYS } from 'components/interfaces/Integrations/Integrations-Vercel.constants'
+import ProjectLinker, { ForeignProject } from 'components/interfaces/Integrations/ProjectLinker'
import { Markdown } from 'components/interfaces/Markdown'
-import IntegrationWindowLayout from 'components/layouts/IntegrationWindowLayout'
+import { VercelIntegrationLayout } from 'components/layouts'
- import { ScaffoldContainer, ScaffoldDivider } from 'components/layouts/Scaffold'
+ import { ScaffoldColumn, ScaffoldContainer, ScaffoldDivider } from 'components/layouts/Scaffold'
+import { vercelIcon } from 'components/to-be-cleaned/ListIcons'
import { useOrgIntegrationsQuery } from 'data/integrations/integrations-query-org-only'
++import { useIntegrationsVercelConnectionSyncEnvsMutation } from 'data/integrations/integrations-vercel-connection-sync-envs-mutation'
+import { useIntegrationVercelConnectionsCreateMutation } from 'data/integrations/integrations-vercel-connections-create-mutation'
import { useVercelProjectsQuery } from 'data/integrations/integrations-vercel-projects-query'
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
import { useProjectsQuery } from 'data/projects/projects-query'
+import { BASE_PATH } from 'lib/constants'
import { EMPTY_ARR } from 'lib/void'
-
import { NextPageWithLayout, Organization } from 'types'
import { IconBook, IconLifeBuoy, LoadingLine } from 'ui'
- import { ENV_VAR_RAW_KEYS } from 'components/interfaces/Integrations/Integrations-Vercel.constants'
- import { useIntegrationsVercelConnectionSyncEnvsMutation } from 'data/integrations/integrations-vercel-connection-sync-envs-mutation'
- import { toast } from 'react-hot-toast'
+const VERCEL_ICON = (
+ <svg xmlns="http://www.w3.org/2000/svg" fill="white" viewBox="0 0 512 512" className="w-6">
+ <path fill-rule="evenodd" d="M256,48,496,464H16Z" />
+ </svg>
+)
+
const VercelIntegration: NextPageWithLayout = () => {
const { slug, configurationId, next, organizationSlug } = useParams()
@@@ -45,16 -33,13 +44,18 @@@
const organization = data?.find((organization: Organization) => organization.slug === slug)
- const integration = integrationData?.find((x) => x.metadata?.configuration_id === configurationId)
+ const integration = integrationData?.find(
+ (x) =>
+ x.metadata !== undefined &&
+ 'configuration_id' in x.metadata &&
+ x.metadata?.configuration_id === configurationId
+ )
- const { data: supabaseProjectsData } = useProjectsQuery({
- enabled: integration?.id !== undefined,
- })
+ const { data: supabaseProjectsData, isLoading: isLoadingSupabaseProjectsData } = useProjectsQuery(
+ {
+ enabled: integration?.id !== undefined,
+ }
+ )
const supabaseProjects = useMemo(
() =>
@@@ -62,118 -47,53 +63,124 @@@
?.filter((project) => project.organization_id === organization?.id)
.map((project) => ({ id: project.id.toString(), name: project.name, ref: project.ref })) ??
EMPTY_ARR,
- [organizationSlug, supabaseProjectsData]
+ [organization?.id, supabaseProjectsData]
)
- const { data: vercelProjectsData } = useVercelProjectsQuery(
- {
- organization_integration_id: integration?.id,
- },
- { enabled: integration?.id !== undefined }
- )
+ const { data: vercelProjectsData, isLoading: isLoadingVercelProjectsData } =
+ useVercelProjectsQuery(
+ {
+ organization_integration_id: integration?.id,
+ },
+ { enabled: integration?.id !== undefined }
+ )
const vercelProjects = useMemo(() => vercelProjectsData ?? EMPTY_ARR, [vercelProjectsData])
+ const vercelProjectsById = useMemo(() => keyBy(vercelProjects, 'id'), [vercelProjects])
+
+ const getForeignProjectIcon = useCallback(
+ (_project: ForeignProject) => {
+ const project = vercelProjectsById[_project.id]
+
+ return !project?.framework ? (
+ vercelIcon
+ ) : (
+ <img
+ src={`${BASE_PATH}/img/icons/frameworks/${project.framework}.svg`}
+ width={21}
+ height={21}
+ alt={`icon`}
+ />
+ )
+ },
+ [vercelProjectsById]
+ )
+
+ const { mutateAsync: syncEnvs } = useIntegrationsVercelConnectionSyncEnvsMutation()
+ const { mutate: createConnections, isLoading: isCreatingConnection } =
+ useIntegrationVercelConnectionsCreateMutation({
+ async onSuccess({ id }) {
+ try {
+ await syncEnvs({ connectionId: id })
+ } catch (error: any) {
+ toast.error('Failed to sync environment variables: ', error.message)
+ }
+
+ if (next) {
+ window.location.href = next
+ }
+ },
+ })
+
+ const onCreateConnections = useCallback(
+ (vars) => {
+ createConnections({
+ ...vars,
+ connection: {
+ ...vars.connection,
+ metadata: {
+ ...vars.connection.metadata,
+ supabaseConfig: {
+ projectEnvVars: {
+ write: true,
+ },
+ },
+ },
+ },
+ })
+ },
+ [createConnections]
+ )
return (
<>
- <LoadingLine loading={loading} />
++ <LoadingLine loading={isCreatingConnection} />
<main className="overflow-auto flex flex-col h-full">
- <LoadingLine loading={isCreatingConnection} />
<>
<ScaffoldContainer className="flex flex-col gap-6 grow py-8">
- <header>
- <h1 className="text-xl text-scale-1200">
- Link a Supabase project to a Vercel project
- </h1>
- <Markdown
- className="text-scale-900"
- content={`
+ <ScaffoldColumn className="!max-w-[900px] mx-auto w-full">
+ <header>
+ <h1 className="text-xl text-scale-1200">
+ Link a Supabase project to a Vercel project
+ </h1>
+ <Markdown
+ className="text-scale-900"
+ content={`
This Supabase integration manages your environment variables automatically to provide the latest keys in the unlikely event that you will need to refresh your JWT token.
`}
+ />
+ </header>
++
+ <ProjectLinker
+ organizationIntegrationId={integration?.id}
+ foreignProjects={vercelProjects}
+ supabaseProjects={supabaseProjects}
- onCreateConnections={() => {
++ onCreateConnections={onCreateConnections}
++ installedConnections={integration?.connections}
++ isLoading={isCreatingConnection}
++ integrationIcon={VERCEL_ICON}
++ getForeignProjectIcon={getForeignProjectIcon}
++ choosePrompt="Choose Vercel Project"
++ onSkip={() => {
+ if (next) {
+ window.location.href = next
+ }
+ }}
- installedConnections={integration?.connections}
- setLoading={setLoading}
- showSkip={true}
+ loadingForeignProjects={isLoadingVercelProjectsData}
+ loadingSupabaseProjects={isLoadingSupabaseProjectsData}
/>
- </header>
- <ProjectLinker
- organizationIntegrationId={integration?.id}
- foreignProjects={vercelProjects}
- supabaseProjects={supabaseProjects}
- onCreateConnections={onCreateConnections}
- installedConnections={integration?.connections}
- isLoading={isCreatingConnection}
- integrationIcon={VERCEL_ICON}
- getForeignProjectIcon={getForeignProjectIcon}
- choosePrompt="Choose Vercel Project"
- onSkip={() => {
- if (next) {
- window.location.href = next
- }
- }}
- />
- <Markdown
- content={`
++ <Markdown
++ content={`
+The following environment variables will be added:
+
+${ENV_VAR_RAW_KEYS.map((x) => {
+ return `
+ \n
+ - \`${x}\`
+`
+})}
+`}
- />
++ />
+ </ScaffoldColumn>
</ScaffoldContainer>
</>
diff --cc studio/pages/integrations/vercel/install.tsx
index 89ca43f3906,a323420f3d5..a93bee324e4
--- a/studio/pages/integrations/vercel/install.tsx
+++ b/studio/pages/integrations/vercel/install.tsx
@@@ -1,16 -1,39 +1,39 @@@
++import { useRouter } from 'next/router'
++import { useEffect, useRef, useState } from 'react'
++
import { useParams } from 'common'
import { Markdown } from 'components/interfaces/Markdown'
-import IntegrationWindowLayout from 'components/layouts/IntegrationWindowLayout'
+import VercelIntegrationWindowLayout from 'components/layouts/IntegrationsLayout/VercelIntegrationWindowLayout'
import { ScaffoldColumn, ScaffoldContainer, ScaffoldDivider } from 'components/layouts/Scaffold'
import { useIntegrationsQuery } from 'data/integrations/integrations-query'
import { IntegrationName } from 'data/integrations/integrations.types'
import { useVercelIntegrationCreateMutation } from 'data/integrations/vercel-integration-create-mutation'
import { useOrganizationsQuery } from 'data/organizations/organizations-query'
import { useStore } from 'hooks'
--import { useRouter } from 'next/router'
- import { useState } from 'react'
-import { useEffect, useRef, useState } from 'react'
-import { useVercelIntegrationInstallationState } from 'state/vercel-integration-installation'
import { NextPageWithLayout, Organization } from 'types'
- import { Alert, Badge, Button, IconBook, IconHexagon, IconLifeBuoy, Listbox, LoadingLine } from 'ui'
+ import {
+ AlertDescription_Shadcn_,
+ AlertTitle_Shadcn_,
+ Alert_Shadcn_,
+ Badge,
+ Button,
+ CommandEmpty_Shadcn_,
+ CommandGroup_Shadcn_,
+ CommandInput_Shadcn_,
+ CommandItem_Shadcn_,
+ CommandList_Shadcn_,
+ Command_Shadcn_,
+ IconAlertTriangle,
+ IconBook,
+ IconChevronDown,
+ IconHexagon,
+ IconInfo,
+ IconLifeBuoy,
+ LoadingLine,
+ PopoverContent_Shadcn_,
+ PopoverTrigger_Shadcn_,
+ Popover_Shadcn_,
+ } from 'ui'
/**
* Organization type with `installationInstalled` added
@@@ -32,38 -55,62 +55,57 @@@ export type VercelIntegrationFlow = 'de
const VercelIntegration: NextPageWithLayout = () => {
const router = useRouter()
const { ui } = useStore()
- const { code, configurationId, next, teamId, source, externalId } = useParams()
+ const { code, configurationId, teamId, source, externalId } = useParams()
- const [selectedOrg, setSelectedOrg] = useState<Organization | null>(null)
+ const [selectedOrg, setSelectedOrg] = useState<OrganizationsResponseWithInstalledData | null>(
+ null
+ )
const [organizationIntegrationId, setOrganizationIntegrationId] = useState<string | null>(null)
- const snapshot = useVercelIntegrationInstallationState()
-
- const flow: VercelIntegrationFlow = externalId ? 'marketing' : 'deploy-button'
-
/**
* Fetch the list of organization based integration installations for Vercel.
*
* Array of integrations installed on all
*/
- const { data: integrationData, isLoading: integrationDataLoading } = useIntegrationsQuery()
+ const { data: integrationData } = useIntegrationsQuery()
- const { data: organizationsData, isLoading: isLoadingOrganizationsQuery } = useOrganizationsQuery(
- {
- onSuccess(organizations) {
- const firstOrg = organizations?.[0]
- if (firstOrg && selectedOrg === null) {
- setSelectedOrg(firstOrg)
- router.query.organizationSlug = firstOrg.slug
- }
- },
+ const { data: organizationsData, isLoading: isLoadingOrganizationsQuery } =
+ useOrganizationsQuery()
+
+ useEffect(() => {
+ if (organizationsData !== undefined && integrationData !== undefined) {
+ const firstOrg = organizationsWithInstalls(organizationsData)?.[0]
+
+ if (firstOrg && selectedOrg === null) {
+ setSelectedOrg(firstOrg)
- snapshot.setSelectedOrganizationSlug(firstOrg.slug)
+ router.query.organizationSlug = firstOrg.slug
+ }
}
- )
+ }, [organizationsData, integrationData])
/**
- * Flat array of org slugs that have integration installed
+ * Find installedConnections
*/
- const flatInstalledConnectionsIds: string[] | [] =
- integrationData && integrationData.length > 0
- ? integrationData
- .filter((x) => x.integration.name === 'Vercel')
- .map((x) => x.organization.slug)
+ function organizationsWithInstalls(organizations?: OrganizationsResponseWithInstalledData[]) {
+ /**
+ * Flat array of org slugs that have integration installed
+ *
+ */
+ const flatInstalledConnectionsIds: string[] | [] =
+ integrationData && integrationData.length > 0
+ ? integrationData
+ .filter((x) => x.integration.name === 'Vercel')
+ .map((x) => x.organization.slug)
+ : []
+
+ return organizations
+ ? organizations?.map((org) => {
+ return {
+ ...org,
+ installationInstalled: flatInstalledConnectionsIds.includes(org.slug) ? true : false,
+ }
+ })
: []
+ }
/**
* Organizations with extra `installationInstalled` attribute
@@@ -161,9 -204,16 +197,16 @@@
const dataLoading = isLoadingVercelIntegrationCreateMutation || isLoadingOrganizationsQuery
+ const disableInstallationForm =
+ (isLoadingVercelIntegrationCreateMutation && !dataLoading) ||
+ // disables installation button if integration is already installed and it is Marketplace flow
+ (selectedOrg && selectedOrg?.installationInstalled && source === 'marketplace' && !dataLoading)
+ ? true
+ : false
+
return (
<>
- <main className="overflow-auto flex flex-col h-full">
+ <main className="overflow-auto flex flex-col h-full bg-scale-400">
<LoadingLine loading={isLoadingVercelIntegrationCreateMutation} />
{organizationIntegrationId === null && (
<>
@@@ -185,7 -251,7 +244,7 @@@
<Button
size="medium"
className="self-end"
- disabled={isLoadingVercelIntegrationCreateMutation}
- disabled={disableInstallationForm}
++ disabled={disableInstallationForm || isLoadingVercelIntegrationCreateMutation}
loading={isLoadingVercelIntegrationCreateMutation}
onClick={onInstall}
>