Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
fix: added tsx files
Browse files
frontend/src/components/shared/AuthContainer.tsx
ADDED
@@ -0,0 +1,150 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React from "react";
|
2 |
+
import {
|
3 |
+
Box,
|
4 |
+
Typography,
|
5 |
+
Button,
|
6 |
+
Chip,
|
7 |
+
Stack,
|
8 |
+
Paper,
|
9 |
+
CircularProgress,
|
10 |
+
} from "@mui/material";
|
11 |
+
import HFLogo from "../Logo/HFLogo";
|
12 |
+
import { useAuth } from "../../hooks/useAuth";
|
13 |
+
import LogoutIcon from "@mui/icons-material/Logout";
|
14 |
+
import { useNavigate } from "react-router-dom";
|
15 |
+
import { useTranslation, declareComponentKeys } from "i18n";
|
16 |
+
|
17 |
+
function AuthContainer({ actionText = "DO_ACTION" }) {
|
18 |
+
const { isAuthenticated, user, login, logout, loading } = useAuth();
|
19 |
+
const navigate = useNavigate();
|
20 |
+
const {t} = useTranslation({AuthContainer});
|
21 |
+
|
22 |
+
const handleLogout = () => {
|
23 |
+
if (isAuthenticated && logout) {
|
24 |
+
logout();
|
25 |
+
navigate("/", { replace: true });
|
26 |
+
window.location.reload();
|
27 |
+
}
|
28 |
+
};
|
29 |
+
|
30 |
+
if (loading) {
|
31 |
+
return (
|
32 |
+
<Paper
|
33 |
+
elevation={0}
|
34 |
+
sx={{
|
35 |
+
p: 3,
|
36 |
+
mb: 4,
|
37 |
+
border: "1px solid",
|
38 |
+
borderColor: "grey.300",
|
39 |
+
display: "flex",
|
40 |
+
flexDirection: "column",
|
41 |
+
alignItems: "center",
|
42 |
+
gap: 2,
|
43 |
+
}}
|
44 |
+
>
|
45 |
+
<CircularProgress size={24} />
|
46 |
+
</Paper>
|
47 |
+
);
|
48 |
+
}
|
49 |
+
|
50 |
+
if (!isAuthenticated) {
|
51 |
+
return (
|
52 |
+
<Paper
|
53 |
+
elevation={0}
|
54 |
+
sx={{
|
55 |
+
p: 3,
|
56 |
+
mb: 4,
|
57 |
+
border: "1px solid",
|
58 |
+
borderColor: "grey.300",
|
59 |
+
display: "flex",
|
60 |
+
flexDirection: "column",
|
61 |
+
alignItems: "center",
|
62 |
+
gap: 2,
|
63 |
+
}}
|
64 |
+
>
|
65 |
+
<Typography variant="h6" align="center">
|
66 |
+
{t("login")}
|
67 |
+
</Typography>
|
68 |
+
<Typography variant="body2" color="text.secondary" align="center">
|
69 |
+
{t("need")}
|
70 |
+
</Typography>
|
71 |
+
<Button
|
72 |
+
variant="contained"
|
73 |
+
onClick={login}
|
74 |
+
startIcon={
|
75 |
+
<Box
|
76 |
+
sx={{
|
77 |
+
width: 20,
|
78 |
+
height: 20,
|
79 |
+
display: "flex",
|
80 |
+
alignItems: "center",
|
81 |
+
}}
|
82 |
+
>
|
83 |
+
<HFLogo />
|
84 |
+
</Box>
|
85 |
+
}
|
86 |
+
sx={{
|
87 |
+
textTransform: "none",
|
88 |
+
fontWeight: 600,
|
89 |
+
py: 1,
|
90 |
+
px: 2,
|
91 |
+
}}
|
92 |
+
>
|
93 |
+
{t("button")}
|
94 |
+
</Button>
|
95 |
+
</Paper>
|
96 |
+
);
|
97 |
+
}
|
98 |
+
|
99 |
+
return (
|
100 |
+
<Paper
|
101 |
+
elevation={0}
|
102 |
+
sx={{ p: 2, border: "1px solid", borderColor: "grey.300", mb: 4 }}
|
103 |
+
>
|
104 |
+
<Stack
|
105 |
+
direction="row"
|
106 |
+
spacing={2}
|
107 |
+
alignItems="center"
|
108 |
+
justifyContent="space-between"
|
109 |
+
>
|
110 |
+
<Stack direction="row" spacing={1} alignItems="center">
|
111 |
+
<Typography variant="body1">
|
112 |
+
{t("loggedin", {user: (user !== null ? user!['username'] : "inconnu")})}
|
113 |
+
Connected as <strong>{user!['username']}</strong>
|
114 |
+
</Typography>
|
115 |
+
<Chip
|
116 |
+
label={`Ready to ${actionText}`}
|
117 |
+
color="success"
|
118 |
+
size="small"
|
119 |
+
variant="outlined"
|
120 |
+
/>
|
121 |
+
</Stack>
|
122 |
+
<Button
|
123 |
+
variant="contained"
|
124 |
+
onClick={handleLogout}
|
125 |
+
endIcon={<LogoutIcon />}
|
126 |
+
color="primary"
|
127 |
+
sx={{
|
128 |
+
minWidth: 120,
|
129 |
+
height: 36,
|
130 |
+
textTransform: "none",
|
131 |
+
fontSize: "0.9375rem",
|
132 |
+
}}
|
133 |
+
>
|
134 |
+
{t("logout")}
|
135 |
+
</Button>
|
136 |
+
</Stack>
|
137 |
+
</Paper>
|
138 |
+
);
|
139 |
+
}
|
140 |
+
|
141 |
+
const { i18n } = declareComponentKeys<
|
142 |
+
| "login"
|
143 |
+
| "need"
|
144 |
+
| "logout"
|
145 |
+
| "button"
|
146 |
+
| { K: "loggedin"; P: { user: string; }; R: JSX.Element }
|
147 |
+
>()({ AuthContainer });
|
148 |
+
export type I18n = typeof i18n;
|
149 |
+
|
150 |
+
export default AuthContainer;
|
frontend/src/pages/AddModelPage/AddModelPage.tsx
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import React from "react";
|
2 |
+
import { Box, CircularProgress } from "@mui/material";
|
3 |
+
import { useAuth } from "../../hooks/useAuth";
|
4 |
+
import PageHeader from "../../components/shared/PageHeader";
|
5 |
+
import EvaluationQueues from "./components/EvaluationQueues/EvaluationQueues";
|
6 |
+
import ModelSubmissionForm from "./components/ModelSubmissionForm/ModelSubmissionForm";
|
7 |
+
import SubmissionGuide from "./components/SubmissionGuide/SubmissionGuide";
|
8 |
+
import { useTranslation, declareComponentKeys } from "i18n";
|
9 |
+
|
10 |
+
function AddModelPage() {
|
11 |
+
const { isAuthenticated, loading, user } = useAuth();
|
12 |
+
const {t} = useTranslation({AddModelPage});
|
13 |
+
|
14 |
+
if (loading) {
|
15 |
+
return (
|
16 |
+
<Box
|
17 |
+
sx={{
|
18 |
+
display: "flex",
|
19 |
+
justifyContent: "center",
|
20 |
+
alignItems: "center",
|
21 |
+
height: "100vh",
|
22 |
+
}}
|
23 |
+
>
|
24 |
+
<CircularProgress />
|
25 |
+
</Box>
|
26 |
+
);
|
27 |
+
}
|
28 |
+
|
29 |
+
return (
|
30 |
+
<Box sx={{ width: "100%", maxWidth: 1200, margin: "0 auto", padding: 4 }}>
|
31 |
+
<PageHeader
|
32 |
+
title={t("title")}
|
33 |
+
subtitle={
|
34 |
+
<>
|
35 |
+
{t("subtitle")}
|
36 |
+
</>
|
37 |
+
}
|
38 |
+
/>
|
39 |
+
|
40 |
+
<SubmissionGuide />
|
41 |
+
|
42 |
+
<ModelSubmissionForm user={user} isAuthenticated={isAuthenticated} />
|
43 |
+
|
44 |
+
<EvaluationQueues defaultExpanded={false} />
|
45 |
+
</Box>
|
46 |
+
);
|
47 |
+
}
|
48 |
+
|
49 |
+
const { i18n } = declareComponentKeys<
|
50 |
+
| "title"
|
51 |
+
| "subtitle"
|
52 |
+
>()({ AddModelPage });
|
53 |
+
export type I18n = typeof i18n;
|
54 |
+
|
55 |
+
export default AddModelPage;
|