From ff67cae0fc1ee7c1609b2db7c04c250970814bb2 Mon Sep 17 00:00:00 2001 From: Abh1noob Date: Fri, 8 Mar 2024 20:06:18 +0530 Subject: [PATCH] basics --- devsoc24-portal-fe/src/app/page.tsx | 103 +++++++++++++++--- .../src/components/forms/join-team-form.tsx | 47 ++++++-- .../src/components/teamCard.tsx | 79 +++++++++----- devsoc24-portal-fe/src/store/store.tsx | 50 +++++++++ 4 files changed, 226 insertions(+), 53 deletions(-) diff --git a/devsoc24-portal-fe/src/app/page.tsx b/devsoc24-portal-fe/src/app/page.tsx index 14baf47..3cb8a1f 100644 --- a/devsoc24-portal-fe/src/app/page.tsx +++ b/devsoc24-portal-fe/src/app/page.tsx @@ -1,13 +1,18 @@ "use client"; import Image from "next/image"; import { useRouter } from "next/navigation"; -import { Suspense, useEffect } from "react"; +import { Suspense, useEffect, useState } from "react"; import Logo from "@/components/logo"; import Dashtitle from "@/assets/images/titleDashboard.svg"; import CustomCard from "@/components/customCard"; import TeamCard from "@/components/teamCard"; import axios, { AxiosError, AxiosResponse } from "axios"; -import { useIdeaStore, useTeamStore } from "@/store/store"; +import { + useIdeaStore, + useTeamStore, + useUserStore, + userProps, +} from "@/store/store"; import Loading from "./loading"; interface ideaProps { @@ -31,9 +36,46 @@ interface teamProps { status: string; } +interface teamDataUserProps { + name: string; + reg_no: string; + email: string; +} + +interface teamDataProps { + message?: string; + status?: string; + team?: { + team_name: string; + team_code: string; + leaderid: string; + round: 0; + users: teamDataUserProps[]; + idea: { + title: string; + description: string; + track: string; + github_link: string; + figma_link: string; + others: string; + }; + project: { + name: string; + description: string; + track: string; + github_link: string; + figma_link: string; + others: string; + }; + }; +} + export default function HomePage() { const { idea, setIdea } = useIdeaStore(); const { team, setTeam } = useTeamStore(); + const { user, setUser } = useUserStore(); + const [teamData, setTeamData] = useState(null); + const login = async () => { const response = await axios.post( `${process.env.NEXT_PUBLIC_API_URL}/login`, @@ -49,13 +91,13 @@ export default function HomePage() { const fetchData = async () => { try { - const response: AxiosResponse = await axios.get( - `${process.env.NEXT_PUBLIC_API_URL}/idea`, + const response: AxiosResponse = await axios.get( + `${process.env.NEXT_PUBLIC_API_URL}/user/me`, { withCredentials: true, }, ); - console.log(response); + setUser(response.data); } catch (e) { if (axios.isAxiosError(e)) { switch (e.response?.status) { @@ -69,15 +111,17 @@ export default function HomePage() { } } } - //Team Get + }; + + const fetchTeam = async () => { try { - const response: AxiosResponse = await axios.get( + const response: AxiosResponse = await axios.get( `${process.env.NEXT_PUBLIC_API_URL}/team`, { withCredentials: true, }, ); - console.log(response); + setTeamData(response.data); } catch (e) { if (axios.isAxiosError(e)) { switch (e.response?.status) { @@ -93,14 +137,47 @@ export default function HomePage() { } }; + const fetchIdea = async () => { + try { + const response: AxiosResponse = await axios.get( + `${process.env.NEXT_PUBLIC_API_URL}/idea`, + { + withCredentials: true, + }, + ); + console.log("FETCH IDEA: ", response); + } catch (e) { + if (axios.isAxiosError(e)) { + switch (e.response?.status) { + case 404: + console.log("no team"); + case 417: + console.log("team no idea"); + default: + console.log(e); + } + } + } + }; + useEffect(() => { const fetchDataAndLogin = async () => { await login(); await fetchData(); + await fetchIdea(); }; void fetchDataAndLogin(); }, []); + useEffect(() => { + if (user.data.team_id === "00000000-0000-0000-0000-000000000000") { + console.log("Loner saala"); + setTeam(true); + } else { + void fetchTeam(); + } + }, [user]); + const noTeamCard = [ { text: "+ Create Team", @@ -123,14 +200,6 @@ export default function HomePage() { ]; const router = useRouter(); - // useEffect(() => { - // const token = localStorage.getItem("token"); - // if (token) { - // router.push("./login"); - // } else { - // router.push("./signup"); - // } - // }); return ( }>
@@ -148,7 +217,7 @@ export default function HomePage() { buttonDetails={noTeamCard} /> ) : ( - + )} ; @@ -36,6 +30,7 @@ export default function JoinTeamForm() { async function onSubmit(data: CreateTeamFormValues) { console.log(data); + console.log("submittt") // const toastId = toast.loading("Logging in...", { autoClose: false }); // const res = await loginUser(data); @@ -54,6 +49,33 @@ export default function JoinTeamForm() { // } } + const handleJoinTeam = async (e: string) => { + console.log("clicked"); + try { + const response = await axios.post( + `${process.env.NEXT_PUBLIC_API_URL}/team/join`, + { + code: e, + }, + { + withCredentials: true, + }, + ); + console.log("FETCH IDEA: ", response); + } catch (e) { + if (axios.isAxiosError(e)) { + switch (e.response?.status) { + // case 404: + // console.log("no team"); + // case 417: + // console.log("team no idea"); + default: + console.log(e); + } + } + } + }; + return (
- + {/* Display error message */} + {createTeamForm.formState.errors.teamCode && ( + + {createTeamForm.formState.errors.teamCode.message} + + )} )} /> diff --git a/devsoc24-portal-fe/src/components/teamCard.tsx b/devsoc24-portal-fe/src/components/teamCard.tsx index ac895ff..098c362 100644 --- a/devsoc24-portal-fe/src/components/teamCard.tsx +++ b/devsoc24-portal-fe/src/components/teamCard.tsx @@ -3,19 +3,42 @@ import { useState } from "react"; import { Crown, BadgeMinus, Files, Check } from "lucide-react"; import { Button } from "@/components/ui/button"; import { CopyToClipboard } from "react-copy-to-clipboard"; -const team = { - memberName: "John dobecrazy", - teamName: "Team valhalla", - isLeader: true, - teamMembers: [ - { name: "John doe", isLeader: false }, - { name: "John doe", isLeader: false }, - { name: "John doe", isLeader: false }, - ], - teamCode: "123456", -}; -function TeamCard() { +interface teamDataUserProps { + name: string; + reg_no: string; + email: string; +} + +interface teamDataProps { + message?: string; + status?: string; + team?: { + team_name: string; + team_code: string; + leaderid: string; + round: 0; + users: teamDataUserProps[]; + idea: { + title: string; + description: string; + track: string; + github_link: string; + figma_link: string; + others: string; + }; + project: { + name: string; + description: string; + track: string; + github_link: string; + figma_link: string; + others: string; + }; + }; +} + +const TeamCard: React.FC = (props) => { const [isCopied, setIsCopied] = useState(false); const onCopyText = () => { setIsCopied(true); @@ -31,23 +54,23 @@ function TeamCard() { Your Devsoc Team
-

{team.teamName}

+

{props.team?.team_name}

Team Members

- {team.memberName} - {team.isLeader && ( + {props.team?.users[0]?.name} + {/* {team.isLeader && ( - )} + )} */}
- {team.teamMembers.map((member, index) => ( + {props.team?.users.map((member, index) => (
{member.name} - {member.isLeader ? ( + {/* {member.isLeader ? ( @@ -55,20 +78,24 @@ function TeamCard() { - )} + )} */}
))} - - - + {props.team && ( + + + + )}
); -} +}; export default TeamCard; diff --git a/devsoc24-portal-fe/src/store/store.tsx b/devsoc24-portal-fe/src/store/store.tsx index 7b6fcd0..c0fa692 100644 --- a/devsoc24-portal-fe/src/store/store.tsx +++ b/devsoc24-portal-fe/src/store/store.tsx @@ -25,3 +25,53 @@ export const useTeamStore = create((set) => ({ team: false, setTeam: (team: boolean) => set({ team }), })); + +export interface userProps { + data: { + id: string; + first_name: string; + last_name: string; + reg_no: string; + email: string; + phone: string; + college: string; + city: string; + state: string; + gender: string; + role: string; + team_id: string; + }; + message: string; + status: string; +} + +interface userStore { + user: userProps; + setUser: (setUser: userProps) => void; +} + +export const useUserStore = create((set) => ({ + user: { + data: { + id: "", + first_name: "", + last_name: "", + reg_no: "", + email: "", + phone: "", + college: "", + city: "", + state: "", + gender: "", + role: "", + team_id: "", + }, + message: "", + status: "", + }, + setUser: (userData: userProps) => + set((state) => ({ + ...state, + user: userData, + })), +}));