@@ -10,7 +10,7 @@ import Form from '@common/components/form/Form';
10
10
import ModalConfirm from '@common/components/ModalConfirm' ;
11
11
import useToggle from '@common/hooks/useToggle' ;
12
12
import Yup from '@common/validation/yup' ;
13
- import React , { useMemo } from 'react' ;
13
+ import React , { useEffect , useMemo , useRef } from 'react' ;
14
14
import { ObjectSchema } from 'yup' ;
15
15
16
16
interface FormValues {
@@ -34,6 +34,13 @@ export default function PublicationContactForm({
34
34
onSubmit,
35
35
} : Props ) {
36
36
const [ showConfirmModal , toggleConfirmModal ] = useToggle ( false ) ;
37
+ const submitButtonRef = useRef < HTMLButtonElement > ( null ) ;
38
+
39
+ useEffect ( ( ) => {
40
+ if ( showConfirmModal === false ) {
41
+ submitButtonRef . current ?. focus ( ) ;
42
+ }
43
+ } , [ showConfirmModal ] ) ;
37
44
38
45
const handleSubmit = async ( values : FormValues ) => {
39
46
const contact = values ;
@@ -111,26 +118,30 @@ export default function PublicationContactForm({
111
118
/>
112
119
113
120
< ButtonGroup >
114
- < Button type = "submit" > Update contact details</ Button >
121
+ < Button type = "submit" ref = { submitButtonRef } >
122
+ Update contact details
123
+ </ Button >
115
124
< ButtonText onClick = { onCancel } > Cancel</ ButtonText >
116
125
</ ButtonGroup >
117
126
</ Form >
118
127
119
- < ModalConfirm
120
- title = "Confirm contact changes"
121
- onConfirm = { async ( ) => {
122
- await form . handleSubmit ( handleSubmit ) ( ) ;
123
- } }
124
- onExit = { toggleConfirmModal . off }
125
- onCancel = { toggleConfirmModal . off }
126
- open = { showConfirmModal }
127
- >
128
- < p >
129
- Any changes made here will appear on the public site
130
- immediately.
131
- </ p >
132
- < p > Are you sure you want to save the changes?</ p >
133
- </ ModalConfirm >
128
+ { showConfirmModal && (
129
+ < ModalConfirm
130
+ title = "Confirm contact changes"
131
+ onConfirm = { async ( ) => {
132
+ await form . handleSubmit ( handleSubmit ) ( ) ;
133
+ } }
134
+ onExit = { toggleConfirmModal . off }
135
+ onCancel = { toggleConfirmModal . off }
136
+ open
137
+ >
138
+ < p >
139
+ Any changes made here will appear on the public site
140
+ immediately.
141
+ </ p >
142
+ < p > Are you sure you want to save the changes?</ p >
143
+ </ ModalConfirm >
144
+ ) }
134
145
</ >
135
146
) ;
136
147
} }
0 commit comments