@@ -9,10 +9,10 @@ import {
99} from "@heroicons/react/20/solid" ;
1010import { BookOpenIcon } from "@heroicons/react/24/solid" ;
1111import { 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" ;
1313import { type ActionFunctionArgs , json , type LoaderFunctionArgs } from "@remix-run/server-runtime" ;
1414import { GitMeta } from "@trigger.dev/core/v3" ;
15- import { useCallback } from "react" ;
15+ import { useCallback , useEffect , useState } from "react" ;
1616import { typedjson , useTypedLoaderData } from "remix-typedjson" ;
1717import { z } from "zod" ;
1818import { BranchEnvironmentIconSmall } from "~/assets/icons/EnvironmentIcons" ;
@@ -143,7 +143,7 @@ export async function action({ request }: ActionFunctionArgs) {
143143 }
144144
145145 return redirectWithSuccessMessage (
146- branchesPath ( result . organization , result . project , result . branch ) ,
146+ ` ${ branchesPath ( result . organization , result . project , result . branch ) } ?dialogClosed=true` ,
147147 request ,
148148 `Branch "${ result . branch . branchName } " created`
149149 ) ;
@@ -217,8 +217,8 @@ export default function Page() {
217217 { limits . isAtLimit ? (
218218 < UpgradePanel limits = { limits } canUpgrade = { canUpgrade ?? false } />
219219 ) : (
220- < Dialog >
221- < DialogTrigger asChild >
220+ < NewBranchPanel
221+ button = {
222222 < Button
223223 variant = "primary/small"
224224 shortcut = { { key : "n" } }
@@ -229,11 +229,9 @@ export default function Page() {
229229 >
230230 New branch
231231 </ Button >
232- </ DialogTrigger >
233- < DialogContent >
234- < NewBranchPanel parentEnvironment = { branchableEnvironment } />
235- </ DialogContent >
236- </ Dialog >
232+ }
233+ parentEnvironment = { branchableEnvironment }
234+ />
237235 ) }
238236 </ PageAccessories >
239237 </ NavBar >
@@ -528,8 +526,17 @@ function UpgradePanel({
528526 ) ;
529527}
530528
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+ } ) {
532536 const lastSubmission = useActionData < typeof action > ( ) ;
537+ const location = useLocation ( ) ;
538+ const [ searchParams , setSearchParams ] = useSearchParams ( ) ;
539+ const [ isOpen , setIsOpen ] = useState ( false ) ;
533540
534541 const [ form , { parentEnvironmentId, branchName, failurePath } ] = useForm ( {
535542 id : "create-branch" ,
@@ -540,51 +547,67 @@ export function NewBranchPanel({ parentEnvironment }: { parentEnvironment: { id:
540547 shouldRevalidate : "onInput" ,
541548 } ) ;
542549
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+
543560 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 >
589612 ) ;
590613}
0 commit comments