1- import { Dispatch , FC , SetStateAction , useContext , useEffect , useState } from 'react'
1+ import { Dispatch , FC , SetStateAction , useCallback , useContext , useEffect , useState } from 'react'
22
33import { Form , FormDefinition , formGetInputModel , FormInputModel } from '../form'
44import { LoadingSpinner } from '../loading-spinner'
@@ -19,20 +19,28 @@ const ContactSupportForm: FC<ContactSupportFormProps> = (props: ContactSupportFo
1919
2020 const { profile } : ProfileContextData = useContext ( profileContext )
2121
22- const [ loading , setLoading ] : [ boolean , Dispatch < SetStateAction < boolean > > ] = useState < boolean > ( false )
23- const [ saveOnSuccess , setSaveOnSuccess ] : [ boolean , Dispatch < SetStateAction < boolean > > ] = useState < boolean > ( false )
22+ const [ loading , setLoading ] : [ boolean , Dispatch < SetStateAction < boolean > > ]
23+ = useState < boolean > ( false )
24+ const [ saveOnSuccess , setSaveOnSuccess ] : [ boolean , Dispatch < SetStateAction < boolean > > ]
25+ = useState < boolean > ( false )
2426
2527 useEffect ( ( ) => {
2628 if ( ! loading && saveOnSuccess ) {
2729 props . onSave ( )
2830 }
29- } , [ loading , saveOnSuccess ] )
31+ } , [ loading , saveOnSuccess , props . onSave ] )
3032
31- function generateRequest ( inputs : ReadonlyArray < FormInputModel > ) : ContactSupportRequest {
32- const firstName : string = formGetInputModel ( inputs , ContactSupportFormField . first ) . value as string
33- const lastName : string = formGetInputModel ( inputs , ContactSupportFormField . last ) . value as string
34- const email : string = formGetInputModel ( inputs , ContactSupportFormField . email ) . value as string
35- const question : string = formGetInputModel ( inputs , ContactSupportFormField . question ) . value as string
33+ const generateRequest = useCallback ( (
34+ inputs : ReadonlyArray < FormInputModel > ,
35+ ) : ContactSupportRequest => {
36+ const firstName : string
37+ = formGetInputModel ( inputs , ContactSupportFormField . first ) . value as string
38+ const lastName : string
39+ = formGetInputModel ( inputs , ContactSupportFormField . last ) . value as string
40+ const email : string
41+ = formGetInputModel ( inputs , ContactSupportFormField . email ) . value as string
42+ const question : string
43+ = formGetInputModel ( inputs , ContactSupportFormField . question ) . value as string
3644 return {
3745 challengeId : props . workId ,
3846 email,
@@ -41,15 +49,16 @@ const ContactSupportForm: FC<ContactSupportFormProps> = (props: ContactSupportFo
4149 lastName,
4250 question,
4351 }
44- }
52+ } , [ props . workId ] )
4553
46- async function saveAsync ( request : ContactSupportRequest ) : Promise < void > {
54+ const saveAsync = useCallback ( async ( request : ContactSupportRequest ) : Promise < void > = > {
4755 setLoading ( true )
4856 return contactSupportSubmitRequestAsync ( request )
4957 . then ( ( ) => {
5058 setSaveOnSuccess ( true )
51- } ) . finally ( ( ) => setLoading ( false ) )
52- }
59+ } )
60+ . finally ( ( ) => setLoading ( false ) )
61+ } , [ ] )
5362
5463 const emailElement : JSX . Element | undefined = ! ! profile ?. email
5564 ? (
@@ -69,10 +78,10 @@ const ContactSupportForm: FC<ContactSupportFormProps> = (props: ContactSupportFo
6978 Hi
7079 { ' ' }
7180 { profile ?. firstName || 'there' }
72- , we' re here to help.
81+ , we' re here to help.
7382 </ p >
7483 < p >
75- Please describe what you' d like to discuss, and a
84+ Please describe what you' d like to discuss, and a
7685 Topcoder Solutions Expert will email you back
7786 { emailElement }
7887 within one business day.
0 commit comments