diff --git a/app/create/team/page.jsx b/app/create/team/page.jsx index 690d1c9..761a599 100644 --- a/app/create/team/page.jsx +++ b/app/create/team/page.jsx @@ -100,16 +100,17 @@ export default function CreateTeamForm() { }; return ( -
-
+
+
-

+

Create Team

-

+

Create your team and start competing

+
diff --git a/app/create/tournament/page.js b/app/create/tournament/page.js index ef210bf..078bc87 100644 --- a/app/create/tournament/page.js +++ b/app/create/tournament/page.js @@ -1,460 +1,495 @@ -"use client" -import { useEffect, useState } from 'react'; -import axios from 'axios'; -import { platforms, timezones } from './tournament/data'; +"use client"; +import { useEffect, useState } from "react"; +import axios from "axios"; +import { platforms, timezones } from "./tournament/data"; +import { Button } from "../../../@/components/ui/button"; export default function Page() { - const [selectedPlatform, setSelectedPlatform] = useState(""); - const [participantType, setParticipantType] = useState(""); - const [selectedTimezone, setSelectedTimezone] = useState(""); - const [tournamentName, setTournamentName] = useState(""); - const [size, setSize] = useState(""); - const [isSubmitting, setIsSubmitting] = useState(false); - const [successMessage, setSuccessMessage] = useState(""); - const [errorMessage, setErrorMessage] = useState(""); - const [games, setGames] = useState([]); - - // Add new state variables for additional fields - const [tournamentFormat, setTournamentFormat] = useState(""); - const [registrationEndDate, setRegistrationEndDate] = useState(""); - const [tournamentStartDate, setTournamentStartDate] = useState(""); - const [tournamentEndDate, setTournamentEndDate] = useState(""); - const [maxTeamMembers, setMaxTeamMembers] = useState(""); - const [minTeamMembers, setMinTeamMembers] = useState(""); - const [maxTeams, setMaxTeams] = useState(""); - const [minTeams, setMinTeams] = useState(""); - const [tournamentVisibility, setTournamentVisibility] = useState(""); - const [inviteCode, setInviteCode] = useState(""); - - const [prizeConfig, setPrizeConfig] = useState([]); - const [rules, setRules] = useState([]); - const [sponsors, setSponsors] = useState([]); - const [gameParameter, setGameParameter] = useState(""); - const [parameterPoints, setParameterPoints] = useState(""); - const [roundType, setRoundType] = useState(""); - const [numberOfMatches, setNumberOfMatches] = useState(""); - const [qualifyingTeamsPerGroup, setQualifyingTeamsPerGroup] = useState("1"); - const [wildcardPlayers, setWildcardPlayers] = useState(""); - const [teamsPerGroup, setTeamsPerGroup] = useState(""); - const [roundName, setRoundName] = useState(""); - const [tournamentIcon, setTournamentIcon] = useState(null); - const [tournamentBanner, setTournamentBanner] = useState(null); - - - useEffect(() => { - const fetchGames = async () => { - try { - const response = await axios.get('/api/games'); - setGames(response.data); - } catch (error) { - console.error("Error while fetching game data: ", error); - } - }; - fetchGames(); - }, []); - - const handleSubmit = async (e) => { - e.preventDefault(); - setIsSubmitting(true); - setSuccessMessage(""); - setErrorMessage(""); - - if ( - !tournamentName || - !selectedPlatform || - !participantType || - !selectedTimezone || - !size - ) { - setErrorMessage("Please fill out all fields."); - setIsSubmitting(false); - return; - } - - const formData = { - tournamentName, - selectedPlatform, - participantType, - selectedTimezone, - size, - }; - - try { - const response = await axios.post("/api/tournaments", formData); - setSuccessMessage(response.data.message); - setTournamentName(""); - setSelectedPlatform(""); - setParticipantType(""); - setSelectedTimezone(""); - setSize(""); - } catch (error) { - if (error.response) { - setErrorMessage(error.response.data.message); - } else { - setErrorMessage("An error occurred. Please try again."); - } - } finally { - setIsSubmitting(false); - } - }; - - const handleReset = () => { - setTournamentName(""); - setSelectedPlatform(""); - setParticipantType(""); - setSelectedTimezone(""); - setSize(""); - setSuccessMessage(""); - setErrorMessage(""); - }; - - const handleIconUpload = (event) => { - const file = event.target.files[0]; - if (file && file.type.substr(0, 5) === "image") { - setTournamentIcon(URL.createObjectURL(file)); - } else { - alert("Please select an image file"); - } + const [selectedPlatform, setSelectedPlatform] = useState(""); + const [participantType, setParticipantType] = useState(""); + const [selectedTimezone, setSelectedTimezone] = useState(""); + const [tournamentName, setTournamentName] = useState(""); + const [size, setSize] = useState(""); + const [isSubmitting, setIsSubmitting] = useState(false); + const [successMessage, setSuccessMessage] = useState(""); + const [errorMessage, setErrorMessage] = useState(""); + const [games, setGames] = useState([]); + + // Add new state variables for additional fields + const [tournamentFormat, setTournamentFormat] = useState(""); + const [registrationEndDate, setRegistrationEndDate] = useState(""); + const [tournamentStartDate, setTournamentStartDate] = useState(""); + const [tournamentEndDate, setTournamentEndDate] = useState(""); + const [maxTeamMembers, setMaxTeamMembers] = useState(""); + const [minTeamMembers, setMinTeamMembers] = useState(""); + const [maxTeams, setMaxTeams] = useState(""); + const [minTeams, setMinTeams] = useState(""); + const [tournamentVisibility, setTournamentVisibility] = useState(""); + const [inviteCode, setInviteCode] = useState(""); + + const [prizeConfig, setPrizeConfig] = useState([]); + const [rules, setRules] = useState([]); + const [sponsors, setSponsors] = useState([]); + const [gameParameter, setGameParameter] = useState(""); + const [parameterPoints, setParameterPoints] = useState(""); + const [roundType, setRoundType] = useState(""); + const [numberOfMatches, setNumberOfMatches] = useState(""); + const [qualifyingTeamsPerGroup, setQualifyingTeamsPerGroup] = useState("1"); + const [wildcardPlayers, setWildcardPlayers] = useState(""); + const [teamsPerGroup, setTeamsPerGroup] = useState(""); + const [roundName, setRoundName] = useState(""); + const [tournamentIcon, setTournamentIcon] = useState(null); + const [tournamentBanner, setTournamentBanner] = useState(null); + + useEffect(() => { + const fetchGames = async () => { + try { + const response = await axios.get("/api/games"); + setGames(response.data); + } catch (error) { + console.error("Error while fetching game data: ", error); + } }; - - const handleBannerUpload = (event) => { - const file = event.target.files[0]; - if (file && file.type.substr(0, 5) === "image") { - setTournamentBanner(URL.createObjectURL(file)); - } else { - alert("Please select an image file"); - } + fetchGames(); + }, []); + + const handleSubmit = async (e) => { + e.preventDefault(); + setIsSubmitting(true); + setSuccessMessage(""); + setErrorMessage(""); + + if ( + !tournamentName || + !selectedPlatform || + !participantType || + !selectedTimezone || + !size + ) { + setErrorMessage("Please fill out all fields."); + setIsSubmitting(false); + return; + } + + const formData = { + tournamentName, + selectedPlatform, + participantType, + selectedTimezone, + size, }; - return ( -
-
-

Create New Tournament

- -
-
- - -
-
- - -
-
- -
- - -
- -
- - setTournamentName(e.target.value)} - placeholder="Enter Tournament Title" - /> -
- -
- - -
- -
- - setRegistrationEndDate(e.target.value)} - /> -
- -
- - setTournamentStartDate(e.target.value)} - /> -
- -
- - setTournamentEndDate(e.target.value)} - /> -
- -
- - setMaxTeamMembers(e.target.value)} - placeholder="Maximum Number of Team Members" - /> -
- -
- - setMinTeamMembers(e.target.value)} - placeholder="Minimum Number of Team Members" - /> -
- -
- - setMaxTeams(e.target.value)} - placeholder="Enter Maximum Number of Teams" - /> -
- -
- - setMinTeams(e.target.value)} - placeholder="Enter Minimum Number of Teams" - /> -
- -
- - -
- -
- - setInviteCode(e.target.value)} - placeholder="Enter Invite Code" - /> -
- - - {/* Prize Configuration */} -
-

