From 37efd008baf1ec78b4d4e4317eb9bd97de4a14fe Mon Sep 17 00:00:00 2001 From: Faisal khan Date: Sat, 14 Oct 2023 22:59:22 +0530 Subject: [PATCH] added firstName and lastName in user form --- .../Onboarding/pages/OnboardAccount.tsx | 8 +- .../pages/{UsernameForm.tsx => UserForm.tsx} | 85 +++++++++++++++++-- .../recoil/src/context/OnboardingProvider.tsx | 9 +- 3 files changed, 88 insertions(+), 14 deletions(-) rename packages/app-extension/src/components/Onboarding/pages/{UsernameForm.tsx => UserForm.tsx} (52%) diff --git a/packages/app-extension/src/components/Onboarding/pages/OnboardAccount.tsx b/packages/app-extension/src/components/Onboarding/pages/OnboardAccount.tsx index b1564812f..a65ad87ea 100644 --- a/packages/app-extension/src/components/Onboarding/pages/OnboardAccount.tsx +++ b/packages/app-extension/src/components/Onboarding/pages/OnboardAccount.tsx @@ -24,7 +24,7 @@ import { HardwareOnboard } from "./HardwareOnboard"; import { InviteCodeForm } from "./InviteCodeForm"; import { KeyringTypeSelector } from "./KeyringTypeSelector"; import { NotificationsPermission } from "./NotificationsPermission"; -import { UsernameForm } from "./UsernameForm"; +import { UserForm } from "./UserForm"; export const OnboardAccount = ({ onRecover, @@ -74,11 +74,11 @@ export const OnboardAccount = ({ nextStep(); }} />, - { - setOnboardingData({ username }); + onNext={(username, firstName, lastName) => { + setOnboardingData({ username, firstName, lastName }); nextStep(); }} />, diff --git a/packages/app-extension/src/components/Onboarding/pages/UsernameForm.tsx b/packages/app-extension/src/components/Onboarding/pages/UserForm.tsx similarity index 52% rename from packages/app-extension/src/components/Onboarding/pages/UsernameForm.tsx rename to packages/app-extension/src/components/Onboarding/pages/UserForm.tsx index 627494a16..a78d86f33 100644 --- a/packages/app-extension/src/components/Onboarding/pages/UsernameForm.tsx +++ b/packages/app-extension/src/components/Onboarding/pages/UserForm.tsx @@ -1,19 +1,21 @@ import { type FormEvent, useCallback, useEffect, useState } from "react"; -import { PrimaryButton,TextInput } from "@coral-xyz/react-common"; +import { PrimaryButton, TextInput } from "@coral-xyz/react-common"; import { useCustomTheme } from "@coral-xyz/themes"; import { AlternateEmail } from "@mui/icons-material"; import { Box, InputAdornment } from "@mui/material"; import { Header, SubtextParagraph } from "../../common"; -export const UsernameForm = ({ +export const UserForm = ({ inviteCode, onNext, }: { inviteCode: string; - onNext: (username: string) => void; + onNext: (username: string, firstName: string, lastName: string) => void; }) => { const [username, setUsername] = useState(""); + const [firstName, setFirstName] = useState(""); + const [lastName, setLastName] = useState(""); const [error, setError] = useState(""); const theme = useCustomTheme(); @@ -34,12 +36,12 @@ export const UsernameForm = ({ const json = await res.json(); if (!res.ok) throw new Error(json.message || "There was an error"); - onNext(username); + onNext(username, firstName, lastName); } catch (err: any) { setError(err.message); } }, - [username] + [username, firstName, lastName] ); return ( @@ -53,16 +55,14 @@ export const UsernameForm = ({ justifyContent: "space-between", }} > - +
Others can see and find you by this username, and it will be associated with your primary wallet address.
-
Choose wisely if you'd like to remain anonymous.
-
Have fun!
@@ -73,7 +73,8 @@ export const UsernameForm = ({ marginBottom: "16px", }} > - + {/* username */} + + {/* firstname */} + + { + setFirstName( + e.target.value.toLowerCase().replace(/[^a-z0-9_]/g, "") + ); + }} + error={error ? true : false} + errorMessage={error} + startAdornment={ + + + + } + /> + + {/* lastName */} + + { + setLastName( + e.target.value.toLowerCase().replace(/[^a-z0-9_]/g, "") + ); + }} + error={error ? true : false} + errorMessage={error} + startAdornment={ + + + + } + /> + diff --git a/packages/recoil/src/context/OnboardingProvider.tsx b/packages/recoil/src/context/OnboardingProvider.tsx index e9499b6a8..05aa3b287 100644 --- a/packages/recoil/src/context/OnboardingProvider.tsx +++ b/packages/recoil/src/context/OnboardingProvider.tsx @@ -81,6 +81,8 @@ export type OnboardingData = { complete: boolean; inviteCode: string | undefined; username: string | null; + firstName: string | null; + lastName: string | null; action: string; keyringType: KeyringType | null; blockchain: Blockchain | null; @@ -102,6 +104,8 @@ const defaultState = { complete: false, inviteCode: undefined, username: null, + firstName: null, + lastName: null, action: "create", keyringType: null, blockchain: null, @@ -278,7 +282,8 @@ export function OnboardingProvider({ // const createUser = useCallback( async (data: Partial) => { - const { inviteCode, userId, username, keyringType } = data; + const { inviteCode, userId, username, firstName, lastName, keyringType } = + data; // If userId is provided, then we are onboarding via the recover flow. if (userId) { @@ -312,6 +317,8 @@ export function OnboardingProvider({ // const body = JSON.stringify({ username, + firstName, + lastName, inviteCode, waitlistId: getWaitlistId?.(), blockchainPublicKeys,