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

Function onSubmit

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

Source from the content-addressed store, hash-verified

233 });
234
235 const onSubmit = async (e: React.FormEvent) => {
236 e.preventDefault();
237
238 if (isCheckPending || alreadyExists) {
239 return;
240 }
241
242 setTurnstileError(false);
243 logRef.current({
244 event_name: AuthEventNames.SubmitSignUpForm,
245 });
246
247 setIsSubmitted(true);
248 const form = e.target as HTMLFormElement;
249 const { optOutMarketing, ...values } = formToJson<RegistrationFormValues>(
250 formRef?.current ?? form,
251 );
252 delete values['cf-turnstile-response'];
253
254 // Pressing Enter in the name field submits before its blur asks for one
255 if (
256 !isUsernameVisible &&
257 !values['traits.username']?.length &&
258 values['traits.name']?.length
259 ) {
260 values['traits.username'] = await generateUsername(
261 values['traits.name'],
262 ).catch(() => '');
263 }
264
265 const requiresExperienceLevel = !hideExperienceLevel;
266 // Cloud provider is mandatory only when the funnel requests it (the
267 // campaign flow); company/job title stay optional.
268 const requiresCloudProvider = extraFields.includes('cloudProvider');
269 if (
270 !values['traits.name']?.length ||
271 !values['traits.username']?.length ||
272 (requiresExperienceLevel && !values['traits.experienceLevel']?.length) ||
273 (requiresCloudProvider && !values['traits.cloudProvider']?.length)
274 ) {
275 const setHints = { ...hints };
276
277 if (!values['traits.name']?.length) {
278 setHints['traits.name'] = isStartups
279 ? 'Add your name so your team recognizes you.'
280 : 'Please provide name.';
281 }
282 if (!values['traits.username']?.length) {
283 setHints['traits.username'] = 'Please provide username.';
284 }
285 if (
286 requiresExperienceLevel &&
287 !values['traits.experienceLevel']?.length
288 ) {
289 setHints['traits.experienceLevel'] = 'Please provide experience level.';
290 }
291 if (requiresCloudProvider && !values['traits.cloudProvider']?.length) {
292 setHints['traits.cloudProvider'] =

Callers 4

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

Calls 5

formToJsonFunction · 0.90
generateUsernameFunction · 0.90
waitForTurnstileTokenFunction · 0.90
getTurnstileWaitExtraFunction · 0.90
onValidateHandlesFunction · 0.90

Tested by

no test coverage detected