Prize Configuration

- -
- - {/* Rules */} -
-

Rules

- - -
- - {/* Sponsors */} -
-

Sponsors

- -
+ try { + const response = await axios.post("/api/tournaments", formData); + setSuccessMessage(response.data.message); + setTournamentName(""); + setSelectedPlatform(""); + setParticipantType(""); + setSelectedTimezone(""); + setSize(""); + } catch (error) { + if (error.response) { + setErrorMessage(error.response.data.message); + } else { + setErrorMessage("An error occurred. Please try again."); + } + } finally { + setIsSubmitting(false); + } + }; + + const handleReset = () => { + setTournamentName(""); + setSelectedPlatform(""); + setParticipantType(""); + setSelectedTimezone(""); + setSize(""); + setSuccessMessage(""); + setErrorMessage(""); + }; + + const handleIconUpload = (event) => { + const file = event.target.files[0]; + if (file && file.type.substr(0, 5) === "image") { + setTournamentIcon(URL.createObjectURL(file)); + } else { + alert("Please select an image file"); + } + }; + + const handleBannerUpload = (event) => { + const file = event.target.files[0]; + if (file && file.type.substr(0, 5) === "image") { + setTournamentBanner(URL.createObjectURL(file)); + } else { + alert("Please select an image file"); + } + }; + + return ( +
+
+

Create New Tournament

+ +
+
+ + +
+
+ + +
+
+
+
+ + +
+ +
+ + setTournamentName(e.target.value)} + placeholder="Enter Tournament Title" + /> +
+ +
+ + +
+ +
+ + setRegistrationEndDate(e.target.value)} + /> +
+ +
+ + setTournamentStartDate(e.target.value)} + /> +
+ +
+ + setTournamentEndDate(e.target.value)} + /> +
+ +
+ + setMaxTeamMembers(e.target.value)} + placeholder="Maximum Number of Team Members" + /> +
+ +
+ + setMinTeamMembers(e.target.value)} + placeholder="Minimum Number of Team Members" + /> +
+ +
+ + setMaxTeams(e.target.value)} + placeholder="Enter Maximum Number of Teams" + /> +
+ +
+ + setMinTeams(e.target.value)} + placeholder="Enter Minimum Number of Teams" + /> +
+ +
+ + +
+ +
+ + setInviteCode(e.target.value)} + placeholder="Enter Invite Code" + /> +
+
+ + {/* Prize Configuration */} +
+

