diff --git a/apps/web/src/App.jsx b/apps/web/src/App.jsx index f6c2116..efbc9c9 100644 --- a/apps/web/src/App.jsx +++ b/apps/web/src/App.jsx @@ -2,8 +2,6 @@ import { Routes, Route } from "react-router-dom"; import Home from "./pages/home"; import Player from "./pages/app"; -import Login from "./pages/login"; -import Register from "./pages/register"; import Verify from "./pages/verify"; import About from "./pages/about"; import Leaderboard from "./pages/leaderboard"; @@ -17,8 +15,6 @@ const App = () => { } /> } /> } /> - } /> - } /> } /> } /> } /> diff --git a/apps/web/src/components/cards/create-team-card.tsx b/apps/web/src/components/cards/create-team-card.tsx index d4f7148..df65f96 100644 --- a/apps/web/src/components/cards/create-team-card.tsx +++ b/apps/web/src/components/cards/create-team-card.tsx @@ -1,6 +1,5 @@ -import React from "react"; +import React, { useState } from "react"; import apiClient from "../../libs/api.client"; -import { useState } from "react"; import { toast } from "react-toastify"; function CreateTeamCard() { @@ -10,14 +9,29 @@ function CreateTeamCard() { async function submitData(evt) { evt.preventDefault(); try { - const res = await apiClient.post("/team", { + await apiClient.post("/team", { team_name: teamName, join_code: teamCode, + }, { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${localStorage.getItem("token")}`, + }, }); - window.location.href = "/whoami"; + toast.success("Team created successfully"); + + await apiClient.post("/team/join",{ + join_code: teamCode, + }, { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${localStorage.getItem("token")}`, + }, + }); + + toast.success("Team joined successfully"); } catch (err) { - console.error("errr"); - toast.error("Error creating team"); + toast.error(err.response.data.message || "Error creating team"); } } return ( diff --git a/apps/web/src/components/cards/join-team-card.tsx b/apps/web/src/components/cards/join-team-card.tsx index 0dcd9c7..1dcf954 100644 --- a/apps/web/src/components/cards/join-team-card.tsx +++ b/apps/web/src/components/cards/join-team-card.tsx @@ -1,14 +1,33 @@ -import React from "react"; +import React, { useState } from "react"; import apiClient from "../../libs/api.client"; -import { useState } from "react"; +import { toast } from "react-toastify"; function JoinTeamCard() { const [teamCode, setTeamCode] = useState(""); + + async function submitData(evt) { + evt.preventDefault(); + try { + const { data } = await apiClient.post("/team/join", { + join_code: teamCode, + }, { + headers: { + "Content-Type": "application/json", + Authorization: `Bearer ${localStorage.getItem("token")}`, + }, + }); + console.log(data); + toast.success("Team joined successfully"); + window.location.href = "/whoami"; + } catch (err) { + toast.error("Error creating team"); + } + } return (

Join a Team

-
{}}> +
diff --git a/apps/web/src/components/cards/login-card.tsx b/apps/web/src/components/cards/login-card.tsx index 5137005..1faabf1 100644 --- a/apps/web/src/components/cards/login-card.tsx +++ b/apps/web/src/components/cards/login-card.tsx @@ -37,7 +37,7 @@ export const LoginCard = () => { draggable: true, }); setTimeout(() => { - window.location.href = "/app"; + window.location.href = "/"; }, 3000); } else { toast.error("Login Failed!", { diff --git a/apps/web/src/components/cards/register-card.tsx b/apps/web/src/components/cards/register-card.tsx index dc3f25c..6784664 100644 --- a/apps/web/src/components/cards/register-card.tsx +++ b/apps/web/src/components/cards/register-card.tsx @@ -1,7 +1,5 @@ import { useState } from "react"; -import { ToastContainer, toast } from "react-toastify"; -import { Link } from "react-router-dom"; - +import { toast } from "react-toastify"; import apiClient from "../../libs/api.client"; diff --git a/apps/web/src/pages/login.jsx b/apps/web/src/pages/login.jsx deleted file mode 100644 index 33c7757..0000000 --- a/apps/web/src/pages/login.jsx +++ /dev/null @@ -1,127 +0,0 @@ -import { useState } from "react"; -import apiClient from "../libs/api.client"; -import { ToastContainer, toast } from "react-toastify"; -import { Link } from "react-router-dom"; - - -import Navbar from "../components/navbar"; - -function Home() { - const [email, setEmail] = useState(""); - const [password, setPassword] = useState(""); - - let token = localStorage.getItem("token"); - - const handleSubmit = (event) => { - event.preventDefault(); - - apiClient - .post( - "/user/login", - { - email, - password, - }, - { - headers: { - "Content-Type": "application/json", - }, - } - ) - .then((response) => { - if (response.data.message === "Login successful") { - token = response.data.token; - localStorage.setItem("token", token); - toast.success("Login Successful!", { - position: "bottom-right", - autoClose: 3000, - hideProgressBar: true, - closeOnClick: true, - draggable: true, - }); - setTimeout(() => { - window.location.href = "/app"; - }, 3000); - } else { - toast.error("Login Failed!", { - position: "bottom-right", - autoClose: 3000, - hideProgressBar: true, - closeOnClick: true, - draggable: true, - }); - } - }) - .catch(() => { - toast.error("Login Failed!", { - position: "bottom-right", - autoClose: 3000, - hideProgressBar: true, - closeOnClick: true, - draggable: true, - }); - }); - }; - - return ( - <> - -
-

Sign In

- -
-
- -
-
- setEmail(event.target.value)} - placeholder='Enter your email' - /> -
-
-
-
- -
-
- setPassword(event.target.value)} - placeholder='Enter your password' - /> -
-
- - -
-

- Don't have a account, register from{" "} - here. -

- - - ); -} - -export default Home; diff --git a/apps/web/src/pages/news.jsx b/apps/web/src/pages/news.jsx index 5465994..b8fedc8 100644 --- a/apps/web/src/pages/news.jsx +++ b/apps/web/src/pages/news.jsx @@ -5,14 +5,6 @@ function News() { return ( <> - {/* */} ); } diff --git a/apps/web/src/pages/register.jsx b/apps/web/src/pages/register.jsx deleted file mode 100644 index 6ff5f2b..0000000 --- a/apps/web/src/pages/register.jsx +++ /dev/null @@ -1,158 +0,0 @@ -import { useState } from "react"; -import apiClient from "../libs/api.client"; -import { ToastContainer, toast } from "react-toastify"; -import { Link } from "react-router-dom"; - - - -function Home() { - const [email, setEmail] = useState(""); - const [password, setPassword] = useState(""); - const [firstName, setFirstName] = useState(""); - const [lastName, setLastName] = useState(""); - - const handleSubmit = (event) => { - event.preventDefault(); - - apiClient - .post( - "/user/register", - { - email, - password, - firstName, - lastName, - }, - { - headers: { - "Content-Type": "application/json", - }, - } - ) - .then((response) => { - if (response.data.email === email) { - toast.success("Register Successful!", { - position: "bottom-right", - autoClose: 3000, - hideProgressBar: true, - closeOnClick: true, - draggable: true, - }); - setTimeout(() => { - window.location.href = "/verify"; - }, 3000); - } else { - toast.error("Register Failed!", { - position: "bottom-right", - autoClose: 3000, - hideProgressBar: true, - closeOnClick: true, - draggable: true, - }); - } - }) - .catch(() => { - toast.error("Register Failed!", { - position: "bottom-right", - autoClose: 3000, - hideProgressBar: true, - closeOnClick: true, - draggable: true, - }); - }); - }; - - return ( - <> -
- React logo -
-

Login Portal

-
-

Sign In

-
-
-
- -
-
- setEmail(event.target.value)} - placeholder='Enter your email' - /> -
-
-
-
- -
-
- setPassword(event.target.value)} - placeholder='Enter your password' - /> -
-
-
-
- -
-
- setFirstName(event.target.value)} - placeholder='Enter your firstName' - /> -
-
-
-
- -
-
- setLastName(event.target.value)} - placeholder='Enter your lastName' - /> -
-
- -
-
-

- Already have a account? Login from here. -

- - - ); -} - -export default Home; diff --git a/apps/web/src/pages/verify.jsx b/apps/web/src/pages/verify.jsx index 974433c..a29d6aa 100644 --- a/apps/web/src/pages/verify.jsx +++ b/apps/web/src/pages/verify.jsx @@ -2,8 +2,6 @@ import { useState } from "react"; import apiClient from "../libs/api.client"; import { ToastContainer, toast } from "react-toastify"; - - function Home() { const [otp, setOtp] = useState(""); diff --git a/packages/api/services/stats.service.ts b/packages/api/services/stats.service.ts index e7d869d..1100a7f 100644 --- a/packages/api/services/stats.service.ts +++ b/packages/api/services/stats.service.ts @@ -38,6 +38,14 @@ export class StatsService { throw new Error("No team scores found"); } + else if(scores.length === 0){ + return { + team_id: teamId, + score: 0, + submissions: [], + }; + } + const teamScore: ITeamStats = { team_id: teamId, team_name: scores[0].team.name, @@ -60,6 +68,7 @@ export class StatsService { return teamScore; } catch (error: any) { + console.log(error); throw new Error(error.message); } };