@@ -10,7 +10,7 @@ import Panel from 'components/ui/Panel'
1010import { getAPIKeys , useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
1111import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
1212import { useFlag } from 'hooks/ui/useFlag'
13- import { useAppStateSnapshot } from 'state/app-state '
13+ import { parseAsBoolean , useQueryState } from 'nuqs '
1414import {
1515 Button ,
1616 DIALOG_PADDING_X ,
@@ -33,10 +33,14 @@ import ConnectDropdown from './ConnectDropdown'
3333import ConnectTabContent from './ConnectTabContent'
3434
3535const Connect = ( ) => {
36- const state = useAppStateSnapshot ( )
3736 const { ref : projectRef } = useParams ( )
3837 const connectDialogUpdate = useFlag ( 'connectDialogUpdate' )
3938
39+ const [ showConnect , setShowConnect ] = useQueryState (
40+ 'showConnect' ,
41+ parseAsBoolean . withDefault ( false )
42+ )
43+
4044 const [ connectionObject , setConnectionObject ] = useState < ConnectionType [ ] > ( FRAMEWORKS )
4145 const [ selectedParent , setSelectedParent ] = useState ( connectionObject [ 0 ] . key ) // aka nextjs
4246 const [ selectedChild , setSelectedChild ] = useState (
@@ -148,141 +152,135 @@ const Connect = () => {
148152 } )
149153
150154 return (
151- < >
152- < Dialog open = { state . showConnectDialog } onOpenChange = { state . setShowConnectDialog } >
153- < DialogTrigger asChild >
154- < Button
155- type = { connectDialogUpdate ? 'default' : 'primary' }
156- className = { cn ( connectDialogUpdate && 'rounded-full' ) }
157- icon = { < Plug className = "rotate-90" /> }
158- >
159- < span > Connect</ span >
160- </ Button >
161- </ DialogTrigger >
162- < DialogContent className = { cn ( 'sm:max-w-5xl p-0' ) } centered = { false } >
163- < DialogHeader className = { DIALOG_PADDING_X } >
164- < DialogTitle > Connect to your project</ DialogTitle >
165- < DialogDescription >
166- Get the connection strings and environment variables for your app
167- </ DialogDescription >
168- </ DialogHeader >
155+ < Dialog open = { showConnect } onOpenChange = { ( open ) => setShowConnect ( ! open ? null : open ) } >
156+ < DialogTrigger asChild >
157+ < Button
158+ type = { connectDialogUpdate ? 'default' : 'primary' }
159+ className = { cn ( connectDialogUpdate && 'rounded-full' ) }
160+ icon = { < Plug className = "rotate-90" /> }
161+ >
162+ < span > Connect</ span >
163+ </ Button >
164+ </ DialogTrigger >
165+ < DialogContent className = { cn ( 'sm:max-w-5xl p-0' ) } centered = { false } >
166+ < DialogHeader className = { DIALOG_PADDING_X } >
167+ < DialogTitle > Connect to your project</ DialogTitle >
168+ < DialogDescription >
169+ Get the connection strings and environment variables for your app
170+ </ DialogDescription >
171+ </ DialogHeader >
169172
170- < Tabs_Shadcn_
171- defaultValue = "direct"
172- onValueChange = { ( value ) => handleConnectionType ( value ) }
173- >
174- < TabsList_Shadcn_ className = { cn ( 'flex gap-x-4' , DIALOG_PADDING_X ) } >
175- { CONNECTION_TYPES . map ( ( type ) => (
176- < TabsTrigger_Shadcn_ key = { type . key } value = { type . key } className = "px-0" >
177- { type . label }
178- </ TabsTrigger_Shadcn_ >
179- ) ) }
180- </ TabsList_Shadcn_ >
173+ < Tabs_Shadcn_ defaultValue = "direct" onValueChange = { ( value ) => handleConnectionType ( value ) } >
174+ < TabsList_Shadcn_ className = { cn ( 'flex gap-x-4' , DIALOG_PADDING_X ) } >
175+ { CONNECTION_TYPES . map ( ( type ) => (
176+ < TabsTrigger_Shadcn_ key = { type . key } value = { type . key } className = "px-0" >
177+ { type . label }
178+ </ TabsTrigger_Shadcn_ >
179+ ) ) }
180+ </ TabsList_Shadcn_ >
181181
182- { CONNECTION_TYPES . map ( ( type ) => {
183- const hasChildOptions =
184- ( connectionObject . find ( ( parent ) => parent . key === selectedParent ) ?. children
185- . length || 0 ) > 0
186- const hasGrandChildOptions =
187- ( connectionObject
188- . find ( ( parent ) => parent . key === selectedParent )
189- ?. children . find ( ( child ) => child . key === selectedChild ) ?. children . length || 0 ) > 0
190-
191- if ( type . key === 'direct' ) {
192- return (
193- < TabsContent_Shadcn_
194- key = "direct"
195- value = "direct"
196- className = { cn ( '!mt-0' , 'p-0' , 'flex flex-col gap-6' ) }
197- >
198- < div className = { DIALOG_PADDING_Y } >
199- { connectDialogUpdate ? (
200- < DatabaseConnectionString />
201- ) : (
202- < div className = "px-7" >
203- < OldDatabaseConnectionString appearance = "minimal" />
204- </ div >
205- ) }
206- </ div >
207- </ TabsContent_Shadcn_ >
208- )
209- }
182+ { CONNECTION_TYPES . map ( ( type ) => {
183+ const hasChildOptions =
184+ ( connectionObject . find ( ( parent ) => parent . key === selectedParent ) ?. children . length ||
185+ 0 ) > 0
186+ const hasGrandChildOptions =
187+ ( connectionObject
188+ . find ( ( parent ) => parent . key === selectedParent )
189+ ?. children . find ( ( child ) => child . key === selectedChild ) ?. children . length || 0 ) > 0
210190
191+ if ( type . key === 'direct' ) {
211192 return (
212193 < TabsContent_Shadcn_
213- key = { `content- ${ type . key } ` }
214- value = { type . key }
215- className = { cn ( DIALOG_PADDING_X , DIALOG_PADDING_Y , '!mt-0 ' ) }
194+ key = "direct"
195+ value = "direct"
196+ className = { cn ( '!mt-0' , 'p-0' , 'flex flex-col gap-6 ' ) }
216197 >
217- < div className = "flex justify-between" >
218- < div className = "flex items-center gap-3" >
198+ < div className = { DIALOG_PADDING_Y } >
199+ { connectDialogUpdate ? (
200+ < DatabaseConnectionString />
201+ ) : (
202+ < div className = "px-7" >
203+ < OldDatabaseConnectionString appearance = "minimal" />
204+ </ div >
205+ ) }
206+ </ div >
207+ </ TabsContent_Shadcn_ >
208+ )
209+ }
210+
211+ return (
212+ < TabsContent_Shadcn_
213+ key = { `content-${ type . key } ` }
214+ value = { type . key }
215+ className = { cn ( DIALOG_PADDING_X , DIALOG_PADDING_Y , '!mt-0' ) }
216+ >
217+ < div className = "flex justify-between" >
218+ < div className = "flex items-center gap-3" >
219+ < ConnectDropdown
220+ state = { selectedParent }
221+ updateState = { handleParentChange }
222+ label = {
223+ connectionObject === FRAMEWORKS || connectionObject === MOBILES
224+ ? 'Framework'
225+ : 'Tool'
226+ }
227+ items = { connectionObject }
228+ />
229+ { selectedParent && hasChildOptions && (
219230 < ConnectDropdown
220- state = { selectedParent }
221- updateState = { handleParentChange }
222- label = {
223- connectionObject === FRAMEWORKS || connectionObject === MOBILES
224- ? 'Framework'
225- : 'Tool'
226- }
227- items = { connectionObject }
231+ state = { selectedChild }
232+ updateState = { handleChildChange }
233+ label = "Using"
234+ items = { getChildOptions ( ) }
235+ />
236+ ) }
237+ { selectedChild && hasGrandChildOptions && (
238+ < ConnectDropdown
239+ state = { selectedGrandchild }
240+ updateState = { handleGrandchildChange }
241+ label = "With"
242+ items = { getGrandchildrenOptions ( ) }
228243 />
229- { selectedParent && hasChildOptions && (
230- < ConnectDropdown
231- state = { selectedChild }
232- updateState = { handleChildChange }
233- label = "Using"
234- items = { getChildOptions ( ) }
235- />
236- ) }
237- { selectedChild && hasGrandChildOptions && (
238- < ConnectDropdown
239- state = { selectedGrandchild }
240- updateState = { handleGrandchildChange }
241- label = "With"
242- items = { getGrandchildrenOptions ( ) }
243- />
244- ) }
245- </ div >
246- { connectionObject . find ( ( item ) => item . key === selectedParent ) ?. guideLink && (
247- < Button asChild type = "default" icon = { < ExternalLink strokeWidth = { 1.5 } /> } >
248- < a
249- target = "_blank"
250- rel = "noreferrer"
251- href = {
252- connectionObject . find ( ( item ) => item . key === selectedParent )
253- ?. guideLink || ''
254- }
255- >
256- { connectionObject . find ( ( item ) => item . key === selectedParent ) ?. label } { ' ' }
257- guide
258- </ a >
259- </ Button >
260244 ) }
261245 </ div >
262- < p className = "text-xs text-foreground-lighter my-3" >
263- Add the following files below to your application
264- </ p >
265- < ConnectTabContent
266- projectKeys = { projectKeys }
267- filePath = { filePath }
268- className = "rounded-b-none"
269- />
270- < Panel . Notice
271- className = "border border-t-0 rounded-lg rounded-t-none"
272- title = "New API keys coming Q4 2024"
273- description = { `
246+ { connectionObject . find ( ( item ) => item . key === selectedParent ) ?. guideLink && (
247+ < Button asChild type = "default" icon = { < ExternalLink strokeWidth = { 1.5 } /> } >
248+ < a
249+ target = "_blank"
250+ rel = "noreferrer"
251+ href = {
252+ connectionObject . find ( ( item ) => item . key === selectedParent ) ?. guideLink ||
253+ ''
254+ }
255+ >
256+ { connectionObject . find ( ( item ) => item . key === selectedParent ) ?. label } guide
257+ </ a >
258+ </ Button >
259+ ) }
260+ </ div >
261+ < p className = "text-xs text-foreground-lighter my-3" >
262+ Add the following files below to your application
263+ </ p >
264+ < ConnectTabContent
265+ projectKeys = { projectKeys }
266+ filePath = { filePath }
267+ className = "rounded-b-none"
268+ />
269+ < Panel . Notice
270+ className = "border border-t-0 rounded-lg rounded-t-none"
271+ title = "New API keys coming Q4 2024"
272+ description = { `
274273\`anon\` and \`service_role\` API keys will be changing to \`publishable\` and \`secret\` API keys.
275274` }
276- href = "https://github.com/orgs/supabase/discussions/29260"
277- buttonText = "Read the announcement"
278- />
279- </ TabsContent_Shadcn_ >
280- )
281- } ) }
282- </ Tabs_Shadcn_ >
283- </ DialogContent >
284- </ Dialog >
285- </ >
275+ href = "https://github.com/orgs/supabase/discussions/29260"
276+ buttonText = "Read the announcement"
277+ />
278+ </ TabsContent_Shadcn_ >
279+ )
280+ } ) }
281+ </ Tabs_Shadcn_ >
282+ </ DialogContent >
283+ </ Dialog >
286284 )
287285}
288286
0 commit comments