Skip to content

Commit

Permalink
Merge pull request #18 from Abh1noob/master
Browse files Browse the repository at this point in the history
feat: bigger fatter prrerr
  • Loading branch information
Abh1noob committed Mar 10, 2024
2 parents 96d5c7c + 7241614 commit b7cfeef
Show file tree
Hide file tree
Showing 15 changed files with 326 additions and 801 deletions.
56 changes: 18 additions & 38 deletions devsoc24-portal-fe/src/app/edit-idea/edit-idea-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { Button } from "@/components/ui/button";
import { ideaSchema } from "@/schemas/idea";
import toast, { Toaster } from 'react-hot-toast';
import toast, { Toaster } from "react-hot-toast";

import axios from "axios";
import { useRouter } from "next/navigation";
Expand All @@ -33,7 +33,7 @@ interface SubmitProjectResponse {
data: unknown;
}

interface GetIdea{
interface GetIdea {
data: FormValues;
message: string;
status: string;
Expand All @@ -42,19 +42,23 @@ interface GetIdea{
import send from "@/assets/images/Send.svg";
import Image from "next/image";
import { useEffect } from "react";
import ToastContainer from "@/components/ToastContainer";
const tracks = ["Track 1", "Track 2", "Track 3"];

export default function EditIdeaForm() {
useEffect(() => {
async function getIdeaSubmission() {
try {
const res = await axios.get<GetIdea>(`${process.env.NEXT_PUBLIC_API_URL}/idea`, {
withCredentials: true,
});
const res = await axios.get<GetIdea>(
`${process.env.NEXT_PUBLIC_API_URL}/idea`,
{
withCredentials: true,
},
);
console.log(res.data.data);
form.reset(res.data.data);
} catch (error) {
console.log("Error getting idea submission:", error)
console.log("Error getting idea submission:", error);
}
}
void getIdeaSubmission();
Expand All @@ -74,50 +78,26 @@ export default function EditIdeaForm() {
});

async function onSubmit(data: FormValues) {
try {
console.log(data);
const toastId = toast.loading("Idea Submitted", { autoClose: false });
const handleSubmit = async () => {
const res = await axios.patch<SubmitProjectResponse>(
`${process.env.NEXT_PUBLIC_API_URL}/idea/update`,
data,
{
withCredentials: true,
},
);
};

if (res.data.status === "success") {
toast.update(toastId, {
render: (
<div className="">
<h2 className="font-semibold">Idea Submitted</h2>
</div>
),
type: "success",
isLoading: false,
autoClose: 2000,
});
} else {
toast.update(toastId, {
render: (
<div className="">
<h2 className="font-semibold">Failed to submit idea</h2>
<p>Please try again.</p>
</div>
),
type: "error",
isLoading: false,
autoClose: 2000,
});
}
} catch (error) {
console.error("Error submitting idea:", error);
toast.error("Failed to submit idea");
}
void toast.promise(handleSubmit(), {
loading: `Loading`,
success: `Idea Submitted`,
error: `Something went wrong`,
});
}

return (
<>
<ToastContainer />
<ToastContainer />
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
<div className="flex justify-start gap-16 max-[931px]:flex-col max-[931px]:gap-6">
Expand Down
57 changes: 18 additions & 39 deletions devsoc24-portal-fe/src/app/edit-project/edit-subject-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { Input } from "@/components/ui/input";
import { Textarea } from "@/components/ui/textarea";
import { Button } from "@/components/ui/button";
import { ideaSchema } from "@/schemas/idea";
import toast, { Toaster } from 'react-hot-toast';
import toast, { Toaster } from "react-hot-toast";

import axios from "axios";
import { useRouter } from "next/navigation";
Expand All @@ -33,7 +33,7 @@ interface SubmitProjectResponse {
data: unknown;
}

interface GetIdea{
interface GetIdea {
data: FormValues;
message: string;
status: string;
Expand All @@ -42,19 +42,23 @@ interface GetIdea{
import send from "@/assets/images/Send.svg";
import Image from "next/image";
import { useEffect } from "react";
import ToastContainer from "@/components/ToastContainer";
const tracks = ["Track 1", "Track 2", "Track 3"];

export default function EditProjectForm() {
useEffect(() => {
async function getIdeaSubmission() {
try {
const res = await axios.get<GetIdea>(`${process.env.NEXT_PUBLIC_API_URL}/project`, {
withCredentials: true,
});
const res = await axios.get<GetIdea>(
`${process.env.NEXT_PUBLIC_API_URL}/project`,
{
withCredentials: true,
},
);
console.log(res.data.data);
form.reset(res.data.data);
} catch (error) {
console.log("Error getting idea submission:", error)
console.log("Error getting idea submission:", error);
}
}
void getIdeaSubmission();
Expand All @@ -74,50 +78,25 @@ export default function EditProjectForm() {
});

async function onSubmit(data: FormValues) {
try {
console.log(data);
const toastId = toast.loading("Project Submitted", { autoClose: false });
const handleSubmit = async () => {
const res = await axios.patch<SubmitProjectResponse>(
`${process.env.NEXT_PUBLIC_API_URL}/project/update`,
data,
{
withCredentials: true,
},
);

if (res.data.status === "success") {
toast.update(toastId, {
render: (
<div className="">
<h2 className="font-semibold">Project Submitted</h2>
</div>
),
type: "success",
isLoading: false,
autoClose: 2000,
});
} else {
toast.update(toastId, {
render: (
<div className="">
<h2 className="font-semibold">Failed to submit project</h2>
<p>Please try again.</p>
</div>
),
type: "error",
isLoading: false,
autoClose: 2000,
});
}
} catch (error) {
console.error("Error submitting idea:", error);
toast.error("Failed to submit idea");
}
};
void toast.promise(handleSubmit(), {
loading: "Loading...",
success: `Project Submitted Successfully`,
error: `Something went wrong`,
});
}

return (
<>
<ToastContainer />
<ToastContainer />
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)}>
<div className="flex justify-start gap-16 max-[931px]:flex-col max-[931px]:gap-6">
Expand Down
96 changes: 31 additions & 65 deletions devsoc24-portal-fe/src/app/forgot/forgot-pass-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { Button } from "@/components/ui/button";
import toast, { Toaster } from 'react-hot-toast';
import toast, { Toaster } from "react-hot-toast";
import { useRouter } from "next/navigation";
import { MailIcon } from "lucide-react";
import Link from "next/link";
Expand All @@ -35,75 +35,41 @@ export default function ForgotForm() {

async function onSubmit(form: ForgotFormValues) {
console.log(form);
// const toastId = toast.loading("Sending...", { autoClose: false });
try {
const handleSubmit = async () => {
await axios.post<APIResponse>(
`${process.env.NEXT_PUBLIC_API_URL}/reset-password`,
{ email: form.email },
{
withCredentials: true,
},
);
// toast.update(toastId, {
// render: (
// <div className="">
// <h2 className="font-semibold">OTP sent successfully!</h2>
// <p>Redirecting...</p>
// </div>
// ),
// type: "success",
// isLoading: false,
// autoClose: 2000,
// });
setTimeout(() => {
void router.push("/reset?email=" + form.email);
}, 1500);
} catch (err) {
console.log(err);
if (axios.isAxiosError(err)) {
const error = err as AxiosError;
if (error.response?.status === 404) {
// toast.update(toastId, {
// render: (
// <div className="">
// <h2 className="font-semibold">Account not found!</h2>
// <p>Please signup.</p>
// </div>
// ),
// type: "error",
// isLoading: false,
// autoClose: 2000,
// });
} else if (error.response?.status === 403) {
// toast.update(toastId, {
// render: (
// <div className="">
// <h2 className="font-semibold">Email not verified!</h2>
// <p>Please verify your email.</p>
// </div>
// ),
// type: "error",
// isLoading: false,
// autoClose: 2000,
// });
setTimeout(() => {
void router.push("/signup/verify?email=" + form.email);
}, 1500);
} else if (error.response?.status === 400) {
// toast.update(toastId, {
// render: <BadRequest />,
// type: "error",
// isLoading: false,
// autoClose: 2000,
// });
};
void toast.promise(handleSubmit(), {
loading: "Loading...",
success: (temp) => {
setTimeout(() => {
void router.push("/reset?email=" + form.email);
}, 1500);
return `OTP sent successfully!\nRedirecting...`;
},
error: (err: AxiosError) => {
switch (err.response?.status) {
case 404:
return `Account Not Found`;
case 409:
return `Incorrect Credentials`;
case 403:
setTimeout(() => {
void router.push("/signup/verify?email=" + form.email);
}, 1500);
return `Email Not Verified`;
case 400:
return `Please check your input and try again`;
default:
return `Something went wrong`;
}
return;
}
// toast.update(toastId, {
// render: <ServerError />,
// type: "error",
// isLoading: false,
// autoClose: 2000,
// });
return;
}
},
});
}

return (
Expand Down
6 changes: 3 additions & 3 deletions devsoc24-portal-fe/src/app/login/login-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ export default function LoginForm() {
);
};

toast.promise(submitForm(), {
loading: "Logging In",
void toast.promise(submitForm(), {
loading: "Loading...",
success: (temp) => {
void router.push("/");
return `Logged In`;
},
error: (err) => {
error: (err: AxiosError) => {
switch (err.response?.status) {
case 404:
return `Account Not Found`;
Expand Down
2 changes: 1 addition & 1 deletion devsoc24-portal-fe/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default function HomePage() {
};

const handleLogout = async () => {
toast.promise(logout(), {
void toast.promise(logout(), {
loading: "Logging Out...",
success: "Logged Out",
error: "Something went wrong",
Expand Down
Loading

0 comments on commit b7cfeef

Please sign in to comment.