@@ -4,6 +4,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
4
4
import { useEffect } from "react" ;
5
5
import { useForm } from "react-hook-form" ;
6
6
7
+ import { api } from "~/lib/api" ;
7
8
import {
8
9
APPL_EXP_MAX_LENGTH ,
9
10
APPL_RESUME_MAX_LENGTH ,
@@ -16,25 +17,45 @@ import Spinner from "../utils/Spinner";
16
17
17
18
const ApplicantForm = ( {
18
19
applicant,
19
- onSubmit,
20
20
forceNewOnEdit = false ,
21
+ onSuccess,
21
22
} : {
22
23
applicant : ApplicantFormData | undefined ;
23
- onSubmit : ( data : ApplicantFormData ) => void ;
24
24
forceNewOnEdit ?: boolean ;
25
+ onSuccess ?: ( ) => void ;
25
26
} ) => {
27
+ const utils = api . useContext ( ) ;
28
+
26
29
const {
27
30
register,
28
31
handleSubmit,
29
32
reset,
30
33
watch,
31
- formState : { errors, isValid, isSubmitting , isDirty } ,
34
+ formState : { errors, isValid, isDirty } ,
32
35
} = useForm < ApplicantFormData > ( {
33
36
resolver : zodResolver ( applicantSchema ) ,
34
37
mode : "onTouched" ,
35
38
defaultValues : applicant ,
36
39
} ) ;
37
40
41
+ const { mutateAsync : upsertApplicant , isLoading : isSubmitting } =
42
+ api . applicant . createOrUpdate . useMutation ( {
43
+ onSuccess : ( ) => {
44
+ void utils . applicant . getForLoggedUser . invalidate ( ) ;
45
+ void utils . user . getOnboardingState . invalidate ( ) ;
46
+ onSuccess ?.( ) ;
47
+ } ,
48
+ } ) ;
49
+
50
+ const onSubmit = ( data : ApplicantFormData ) => {
51
+ const setAsMain = ! applicant || applicant . isMain ;
52
+
53
+ void upsertApplicant ( {
54
+ applicant : data ,
55
+ setAsMain,
56
+ } ) ;
57
+ } ;
58
+
38
59
useEffect ( ( ) => {
39
60
reset ( applicant ) ;
40
61
} , [ applicant , reset ] ) ;
@@ -56,7 +77,7 @@ const ApplicantForm = ({
56
77
< div className = "relative w-1/2" >
57
78
< input
58
79
type = "text"
59
- className = "peer input-bordered input-primary input block w-full focus:outline-offset-0"
80
+ className = "peer input-bordered input-secondary input block w-full focus:outline-offset-0"
60
81
placeholder = " "
61
82
id = { "firstName" }
62
83
{ ...register ( "firstName" ) }
@@ -73,7 +94,7 @@ const ApplicantForm = ({
73
94
< input
74
95
type = "text"
75
96
id = "lastName"
76
- className = "peer input-bordered input-primary input block w-full focus:outline-offset-0"
97
+ className = "peer input-bordered input-secondary input block w-full focus:outline-offset-0"
77
98
placeholder = " "
78
99
{ ...register ( "lastName" ) }
79
100
disabled = { isSubmitting }
@@ -98,7 +119,7 @@ const ApplicantForm = ({
98
119
< input
99
120
type = "text"
100
121
id = "title"
101
- className = "peer input-bordered input-primary input block w-full focus:outline-offset-0"
122
+ className = "peer input-bordered input-secondary input block w-full focus:outline-offset-0"
102
123
placeholder = " "
103
124
{ ...register ( "jobTitle" ) }
104
125
disabled = { isSubmitting }
@@ -118,7 +139,7 @@ const ApplicantForm = ({
118
139
< div className = "relative" >
119
140
< textarea
120
141
id = "resume"
121
- className = "peer textarea-bordered textarea-primary textarea w-full focus:outline-offset-0"
142
+ className = "peer textarea-bordered textarea-secondary scrollbar-thin scrollbar-thumb-secondary hover:scrollbar-thumb-secondary/50 scrollbar-track-base-300 textarea w-full focus:outline-offset-0"
122
143
placeholder = " "
123
144
{ ...register ( "resume" ) }
124
145
disabled = { isSubmitting }
@@ -144,7 +165,7 @@ const ApplicantForm = ({
144
165
< div className = "relative" >
145
166
< textarea
146
167
id = "skills"
147
- className = "peer textarea-bordered textarea-primary textarea w-full focus:outline-offset-0"
168
+ className = "peer textarea-bordered textarea-secondary scrollbar-thin scrollbar-thumb-secondary hover:scrollbar-thumb-secondary/50 scrollbar-track-base-300 textarea w-full focus:outline-offset-0"
148
169
placeholder = " "
149
170
{ ...register ( "skills" ) }
150
171
disabled = { isSubmitting }
@@ -171,7 +192,7 @@ const ApplicantForm = ({
171
192
< div className = "relative" >
172
193
< textarea
173
194
id = "experience"
174
- className = "peer textarea-bordered textarea-primary textarea w-full focus:outline-offset-0"
195
+ className = "peer textarea-bordered textarea-secondary textarea w-full focus:outline-offset-0 scrollbar-thin scrollbar-thumb-secondary hover:scrollbar-thumb-secondary/50 scrollbar-track-base-300 "
175
196
placeholder = " "
176
197
{ ...register ( "experience" ) }
177
198
disabled = { isSubmitting }
@@ -196,7 +217,7 @@ const ApplicantForm = ({
196
217
</ div >
197
218
198
219
< button
199
- disabled = { ! isValid || isSubmitting }
220
+ disabled = { ! isValid || isSubmitting || ! isDirty }
200
221
type = "submit"
201
222
className = "btn-primary btn"
202
223
>
0 commit comments