-
Notifications
You must be signed in to change notification settings - Fork 2
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 #301 from dataforgoodfr/feat/D4G-294-remove-game
Feat/d4g 294 remove game
- Loading branch information
Showing
13 changed files
with
296 additions
and
98 deletions.
There are no files selected for viewing
33 changes: 23 additions & 10 deletions
33
packages/client/src/modules/administration/Games/Game/services/mutations.ts
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,23 +1,36 @@ | ||
import { useMutation, useQueryClient } from "react-query"; | ||
import { http } from "../../../../../utils/request"; | ||
|
||
export const useRemovePlayerMutation = (gameId: number) => { | ||
export { useRemoveGameMutation, useRemovePlayerMutation }; | ||
|
||
const useRemoveGameMutation = () => { | ||
const queryClient = useQueryClient(); | ||
|
||
const removeGameMutation = useMutation< | ||
Response, | ||
{ message: string }, | ||
{ gameId: number } | ||
>(({ gameId }) => http.delete(`/api/games/${gameId}`), { | ||
onSuccess: () => { | ||
queryClient.invalidateQueries(`games`); | ||
}, | ||
}); | ||
|
||
return { removeGameMutation }; | ||
}; | ||
|
||
const useRemovePlayerMutation = (gameId: number) => { | ||
const queryClient = useQueryClient(); | ||
|
||
const removePlayerMutation = useMutation< | ||
Response, | ||
{ message: string }, | ||
{ userId: number } | ||
>( | ||
({ userId }) => { | ||
return http.post("/api/games/remove-player", { gameId, userId }); | ||
>(({ userId }) => http.post("/api/games/remove-player", { gameId, userId }), { | ||
onSuccess: () => { | ||
queryClient.invalidateQueries(`/api/games/${gameId}/players`); | ||
}, | ||
{ | ||
onSuccess: () => { | ||
queryClient.invalidateQueries(`/api/games/${gameId}/players`); | ||
}, | ||
} | ||
); | ||
}); | ||
|
||
return { removePlayerMutation }; | ||
}; |
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,21 @@ | ||
import { useCallback, useState } from "react"; | ||
|
||
export { useDialog }; | ||
|
||
function useDialog() { | ||
const [isOpen, setIsOpen] = useState<boolean>(false); | ||
|
||
const openDialog = useCallback(() => { | ||
setIsOpen(true); | ||
}, [setIsOpen]); | ||
|
||
const closeDialog = useCallback(() => { | ||
setIsOpen(false); | ||
}, [setIsOpen]); | ||
|
||
return { | ||
isOpen, | ||
closeDialog, | ||
openDialog, | ||
}; | ||
} |
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.