Skip to content

Commit

Permalink
user api
Browse files Browse the repository at this point in the history
  • Loading branch information
aditansh committed Mar 8, 2024
1 parent 6a11e9d commit e5ff34a
Show file tree
Hide file tree
Showing 12 changed files with 779 additions and 529 deletions.
17 changes: 1 addition & 16 deletions devsoc24-portal-fe/src/app/forgot/forgot-pass-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,7 @@ export default function ForgotForm() {

async function onSubmit(data: ForgotFormValues) {
console.log(data);
// const toastId = toast.loading("Logging in...", { autoClose: false });
// const res = await loginUser(data);

// toast.update(toastId, {
// render:
// res === 200 ? "Login successful!" : res !== 500 ? res : <ServerError />,
// type: res === 200 ? "success" : "error",
// isLoading: false,
// autoClose: 2000,
// });

// if (res === 200) {
// setTimeout(() => {
// void router.push("/overview");
// }, 2000);
// }

}

return (
Expand Down
11 changes: 8 additions & 3 deletions devsoc24-portal-fe/src/app/login/login-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import "react-toastify/dist/ReactToastify.css";
import { useRouter } from "next/navigation";
import { EyeIcon, EyeOffIcon, LockKeyholeIcon, MailIcon } from "lucide-react";
import Link from "next/link";
import { type LoginResponse } from "@/schemas/api";
import { type APIResponse, type LoginResponse } from "@/schemas/api";
import axios, { type AxiosError } from "axios";
import { BadRequest, ServerError } from "@/components/toast";

Expand All @@ -39,7 +39,7 @@ export default function LoginForm() {
async function onSubmit(formVal: LoginFormValues) {
const toastId = toast.loading("Logging in...", { autoClose: false });
try {
const { data } = await axios.post<LoginResponse>(
const { data } = await axios.post<APIResponse>(
`${process.env.NEXT_PUBLIC_API_URL}/login`,
{ email: formVal.email, password: formVal.password },
);
Expand All @@ -54,8 +54,10 @@ export default function LoginForm() {
isLoading: false,
autoClose: 2000,
});
const res = data.data as LoginResponse;

setTimeout(() => {
if (data.profile_complete) {
if (res.profile_complete) {
void router.push("/");
} else {
void router.push("/signup/details?email=" + formVal.email);
Expand Down Expand Up @@ -101,6 +103,9 @@ export default function LoginForm() {
isLoading: false,
autoClose: 2000,
});
setTimeout(() => {
void router.push("/signup/verify?email=" + formVal.email);
}, 1500);
} else if (error.response?.status === 400) {
toast.update(toastId, {
render: <BadRequest />,
Expand Down
2 changes: 0 additions & 2 deletions devsoc24-portal-fe/src/app/reset/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import React, { useEffect, useState } from "react";
import Logo from "@/components/logo";
import { ModeToggle } from "@/components/theme-toggle";
import { Card, CardContent, CardHeader } from "@/components/ui/card";
import Image from "next/image";
import title from "@/assets/images/title.svg";
Expand Down Expand Up @@ -31,7 +30,6 @@ export default function Page() {
<main className="flex min-h-screen flex-col items-center bg-[url('/images/bg.svg')] bg-cover bg-no-repeat">
<div className="flex h-[10%] w-full items-center justify-between bg-background px-6 py-2">
<Logo className="h-9/10 w-auto" />
{/* <ModeToggle /> */}
</div>
<div className="flex max-w-[90vw] grow items-center justify-center">
<Card className="w-fit">
Expand Down
4 changes: 2 additions & 2 deletions devsoc24-portal-fe/src/app/signup/details/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { DiscordIcon } from "@/assets/images/discord";
import TeamDetailsForm from "./team-form";

export default function Page() {
const [form, setForm] = useState(0);
const [form, setForm] = useState(2);
const [isBannerVisible, setIsBannerVisible] = useState(true);

return (
Expand Down Expand Up @@ -64,7 +64,7 @@ export default function Page() {
</p>
{form === 0 && <PersonalDetails setForm={setForm} />}
{form === 1 && <CollegeDetailsForm setForm={setForm} />}
{form === 2 && <TeamDetailsForm setForm={setForm} />}
{form === 2 && <TeamDetailsForm />}
</div>
</main>
);
Expand Down
35 changes: 13 additions & 22 deletions devsoc24-portal-fe/src/app/signup/details/personal-details-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,18 @@ export default function PersonalDetails({
useEffect(() => {
form.setValue("firstName", localStorage.getItem("first_name") ?? "");
form.setValue("lastName", localStorage.getItem("last_name") ?? "");
form.setValue("email", email ?? "");
form.setValue("phoneNumber", localStorage.getItem("phone_number") ?? "");
form.setValue("country", localStorage.getItem("country") ?? "+91");
const gender = localStorage.getItem("gender");
console.log(gender);

switch (gender) {
case "Male": {
form.setValue("gender", "Male");
break;
}
case "Female": {
form.setValue("gender", "Female");
break;
}
case "Others": {
form.setValue("gender", "Others");
break;
}
case "Prefer Not to Say": {
form.setValue("gender", "Prefer Not to Say");
break;
}
}
});
form.setValue(
"gender",
(localStorage.getItem("gender") as
| "Male"
| "Female"
| "Others"
| "Prefer Not to Say") ?? undefined,
);
}, []);

async function onSubmit(data: PersonalDetailsFormValues) {
localStorage.setItem("first_name", data.firstName);
Expand Down Expand Up @@ -104,6 +92,7 @@ export default function PersonalDetails({
type="text"
placeholder="First Name"
autoComplete="First Name"
required
{...field}
className={` ${
form.getFieldState("firstName").invalid
Expand Down Expand Up @@ -155,6 +144,7 @@ export default function PersonalDetails({
type="email"
placeholder="Email Address"
autoComplete="email"
required
disabled
{...field}
className={` ${
Expand Down Expand Up @@ -206,6 +196,7 @@ export default function PersonalDetails({
type="text"
placeholder="Phone Number"
autoComplete="phone"
required
{...field}
className={`pl-[80px] ${
form.getFieldState("phoneNumber").invalid
Expand Down
15 changes: 9 additions & 6 deletions devsoc24-portal-fe/src/app/signup/details/team-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,10 @@ import React, { useState } from "react";
import CreateTeamForm from "@/components/forms/create-team-form";
import JoinTeamForm from "@/components/forms/join-team-form";
import { Button } from "@/components/ui/button";
import { useRouter } from "next/navigation";

export default function TeamDetailsForm({
setForm,
}: {
setForm: React.Dispatch<React.SetStateAction<number>>;
}) {
export default function TeamDetailsForm() {
const router = useRouter();
const [isNewTeam, setisNewTeam] = useState(false);

return (
Expand All @@ -35,7 +33,12 @@ export default function TeamDetailsForm({
</p>
</div>
{isNewTeam ? <CreateTeamForm /> : <JoinTeamForm />}
<Button className="mx-auto mt-10 w-fit">Skip</Button>
<Button
className="mx-auto mt-10 w-fit"
onClick={() => void router.push("/")}
>
Skip
</Button>
<p className="text-muted-primary mx-auto pt-2">
You can join / create a team later!
</p>
Expand Down
2 changes: 0 additions & 2 deletions devsoc24-portal-fe/src/app/signup/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import React, { useEffect, useState } from "react";
import Logo from "@/components/logo";
import { ModeToggle } from "@/components/theme-toggle";
import { Card, CardContent, CardHeader } from "@/components/ui/card";
import Image from "next/image";
import title from "@/assets/images/title.svg";
Expand Down Expand Up @@ -31,7 +30,6 @@ export default function Page() {
<main className="flex min-h-screen flex-col items-center bg-[url('/images/bg.svg')] bg-cover bg-no-repeat">
<div className="flex h-[10%] w-full items-center justify-between bg-background px-6 py-2">
<Logo className="h-9/10 w-auto" />
{/* <ModeToggle /> */}
</div>
<div className="flex max-w-[90vw] grow items-center justify-center">
<Card className="w-fit">
Expand Down
Loading

0 comments on commit e5ff34a

Please sign in to comment.