Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
sweepstake
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Arjun Jhukal
sweepstake
Commits
9a49c7cc
Commit
9a49c7cc
authored
Oct 17, 2025
by
Arjun Jhukal
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
updated the game delete and updated the invalidate logic
parent
58c945b4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
88 additions
and
23 deletions
+88
-23
index.tsx
...components/pages/dashboard/adminDashboard/games/index.tsx
+37
-4
gameApi.ts
src/services/gameApi.ts
+51
-19
No files found.
src/components/pages/dashboard/adminDashboard/games/index.tsx
View file @
9a49c7cc
"use client"
;
import
{
useGetAllGamesQuery
}
from
'@/services/gameApi'
import
ActionGroup
from
'@/components/molecules/Action'
;
import
{
useAppDispatch
}
from
'@/hooks/hook'
;
import
{
useDeleteGameByIdMutation
,
useGetAllGamesQuery
}
from
'@/services/gameApi'
import
{
showToast
,
ToastVariant
}
from
'@/slice/toastSlice'
;
import
{
GameItem
}
from
'@/types/game'
;
import
Image
from
'next/image'
;
import
Link
from
'next/link'
;
...
...
@@ -38,6 +41,8 @@ function GameSkeleton() {
}
export
default
function
AdminGameList
()
{
const
{
data
,
isLoading
}
=
useGetAllGamesQuery
();
const
[
deleteGame
,
{
isLoading
:
deleting
}]
=
useDeleteGameByIdMutation
();
const
dispatch
=
useAppDispatch
();
return
(
<
div
className=
"admin__games grid md:grid-cols-2 lg:grid-cols-3 2xl:grid-cols-4 gap-6"
>
{
isLoading
&&
...
...
@@ -50,9 +55,37 @@ export default function AdminGameList() {
className=
"admin__game__card bg-[#F4F6FC] p-4 lg:p-6 rounded-[16px]"
>
{
/* Game Name */
}
<
h2
className=
"text-16 leading-[120%] font-bold mb-4"
>
{
game
.
name
}
</
h2
>
<
div
className=
"flex justify-between items-start"
>
<
h2
className=
"text-16 leading-[120%] font-bold mb-4"
>
{
game
.
name
}
</
h2
>
<
ActionGroup
onDelete=
{
async
()
=>
{
try
{
const
response
=
await
deleteGame
({
id
:
game
.
id
}).
unwrap
();
dispatch
(
showToast
(
{
variant
:
ToastVariant
.
SUCCESS
,
message
:
response
?.
message
||
"Game Deleted Successfully"
}
)
)
}
catch
(
e
)
{
dispatch
(
showToast
(
{
variant
:
ToastVariant
.
ERROR
,
message
:
"Unable to Delete Game"
}
)
)
}
}
}
/>
</
div
>
{
/* Type & Provider */
}
<
ul
className=
"flex justify-between items-center mb-6"
>
...
...
src/services/gameApi.ts
View file @
9a49c7cc
import
{
createApi
}
from
"@reduxjs/toolkit/query/react"
;
import
{
baseQuery
}
from
"./baseQuery"
;
import
{
GameProps
,
GameResponseProps
,
SingleGameResponse
}
from
"@/types/game"
;
import
{
Game
Item
,
Game
Props
,
GameResponseProps
,
SingleGameResponse
}
from
"@/types/game"
;
import
{
GlobalResponse
}
from
"@/types/config"
;
export
const
gameApi
=
createApi
({
reducerPath
:
"gameApi"
,
baseQuery
:
baseQuery
,
tagTypes
:
[
"
g
ames"
],
tagTypes
:
[
"
G
ames"
],
endpoints
:
(
builder
)
=>
({
// ➕ Add a new game
addGame
:
builder
.
mutation
<
GlobalResponse
,
FormData
>
({
query
:
(
body
)
=>
({
url
:
"/api/admin/add-game"
,
method
:
"POST"
,
body
:
body
body
,
}),
invalidatesTags
:
[
"games"
]
invalidatesTags
:
[
{
type
:
"Games"
,
id
:
"LIST"
}],
}),
// 📋 Fetch all games
getAllGames
:
builder
.
query
<
GameResponseProps
,
void
>
({
query
:
()
=>
({
url
:
'/api/admin/games'
,
method
:
'GET'
,
url
:
"/api/admin/games"
,
method
:
"GET"
,
}),
providesTags
:
[
'games'
]
providesTags
:
(
result
)
=>
result
?.
data
?.
data
?
[
{
type
:
"Games"
,
id
:
"LIST"
},
...
result
.
data
.
data
.
map
((
game
:
GameItem
)
=>
({
type
:
"Games"
as
const
,
id
:
game
.
id
,
})),
]
:
[{
type
:
"Games"
,
id
:
"LIST"
}],
}),
// 🎮 Get single game by ID
getGameById
:
builder
.
query
<
SingleGameResponse
,
{
id
:
string
|
number
}
>
({
query
:
({
id
})
=>
({
url
:
`/api/admin/game/
${
id
}
`
,
method
:
'GET'
,
method
:
"GET"
,
}),
providesTags
:
[
'games'
]
providesTags
:
(
result
,
error
,
{
id
})
=>
[{
type
:
"Games"
,
id
}],
}),
updateGameById
:
builder
.
mutation
<
SingleGameResponse
,
{
id
:
string
|
number
,
body
:
FormData
}
>
({
// ✏️ Update game by ID
updateGameById
:
builder
.
mutation
<
SingleGameResponse
,
{
id
:
string
|
number
;
body
:
FormData
}
>
({
query
:
({
id
,
body
})
=>
({
url
:
`/api/admin/game/
${
id
}
`
,
method
:
"POST"
,
body
:
body
body
,
}),
invalidatesTags
:
[
"games"
]
invalidatesTags
:
(
result
,
error
,
{
id
})
=>
[
{
type
:
"Games"
,
id
},
{
type
:
"Games"
,
id
:
"LIST"
},
],
}),
// ❌ Delete game by ID
deleteGameById
:
builder
.
mutation
<
GlobalResponse
,
{
id
:
string
|
number
}
>
({
query
:
({
id
})
=>
({
url
:
`/api/admin/game/
${
id
}
`
,
method
:
"DELETE"
method
:
"DELETE"
,
}),
invalidatesTags
:
[
"games"
]
})
})
})
invalidatesTags
:
(
result
,
error
,
{
id
})
=>
[
{
type
:
"Games"
,
id
},
{
type
:
"Games"
,
id
:
"LIST"
},
],
}),
}),
});
export
const
{
useAddGameMutation
,
useGetAllGamesQuery
,
useGetGameByIdQuery
,
useUpdateGameByIdMutation
,
useDeleteGameByIdMutation
}
=
gameApi
;
\ No newline at end of file
export
const
{
useAddGameMutation
,
useGetAllGamesQuery
,
useGetGameByIdQuery
,
useUpdateGameByIdMutation
,
useDeleteGameByIdMutation
,
}
=
gameApi
;
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment