Skip to content

Commit

Permalink
Merge pull request #36 from NishantGupt786/master
Browse files Browse the repository at this point in the history
pr
  • Loading branch information
NishantGupt786 authored Mar 13, 2024
2 parents 7186e81 + 763bde2 commit e9b308b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 51 deletions.
48 changes: 2 additions & 46 deletions devsoc24-portal-fe/src/app/home/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,48 +161,12 @@ export default function HomePage() {
}
};

const fetchIdea = async () => {
try {
const response: AxiosResponse<ideaProps> = await axios.get(
`${process.env.NEXT_PUBLIC_API_URL}/idea`,
{
withCredentials: true,
},
);
SetIdea("idea found");
// console.log("FETCH IDEA: ", response);
} catch (e) {
if (axios.isAxiosError(e)) {
const axiosError = e as AxiosError<APIResponse>;
switch (axiosError.response?.status) {
case 401:
router.push("/");
break;
case 404:
if (axiosError.response?.data.message === "user does not exist") {
router.push("/");
}
// console.log("no team");
break;
case 417:
// console.log("team no idea");
break;
case 409:
setIdea(409);
break;
default:
// console.log(e);
break;
}
}
}
};

useEffect(() => {
const fetchDataAndLogin = async () => {
// await login();
await fetchData();
await fetchIdea();
SetIdea("idea found");
};
void fetchDataAndLogin();
}, []);
Expand All @@ -214,14 +178,6 @@ export default function HomePage() {
} else {
void fetchTeam();
}
if (user.data.is_leader) {
// console.log("Leader saala");
setIsLeader(true);
}
if (user.data.is_leader)
if (user.data.id === teamData.team?.leader_id) {
setIsLeader(true);
}
}, []);

const noTeamCard = [
Expand Down Expand Up @@ -253,7 +209,7 @@ export default function HomePage() {
{
text: "Submit An Idea",
showModal: getIdea !== "idea found" && getIdea !== "",
modalType: idea === 409 ? "Choice" : "JoinTeam",
modalType: "Choice",
routeTo: "/submit-idea",
},
];
Expand Down
19 changes: 15 additions & 4 deletions devsoc24-portal-fe/src/components/team/joinTeam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,23 @@ import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import { useRef } from "react";
import axios from "axios";
import { useTeamDataStore, useTeamStore } from "@/store/store";
import {
useTeamDataStore,
useTeamStore,
IdeaStore,
useLeaderStore,
useTeamEditStore,
} from "@/store/store";
import { useRouter } from "next/navigation";
import { type APIResponse } from "@/schemas/api";

function JoinTeam() {
const inputRef = useRef<HTMLInputElement>(null);
const { team, setTeam } = useTeamStore();
const { teamData, setTeamData } = useTeamDataStore();

const { isLeader, setIsLeader } = useLeaderStore();
const { getIdea, SetIdea } = IdeaStore();
const { edit, setEdit } = useTeamEditStore();
const router = useRouter();
const handleClick = async () => {
try {
Expand All @@ -32,14 +40,17 @@ function JoinTeam() {
},
);
void fetchTeam();
setEdit(false);
SetIdea("idea found");
setIsLeader(false);
setTeam(false);
} catch (e) {
if (axios.isAxiosError(e)) {
switch (e.response?.status) {
case 202:
// console.log("Accepted");
// console.log("Accepted");
default:
// console.log(e);
// console.log(e);
}
}
}
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 @@ -152,6 +152,6 @@ interface ideaInterface {
}

export const IdeaStore = create<ideaInterface>((set) => ({
getIdea: "",
getIdea: "a",
SetIdea: (getIdea: string) => set({ getIdea }),
}));

0 comments on commit e9b308b

Please sign in to comment.