-
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.
Merge pull request #191 from Andres2D/update-team
Update team
- Loading branch information
Showing
8 changed files
with
222 additions
and
3 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
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,32 @@ | ||
@import '../../../../styles/breakpoints'; | ||
|
||
.modal { | ||
.shieldSelector { | ||
margin-top: 10px; | ||
display: flex; | ||
flex-direction: column; | ||
gap: 5px; | ||
|
||
.shields { | ||
margin: 10px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
align-content: space-between; | ||
gap: 15px; | ||
height: 200px; | ||
flex-wrap: wrap; | ||
overflow-y: scroll; | ||
|
||
.shield { | ||
cursor: pointer; | ||
} | ||
} | ||
} | ||
} | ||
|
||
@media (max-width: $medium-small-device) { | ||
.modal { | ||
width: 90% !important; | ||
} | ||
} |
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,142 @@ | ||
import { EditIcon } from '@chakra-ui/icons'; | ||
import { | ||
Button, | ||
FormControl, | ||
FormLabel, | ||
IconButton, | ||
Image, | ||
Input, | ||
Modal, | ||
ModalBody, | ||
ModalCloseButton, | ||
ModalContent, | ||
ModalFooter, | ||
ModalHeader, | ||
ModalOverlay, | ||
useDisclosure | ||
} from '@chakra-ui/react'; | ||
import { getAllTeams, getTeamPng } from 'empty-skull'; | ||
import type { NextPage } from 'next'; | ||
import { useRef, useState } from 'react'; | ||
import { useMutation } from 'react-query'; | ||
import { useSelector, useDispatch } from 'react-redux'; | ||
import { RootState } from '../../../../interfaces/State'; | ||
import { updateTeam } from '../../../../services/api-configuration'; | ||
import { matchDetailsActions } from '../../../../store/match-details.slice'; | ||
import styles from './set-team.module.scss'; | ||
|
||
interface Props { | ||
isAway: boolean; | ||
} | ||
|
||
const SetTeam: NextPage<Props> = ({isAway}) => { | ||
const matchDetails = useSelector((state: RootState) => state.matchDetails).match; | ||
const teamDetail = isAway ? matchDetails.away_team : matchDetails.home_team; | ||
|
||
const nameRef = useRef<HTMLInputElement>(null); | ||
const teamShieldRef = useRef<HTMLInputElement>(null); | ||
const { isOpen, onOpen, onClose } = useDisclosure(); | ||
const [shieldList, setShieldList] = useState(getAllTeams()); | ||
const [shield, setShield] = useState(teamDetail.shield); | ||
const dispatch = useDispatch(); | ||
const { mutate } = useMutation(updateTeam); | ||
|
||
const searchShield = () => { | ||
if(!teamShieldRef?.current?.value) { | ||
setShieldList(getAllTeams()); | ||
return; | ||
} | ||
|
||
const shields = getTeamPng(teamShieldRef?.current?.value); | ||
setShieldList(Array.isArray(shields) ? shields : [shields]); | ||
} | ||
|
||
const teams = shieldList.map((team) => ( | ||
<Image | ||
width={70} | ||
key={team.img} | ||
height={70} | ||
src={team.img} | ||
alt={team.name} | ||
className={styles.shield} | ||
title={team.name} | ||
onClick={() => setShield(team.img)} | ||
/> | ||
)); | ||
|
||
const updateShield = () => { | ||
dispatch(matchDetailsActions.updateTeam({ | ||
team: isAway ? 'away_team' : 'home_team', | ||
setting: { | ||
name: nameRef?.current?.value || teamDetail.name , | ||
shield | ||
} | ||
})); | ||
mutate({ | ||
name:nameRef?.current?.value || teamDetail.name, | ||
shield, | ||
_id: teamDetail._id, | ||
formation: teamDetail.formation | ||
}); | ||
onClose(); | ||
}; | ||
|
||
return ( | ||
<> | ||
<IconButton | ||
className={styles.edit} | ||
colorScheme='transparent' | ||
size='lg' | ||
aria-label='Edit team' | ||
onClick={onOpen} | ||
icon={<EditIcon />} | ||
/> | ||
<Modal isOpen={isOpen} onClose={onClose}> | ||
<ModalOverlay /> | ||
<ModalContent className={styles.modal}> | ||
<ModalHeader>Edit team</ModalHeader> | ||
<ModalCloseButton /> | ||
<ModalBody> | ||
<FormControl> | ||
<FormLabel>Team name</FormLabel> | ||
<Input | ||
type='text' | ||
defaultValue={teamDetail.name} | ||
ref={nameRef} | ||
/> | ||
</FormControl> | ||
<div className={styles.shieldSelector}> | ||
<FormLabel>Team shield</FormLabel> | ||
<Image | ||
width={70} | ||
height={70} | ||
src={shield} | ||
alt={teamDetail.name} | ||
className={styles.shield} | ||
title={teamDetail.name} | ||
/> | ||
<Input | ||
placeholder='Search shield' | ||
ref={teamShieldRef} | ||
onChange={searchShield} | ||
/> | ||
<div className={styles.shields}> | ||
{teams} | ||
</div> | ||
</div> | ||
</ModalBody> | ||
<ModalFooter> | ||
<Button colorScheme="green" mr={3} onClick={updateShield}> | ||
Update | ||
</Button> | ||
<Button colorScheme="red" mr={3} onClick={onClose}> | ||
Cancel | ||
</Button> | ||
</ModalFooter> | ||
</ModalContent> | ||
</Modal> | ||
</> | ||
); | ||
} | ||
|
||
export default SetTeam; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
$extra-large-device: 1090px; | ||
$large-device: 995px; | ||
$medium-large-device: 845px; | ||
$medium-device-extra: 600px; | ||
|
f6f0d55
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
cotejoapp – ./
cotejoapp.vercel.app
cotejoapp-andres2d.vercel.app
cotejoapp-git-main-andres2d.vercel.app