-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tournaments list with filtering form
- Loading branch information
Showing
17 changed files
with
298 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
node_modules/ | ||
.idea/ | ||
.build/ | ||
build/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import React, {forwardRef, useEffect, useImperativeHandle, useState} from 'react'; | ||
import {TournamentService} from "../services/TournamentService"; | ||
import './TournamentFilterForm.scss'; | ||
|
||
const TournamentFilterForm = forwardRef(function TournamentFilterForm({ | ||
currentPage, | ||
setCurrentPage, | ||
tournamentsPerPage, | ||
setFilteredTournaments, | ||
setPageCount, | ||
setMessage | ||
}, ref) { | ||
const [tournamentTitle, setTournamentTitle] = useState(''); | ||
const [minPlayOutDate, setMinPlayOutDate] = useState(new Date(0)); | ||
const [maxPlayOutDate, setMaxPlayOutDate] = useState(new Date(new Date().setFullYear(new Date().getFullYear() + 10))); | ||
const [creator, setCreator] = useState(''); | ||
const [userParticipation, setUserParticipation] = useState(''); | ||
|
||
const filterTournaments = async (e) => { | ||
if (e) { | ||
e.preventDefault() | ||
} | ||
const body = constructObject(); | ||
TournamentService.getFilteredTournaments(currentPage, tournamentsPerPage, body) | ||
.then((response) => { | ||
setPageCount(response.data.data.amountOfPages); | ||
setFilteredTournaments(response.data.data.page); | ||
if (response.data.data.amountOfPages < currentPage) { | ||
setCurrentPage(0); | ||
} | ||
}).catch((error) => { | ||
setMessage('Error loading tournaments'); | ||
}); | ||
} | ||
|
||
useEffect(() => { | ||
filterTournaments(); | ||
}, [currentPage]); | ||
|
||
useImperativeHandle(ref, () => ({ | ||
filterTournaments | ||
})); | ||
|
||
const constructObject = () => { | ||
const data = { | ||
tournamentTitle, | ||
minPlayOutDate, | ||
maxPlayOutDate, | ||
creator, | ||
userParticipation | ||
}; | ||
|
||
Object.keys(data).forEach(key => { | ||
if (data[key] === undefined) { | ||
data[key] = ''; | ||
} | ||
}); | ||
|
||
return data; | ||
} | ||
|
||
const handleClearClick = (selectedObject) => { | ||
setUserParticipation(''); | ||
setCreator(''); | ||
setMaxPlayOutDate(new Date(new Date(new Date().setFullYear(new Date().getFullYear() + 10)))); | ||
setMinPlayOutDate(new Date(0)); | ||
setTournamentTitle(''); | ||
}; | ||
|
||
return ( | ||
<div className="tournaments-form-container"> | ||
<form onSubmit={filterTournaments}> | ||
<h2>Filter tournaments</h2> | ||
<div className="tournaments-form"> | ||
<div className="tournaments-form-wrapper"> | ||
<label htmlFor="title">Title</label> | ||
<input | ||
type="text" | ||
id="title" | ||
value={tournamentTitle} | ||
onChange={(e) => setTournamentTitle(e.target.value)} | ||
placeholder="Enter tournament title" | ||
maxLength="30" | ||
/> | ||
</div> | ||
<div className="tournaments-form-wrapper"> | ||
<label htmlFor="minDate">From date</label> | ||
<input | ||
type="date" | ||
id="minDate" | ||
value={minPlayOutDate} | ||
onChange={(e) => setMinPlayOutDate(e.target.value)} | ||
placeholder="Enter from date" | ||
maxLength="30" | ||
/> | ||
</div> | ||
<div className="tournaments-form-wrapper"> | ||
<label htmlFor="maxDate">To date</label> | ||
<input | ||
type="date" | ||
id="maxDate" | ||
value={maxPlayOutDate} | ||
onChange={(e) => setMaxPlayOutDate(e.target.value)} | ||
placeholder="Enter to date" | ||
maxLength="30" | ||
/> | ||
</div> | ||
<div className="tournaments-form-wrapper"> | ||
<label htmlFor="creator">Creator</label> | ||
<input | ||
type="text" | ||
id="creator" | ||
value={creator} | ||
onChange={(e) => setCreator(e.target.value)} | ||
placeholder="Enter creator username" | ||
maxLength="30" | ||
/> | ||
</div> | ||
<div className="tournaments-form-wrapper"> | ||
<label htmlFor="partcipating">Participant</label> | ||
<input | ||
type="text" | ||
id="partcipating" | ||
value={userParticipation} | ||
onChange={(e) => setUserParticipation(e.target.value)} | ||
placeholder="Enter username of partcipating user" | ||
maxLength="30" | ||
/> | ||
</div> | ||
<div className="tournaments-form-button-container"> | ||
<button type="submit" className="submit">Filter</button> | ||
<button onClick={handleClearClick}>Clear</button> | ||
</div> | ||
</div> | ||
</form> | ||
</div> | ||
) | ||
}) | ||
|
||
export default TournamentFilterForm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
.tournaments-form-container { | ||
margin-top: 25px; | ||
h2 { | ||
margin: 20px 0; | ||
text-align: center; | ||
overflow-wrap: break-word; | ||
} | ||
.tournaments-form { | ||
display: flex; | ||
flex-wrap: wrap; | ||
flex-direction: row; | ||
.tournaments-form-wrapper { | ||
max-width: 100%; | ||
} | ||
.tournaments-form-button-container { | ||
display: flex; | ||
flex-grow: 1; | ||
margin-top: 10px; | ||
justify-content: space-evenly; | ||
} | ||
div { | ||
padding: 0 20px; | ||
label { | ||
margin-right: 20px; | ||
overflow-wrap: break-word; | ||
} | ||
} | ||
} | ||
border: 2px solid #393a39; | ||
margin-bottom: 20px; | ||
padding: 10px; | ||
font-family: Arial, Helvetica, sans-serif; | ||
|
||
@media (max-width: 768px) { | ||
font-size: 0.8rem; | ||
width: 100%; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.