@@ -7,18 +7,23 @@ import { Organization } from '@/schemas/Organization.schema';
77
88const validationSchema = yup . object ( {
99 organizationName : yup . string ( ) . required ( 'The organization name must be at least 3 characters' ) . min ( 3 ) ,
10+ prefix : yup
11+ . string ( )
12+ . optional ( )
13+ . matches ( / ^ [ a - z A - Z 0 - 9 ] + $ / , 'Prefix must contain only alphanumeric characters (a-z, A-Z, 0-9)' )
14+ . max ( 20 , 'Prefix must be 20 characters or less' ) ,
1015} ) ;
1116
1217interface FormProps {
1318 myOrganization : Organization ;
14- onSubmit : ( organizationName : string ) => Promise < any > ;
19+ onSubmit : ( values : { organizationName : string ; prefix : string } ) => Promise < any > ;
1520 onCancel : ( ) => void ;
1621}
1722
1823const EditOrganizationForm : React . FC < FormProps > = ( { myOrganization, onSubmit, onCancel } : FormProps ) => {
1924 const handleSubmit = useCallback (
20- async ( values : { organizationName : string } , { setSubmitting } ) => {
21- await onSubmit ( values . organizationName ) ;
25+ async ( values : { organizationName : string ; prefix : string } , { setSubmitting } ) => {
26+ await onSubmit ( values ) ;
2227 setSubmitting ( false ) ;
2328 } ,
2429 [ onSubmit ] ,
@@ -30,7 +35,7 @@ const EditOrganizationForm: React.FC<FormProps> = ({ myOrganization, onSubmit, o
3035
3136 return (
3237 < Formik
33- initialValues = { { organizationName : myOrganization . name } }
38+ initialValues = { { organizationName : myOrganization . name , prefix : myOrganization . prefix } }
3439 validationSchema = { validationSchema }
3540 onSubmit = { handleSubmit }
3641 >
@@ -61,6 +66,29 @@ const EditOrganizationForm: React.FC<FormProps> = ({ myOrganization, onSubmit, o
6166 { touched . organizationName && (
6267 < ErrorMessage name = "organizationName" component = "div" className = "text-red-600" />
6368 ) }
69+ < Field name = "prefix" >
70+ { ( { field } ) => (
71+ < div className = "flex justify-start align-middle" >
72+ < div >
73+ < p className = "font-bold text-left text-gray-700 dark:text-gray-400 mr-4" >
74+ < FormattedMessage id = "organization-prefix" />
75+ </ p >
76+ </ div >
77+ < TextInput
78+ className = "w-3/5 mb-2"
79+ id = "prefix"
80+ color = { errors . prefix && touched . prefix && 'failure' }
81+ variant = "outlined"
82+ required
83+ type = "text"
84+ maxLength = { 20 }
85+ { ...field }
86+ onChange = { ( event ) => handleChange ( event , field ) }
87+ />
88+ </ div >
89+ ) }
90+ </ Field >
91+ { touched . prefix && < ErrorMessage name = "prefix" component = "div" className = "text-red-600" /> }
6492 < div className = "flex justify-start" >
6593 < p className = "font-bold text-left text-gray-700 dark:text-gray-400 mr-4" >
6694 < FormattedMessage id = "orguid" />
0 commit comments