MCPcopy Create free account
hub / github.com/dailydotdev/apps / onSubmit

Function onSubmit

packages/shared/src/components/auth/RegistrationForm.tsx:177–273  ·  view source on GitHub ↗
(e: React.FormEvent)

Source from the content-addressed store, hash-verified

175 });
176
177 const onSubmit = (e: React.FormEvent) => {
178 e.preventDefault();
179
180 if (isCheckPending || alreadyExists) {
181 return;
182 }
183
184 setTurnstileError(false);
185 logRef.current({
186 event_name: AuthEventNames.SubmitSignUpForm,
187 });
188
189 setIsSubmitted(true);
190 const form = e.target as HTMLFormElement;
191 const { optOutMarketing, ...values } = formToJson<RegistrationFormValues>(
192 formRef?.current ?? form,
193 );
194 delete values['cf-turnstile-response'];
195
196 const requiresExperienceLevel = !hideExperienceLevel;
197 // Cloud provider is mandatory only when the funnel requests it (the
198 // campaign flow); company/job title stay optional.
199 const requiresCloudProvider = extraFields.includes('cloudProvider');
200 if (
201 !values['traits.name']?.length ||
202 !values['traits.username']?.length ||
203 (requiresExperienceLevel && !values['traits.experienceLevel']?.length) ||
204 (requiresCloudProvider && !values['traits.cloudProvider']?.length)
205 ) {
206 const setHints = { ...hints };
207
208 if (!values['traits.name']?.length) {
209 setHints['traits.name'] = 'Please provide name.';
210 }
211 if (!values['traits.username']?.length) {
212 setHints['traits.username'] = 'Please provide username.';
213 }
214 if (
215 requiresExperienceLevel &&
216 !values['traits.experienceLevel']?.length
217 ) {
218 setHints['traits.experienceLevel'] = 'Please provide experience level.';
219 }
220 if (requiresCloudProvider && !values['traits.cloudProvider']?.length) {
221 setHints['traits.cloudProvider'] =
222 'Please provide your cloud provider.';
223 }
224
225 onUpdateHints(setHints);
226 return;
227 }
228
229 if (!turnstileRef?.current?.getResponse()) {
230 logRef.current({
231 event_name: AuthEventNames.SubmitSignUpFormError,
232 extra: JSON.stringify({
233 error: 'Turnstile not valid',
234 }),

Callers 4

handleVerifyFunction · 0.70
handleSubmitFunction · 0.70
handleFormSubmitFunction · 0.70
onChangePasswordSubmitFunction · 0.70

Calls 2

formToJsonFunction · 0.90
onValidateHandlesFunction · 0.90

Tested by

no test coverage detected