Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
aditansh committed Mar 8, 2024
2 parents 4a23bf9 + 527cb70 commit 6a11e9d
Show file tree
Hide file tree
Showing 15 changed files with 1,309 additions and 546 deletions.
400 changes: 258 additions & 142 deletions devsoc24-portal-fe/src/app/edit-idea/edit-idea-form.tsx

Large diffs are not rendered by default.

11 changes: 11 additions & 0 deletions devsoc24-portal-fe/src/app/loading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from "react";

const Loading = () => {
return (
<div>
Loading
</div>
);
};

export default Loading;
245 changes: 207 additions & 38 deletions devsoc24-portal-fe/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,183 @@
"use client";
import Image from "next/image";
import { useRouter } from "next/navigation";
import { 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,
useUserStore,
userProps,
} from "@/store/store";
import Loading from "./loading";

interface ideaProps {
message: string;
status: boolean;
data?: {
title: string;
description: string;
track: string;
github_link: string;
figma_link: string;
others: string;
};
}

interface teamProps {
data: {
token_expired?: boolean;
};
message: string;
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<teamDataProps | null>(null);

const login = async () => {
const response = await axios.post(
`${process.env.NEXT_PUBLIC_API_URL}/login`,
{
email: "[email protected]",
password: "123456",
},
{
withCredentials: true,
},
);
};

const fetchData = async () => {
try {
const response: AxiosResponse<userProps> = await axios.get(
`${process.env.NEXT_PUBLIC_API_URL}/user/me`,
{
withCredentials: true,
},
);
setUser(response.data);
} catch (e) {
if (axios.isAxiosError(e)) {
switch (e.response?.status) {
case 404:
console.log("Idea Not found, but in a team");
case 409:
setIdea(409);
console.log("Not in team");
default:
console.log(e);
}
}
}
};

const fetchTeam = async () => {
try {
const response: AxiosResponse<teamDataProps> = await axios.get(
`${process.env.NEXT_PUBLIC_API_URL}/team`,
{
withCredentials: true,
},
);
setTeamData(response.data);
} catch (e) {
if (axios.isAxiosError(e)) {
switch (e.response?.status) {
case 417:
setTeam(false);
console.log("no team");
case 200:
setTeam(true);
default:
console.log(e);
}
}
}
};

const fetchIdea = async () => {
try {
const response: AxiosResponse<ideaProps> = 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",
Expand All @@ -20,45 +190,44 @@ export default function HomePage() {
modalType: "JoinTeam",
},
];
const ideaCard = [{
text: "Submit An Idea",
showModal: true,
modalType:"IdeaSubmit",
routeTo: "/submit-idea",
}]
const ideaCard = [
{
text: "Submit An Idea",
showModal: true,
modalType: idea === 409 ? "Choice" : "IdeaSubmit",
routeTo: "/submit-idea",
},
];
const router = useRouter();

// useEffect(() => {
// const token = localStorage.getItem("token");
// if (token) {
// router.push("./login");
// } else {
// router.push("./signup");
// }
// });
return (
<main className="flex min-h-screen flex-col items-start bg-[#F4F5FA] overflow-x-hidden">
<div className="flex h-[10%] w-full items-center gap-x-8 bg-background px-6 py-2">
<Logo className="h-9/10 w-auto" />
<Image src={Dashtitle as HTMLImageElement} alt="title" />
</div>
<div className="mt-4 flex flex-col md:flex-row md:flex-wrap gap-4 w-full px-4">
<CustomCard
title="Your Devsoc Team"
cardImage="teamCardImg"
cardContent="No Team Members Yet?"
cardDesc="Start A New Team or Join One"
buttonDetails={noTeamCard}
/>
<CustomCard
title="Idea Submission"
cardImage="ideaSubmissionImg"
cardContent="No Idea Submitted yet"
cardDesc="Submit Your Idea Before < date > < time >"
buttonDetails={ideaCard}
/>
<TeamCard />
</div>
</main>
<Suspense fallback={<Loading />}>
<main className="flex min-h-screen flex-col items-start overflow-x-hidden bg-[#F4F5FA]">
<div className="flex h-[10%] w-full items-center gap-x-8 bg-background px-6 py-2">
<Logo className="h-9/10 w-auto" />
<Image src={Dashtitle as HTMLImageElement} alt="title" />
</div>
<div className="mt-4 flex w-full flex-col gap-4 px-4 md:flex-row md:flex-wrap">
{team ? (
<CustomCard
title="Your Devsoc Team"
cardImage="teamCardImg"
cardContent="No Team Members Yet?"
cardDesc="Start A New Team or Join One"
buttonDetails={noTeamCard}
/>
) : (
<TeamCard {...teamData} />
)}
<CustomCard
title="Idea Submission"
cardImage="ideaSubmissionImg"
cardContent="No Idea Submitted yet"
cardDesc="Submit Your Idea Before < date > <div time >"
buttonDetails={ideaCard}
/>
</div>
</main>
</Suspense>
);
}
6 changes: 3 additions & 3 deletions devsoc24-portal-fe/src/app/submit-idea/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import Logo from "@/components/logo";
import Dashtitle from "@/assets/images/titleDashboard.svg";
import active from "@/assets/images/active.svg"
import SubmitIdeaForm from "./submit-idea-form";
import { ArrowLeft } from 'lucide-react';
import Link from "next/link";

export default function Page() {
return (
Expand All @@ -14,14 +16,12 @@ export default function Page() {
<Image src={Dashtitle as HTMLImageElement} alt="title" />
</div>
<div className="flex h-[100vh] w-[4.7rem] max-[445px]:w-[3.7rem] items-start justify-center gap-x-8 bg-background px-6 py-2 pt-12">
<Image src={active as HTMLImageElement} alt="title" className="scale-150 max-[445px]:scale-[3.5]" />
<Link href="/"><ArrowLeft className="text-[#0019FF]" /></Link>
</div>
<div className="mt-[11vh] ml-[4.7rem] max-[445px]:ml-[3.7rem] absolute pt-5 pl-5 bg-[#F4F5FA] w-[91.9vw] flex flex-col max-[931px]:justify-center ">
<p className="text-black text-4xl font-medium mb-4">Submit An Idea For Devsoc24</p>
<SubmitIdeaForm />
</div>


</main>
)
}
Loading

0 comments on commit 6a11e9d

Please sign in to comment.