diff --git a/app/api/teams/get-teams/route.jsx b/app/api/teams/get-teams/route.jsx new file mode 100644 index 0000000..7c4b80f --- /dev/null +++ b/app/api/teams/get-teams/route.jsx @@ -0,0 +1,14 @@ +import dbConnect from "../../../../lib/dbConnect"; +import { TeamModel } from "../../../../model/Team"; + +export async function GET() { + await dbConnect(); + + try { + const teams = await TeamModel.find(); + return new Response(JSON.stringify({ success: true, teams }), { status: 200 }); + } catch (error) { + console.error('Error fetching teams:', error); + return new Response(JSON.stringify({ success: false, message: 'Error fetching teams' }), { status: 500 }); + } +} \ No newline at end of file diff --git a/app/create-team/page.jsx b/app/create-team/page.jsx index 1bb210b..125968a 100644 --- a/app/create-team/page.jsx +++ b/app/create-team/page.jsx @@ -49,6 +49,7 @@ export default function CreateTeamForm() { players: '', requests: '' }, + shouldFocusError: false, }); const { reset } = form; @@ -56,7 +57,14 @@ export default function CreateTeamForm() { const onSubmit = async (data) => { try { if (teamname !== '' && game !== '' && role !== '' && rank !== '' && server !== '' && language !== '' && players !== '' && requests !== '') { - const response = await axios.post('/api/teams/create-team', data); + + const playersArray = players.split(',').map(player => player.trim()); + const dataWithPlayersArray = { + ...data, + players: playersArray, + }; + + const response = await axios.post('/api/teams/create-team', dataWithPlayersArray); toast({ title: 'Success', @@ -110,7 +118,7 @@ export default function CreateTeamForm() { - + )} /> @@ -119,7 +127,7 @@ export default function CreateTeamForm() { name="teamname" render={({ field }) => ( - Name + Team Name - + )} /> @@ -152,7 +160,7 @@ export default function CreateTeamForm() { }} /> - + )} /> @@ -173,7 +181,7 @@ export default function CreateTeamForm() { }} /> - + )} /> @@ -194,7 +202,7 @@ export default function CreateTeamForm() { }} /> - + )} /> @@ -215,7 +223,7 @@ export default function CreateTeamForm() { }} /> - + )} /> @@ -236,7 +244,7 @@ export default function CreateTeamForm() { }} /> - + )} /> @@ -248,7 +256,7 @@ export default function CreateTeamForm() { Players { @@ -257,7 +265,7 @@ export default function CreateTeamForm() { }} /> - + )} /> @@ -278,7 +286,7 @@ export default function CreateTeamForm() { }} /> - + )} /> diff --git a/app/teams/page.jsx b/app/teams/page.jsx index ec89221..84facd0 100644 --- a/app/teams/page.jsx +++ b/app/teams/page.jsx @@ -1,101 +1,41 @@ +'use client' + import React from 'react'; import FiltersSidebar from '../../components/FiltersSidebar'; import TeamCard from '../../components/TeamCard'; +import { useRouter } from 'next/navigation'; +import { useState, useEffect } from 'react'; +import axios from 'axios'; -const teams = [ - { - name: 'PLX Esports', - game: 'BGMI', - role: 'Scout, Support, Fragger', - rank: 'Ace', - server: 'India', - language: 'English', - description: 'Tamil Players Only For Our ESports Organizational', - }, - { - name: 'HMF - YouTube', - game: 'Free Fire Max', - role: 'IGL', - rank: 'Diamond', - server: 'India', - language: 'Hindi', - description: 'No Requirement', - }, - { - name: 'PLX Esports', - game: 'BGMI', - role: 'Scout, Support, Fragger', - rank: 'Ace', - server: 'India', - language: 'English', - description: 'Tamil Players Only For Our ESports Organizational', - }, - { - name: 'HMF - YouTube', - game: 'Free Fire Max', - role: 'IGL', - rank: 'Diamond', - server: 'India', - language: 'Hindi', - description: 'No Requirement', - }, - { - name: 'PLX Esports', - game: 'BGMI', - role: 'Scout, Support, Fragger', - rank: 'Ace', - server: 'India', - language: 'English', - description: 'Tamil Players Only For Our ESports Organizational', - }, - { - name: 'HMF - YouTube', - game: 'Free Fire Max', - role: 'IGL', - rank: 'Diamond', - server: 'India', - language: 'Hindi', - description: 'No Requirement', - }, - { - name: 'PLX Esports', - game: 'BGMI', - role: 'Scout, Support, Fragger', - rank: 'Ace', - server: 'India', - language: 'English', - description: 'Tamil Players Only For Our ESports Organizational', - }, - { - name: 'HMF - YouTube', - game: 'Free Fire Max', - role: 'IGL', - rank: 'Diamond', - server: 'India', - language: 'Hindi', - description: 'No Requirement', - }, - { - name: 'PLX Esports', - game: 'BGMI', - role: 'Scout, Support, Fragger', - rank: 'Ace', - server: 'India', - language: 'English', - description: 'Tamil Players Only For Our ESports Organizational', - }, - { - name: 'HMF - YouTube', - game: 'Free Fire Max', - role: 'IGL', - rank: 'Diamond', - server: 'India', - language: 'Hindi', - description: 'No Requirement', - }, -]; const TeamFinder = () => { + + const router = useRouter(); + const [teams, setTeams] = useState([]); + + useEffect(() => { + const fetchTeams = async () => { + try { + const response = await axios.get('/api/teams/get-teams'); + if (response.data.success) { + setTeams(response.data.teams); + } else { + console.error('Failed to fetch teams:', response.data.message); + } + } catch (error) { + console.error('Error fetching teams:', error); + } + }; + + fetchTeams(); + }, []); + + + const NavigateToCreateTeam = () => { + router.push('/create-team'); + }; + + return (

TEAM FINDER

@@ -105,6 +45,7 @@ const TeamFinder = () => {

Find Team

+
diff --git a/components/Navbar.jsx b/components/Navbar.jsx index aeaf362..9891ee5 100644 --- a/components/Navbar.jsx +++ b/components/Navbar.jsx @@ -107,7 +107,10 @@ const navLinks = [ title: "Games", href: "/games", }, - + { + title: "Teams", + href: "/teams", + }, { title: "Blogs", href: "/blogs", diff --git a/components/TeamCard.jsx b/components/TeamCard.jsx index 8d526cd..e7f53e6 100644 --- a/components/TeamCard.jsx +++ b/components/TeamCard.jsx @@ -7,40 +7,46 @@ const TeamCard = ({ team }) => {
{`${team.name} -

{team.name}

+

{team.teamname}

-
- Game: +
+ Game {team.game}
-
- Role: +
+ Role {team.role}
-
- Rank: +
+ Rank {team.rank}
-
- Server: +
+ Server {team.server}
-
- Language: +
+ Language {team.language}
-
- Looking for: - {team.description} +
+
+ Players + {team.players.join(', ')} +
+
+ Looking for + {team.requests} +
diff --git a/model/Schema/teamSchema.js b/model/Schema/teamSchema.js index 01d08b6..b0466e2 100644 --- a/model/Schema/teamSchema.js +++ b/model/Schema/teamSchema.js @@ -1,13 +1,12 @@ import { z } from 'zod'; export const teamSchema = z.object({ - teamname: z.string(), - game: z.string(), - role: z.string(), - rank: z.string(), - server: z.string(), - language: z.string(), - players: z.string(), - requests: z.string(), - -}); + teamname: z.string().min(4, { message: 'Team name must be at least 4 characters long' }), + game: z.string().min(4, { message: 'Game name must be at least 4 characters long' }), + role: z.string().min(4, { message: 'Role must be at least 4 characters long' }), + rank: z.string().min(4, { message: 'Rank must be at least 4 characters long' }), + server: z.string().min(4, { message: 'Server must be at least 4 characters long' }), + language: z.string().min(4, { message: 'Language must be at least 4 characters long' }), + players: z.string().min(4, { message: 'Players field must be at least 4 characters long' }), + requests: z.string().min(4, { message: 'Requests field must be at least 4 characters long' }), +}); \ No newline at end of file diff --git a/model/Team.js b/model/Team.js index 2db829c..1d267fa 100644 --- a/model/Team.js +++ b/model/Team.js @@ -8,8 +8,8 @@ const TeamSchema = new mongoose.Schema({ rank: { type: String, required: true }, server: { type: String, required: true }, language: { type: String, required: true }, - players: [{ type: String }], - requests: [{ type: String }] + players: [{ type: String, required: true }], + requests: { type: String, required: true } }); diff --git a/prisma/seed.js b/prisma/seed.js index 7117c86..358c7ff 100644 --- a/prisma/seed.js +++ b/prisma/seed.js @@ -170,7 +170,7 @@ async function main() { // seed Team (mongoose) const teamData = [ { - image: 'https://example.com/image1.jpg', + image: 'https://placehold.co/60', teamname: 'Epic Warriors', game: 'League of Legends', role: 'ADC', @@ -178,10 +178,10 @@ async function main() { server: 'NA', language: 'English', players: ['Player1', 'Player2'], - requests: ['No toxic behavior', 'Must have a mic'] + requests: 'No toxic behavior' }, { - image: 'https://example.com/image2.jpg', + image: 'https://placehold.co/60', teamname: 'Pro Gamers', game: 'CS:GO', role: 'In-Game Leader', @@ -189,7 +189,7 @@ async function main() { server: 'EU', language: 'English', players: ['Player3', 'Player4'], - requests: ['Good communication skills', 'Must be punctual'] + requests: 'Good communication skills and has to be punctual' } ];