Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added firstname and lastname to onboarding form #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ export const OnboardAccount = ({
<UsernameForm
key="UsernameForm"
inviteCode={inviteCode!}
onNext={(username) => {
setOnboardingData({ username });
onNext={(username, firstname, lastname) => {
setOnboardingData({ username, firstname, lastname });
nextStep();
}}
/>,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
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";
Expand All @@ -11,16 +11,26 @@ export const UsernameForm = ({
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 [firstnameError, setFirstnameError] = useState("");
const [lastnameError, setLastnameError] = useState("");
const theme = useCustomTheme();

useEffect(() => {
setError("");
}, [username]);

useEffect(() => {
setFirstnameError("");
}, [firstname]);
useEffect(() => {
setLastnameError("");
}, [lastname]);
const handleSubmit = useCallback(
async (e: FormEvent) => {
e.preventDefault();
Expand All @@ -31,15 +41,40 @@ export const UsernameForm = ({
"x-backpack-invite-code": String(inviteCode),
},
});
console.log(res);
const json = await res.json();
if (!res.ok) throw new Error(json.message || "There was an error");

onNext(username);
console.log(json.message);
if (!res.ok) {
if (firstname.length < 3 || firstname.length > 15) {
setFirstnameError("First Name should be between 3-15 characters ");
}

if (lastname.length < 3 || lastname.length > 15) {
setLastnameError("Last Name should be between 3-15 characters ");
}
setError(json.message);
throw new Error(json.message || "There was an error");
}
if (firstname.length < 3 || firstname.length > 15) {
setFirstnameError("First Name should be between 3-15 characters ");
if (lastname.length < 3 || lastname.length > 15) {
setLastnameError("Last Name should be between 3-15 characters ");
}
throw new Error("invalid firstname");
}

if (lastname.length < 3 || lastname.length > 15) {
setLastnameError("Last Name should be between 3-15 characters ");
throw new Error("invalid firstname");
}

onNext(username, firstname, lastname);
} catch (err: any) {
setError(err.message);
console.log(err);
}
},
[username]
[username, firstname, lastname]
);

return (
Expand Down Expand Up @@ -105,6 +140,42 @@ export const UsernameForm = ({
}
/>
</Box>
<Box style={{ marginBottom: "16px" }}>
<TextInput
inputProps={{
name: "firstname",
autoComplete: "off",
spellCheck: "false",
autoFocus: true,
}}
placeholder="First Name"
type="text"
value={firstname}
setValue={(e) => {
setFirstname(e.target.value);
}}
error={firstnameError ? true : false}
errorMessage={firstnameError}
/>
</Box>
<Box style={{ marginBottom: "16px" }}>
<TextInput
inputProps={{
name: "lastname",
autoComplete: "off",
spellCheck: "false",
autoFocus: true,
}}
placeholder="Last Name"
type="text"
value={lastname}
setValue={(e) => {
setLastname(e.target.value);
}}
error={lastnameError ? true : false}
errorMessage={lastnameError}
/>
</Box>
<PrimaryButton label="Continue" type="submit" />
</Box>
</form>
Expand Down
9 changes: 8 additions & 1 deletion packages/recoil/src/context/OnboardingProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -102,6 +104,8 @@ const defaultState = {
complete: false,
inviteCode: undefined,
username: null,
firstname: null,
lastname: null,
action: "create",
keyringType: null,
blockchain: null,
Expand Down Expand Up @@ -278,7 +282,8 @@ export function OnboardingProvider({
//
const createUser = useCallback(
async (data: Partial<OnboardingData>) => {
const { inviteCode, userId, username, keyringType } = data;
const { inviteCode, userId, username, keyringType, firstname, lastname } =
data;

// If userId is provided, then we are onboarding via the recover flow.
if (userId) {
Expand Down Expand Up @@ -312,6 +317,8 @@ export function OnboardingProvider({
//
const body = JSON.stringify({
username,
firstname,
lastname,
inviteCode,
waitlistId: getWaitlistId?.(),
blockchainPublicKeys,
Expand Down