Skip to content

Commit

Permalink
feat(user-registration): user registration frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
bas-kirill committed Aug 14, 2024
1 parent 7f0bcff commit a010dbe
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
10 changes: 4 additions & 6 deletions client/src/pages/registration/api/action.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import { SERVER_URL } from "shared/config";
import { API_REGISTRATION } from "shared/config/backend";

interface RegistrationRequestBody {
name: string;
surname: string;
fullName: string;
login: string;
password: string;
}
Expand All @@ -18,7 +17,7 @@ export interface RegistrationAction {
export const action: ActionFunction = async ({
request,
}): Promise<RegistrationAction> => {
const { name, surname, login, password, errors } = parseForm(
const { fullName, login, password, errors } = parseForm(
await request.formData(),
);

Expand All @@ -29,8 +28,7 @@ export const action: ActionFunction = async ({
}

const registrationRequestBody: RegistrationRequestBody = {
name: name,
surname: surname,
fullName: fullName,
login: login,
password: password,
};
Expand All @@ -48,6 +46,6 @@ export const action: ActionFunction = async ({
}

return {
errors: [`Failed to authenticate: '${status}' code`],
errors: [`User already exists`],
};
};
24 changes: 9 additions & 15 deletions client/src/pages/registration/model/parseForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,34 @@ import { MINIMAL_PASSWORD_LENGTH } from "shared/config/frontend";
export function parseForm(data: FormData) {
const errors = [];

const name = data.get("name");
if (typeof name !== "string" || name === "") {
const fullName = data.get("fullName");
if (typeof fullName !== "string" || fullName.trim() === "") {
errors.push("Type name at form");
}

const surname = data.get("surname");
if (typeof surname !== "string" || surname === "") {
errors.push("Type surname at form");
}

const login = data.get("login");
if (typeof login !== "string" || login === "") {
if (typeof login !== "string" || login.trim() === "") {
errors.push("Type login at form");
}

if (typeof login === "string" && login.length < 4) {
errors.push("Login must greater than 3 symbols");
if (typeof login === "string" && login.trim() === "") {
errors.push("Type login at form");
}

const password = data.get("password");
if (typeof password !== "string" || password === "") {
if (typeof password !== "string" || password.trim() === "") {
errors.push("Type password at form");
}

if (
typeof password === "string" &&
password.length < MINIMAL_PASSWORD_LENGTH
) {
errors.push(`Password must greater ${MINIMAL_PASSWORD_LENGTH} symbols`);
errors.push(`Password length less than ${MINIMAL_PASSWORD_LENGTH}`);
}

return { name, surname, login, password, errors } as {
name: string;
surname: string;
return { fullName, login, password, errors } as {
fullName: string;
login: string;
password: string;
errors: string[];
Expand Down
3 changes: 1 addition & 2 deletions client/src/pages/registration/ui/RegistrationPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ export const RegistrationPage = () => {
)}

<Form method="POST">
<input type="text" name="name" placeholder={"Name"} />
<input type="text" name="surname" placeholder={"Surname"} />
<input type="text" name="fullName" placeholder={"Full Name"} />
<input type="text" name="login" placeholder={"Login"} />
<input type="password" name="password" placeholder={"Password"} />
<input type="submit" value="Registration" />
Expand Down

0 comments on commit a010dbe

Please sign in to comment.