@@ -11,12 +11,14 @@ import { useUpdateCurrentUserMutation } from "../data/current-user/update-mutati
11
11
import { useOnBlurError } from "../hooks/use-onblur-error" ;
12
12
import { OnboardingStep } from "./OnboardingStep" ;
13
13
import { LinkedInBanner } from "./LinkedInBanner" ;
14
+ import { useFeatureFlags } from "../contexts/FeatureFlagContext" ;
14
15
15
16
type Props = {
16
17
user : User ;
17
18
onComplete ( user : User ) : void ;
18
19
} ;
19
20
export const StepUserInfo : FC < Props > = ( { user, onComplete } ) => {
21
+ const { linkedinConnectionForOnboarding } = useFeatureFlags ( ) ;
20
22
const updateUser = useUpdateCurrentUserMutation ( ) ;
21
23
// attempt to split provided name for default input values
22
24
const { first, last } = getInitialNameParts ( user ) ;
@@ -37,7 +39,8 @@ export const StepUserInfo: FC<Props> = ({ user, onComplete }) => {
37
39
...additionalData ,
38
40
profile : {
39
41
...profile ,
40
- emailAddress,
42
+ // If still no email provided, default to "primary" email
43
+ emailAddress : emailAddress || User . getPrimaryEmail ( user ) ,
41
44
lastUpdatedDetailsNudge : new Date ( ) . toISOString ( ) ,
42
45
} ,
43
46
} ,
@@ -49,25 +52,32 @@ export const StepUserInfo: FC<Props> = ({ user, onComplete }) => {
49
52
} catch ( e ) {
50
53
console . error ( e ) ;
51
54
}
52
- } , [ emailAddress , firstName , lastName , onComplete , updateUser , user . additionalData ] ) ;
53
-
54
- const onLinkedInSuccess = async ( profile : LinkedInProfile ) => {
55
- if ( ! firstName && profile . firstName ) {
56
- setFirstName ( profile . firstName ) ;
57
- }
58
- if ( ! lastName && profile . lastName ) {
59
- setLastName ( profile . lastName ) ;
60
- }
61
- if ( ! emailAddress && profile . emailAddress ) {
62
- setEmailAddress ( profile . emailAddress ) ;
63
- }
64
- handleSubmit ( ) ;
65
- } ;
55
+ } , [ emailAddress , firstName , lastName , onComplete , updateUser , user ] ) ;
56
+
57
+ const onLinkedInSuccess = useCallback (
58
+ async ( profile : LinkedInProfile ) => {
59
+ if ( ! firstName && profile . firstName ) {
60
+ setFirstName ( profile . firstName ) ;
61
+ }
62
+ if ( ! lastName && profile . lastName ) {
63
+ setLastName ( profile . lastName ) ;
64
+ }
65
+ if ( ! emailAddress && profile . emailAddress ) {
66
+ setEmailAddress ( profile . emailAddress ) ;
67
+ }
68
+ handleSubmit ( ) ;
69
+ } ,
70
+ [ emailAddress , firstName , handleSubmit , lastName ] ,
71
+ ) ;
66
72
67
73
const firstNameError = useOnBlurError ( "Please enter a value" , ! ! firstName ) ;
68
74
const lastNameError = useOnBlurError ( "Please enter a value" , ! ! lastName ) ;
75
+ const emailError = useOnBlurError ( "Please enter your email address" , ! ! emailAddress ) ;
69
76
70
- const isValid = [ firstNameError , lastNameError ] . every ( ( e ) => e . isValid ) ;
77
+ const isValid =
78
+ [ firstNameError , lastNameError ] . every ( ( e ) => e . isValid ) &&
79
+ // If we're using LinkedIn, we don't need to validate the email input, otherwise we do
80
+ ( linkedinConnectionForOnboarding || ( ! linkedinConnectionForOnboarding && emailError . isValid ) ) ;
71
81
72
82
return (
73
83
< OnboardingStep
@@ -77,8 +87,8 @@ export const StepUserInfo: FC<Props> = ({ user, onComplete }) => {
77
87
isValid = { isValid }
78
88
isSaving = { updateUser . isLoading }
79
89
onSubmit = { handleSubmit }
80
- submitButtonText = "Continue with 100 credits per month"
81
- submitButtonType = "secondary"
90
+ submitButtonText = { linkedinConnectionForOnboarding ? "Continue with 100 credits per month" : undefined }
91
+ submitButtonType = { linkedinConnectionForOnboarding ? "secondary" : undefined }
82
92
>
83
93
{ user . avatarUrl && (
84
94
< div className = "my-4 flex justify-center" >
@@ -108,7 +118,19 @@ export const StepUserInfo: FC<Props> = ({ user, onComplete }) => {
108
118
/>
109
119
</ div >
110
120
111
- < LinkedInBanner onSuccess = { onLinkedInSuccess } />
121
+ { linkedinConnectionForOnboarding ? (
122
+ < LinkedInBanner onSuccess = { onLinkedInSuccess } />
123
+ ) : (
124
+ < TextInputField
125
+ value = { emailAddress }
126
+ label = "Work Email"
127
+ type = "email"
128
+ error = { emailError . message }
129
+ onBlur = { emailError . onBlur }
130
+ onChange = { setEmailAddress }
131
+ required
132
+ />
133
+ ) }
112
134
</ OnboardingStep >
113
135
) ;
114
136
} ;
0 commit comments