@@ -9,10 +9,10 @@ import {
9
9
} from "@heroicons/react/20/solid" ;
10
10
import { BookOpenIcon } from "@heroicons/react/24/solid" ;
11
11
import { DialogClose } from "@radix-ui/react-dialog" ;
12
- import { Form , useActionData , useSearchParams } from "@remix-run/react" ;
12
+ import { Form , useActionData , useLocation , useSearchParams } from "@remix-run/react" ;
13
13
import { type ActionFunctionArgs , json , type LoaderFunctionArgs } from "@remix-run/server-runtime" ;
14
14
import { GitMeta } from "@trigger.dev/core/v3" ;
15
- import { useCallback } from "react" ;
15
+ import { useCallback , useEffect , useState } from "react" ;
16
16
import { typedjson , useTypedLoaderData } from "remix-typedjson" ;
17
17
import { z } from "zod" ;
18
18
import { BranchEnvironmentIconSmall } from "~/assets/icons/EnvironmentIcons" ;
@@ -143,7 +143,7 @@ export async function action({ request }: ActionFunctionArgs) {
143
143
}
144
144
145
145
return redirectWithSuccessMessage (
146
- branchesPath ( result . organization , result . project , result . branch ) ,
146
+ ` ${ branchesPath ( result . organization , result . project , result . branch ) } ?dialogClosed=true` ,
147
147
request ,
148
148
`Branch "${ result . branch . branchName } " created`
149
149
) ;
@@ -217,8 +217,8 @@ export default function Page() {
217
217
{ limits . isAtLimit ? (
218
218
< UpgradePanel limits = { limits } canUpgrade = { canUpgrade ?? false } />
219
219
) : (
220
- < Dialog >
221
- < DialogTrigger asChild >
220
+ < NewBranchPanel
221
+ button = {
222
222
< Button
223
223
variant = "primary/small"
224
224
shortcut = { { key : "n" } }
@@ -229,11 +229,9 @@ export default function Page() {
229
229
>
230
230
New branch
231
231
</ Button >
232
- </ DialogTrigger >
233
- < DialogContent >
234
- < NewBranchPanel parentEnvironment = { branchableEnvironment } />
235
- </ DialogContent >
236
- </ Dialog >
232
+ }
233
+ parentEnvironment = { branchableEnvironment }
234
+ />
237
235
) }
238
236
</ PageAccessories >
239
237
</ NavBar >
@@ -528,8 +526,17 @@ function UpgradePanel({
528
526
) ;
529
527
}
530
528
531
- export function NewBranchPanel ( { parentEnvironment } : { parentEnvironment : { id : string } } ) {
529
+ export function NewBranchPanel ( {
530
+ button,
531
+ parentEnvironment,
532
+ } : {
533
+ button : React . ReactNode ;
534
+ parentEnvironment : { id : string } ;
535
+ } ) {
532
536
const lastSubmission = useActionData < typeof action > ( ) ;
537
+ const location = useLocation ( ) ;
538
+ const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
539
+ const [ isOpen , setIsOpen ] = useState ( false ) ;
533
540
534
541
const [ form , { parentEnvironmentId, branchName, failurePath } ] = useForm ( {
535
542
id : "create-branch" ,
@@ -540,51 +547,67 @@ export function NewBranchPanel({ parentEnvironment }: { parentEnvironment: { id:
540
547
shouldRevalidate : "onInput" ,
541
548
} ) ;
542
549
550
+ useEffect ( ( ) => {
551
+ if ( searchParams . has ( "dialogClosed" ) ) {
552
+ setSearchParams ( ( s ) => {
553
+ s . delete ( "dialogClosed" ) ;
554
+ return s ;
555
+ } ) ;
556
+ setIsOpen ( false ) ;
557
+ }
558
+ } , [ searchParams , setSearchParams ] ) ;
559
+
543
560
return (
544
- < >
545
- < DialogHeader > New branch</ DialogHeader >
546
- < div className = "mt-2 flex flex-col gap-4" >
547
- < Form method = "post" { ...form . props } className = "w-full" >
548
- < Fieldset className = "max-w-full gap-y-3" >
549
- < input
550
- value = { parentEnvironment . id }
551
- { ...conform . input ( parentEnvironmentId , { type : "hidden" } ) }
552
- />
553
- < input value = { location . pathname } { ...conform . input ( failurePath , { type : "hidden" } ) } />
554
- < InputGroup className = "max-w-full" >
555
- < Label > Branch name</ Label >
556
- < Input { ...conform . input ( branchName ) } />
557
- < Hint >
558
- Must not contain: spaces < InlineCode variant = "extra-small" > ~</ InlineCode > { " " }
559
- < InlineCode variant = "extra-small" > ^</ InlineCode > { " " }
560
- < InlineCode variant = "extra-small" > :</ InlineCode > { " " }
561
- < InlineCode variant = "extra-small" > ?</ InlineCode > { " " }
562
- < InlineCode variant = "extra-small" > *</ InlineCode > { " " }
563
- < InlineCode variant = "extra-small" > { "[" } </ InlineCode > { " " }
564
- < InlineCode variant = "extra-small" > \</ InlineCode > { " " }
565
- < InlineCode variant = "extra-small" > //</ InlineCode > { " " }
566
- < InlineCode variant = "extra-small" > ..</ InlineCode > { " " }
567
- < InlineCode variant = "extra-small" > { "@{" } </ InlineCode > { " " }
568
- < InlineCode variant = "extra-small" > .lock</ InlineCode >
569
- </ Hint >
570
- < FormError id = { branchName . errorId } > { branchName . error } </ FormError >
571
- </ InputGroup >
572
- < FormError > { form . error } </ FormError >
573
- < FormButtons
574
- confirmButton = {
575
- < Button type = "submit" variant = "primary/medium" >
576
- Create branch
577
- </ Button >
578
- }
579
- cancelButton = {
580
- < DialogClose asChild >
581
- < Button variant = "tertiary/medium" > Cancel</ Button >
582
- </ DialogClose >
583
- }
584
- />
585
- </ Fieldset >
586
- </ Form >
587
- </ div >
588
- </ >
561
+ < Dialog open = { isOpen } onOpenChange = { setIsOpen } >
562
+ < DialogTrigger asChild > { button } </ DialogTrigger >
563
+ < DialogContent >
564
+ < DialogHeader > New branch</ DialogHeader >
565
+ < div className = "mt-2 flex flex-col gap-4" >
566
+ < Form method = "post" { ...form . props } className = "w-full" >
567
+ < Fieldset className = "max-w-full gap-y-3" >
568
+ < input
569
+ value = { parentEnvironment . id }
570
+ { ...conform . input ( parentEnvironmentId , { type : "hidden" } ) }
571
+ />
572
+ < input
573
+ value = { location . pathname }
574
+ { ...conform . input ( failurePath , { type : "hidden" } ) }
575
+ />
576
+ < InputGroup className = "max-w-full" >
577
+ < Label > Branch name</ Label >
578
+ < Input { ...conform . input ( branchName ) } />
579
+ < Hint >
580
+ Must not contain: spaces < InlineCode variant = "extra-small" > ~</ InlineCode > { " " }
581
+ < InlineCode variant = "extra-small" > ^</ InlineCode > { " " }
582
+ < InlineCode variant = "extra-small" > :</ InlineCode > { " " }
583
+ < InlineCode variant = "extra-small" > ?</ InlineCode > { " " }
584
+ < InlineCode variant = "extra-small" > *</ InlineCode > { " " }
585
+ < InlineCode variant = "extra-small" > { "[" } </ InlineCode > { " " }
586
+ < InlineCode variant = "extra-small" > \</ InlineCode > { " " }
587
+ < InlineCode variant = "extra-small" > //</ InlineCode > { " " }
588
+ < InlineCode variant = "extra-small" > ..</ InlineCode > { " " }
589
+ < InlineCode variant = "extra-small" > { "@{" } </ InlineCode > { " " }
590
+ < InlineCode variant = "extra-small" > .lock</ InlineCode >
591
+ </ Hint >
592
+ < FormError id = { branchName . errorId } > { branchName . error } </ FormError >
593
+ </ InputGroup >
594
+ < FormError > { form . error } </ FormError >
595
+ < FormButtons
596
+ confirmButton = {
597
+ < Button type = "submit" variant = "primary/medium" >
598
+ Create branch
599
+ </ Button >
600
+ }
601
+ cancelButton = {
602
+ < DialogClose asChild >
603
+ < Button variant = "tertiary/medium" > Cancel</ Button >
604
+ </ DialogClose >
605
+ }
606
+ />
607
+ </ Fieldset >
608
+ </ Form >
609
+ </ div >
610
+ </ DialogContent >
611
+ </ Dialog >
589
612
) ;
590
613
}
0 commit comments