@@ -6,13 +6,15 @@ import {
66 FolderIcon ,
77 TrashIcon ,
88 LockClosedIcon ,
9+ PlusIcon ,
910} from "@heroicons/react/20/solid" ;
1011import {
1112 Form ,
1213 type MetaFunction ,
1314 useActionData ,
1415 useLocation ,
1516 useNavigation ,
17+ useNavigate ,
1618} from "@remix-run/react" ;
1719import { type LoaderFunctionArgs } from "@remix-run/router" ;
1820import { type ActionFunction , json } from "@remix-run/server-runtime" ;
@@ -87,6 +89,7 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
8789 } ,
8890 select : {
8991 id : true ,
92+ accountHandle : true ,
9093 targetType : true ,
9194 repositories : {
9295 select : {
@@ -429,6 +432,7 @@ type GitHubRepository = {
429432type GitHubAppInstallation = {
430433 id : string ;
431434 targetType : string ;
435+ accountHandle : string ;
432436 repositories : GitHubRepository [ ] ;
433437} ;
434438
@@ -439,8 +443,11 @@ function ConnectGitHubRepoModal({
439443 gitHubAppInstallations : GitHubAppInstallation [ ] ;
440444 projectId : string ;
441445} ) {
442- const [ isModalOpen , setIsModalOpen ] = useState ( false ) ;
446+ const [ isModalOpen , setIsModalOpen ] = useState ( true ) ;
443447 const lastSubmission = useActionData ( ) ;
448+ const organization = useOrganization ( ) ;
449+ const location = useLocation ( ) ;
450+ const navigate = useNavigate ( ) ;
444451
445452 const [ selectedInstallation , setSelectedInstallation ] = useState <
446453 GitHubAppInstallation | undefined
@@ -452,12 +459,11 @@ function ConnectGitHubRepoModal({
452459
453460 const navigation = useNavigation ( ) ;
454461 const isConnectRepositoryLoading =
455- navigation . formData ?. get ( "action" ) === "connect-repository " &&
462+ navigation . formData ?. get ( "action" ) === "connect-repo " &&
456463 ( navigation . state === "submitting" || navigation . state === "loading" ) ;
457464
458465 const [ form , { installationId, repositoryId, projectId } ] = useForm ( {
459- id : "connect-repository" ,
460- // TODO: type this
466+ id : "connect-repo" ,
461467 lastSubmission : lastSubmission as any ,
462468 shouldRevalidate : "onSubmit" ,
463469 onValidate ( { formData } ) {
@@ -500,17 +506,29 @@ function ConnectGitHubRepoModal({
500506 variant = "tertiary/small"
501507 placeholder = "Select account"
502508 dropdownIcon
503- text = {
504- selectedInstallation
505- ? `${ selectedInstallation . targetType } ${ selectedInstallation . id } `
506- : undefined
507- }
509+ text = { selectedInstallation ? selectedInstallation . accountHandle : undefined }
508510 >
509- { gitHubAppInstallations . map ( ( installation ) => (
510- < SelectItem key = { installation . id } value = { installation . id } >
511- { installation . targetType } ({ installation . id } )
512- </ SelectItem >
513- ) ) }
511+ { [
512+ ...gitHubAppInstallations . map ( ( installation ) => (
513+ < SelectItem
514+ key = { installation . id }
515+ value = { installation . id }
516+ icon = { < OctoKitty className = "size-3 text-text-dimmed" /> }
517+ >
518+ { installation . accountHandle }
519+ </ SelectItem >
520+ ) ) ,
521+ < SelectItem
522+ onClick = { ( e ) => {
523+ e . preventDefault ( ) ;
524+ navigate ( githubAppInstallPath ( organization . slug , location . pathname ) ) ;
525+ } }
526+ key = "new-account"
527+ icon = { < PlusIcon className = "size-3 text-text-dimmed" /> }
528+ >
529+ Add account
530+ </ SelectItem > ,
531+ ] }
514532 </ Select >
515533 < FormError id = { installationId . errorId } > { installationId . error } </ FormError >
516534 </ InputGroup >
@@ -555,7 +573,7 @@ function ConnectGitHubRepoModal({
555573 < Button
556574 type = "submit"
557575 name = "action"
558- value = "connect-repository "
576+ value = "connect-repo "
559577 variant = "primary/medium"
560578 LeadingIcon = { isConnectRepositoryLoading ? SpinnerWhite : undefined }
561579 leadingIconClassName = "text-white"
0 commit comments