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
c99f1861
Commit
c99f1861
authored
Oct 05, 2023
by
Nawasan Wisitsingkhon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
login & register: change alert styles;
register: fix photo;
parent
4dd46b2f
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
72 additions
and
37 deletions
+72
-37
Navbar.js
src/components/Navbar.js
+2
-2
member.js
src/pages/admin/member.js
+2
-0
login.js
src/pages/login.js
+8
-15
profile.js
src/pages/profile.js
+41
-0
register.js
src/pages/register.js
+19
-20
No files found.
src/components/Navbar.js
View file @
c99f1861
...
@@ -231,7 +231,7 @@ function Navbar(props) {
...
@@ -231,7 +231,7 @@ function Navbar(props) {
{
{
label
:
""
,
label
:
""
,
element
:
(
element
:
(
<
span
className
=
"inline-block mx-3 hover:underline"
>
<
span
className
=
"inline-block mx-3
p-3
hover:underline"
>
เข้าสู่ระบบ
เข้าสู่ระบบ
<
/span
>
<
/span
>
),
),
...
@@ -241,7 +241,7 @@ function Navbar(props) {
...
@@ -241,7 +241,7 @@ function Navbar(props) {
{
{
label
:
""
,
label
:
""
,
element
:
(
element
:
(
<
span
className
=
"inline-block mx-3 hover:underline"
>
<
span
className
=
"inline-block mx-3
p-3
hover:underline"
>
สมัครสมาชิก
สมัครสมาชิก
<
/span
>
<
/span
>
),
),
...
...
src/pages/admin/member.js
View file @
c99f1861
...
@@ -128,7 +128,9 @@ export default function Member() {
...
@@ -128,7 +128,9 @@ export default function Member() {
<
TableCell
>
{
user
.
id
}
<
/TableCell
>
<
TableCell
>
{
user
.
id
}
<
/TableCell
>
<
TableCell
>
<
TableCell
>
<
img
<
img
className
=
"rounded-lg object-cover"
width
=
{
70
}
width
=
{
70
}
height
=
{
70
}
src
=
{
user
?.
photo
?.
length
?
user
.
photo
:
"/empty.jpg"
}
src
=
{
user
?.
photo
?.
length
?
user
.
photo
:
"/empty.jpg"
}
alt
=
"profile"
alt
=
"profile"
/>
/>
...
...
src/pages/login.js
View file @
c99f1861
...
@@ -9,11 +9,11 @@ import { useState } from "react";
...
@@ -9,11 +9,11 @@ import { useState } from "react";
import
axios
from
"axios"
;
import
axios
from
"axios"
;
import
Head
from
"next/head"
;
import
Head
from
"next/head"
;
import
userCookie
from
"@/components/lib/userCookie"
;
import
userCookie
from
"@/components/lib/userCookie"
;
import
PopupAlert
from
"@/components/PopupAlert"
;
export
default
function
Login
()
{
export
default
function
Login
()
{
const
user
=
useContext
(
UserContext
);
const
user
=
useContext
(
UserContext
);
const
[
errorMessage
,
setErrorMessage
]
=
useState
(
""
);
const
[
message
,
setMessage
]
=
useState
({
message
:
""
,
error
:
false
});
const
[
successMessage
,
setSuccessMessage
]
=
useState
(
""
);
const
[
username
,
setUsername
]
=
useState
(
""
);
const
[
username
,
setUsername
]
=
useState
(
""
);
const
[
password
,
setPassword
]
=
useState
(
""
);
const
[
password
,
setPassword
]
=
useState
(
""
);
...
@@ -39,9 +39,9 @@ export default function Login() {
...
@@ -39,9 +39,9 @@ export default function Login() {
usrsto
.
store
(
response
.
data
.
token
);
usrsto
.
store
(
response
.
data
.
token
);
window
.
location
.
href
=
"/"
;
window
.
location
.
href
=
"/"
;
}
else
if
(
response
.
data
.
status
===
203
)
{
}
else
if
(
response
.
data
.
status
===
203
)
{
set
ErrorMessage
(
"ชื่อผู้ใช้หรือระหัสผ่านไม่ถูกต้อง"
);
set
Message
({
message
:
"ชื่อผู้ใช้หรือระหัสผ่านไม่ถูกต้อง"
,
error
:
true
}
);
setTimeout
(()
=>
{
setTimeout
(()
=>
{
set
ErrorMessage
(
""
);
set
Message
({
message
:
""
,
error
:
true
}
);
},
3000
);
},
3000
);
}
}
}
}
...
@@ -52,17 +52,10 @@ export default function Login() {
...
@@ -52,17 +52,10 @@ export default function Login() {
<
title
>
เข้าสู่ระบบ
|
OpenShop
<
/title
>
<
title
>
เข้าสู่ระบบ
|
OpenShop
<
/title
>
<
/Head
>
<
/Head
>
<
Container
>
<
Container
>
<
Snackbar
<
PopupAlert
ContentProps
=
{{
className
:
"bg-red-500"
}}
isError
=
{
message
.
error
}
anchorOrigin
=
{{
horizontal
:
"center"
,
vertical
:
"top"
}}
message
=
{
message
.
message
}
open
=
{
!!
errorMessage
.
length
}
open
=
{
!!
message
.
message
.
length
}
message
=
{
errorMessage
}
/
>
<
Snackbar
ContentProps
=
{{
className
:
"bg-green-500"
}}
anchorOrigin
=
{{
horizontal
:
"center"
,
vertical
:
"top"
}}
open
=
{
!!
successMessage
.
length
}
message
=
{
successMessage
}
/
>
/
>
<
Grid
container
>
<
Grid
container
>
<
Grid
item
lg
=
{
3
}
md
=
{
0
}
><
/Grid
>
<
Grid
item
lg
=
{
3
}
md
=
{
0
}
><
/Grid
>
...
...
src/pages/profile.js
0 → 100644
View file @
c99f1861
import
{
Box
,
Paper
}
from
"@mui/material"
;
import
React
,
{
useContext
}
from
"react"
;
import
{
UserContext
}
from
"./_app"
;
export
default
function
Profile
()
{
const
user
=
useContext
(
UserContext
);
console
.
log
(
user
.
value
);
return
(
<>
{
user
.
value
?.
token
?
(
<
Box
>
<
Paper
sx
=
{{
p
:
3
,
boxShadow
:
"none"
}}
>
<
div
className
=
"gap-10 mx-auto text-left grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 max-w-[1520px]"
>
<
div
className
=
"mx-auto"
>
<
img
className
=
"inline-block rounded-lg"
width
=
{
300
}
src
=
{
user
.
value
.
photo
.
length
?
user
.
value
.
photo
:
"empty.jpg"
}
alt
=
""
/>
<
/div
>
<
div
className
=
"lg:col-span-2 p-3"
>
<
div
>
{
user
.
value
.
name
}
<
/div
>
<
div
>
{
user
.
value
.
email
}
<
/div
>
<
div
className
=
"text-lg"
>
@{
user
.
value
.
username
}
<
/div
>
<
div
>
{
user
.
value
.
phone
}
<
/div
>
<
div
>
ที่อยู่
{
user
.
value
.
address
}
<
/div
>
<
/div
>
<
/div
>
<
/Paper
>
<
/Box
>
)
:
(
<
Box
>
<
Paper
sx
=
{{
p
:
3
,
textAlign
:
"center"
}}
>
คุณยังไม่ได้เข้าสู่ระบบ
<
/Paper
>
<
/Box
>
)}
<
/
>
);
}
src/pages/register.js
View file @
c99f1861
...
@@ -9,11 +9,11 @@ import { useState } from "react";
...
@@ -9,11 +9,11 @@ import { useState } from "react";
import
axios
from
"axios"
;
import
axios
from
"axios"
;
import
Head
from
"next/head"
;
import
Head
from
"next/head"
;
import
{
useRouter
}
from
"next/router"
;
import
{
useRouter
}
from
"next/router"
;
import
PopupAlert
from
"@/components/PopupAlert"
;
export
default
function
Login
()
{
export
default
function
Login
()
{
const
router
=
useRouter
();
const
router
=
useRouter
();
const
[
errorMessage
,
setErrorMessage
]
=
useState
(
""
);
const
[
message
,
setMessage
]
=
useState
({
message
:
""
,
error
:
false
});
const
[
successMessage
,
setSuccessMessage
]
=
useState
(
""
);
const
user
=
useContext
(
UserContext
);
const
user
=
useContext
(
UserContext
);
const
[
name
,
setName
]
=
useState
(
""
);
const
[
name
,
setName
]
=
useState
(
""
);
const
[
email
,
setEmail
]
=
useState
(
""
);
const
[
email
,
setEmail
]
=
useState
(
""
);
...
@@ -35,14 +35,14 @@ export default function Login() {
...
@@ -35,14 +35,14 @@ export default function Login() {
name
,
name
,
email
,
email
,
phone
,
phone
,
image
,
photo
:
image
,
username
,
username
,
password
,
password
,
});
});
if
(
response
.
data
.
status
===
201
)
{
if
(
response
.
data
.
status
===
201
)
{
set
SuccessMessage
(
"สมัครสมาชิกสำเร็จ!"
);
set
Message
({
message
:
"สมัครสมาชิกสำเร็จ!"
,
error
:
false
}
);
setTimeout
(()
=>
{
setTimeout
(()
=>
{
set
SuccessMessage
(
""
);
set
Message
({
message
:
""
,
error
:
false
}
);
},
3000
);
},
3000
);
setName
(
""
);
setName
(
""
);
setEmail
(
""
);
setEmail
(
""
);
...
@@ -51,14 +51,20 @@ export default function Login() {
...
@@ -51,14 +51,20 @@ export default function Login() {
setUsername
(
""
);
setUsername
(
""
);
setPassword
(
""
);
setPassword
(
""
);
}
else
if
(
response
.
data
.
status
===
202
)
{
}
else
if
(
response
.
data
.
status
===
202
)
{
setErrorMessage
(
"ชื่อผู้ใช้งานนี้ถูกใช้แล้ว กรุณาลองใหม่อีกครั้ง"
);
setMessage
({
message
:
"ชื่อผู้ใช้งานนี้ถูกใช้แล้ว กรุณาลองใหม่อีกครั้ง"
,
error
:
true
,
});
setTimeout
(()
=>
{
setTimeout
(()
=>
{
set
ErrorMessage
(
""
);
set
Message
({
message
:
""
,
error
:
true
}
);
},
3000
);
},
3000
);
}
else
{
}
else
{
setErrorMessage
(
"ขออภัย มีบางอย่างไม่ถูกต้อง กรุณาลองใหม่อีกครั้ง"
);
setMessage
({
message
:
"ขออภัย มีบางอย่างไม่ถูกต้อง กรุณาลองใหม่อีกครั้ง"
,
error
:
true
,
});
setTimeout
(()
=>
{
setTimeout
(()
=>
{
set
ErrorMessage
(
""
);
set
Message
({
message
:
""
,
error
:
true
}
);
},
3000
);
},
3000
);
}
}
}
}
...
@@ -69,17 +75,10 @@ export default function Login() {
...
@@ -69,17 +75,10 @@ export default function Login() {
<
title
>
สมัครสมาชิก
|
OpenShop
<
/title
>
<
title
>
สมัครสมาชิก
|
OpenShop
<
/title
>
<
/Head
>
<
/Head
>
<
Container
>
<
Container
>
<
Snackbar
<
PopupAlert
ContentProps
=
{{
className
:
"bg-red-500"
}}
isError
=
{
message
.
error
}
anchorOrigin
=
{{
horizontal
:
"center"
,
vertical
:
"top"
}}
message
=
{
message
.
message
}
open
=
{
!!
errorMessage
.
length
}
open
=
{
!!
message
.
message
.
length
}
message
=
{
errorMessage
}
/
>
<
Snackbar
ContentProps
=
{{
className
:
"bg-green-500"
}}
anchorOrigin
=
{{
horizontal
:
"center"
,
vertical
:
"top"
}}
open
=
{
!!
successMessage
.
length
}
message
=
{
successMessage
}
/
>
/
>
<
Grid
container
>
<
Grid
container
>
<
Grid
item
lg
=
{
3
}
md
=
{
0
}
><
/Grid
>
<
Grid
item
lg
=
{
3
}
md
=
{
0
}
><
/Grid
>
...
...
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