Skip to content

Commit

Permalink
Merge pull request #10 from Abh1noob/master
Browse files Browse the repository at this point in the history
errors fixed
  • Loading branch information
Abh1noob authored Mar 9, 2024
2 parents fd8fb27 + 19824f1 commit 42de4da
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 115 deletions.
75 changes: 31 additions & 44 deletions devsoc24-portal-fe/src/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,48 +46,6 @@ export default function HomePage() {
const { user, setUser } = useUserStore();
const { teamData, setTeamData } = useTeamDataStore();

// const login = async () => {
// const response = await axios.post(
// `${process.env.NEXT_PUBLIC_API_URL}/#`,
// {
// email: "abhinav@gmail.com",
// password: "123456",
// },
// {
// withCredentials: true,
// },
// );
// };

// const FetchTeam = async () => {
// try {
// const response = 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 401:
// router.push("/#");
// break;
// case 417:
// setTeam(true);
// console.log("no team");
// break;
// case 200:
// setTeam(true);
// break;
// default:
// console.log(e);
// break;
// }
// }
// }
// };
const handleLogout = async () => {
const toastId = toast.loading("Loading...", { autoClose: false });
try {
Expand All @@ -113,7 +71,6 @@ export default function HomePage() {
isLoading: false,
autoClose: 2000,
});
// window.location.reload();
router.push("/#");
} catch (e) {
if (axios.isAxiosError(e)) {
Expand Down Expand Up @@ -159,6 +116,36 @@ export default function HomePage() {
}
}
};

const fetchTeam = async () => {
try {
const response = 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 401:
router.push("/#");
break;
case 417:
setTeam(true);
console.log("no team");
break;
case 200:
setTeam(true);
break;
default:
console.log(e);
break;
}
}
}
};

const fetchIdea = async () => {
try {
Expand Down Expand Up @@ -203,7 +190,7 @@ export default function HomePage() {
console.log("Loner saala");
setTeam(true);
} else {
void FetchTeam(setTeamData, setTeam);
void fetchTeam();
}
}, [user]);

Expand Down
39 changes: 37 additions & 2 deletions devsoc24-portal-fe/src/components/team/createTeam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import { Input } from "@/components/ui/input";
import axios, { AxiosResponse } from "axios";
import z from "zod";
import { useRef } from "react";
import { useTeamStore } from "@/store/store";
import { useIdeaStore, useTeamStore, useUserStore } from "@/store/store";
import { userProps } from "@/interfaces";
import { useRouter } from "next/navigation";

const teamNameSchema = z.object({
name: z.string(),
Expand All @@ -20,6 +22,10 @@ const teamNameSchema = z.object({
function CreateTeam() {
const { team, setTeam } = useTeamStore();
const inputRef = useRef<HTMLInputElement>(null);
const { user, setUser } = useUserStore();
const { idea, setIdea } = useIdeaStore();

const router = useRouter();
const handleClick = async () => {
try {
const response = await axios.post(
Expand All @@ -44,6 +50,35 @@ function CreateTeam() {
}
}
};
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 401:
void router.push("/#");
break;
case 404:
console.log("Idea Not found, but in a team");
break;
case 409:
setIdea(409);
console.log("Not in team");
break;
default:
console.log(e);
break;
}
}
}
};
return (
<>
<DialogContent className="sm:max-w-[425px]">
Expand All @@ -63,7 +98,7 @@ function CreateTeam() {
</div>
<div className="flex justify-center">
<DialogFooter className="sm:justify-start">
<DialogClose asChild>
<DialogClose asChild onClick={fetchData}>
<Button
type="submit"
className="bg-[#458B71]"
Expand Down
35 changes: 1 addition & 34 deletions devsoc24-portal-fe/src/components/teamCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,40 +3,7 @@ import { useEffect, useState } from "react";
import { Crown, BadgeMinus, Files, Check } from "lucide-react";
import { Button } from "@/components/ui/button";
import { CopyToClipboard } from "react-copy-to-clipboard";

interface teamDataUserProps {
name: string;
reg_no: string;
id: string;
}

interface teamDataProps {
message?: string;
status?: string;
team?: {
team_name: string;
team_code: string;
leader_id: 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;
};
};
}
import { teamDataProps } from "@/interfaces";

interface keyProps {
message: string;
Expand Down
2 changes: 1 addition & 1 deletion devsoc24-portal-fe/src/store/store.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,6 @@ export const useTeamDataStore = create<teamDataStore>((set) => ({
setTeamData: (teamDataTemp: teamDataProps) =>
set((state) => ({
...state,
user: teamDataTemp,
teamData: teamDataTemp,
})),
}));
34 changes: 0 additions & 34 deletions devsoc24-portal-fe/src/utils/fetchTeam.tsx

This file was deleted.

0 comments on commit 42de4da

Please # to comment.