From 4d8bf53700a1cec2b4f7ec6ddd132847db550f5f Mon Sep 17 00:00:00 2001 From: NishantGupt786 Date: Mon, 11 Mar 2024 02:50:36 +0530 Subject: [PATCH] pr --- devsoc24-portal-fe/src/app/page.tsx | 2 +- .../src/app/profile/profile-form.tsx | 105 +++++++----------- 2 files changed, 40 insertions(+), 67 deletions(-) diff --git a/devsoc24-portal-fe/src/app/page.tsx b/devsoc24-portal-fe/src/app/page.tsx index 426b753..d369197 100644 --- a/devsoc24-portal-fe/src/app/page.tsx +++ b/devsoc24-portal-fe/src/app/page.tsx @@ -16,7 +16,6 @@ import { import Loading from "./loading"; import TrackComponent from "@/components/track/TrackComponent"; import toast, { Toaster } from "react-hot-toast"; - import { refresh, type userProps } from "@/interfaces"; import { type APIResponse } from "@/schemas/api"; import { @@ -95,6 +94,7 @@ export default function HomePage() { success: "Logged Out", error: "Something went wrong", }); + void router.push("/login"); }; const fetchData = async () => { diff --git a/devsoc24-portal-fe/src/app/profile/profile-form.tsx b/devsoc24-portal-fe/src/app/profile/profile-form.tsx index c3b052f..5edb180 100644 --- a/devsoc24-portal-fe/src/app/profile/profile-form.tsx +++ b/devsoc24-portal-fe/src/app/profile/profile-form.tsx @@ -10,13 +10,13 @@ import { } from "@/components/ui/form"; import { Label } from "@/components/ui/label"; import { Input } from "@/components/ui/input"; -import { Textarea } from "@/components/ui/textarea"; import { Button } from "@/components/ui/button"; import { profileSchema } from "@/schemas/profile"; import toast, { Toaster } from "react-hot-toast"; import blocks from "@/../public/hostels.json"; -import axios from "axios"; -import { useRouter } from "next/navigation"; +import axios, { type AxiosResponse } from "axios"; +import { type userProps } from "@/interfaces"; +import ToastContainer from "@/components/ToastContainer"; interface FormValues { first_name: string; @@ -39,35 +39,29 @@ interface SubmitProjectResponse { data: unknown; } -interface GetIdea { - data: FormValues; - message: string; - status: string; -} - import send from "@/assets/images/Send.svg"; import Image from "next/image"; import { useEffect } from "react"; const tracks = ["Track 1", "Track 2", "Track 3"]; export default function Profile() { - // useEffect(() => { - // async function getIdeaSubmission() { - // try { - // const res = await axios.get( - // `${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); - // } - // } - // void getIdeaSubmission(); - // }, []); + useEffect(() => { + async function getIdeaSubmission() { + try { + const response: AxiosResponse = await axios.get( + `${process.env.NEXT_PUBLIC_API_URL}/user/me`, + { + withCredentials: true, + }, + ); + console.log(response.data.data); + form.reset(response.data.data); + } catch (error) { + console.log("Error getting idea submission:", error); + } + } + void getIdeaSubmission(); + }, []); const form = useForm({ resolver: zodResolver(profileSchema), @@ -84,49 +78,27 @@ export default function Profile() { }); async function onSubmit(data: FormValues) { - // try { - console.log(data); - // const toastId = toast.loading("Idea Submitted", { autoClose: false }); - // const res = await axios.patch( - // `${process.env.NEXT_PUBLIC_API_URL}/idea/update`, - // data, - // { - // withCredentials: true, - // }, - // ); - - // if (res.data.status === "success") { - // toast.update(toastId, { - // render: ( - //
- //

Idea Submitted

- //
- // ), - // type: "success", - // isLoading: false, - // autoClose: 2000, - // }); - // } else { - // toast.update(toastId, { - // render: ( - //
- //

Failed to submit idea

- //

Please try again.

- //
- // ), - // type: "error", - // isLoading: false, - // autoClose: 2000, - // }); - // } - // } catch (error) { - // console.error("Error submitting idea:", error); - // toast.error("Failed to submit idea"); - // } + console.log(data); + const handleSubmit = async () => { + const res = await axios.patch( + `${process.env.NEXT_PUBLIC_API_URL}/idea/update`, + data, + { + withCredentials: true, + }, + ); + console.log(res.data); + }; + void toast.promise(handleSubmit(), { + loading: `Loading`, + success: `Profile updated`, + error: `Something went wrong`, + }); } return ( <> +
-
+