1
1
import React , { useCallback } from 'react' ;
2
2
import { ErrorMessage , Field , Form , Formik } from 'formik' ;
3
3
import * as yup from 'yup' ;
4
- import { FloatingLabel , FormButton } from '@/components' ;
4
+ import { CheckBox , FloatingLabel , FormButton , Label } from '@/components' ;
5
5
import { FormattedMessage , IntlShape , useIntl } from 'react-intl' ;
6
6
7
7
const validationSchema = yup . object ( {
8
8
orgUid : yup . string ( ) . length ( 64 ) . required ( 'OrgUid is required' ) ,
9
9
} ) ;
10
10
11
+ export interface ImportOrganizationProps {
12
+ orgUid : string ;
13
+ isHome : boolean ;
14
+ }
15
+
11
16
interface FormProps {
12
- onSubmit : ( orgUid : string ) => Promise < any > ;
17
+ onSubmit : ( params : ImportOrganizationProps ) => Promise < any > ;
13
18
}
14
19
15
20
const ImportOrganizationForm : React . FC < FormProps > = ( { onSubmit } ) => {
16
21
const intl : IntlShape = useIntl ( ) ;
17
22
18
23
const handleSubmit = useCallback (
19
- async ( values : { orgUid : string } , { setSubmitting } ) => {
20
- await onSubmit ( values . orgUid ) ;
24
+ async ( values : ImportOrganizationProps , { setSubmitting } ) => {
25
+ await onSubmit ( values ) ;
21
26
setSubmitting ( false ) ;
22
27
} ,
23
28
[ onSubmit ] ,
24
29
) ; // Include onSuccess in the dependencies array
25
30
26
31
return (
27
32
< >
28
- < Formik initialValues = { { orgUid : '' } } validationSchema = { validationSchema } onSubmit = { handleSubmit } >
33
+ < Formik initialValues = { { orgUid : '' , isHome : true } } validationSchema = { validationSchema } onSubmit = { handleSubmit } >
29
34
{ ( { errors, touched, isSubmitting } ) => (
30
35
< Form >
31
36
< div className = "mb-4" >
@@ -42,6 +47,14 @@ const ImportOrganizationForm: React.FC<FormProps> = ({ onSubmit }) => {
42
47
) }
43
48
</ Field >
44
49
{ touched . orgUid && < ErrorMessage name = "orgUid" component = "div" className = "text-red-600" /> }
50
+ < div className = "flex space-x-2.5" >
51
+ < Field name = "isHome" > { ( { field } ) => < CheckBox id = "isHome" checked { ...field } /> } </ Field >
52
+ < Label htmlFor = "isHome" >
53
+ < p className = "text-gray-600" >
54
+ < FormattedMessage id = "import-as-home-organization" />
55
+ </ p >
56
+ </ Label >
57
+ </ div >
45
58
</ div >
46
59
< FormButton isSubmitting = { isSubmitting } formikErrors = { errors } >
47
60
< FormattedMessage id = "submit" />
0 commit comments