Skip to content

Commit

Permalink
create and view teams
Browse files Browse the repository at this point in the history
  • Loading branch information
iSouvikKhan committed Jul 24, 2024
1 parent aab4fa1 commit a5bbe02
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 136 deletions.
14 changes: 14 additions & 0 deletions app/api/teams/get-teams/route.jsx
Original file line number Diff line number Diff line change
@@ -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 });
}
}
32 changes: 20 additions & 12 deletions app/create-team/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,22 @@ export default function CreateTeamForm() {
players: '',
requests: ''
},
shouldFocusError: false,
});

const { reset } = form;

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',
Expand Down Expand Up @@ -110,7 +118,7 @@ export default function CreateTeamForm() {
<FormControl>
<Input type="file" {...field} />
</FormControl>
<FormMessage />
<FormMessage className="text-red-500"/>
</FormItem>
)}
/>
Expand All @@ -119,7 +127,7 @@ export default function CreateTeamForm() {
name="teamname"
render={({ field }) => (
<FormItem>
<FormLabel>Name</FormLabel>
<FormLabel>Team Name</FormLabel>
<FormControl>
<Input
placeholder="Name of your team"
Expand All @@ -131,7 +139,7 @@ export default function CreateTeamForm() {
}}
/>
</FormControl>
<FormMessage />
<FormMessage className="text-red-500"/>
</FormItem>
)}
/>
Expand All @@ -152,7 +160,7 @@ export default function CreateTeamForm() {
}}
/>
</FormControl>
<FormMessage />
<FormMessage className="text-red-500"/>
</FormItem>
)}
/>
Expand All @@ -173,7 +181,7 @@ export default function CreateTeamForm() {
}}
/>
</FormControl>
<FormMessage />
<FormMessage className="text-red-500"/>
</FormItem>
)}
/>
Expand All @@ -194,7 +202,7 @@ export default function CreateTeamForm() {
}}
/>
</FormControl>
<FormMessage />
<FormMessage className="text-red-500"/>
</FormItem>
)}
/>
Expand All @@ -215,7 +223,7 @@ export default function CreateTeamForm() {
}}
/>
</FormControl>
<FormMessage />
<FormMessage className="text-red-500"/>
</FormItem>
)}
/>
Expand All @@ -236,7 +244,7 @@ export default function CreateTeamForm() {
}}
/>
</FormControl>
<FormMessage />
<FormMessage className="text-red-500"/>
</FormItem>
)}
/>
Expand All @@ -248,7 +256,7 @@ export default function CreateTeamForm() {
<FormLabel>Players</FormLabel>
<FormControl>
<Input
placeholder="Players in your team"
placeholder="player_1 , player_2 , ..."
{...field}
value={players}
onChange={(e) => {
Expand All @@ -257,7 +265,7 @@ export default function CreateTeamForm() {
}}
/>
</FormControl>
<FormMessage />
<FormMessage className="text-red-500"/>
</FormItem>
)}
/>
Expand All @@ -278,7 +286,7 @@ export default function CreateTeamForm() {
}}
/>
</FormControl>
<FormMessage />
<FormMessage className="text-red-500"/>
</FormItem>
)}
/>
Expand Down
125 changes: 33 additions & 92 deletions app/teams/page.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<div className="p-4">
<p className="text-2xl ml-4 mb-4 font-semibold tracking-wide">TEAM FINDER</p>
Expand All @@ -105,6 +45,7 @@ const TeamFinder = () => {
<div className="border-b-4 mb-4">
<div className="flex justify-between mb-4">
<h2 className="text-2xl">Find Team</h2>
<button className="bg-orange-500 px-4 py-2 rounded" onClick={NavigateToCreateTeam}>Create Team</button>
</div>
<div className="mb-4 flex flex-wrap gap-2 justify-between">
<button className="bg-indigo-400 px-4 py-2 rounded text-sm">Request Raised</button>
Expand Down
5 changes: 4 additions & 1 deletion components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,10 @@ const navLinks = [
title: "Games",
href: "/games",
},

{
title: "Teams",
href: "/teams",
},
{
title: "Blogs",
href: "/blogs",
Expand Down
36 changes: 21 additions & 15 deletions components/TeamCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,46 @@ const TeamCard = ({ team }) => {
<div className="flex justify-between items-center mb-5">
<div className="flex items-center">
<img
src={team.dp || 'https://via.placeholder.com/40'}
src={team.image || 'https://via.placeholder.com/40'}
alt={`${team.name} logo`}
className="w-10 h-10 rounded-full mr-4"
/>
<h3 className="text-xl">{team.name}</h3>
<h3 className="text-xl">{team.teamname}</h3>
</div>
<button className="bg-transparent border-2 border-blue-800 px-4 py-2 rounded hidden md:block">Request to join</button>
</div>
</div>
<div className="grid grid-cols-1 md:grid-cols-5 gap-x-4 my-5">
<div>
<span className="text-yellow-500">Game:</span>
<div className='my-2'>
<span className="text-yellow-500">Game</span>
<span className="block">{team.game}</span>
</div>
<div>
<span className="text-yellow-500">Role:</span>
<div className='my-2'>
<span className="text-yellow-500">Role</span>
<span className="block">{team.role}</span>
</div>
<div>
<span className="text-yellow-500">Rank:</span>
<div className='my-2'>
<span className="text-yellow-500">Rank</span>
<span className="block">{team.rank}</span>
</div>
<div>
<span className="text-yellow-500">Server:</span>
<div className='my-2'>
<span className="text-yellow-500">Server</span>
<span className="block">{team.server}</span>
</div>
<div>
<span className="text-yellow-500">Language:</span>
<div className='my-2'>
<span className="text-yellow-500">Language</span>
<span className="block">{team.language}</span>
</div>
</div>
<div className="mt-2 mb-4">
<span className="text-yellow-500">Looking for:</span>
<span className="block">{team.description}</span>
<div className="grid grid-cols-1 md:grid-cols-5 gap-x-4 my-5">
<div className='my-2'>
<span className="text-yellow-500">Players</span>
<span className="block">{team.players.join(', ')}</span>
</div>
<div className='my-2'>
<span className="text-yellow-500">Looking for</span>
<span className="block">{team.requests}</span>
</div>
</div>
<div className="flex justify-center md:hidden">
<button className="bg-transparent border-2 border-blue-800 px-4 py-2 rounded">Request to join</button>
Expand Down
19 changes: 9 additions & 10 deletions model/Schema/teamSchema.js
Original file line number Diff line number Diff line change
@@ -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' }),
});
4 changes: 2 additions & 2 deletions model/Team.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
});


Expand Down
Loading

0 comments on commit a5bbe02

Please sign in to comment.