Skip to content

Commit

Permalink
Merge pull request #6 from Abh1noob/master
Browse files Browse the repository at this point in the history
basics
  • Loading branch information
Abh1noob committed Mar 8, 2024
2 parents da98895 + ff67cae commit 527cb70
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 53 deletions.
103 changes: 86 additions & 17 deletions devsoc24-portal-fe/src/app/page.tsx
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -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<teamDataProps | null>(null);

const login = async () => {
const response = await axios.post(
`${process.env.NEXT_PUBLIC_API_URL}/login`,
Expand All @@ -49,13 +91,13 @@ export default function HomePage() {

const fetchData = async () => {
try {
const response: AxiosResponse<ideaProps> = await axios.get(
`${process.env.NEXT_PUBLIC_API_URL}/idea`,
const response: AxiosResponse<userProps> = 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) {
Expand All @@ -69,15 +111,17 @@ export default function HomePage() {
}
}
}
//Team Get
};

const fetchTeam = async () => {
try {
const response: AxiosResponse<teamProps> = await axios.get(
const response: AxiosResponse<teamDataProps> = 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) {
Expand All @@ -93,14 +137,47 @@ export default function HomePage() {
}
};

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 @@ -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 (
<Suspense fallback={<Loading />}>
<main className="flex min-h-screen flex-col items-start overflow-x-hidden bg-[#F4F5FA]">
Expand All @@ -148,7 +217,7 @@ export default function HomePage() {
buttonDetails={noTeamCard}
/>
) : (
<TeamCard />
<TeamCard {...teamData} />
)}
<CustomCard
title="Idea Submission"
Expand Down
47 changes: 37 additions & 10 deletions devsoc24-portal-fe/src/components/forms/join-team-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,7 @@ import { joinTeamSchema } from "@/schemas/signup";
import React from "react";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import { type z } from "zod";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { z } from "zod"; // Change this line from { type z } to { z }
import {
Form,
FormControl,
Expand All @@ -22,6 +15,7 @@ import {
} from "@/components/ui/form";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
import axios from "axios"; // Removed AxiosResponse import

type CreateTeamFormValues = z.infer<typeof joinTeamSchema>;

Expand All @@ -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);

Expand All @@ -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 (
<Form {...createTeamForm}>
<form
Expand All @@ -73,14 +95,19 @@ export default function JoinTeamForm() {
placeholder="Team Code"
{...field}
className={` ${
createTeamForm.getFieldState("teamCode").invalid
createTeamForm.formState.errors.teamCode
? "border-red-500 focus:border-input focus:!ring-red-500"
: ""
}`}
/>
</div>
</FormControl>
<FormMessage />
{/* Display error message */}
{createTeamForm.formState.errors.teamCode && (
<FormMessage>
{createTeamForm.formState.errors.teamCode.message}
</FormMessage>
)}
</FormItem>
)}
/>
Expand Down
79 changes: 53 additions & 26 deletions devsoc24-portal-fe/src/components/teamCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<teamDataProps> = (props) => {
const [isCopied, setIsCopied] = useState(false);
const onCopyText = () => {
setIsCopied(true);
Expand All @@ -31,44 +54,48 @@ function TeamCard() {
Your Devsoc Team
</div>
<div className="flex flex-col items-center justify-center p-8">
<p className="text-2xl font-semibold">{team.teamName}</p>
<p className="text-2xl font-semibold">{props.team?.team_name}</p>
<p className="pb-4 text-sm text-[#8B8D97]">Team Members</p>
<div className="mb-2 flex w-full items-center justify-between rounded-lg border-2 border-[#B6B6B6] p-3">
{team.memberName}
{team.isLeader && (
{props.team?.users[0]?.name}
{/* {team.isLeader && (
<span className="text-[#FFBE3D]">
<Crown />
</span>
)}
)} */}
</div>
{team.teamMembers.map((member, index) => (
{props.team?.users.map((member, index) => (
<div
key={index}
className="mb-2 flex w-full items-center justify-between rounded-lg border-2 border-[#B6B6B6] p-3"
>
<span>{member.name}</span>
{member.isLeader ? (
{/* {member.isLeader ? (
<span className="text-[#FFBE3D]">
<Crown />
</span>
) : (
<span className="text-[#AD1136]">
<BadgeMinus />
</span>
)}
)} */}
</div>
))}
<CopyToClipboard text={team.teamCode} onCopy={onCopyText}>
<Button className="mt-4 self-center flex items-center gap-x-2">
<span className="text-white">{isCopied ? <Check size={20} /> : <Files size={20} />}</span>
{team.teamCode}
</Button>
</CopyToClipboard>
{props.team && (
<CopyToClipboard text={props.team?.team_code} onCopy={onCopyText}>
<Button className="mt-4 flex items-center gap-x-2 self-center">
<span className="text-white">
{isCopied ? <Check size={20} /> : <Files size={20} />}
</span>
{props.team?.team_code}
</Button>
</CopyToClipboard>
)}
</div>
</div>
</div>
</>
);
}
};

export default TeamCard;
Loading

0 comments on commit 527cb70

Please sign in to comment.