Skip to content

Commit

Permalink
Add real time update on update match
Browse files Browse the repository at this point in the history
  • Loading branch information
Andres2D committed Feb 18, 2023
1 parent 436adc5 commit 2ab7561
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
19 changes: 17 additions & 2 deletions components/matches/match-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,23 @@ const MatchList: NextPage<Props> = ({ matches }) => {
const { mutate: mutateUpdateMatch } = useMutation(updateMatch, {
onSuccess: async (response) => {
if (response.ok) {
setMatchesList((matches) =>
matches.map((match) => {
if(match._id === selectedMatch?._id) {
return {
...match,
location: response.data.match.location,
date: response.data.match.date,
fullTime: response.data.match.fullTime,
homeScore: response.data.match.homeScore,
awayScore: response.data.match.awayScore
};
}else {
return match;
}
})
);

fulltimeModalOnClose();
updateMatchModalOnClose();
setSelectedMatch(undefined);
Expand Down Expand Up @@ -213,8 +230,6 @@ const MatchList: NextPage<Props> = ({ matches }) => {
location: place || selectedMatch?.location || ''
};

console.log(request);

mutateUpdateMatch(request);
};

Expand Down
6 changes: 3 additions & 3 deletions services/api-configuration.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { create } from 'apisauce'
import { ApiResponse, create } from 'apisauce'
import { ICreateMatchRequest, FullMatch } from '../interfaces/Match';
import { UpdateProfileRequest, RegisterPlayerRequest } from '../interfaces/Player';
import { UpdateTeamRequest } from '../interfaces/Team';
import { IUpdateTeamPlayerRequest, IChangePlayerRequest, LeftMatchRequest } from '../interfaces/TeamPlayer';
import { IUpdateTeamPlayerRequest, IChangePlayerRequest } from '../interfaces/TeamPlayer';

const api = create({
baseURL: '/api',
Expand All @@ -17,7 +17,7 @@ export const changePlayer = (request: IUpdateTeamPlayerRequest | IChangePlayerRe
export const leaveMatch = (id: string) => api.delete('/team-player', { idMatch: id });

export const createMatch = (request: ICreateMatchRequest) => api.post('/match', request);
export const updateMatch = (match: FullMatch) => api.put('/match', match);
export const updateMatch = (match: FullMatch): Promise<ApiResponse<any, any>> => api.put('/match', match);
export const deleteMatch = (id: string) => api.delete('/match', { id });

export const updateTeam = (request: UpdateTeamRequest) => api.put('/team', request);

0 comments on commit 2ab7561

Please sign in to comment.