@@ -8,9 +8,12 @@ import {
88 TextInput ,
99} from '@primer/react'
1010import { Dialog } from '@primer/react/drafts'
11+ import { mirrorNameSchema } from 'server/repos/schema'
1112
1213import { useState } from 'react'
1314
15+ const DEFAULT_REPO_NAME = 'repository-name'
16+
1417interface CreateMirrorDialogProps {
1518 orgLogin : string
1619 forkParentOwnerLogin : string
@@ -29,12 +32,19 @@ export const CreateMirrorDialog = ({
2932 createMirror,
3033} : CreateMirrorDialogProps ) => {
3134 // set to default value of 'repository-name' for display purposes
32- const [ repoName , setRepoName ] = useState ( 'repository-name' )
35+ const [ repoName , setRepoName ] = useState ( DEFAULT_REPO_NAME )
3336
3437 if ( ! isOpen ) {
3538 return null
3639 }
3740
41+ const hasUserInput = repoName !== DEFAULT_REPO_NAME && repoName !== ''
42+ const validation = mirrorNameSchema . safeParse ( repoName )
43+ const validationError =
44+ hasUserInput && ! validation . success
45+ ? validation . error . issues [ 0 ] . message
46+ : null
47+
3848 return (
3949 < Dialog
4050 title = "Create a new mirror"
@@ -44,22 +54,22 @@ export const CreateMirrorDialog = ({
4454 content : 'Cancel' ,
4555 onClick : ( ) => {
4656 closeDialog ( )
47- setRepoName ( 'repository-name' )
57+ setRepoName ( DEFAULT_REPO_NAME )
4858 } ,
4959 } ,
5060 {
5161 content : 'Confirm' ,
5262 variant : 'primary' ,
5363 onClick : ( ) => {
5464 createMirror ( { repoName, branchName : repoName } )
55- setRepoName ( 'repository-name' )
65+ setRepoName ( DEFAULT_REPO_NAME )
5666 } ,
57- disabled : repoName === 'repository-name' || repoName === '' ,
67+ disabled : ! hasUserInput || ! validation . success ,
5868 } ,
5969 ] }
6070 onClose = { ( ) => {
6171 closeDialog ( )
62- setRepoName ( 'repository-name' )
72+ setRepoName ( DEFAULT_REPO_NAME )
6373 } }
6474 width = "large"
6575 >
@@ -71,17 +81,24 @@ export const CreateMirrorDialog = ({
7181 block
7282 placeholder = "e.g. repository-name"
7383 maxLength = { 100 }
84+ validationStatus = { validationError ? 'error' : undefined }
7485 />
75- < FormControl . Caption >
76- This is a private mirror of{ ' ' }
77- < Link
78- href = { `https://github.com/${ forkParentOwnerLogin } /${ forkParentName } ` }
79- target = "_blank"
80- rel = "noreferrer noopener"
81- >
82- { forkParentOwnerLogin } /{ forkParentName }
83- </ Link >
84- </ FormControl . Caption >
86+ { validationError ? (
87+ < FormControl . Validation variant = "error" >
88+ { validationError }
89+ </ FormControl . Validation >
90+ ) : (
91+ < FormControl . Caption >
92+ This is a private mirror of{ ' ' }
93+ < Link
94+ href = { `https://github.com/${ forkParentOwnerLogin } /${ forkParentName } ` }
95+ target = "_blank"
96+ rel = "noreferrer noopener"
97+ >
98+ { forkParentOwnerLogin } /{ forkParentName }
99+ </ Link >
100+ </ FormControl . Caption >
101+ ) }
85102 </ FormControl >
86103 < FormControl >
87104 < FormControl . Label > Mirror location</ FormControl . Label >
0 commit comments