+ Prize Configuration{" "} + +

+ +
- {/* Game Configuration */} -
-

Game Configuration

-
-
- - -
-
- - setParameterPoints(e.target.value)} - placeholder="Enter Parameter Points" - /> -
-
- -
+ {/* Rules */} +
+

+ Rules +

+ + +
- {/* Tournament Configuration */} -
-

Tournament Configuration

-

Round 1

-
-
- - -
-
- - setNumberOfMatches(e.target.value)} - placeholder="Enter Number of Matches" - /> -
-
- - setQualifyingTeamsPerGroup(e.target.value)} - /> -
-
- - setWildcardPlayers(e.target.value)} - placeholder="Enter Number of wildcard players" - /> -
-
- - setTeamsPerGroup(e.target.value)} - placeholder="Enter Number of Teams Per Group" - /> -
-
- - setRoundName(e.target.value)} - placeholder="Enter Round Name" - /> -
-
- -
+ {/* Sponsors */} +
+

Sponsors

+ +
- {/* Create Tournament Button */} -
- -
+ {/* Game Configuration */} +
+

+ Game Configuration{" "} + +

+
+
+ + +
+
+ + setParameterPoints(e.target.value)} + placeholder="Enter Parameter Points" + /> +
+
+ +
- {/* Success and Error Messages */} - {successMessage && ( -
- {successMessage} -
- )} - {errorMessage && ( -
- {errorMessage} -
- )} + {/* Tournament Configuration */} +
+

+ Tournament Configuration +

+

Round 1

+
+
+ + +
+
+ + setNumberOfMatches(e.target.value)} + placeholder="Enter Number of Matches" + /> +
+
+ + setQualifyingTeamsPerGroup(e.target.value)} + /> +
+
+ + setWildcardPlayers(e.target.value)} + placeholder="Enter Number of wildcard players" + />
+
+ + setTeamsPerGroup(e.target.value)} + placeholder="Enter Number of Teams Per Group" + /> +
+
+ + setRoundName(e.target.value)} + placeholder="Enter Round Name" + /> +
+
+
- ); + + {/* Create Tournament Button */} +
+ +
+ + {/* Success and Error Messages */} + {successMessage && ( +
+ {successMessage} +
+ )} + {errorMessage && ( +
+ {errorMessage} +
+ )} +
+
+ ); } diff --git a/components/Footer.jsx b/components/Footer.jsx index 158573a..ee197f7 100644 --- a/components/Footer.jsx +++ b/components/Footer.jsx @@ -93,7 +93,7 @@ export default function Footer() {
-
+
Built and maintained by Sanity Gaming - © 2024