From 255c97e6358abdc3a1c6a46022ef49b02212d7ba Mon Sep 17 00:00:00 2001 From: UdeeshaPrabhashana Date: Sun, 4 Feb 2024 07:02:14 +0530 Subject: [PATCH] Add --- .../Components/TeamRegistration/TeamRegi.tsx | 19 +++++++++--- Frontend/src/Network.ts | 30 +++++++++---------- 2 files changed, 30 insertions(+), 19 deletions(-) diff --git a/Frontend/src/Components/TeamRegistration/TeamRegi.tsx b/Frontend/src/Components/TeamRegistration/TeamRegi.tsx index 1b1f194..858f069 100644 --- a/Frontend/src/Components/TeamRegistration/TeamRegi.tsx +++ b/Frontend/src/Components/TeamRegistration/TeamRegi.tsx @@ -15,7 +15,7 @@ export default function Registration() { const [teamMemberCount, setTeamMemberCount] = useState(2); // Default to 2 members const [teamMembers, setTeamMembers] = useState(["member1", "member2"]); - // const [slotsRemaining, setSlotsRemaining] = useState(0); + const [slotsRemaining, setSlotsRemaining] = useState(0); // get from the form const [university, setUniversity] = useState( @@ -51,7 +51,7 @@ export default function Registration() { background: "#232631", color: "#fff", footer: - ' Join our whatsapp group
', + ' Join our whatsapp group
', }); if (response.success) { reset(); @@ -63,6 +63,17 @@ export default function Registration() { } }; + // get team count Network.shared.getTeamCount() + useEffect(() => { + const fetchData = async () => { + const result = await Network.shared.getTeamCount(); + console.log(result); + setSlotsRemaining(result); + } + fetchData(); + } + , []); + return (
@@ -113,7 +124,7 @@ export default function Registration() {
{/* form disable if no slots remaining , add class to disable */} {/*
*/} - + {/* Team Information */}
@@ -300,7 +311,7 @@ export default function Registration() { className={`btn btn-primary py-2 px-4 text-white ${ isSubmitting ? "btn-loading" : "" }`} - disabled={isSubmitting} + disabled={isSubmitting || slotsRemaining <= 0} />
diff --git a/Frontend/src/Network.ts b/Frontend/src/Network.ts index 6d7703b..64ae2a7 100644 --- a/Frontend/src/Network.ts +++ b/Frontend/src/Network.ts @@ -28,21 +28,21 @@ export class Network { return await response.json(); } - // public async getTeamCount(): Promise { - // const response = await fetch(process.env.REACT_APP_BACKEND_URL + '/api/team/count', { - // method: 'GET', - // headers: { - // 'Content-Type': 'application/json' - // } - // }); - - // if (!response.ok) { - // throw new Error(response.statusText); - // } - - // const data = await response.json(); - // return data.teamCount; - // } + public async getTeamCount(): Promise { + const response = await fetch(process.env.REACT_APP_BACKEND_URL + '/api/teamregi/count', { + method: 'GET', + headers: { + 'Content-Type': 'application/json' + } + }); + + if (!response.ok) { + throw new Error(response.statusText); + } + + const data = await response.json(); + return data.teamCount; + } } export class ResponseModel {