From 436adc5444f4addf8d82e0e872977c2a68c866cd Mon Sep 17 00:00:00 2001 From: Andres2D Date: Sat, 18 Feb 2023 16:10:59 -0500 Subject: [PATCH] Update match layout and integration --- components/matches/match-list.module.scss | 12 +++ components/matches/match-list.tsx | 92 +++++++++++++++++++++-- 2 files changed, 98 insertions(+), 6 deletions(-) diff --git a/components/matches/match-list.module.scss b/components/matches/match-list.module.scss index 7e5979e..599726b 100644 --- a/components/matches/match-list.module.scss +++ b/components/matches/match-list.module.scss @@ -80,6 +80,18 @@ } } +.updateMatch { + display: flex; + flex-direction: column; + + .formControl { + align-items: center; + display: flex; + flex-direction: column; + margin-bottom: 10px; + } +} + @media (max-width: $medium-small-device) { .section { diff --git a/components/matches/match-list.tsx b/components/matches/match-list.tsx index 56fac80..e2f5432 100644 --- a/components/matches/match-list.tsx +++ b/components/matches/match-list.tsx @@ -22,6 +22,8 @@ interface Props { const MatchList: NextPage = ({ matches }) => { const [matchesList, setMatchesList] = useState([]); const [selectedMatch, setSelectedMatch] = useState(); + const [place, setPlace] = useState(); + const [date, setDate] = useState(); const { isOpen: deleteModalIsOpen, onOpen: deleteModalOnOpen, @@ -37,11 +39,18 @@ const MatchList: NextPage = ({ matches }) => { onOpen: fulltimeModalOnOpen, onClose: fulltimeModalOnClose, } = useDisclosure(); + const { + isOpen: updateMatchModalIsOpen, + onOpen: updateMatchModalOnOpen, + onClose: updateMatchModalOnClose + } = useDisclosure(); const toast = useToast(); const homeScoreRef = useRef() as MutableRefObject; const awayScoreRef = useRef() as MutableRefObject; - + + // const placeRef = useRef() as MutableRefObject; + // const dateRef = useRef() as MutableRefObject; useEffect(() => { setMatchesList(matches); @@ -115,6 +124,7 @@ const MatchList: NextPage = ({ matches }) => { onSuccess: async (response) => { if (response.ok) { fulltimeModalOnClose(); + updateMatchModalOnClose(); setSelectedMatch(undefined); toast({ title: 'Match updated', @@ -132,6 +142,7 @@ const MatchList: NextPage = ({ matches }) => { isClosable: true, }); fulltimeModalOnClose(); + updateMatchModalOnClose(); setSelectedMatch(undefined); } }, @@ -161,6 +172,13 @@ const MatchList: NextPage = ({ matches }) => { fulltimeModalOnOpen(); }; + const showUpdateMatchModal = (match: FullMatch) => { + updateMatchModalOnOpen(); + setPlace(match.location); + setDate(match.date); + setSelectedMatch(match); + }; + const handleDeleteMatch = () => { mutateDeleteMatch(selectedMatch?._id!); }; @@ -168,7 +186,7 @@ const MatchList: NextPage = ({ matches }) => { const handleLeaveMatch = () => { mutateLeaveMatch(selectedMatch?._id!); }; - + const handleFulltime = () => { if(homeScoreRef.current.value.trim() === '' || awayScoreRef.current.value.trim() === '' ) { return; @@ -184,6 +202,22 @@ const MatchList: NextPage = ({ matches }) => { mutateUpdateMatch(request); }; + const handleUpdateMatch = () => { + if(!date || !location || date?.trim() === '' || place?.trim() === '' ) { + return; + } + + const request: FullMatch = { + ...selectedMatch!, + date: date || selectedMatch?.date || '', + location: place || selectedMatch?.location || '' + }; + + console.log(request); + + mutateUpdateMatch(request); + }; + const matchesListMap = matchesList.map( ({ _id, @@ -223,7 +257,7 @@ const MatchList: NextPage = ({ matches }) => {

{date}

{location}

- { + { fullTime &&

Full-time

} @@ -248,6 +282,18 @@ const MatchList: NextPage = ({ matches }) => { mb={2} disabled={fullTime} aria-label="Edit match" + onClick={() => + showUpdateMatchModal({ + _id, + date, + location, + away_team, + home_team, + fullTime, + homeScore, + awayScore, + }) + } icon={} /> = ({ matches }) => { } ); + const inputHandler = (input: string, event: any) => { + input === 'place' ? setPlace(event.target.value) : setDate(event.target.value); + }; + return ( <> {matchesListMap} @@ -349,8 +399,8 @@ const MatchList: NextPage = ({ matches }) => { width='50px' height='50px' /> - {selectedMatch?.home_team.name} @@ -365,7 +415,7 @@ const MatchList: NextPage = ({ matches }) => { height='50px' /> {selectedMatch?.away_team.name} @@ -374,6 +424,36 @@ const MatchList: NextPage = ({ matches }) => { + + +
+ + + Place + + inputHandler('place', event)} value={place} /> + + + + Date + + inputHandler('date', event)} value={date} /> + +
+
); };