Skip to content

Commit 7522bae

Browse files
committed
Update: login page
1 parent 6f192c6 commit 7522bae

File tree

1 file changed

+36
-25
lines changed

1 file changed

+36
-25
lines changed

client/src/pages/Login/index.js

Lines changed: 36 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ const Login = () => {
2828
const fileId = useId();
2929

3030
const [file, setFile] = useState(null);
31+
const [success, setSuccess] = useState(false);
32+
const [failed, setFailed] = useState(false);
3133

3234
const handleLogin = async () => {
3335
try {
@@ -38,8 +40,10 @@ const Login = () => {
3840
const fileData = res.data;
3941

4042
console.log(fileData);
43+
44+
setSuccess(true);
4145
} catch (error) {
42-
console.log(error);
46+
setFailed(true);
4347
}
4448
};
4549

@@ -48,30 +52,37 @@ const Login = () => {
4852
<Typography.Heading level={2} style={{ textAlign: "center" }}>
4953
Đăng nhập
5054
</Typography.Heading>
51-
<div>
52-
<label className={styles.fileWrapper} htmlFor={fileId}>
53-
Tải khóa lên để đăng nhập
54-
</label>
55-
56-
<input
57-
type="file"
58-
id={fileId}
59-
onChange={(event) => setFile(event.target.files[0])}
60-
style={{ display: "none" }}
61-
/>
62-
63-
{file && <Alert>Bạn đã tải lên 1 file</Alert>}
64-
65-
<Divider />
66-
67-
<Button block btnType="primary" disabled={!file} onClick={handleLogin}>
68-
Đăng nhập
69-
</Button>
70-
71-
<Typography.Paragraph style={{ marginTop: 10 }}>
72-
Chưa có tài khoản? <Link to="/register">Đăng ký ngay</Link>
73-
</Typography.Paragraph>
74-
</div>
55+
56+
{success ? (
57+
<Typography.Paragraph>Bạn đã đăng nhập thành công!</Typography.Paragraph>
58+
) : (
59+
<div>
60+
<label className={styles.fileWrapper} htmlFor={fileId}>
61+
Tải khóa lên để đăng nhập
62+
</label>
63+
64+
<input
65+
type="file"
66+
id={fileId}
67+
onChange={(event) => setFile(event.target.files[0])}
68+
style={{ display: "none" }}
69+
/>
70+
71+
{file && <Alert>Bạn đã tải lên 1 file</Alert>}
72+
73+
<Divider />
74+
75+
<Button block btnType="primary" disabled={!file} onClick={handleLogin}>
76+
Đăng nhập
77+
</Button>
78+
79+
<Typography.Paragraph style={{ marginTop: 10 }}>
80+
Chưa có tài khoản? <Link to="/register">Đăng ký ngay</Link>
81+
</Typography.Paragraph>
82+
</div>
83+
)}
84+
85+
{failed && <Alert type="error"></Alert>}
7586
</AuthLayout>
7687
);
7788
};

0 commit comments

Comments
 (0)