Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
F
final-exam
Project
Project
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
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nawasan Wisitsingkhon
final-exam
Commits
d93bc232
Commit
d93bc232
authored
Oct 02, 2023
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
alert when change rank success or failed
parent
587d26bd
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
31 additions
and
6 deletions
+31
-6
member.js
src/pages/admin/member.js
+31
-6
No files found.
src/pages/admin/member.js
View file @
d93bc232
...
@@ -3,8 +3,10 @@ import { UserContext } from "../_app";
...
@@ -3,8 +3,10 @@ import { UserContext } from "../_app";
import
Head
from
"next/head"
;
import
Head
from
"next/head"
;
import
axios
from
"axios"
;
import
axios
from
"axios"
;
import
{
import
{
Alert
,
Button
,
Button
,
Paper
,
Paper
,
Snackbar
,
Switch
,
Switch
,
Table
,
Table
,
TableBody
,
TableBody
,
...
@@ -17,15 +19,29 @@ import DeleteMember from "@/components/member/DeleteMember";
...
@@ -17,15 +19,29 @@ import DeleteMember from "@/components/member/DeleteMember";
export
default
function
Member
()
{
export
default
function
Member
()
{
const
user
=
useContext
(
UserContext
);
const
user
=
useContext
(
UserContext
);
const
[
userAll
,
setUserAll
]
=
useState
([]);
const
[
userAll
,
setUserAll
]
=
useState
([]);
const
[
message
,
setMessage
]
=
useState
({
error
:
false
,
message
:
""
});
const
[
deleteState
,
setDeleteState
]
=
useState
({
open
:
false
,
id
:
-
1
});
const
[
deleteState
,
setDeleteState
]
=
useState
({
open
:
false
,
id
:
-
1
});
async
function
changeRank
(
id
,
rank
)
{
async
function
changeRank
(
id
,
rank
)
{
let
response
=
await
axios
.
put
(
try
{
"/api/admin/user/rank"
,
let
response
=
await
axios
.
put
(
{
id
,
rank
},
"/api/admin/user/rank"
,
{
headers
:
{
token
:
user
.
value
.
token
}
}
{
id
,
rank
},
);
{
headers
:
{
token
:
user
.
value
.
token
}
}
fetchApi
();
);
if
(
response
.
data
.
status
===
301
)
{
fetchApi
();
setMessage
({
message
:
"เปลี่ยนสิทธิ์สำเร็จ"
,
error
:
false
});
setTimeout
(()
=>
{
setMessage
({
message
:
""
,
error
:
false
});
},
2000
);
}
}
catch
(
err
)
{
setMessage
({
message
:
"พบข้อผิดพลาด กรุณาลองใหม่อีกครั้ง"
,
error
:
true
});
setTimeout
(()
=>
{
setMessage
({
message
:
""
,
error
:
false
});
},
3000
);
}
}
}
async
function
fetchApi
()
{
async
function
fetchApi
()
{
try
{
try
{
...
@@ -36,6 +52,7 @@ export default function Member() {
...
@@ -36,6 +52,7 @@ export default function Member() {
}
catch
(
err
)
{}
}
catch
(
err
)
{}
}
}
useEffect
(()
=>
{
useEffect
(()
=>
{
// console.log();
fetchApi
();
fetchApi
();
},
[
deleteState
]);
},
[
deleteState
]);
return
(
return
(
...
@@ -43,6 +60,14 @@ export default function Member() {
...
@@ -43,6 +60,14 @@ export default function Member() {
<
Head
>
<
Head
>
<
title
>
รายชื่อสมาชิก
|
admin
<
/title
>
<
title
>
รายชื่อสมาชิก
|
admin
<
/title
>
<
/Head
>
<
/Head
>
<
Snackbar
anchorOrigin
=
{{
horizontal
:
"center"
,
vertical
:
"top"
}}
open
=
{
!!
message
.
message
.
length
}
>
<
Alert
color
=
{
message
.
error
?
"error"
:
"success"
}
>
{
message
.
message
}
<
/Alert
>
<
/Snackbar
>
<
Paper
sx
=
{{
p
:
2
}}
>
<
Paper
sx
=
{{
p
:
2
}}
>
<
Table
>
<
Table
>
<
TableHead
>
<
TableHead
>
...
...
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