-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProfilePage.tsx
255 lines (209 loc) · 10.8 KB
/
ProfilePage.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
import React, {useEffect, useState} from 'react';
import Avatar from '@mui/material/Avatar';
import Button from '@mui/material/Button';
import Paper from '@mui/material/Paper';
import Typography from '@mui/material/Typography';
import SettingsIcon from '@mui/icons-material/Settings';
import EmojiEvents from '@mui/icons-material/EmojiEvents';
import {CardActions, Container, Grid, IconButton, LinearProgress, useMediaQuery} from "@mui/material";
import './profile_page.scss'
import UserProfileSettings from "./UserProfileSettings";
import {Helmet} from "react-helmet-async";
import {ProfilePageProps} from "../../types/types";
import {useTheme} from "@mui/system";
import {makeStyles} from "tss-react/mui";
import {useAuth} from "../AuthContext/AuthContext";
import {useNavigate} from "react-router-dom";
import AchievedItem from "./AchievedItem";
import AnchorIcon from '@mui/icons-material/Anchor';
import CelebrationIcon from '@mui/icons-material/Celebration';
import RocketIcon from '@mui/icons-material/Rocket';
import MilitaryTechIcon from '@mui/icons-material/MilitaryTech';
import StarIcon from '@mui/icons-material/Star';
import Preloader from "../Preloader/Preloader";
import ChangePasswordForm from "./ChangePasswordForm";
import ResetAchievementsButton from "./ResetAchievementsButton";
import ArrowForwardIosIcon from '@mui/icons-material/ArrowForwardIos';
const useStyles = makeStyles()((theme) => ({
levelCounter: {
background: theme.palette.primary.light,
fontWeight: 800,
},
}))
const ProfilePage: React.FC<ProfilePageProps> = ({
username,
avatar,
lessonsVisited,
achievementLevel,
achievements,
historyList,
achievedList,
isLoading,
currentUserDate
}) => {
const {isAuthenticated,deleteProfile} = useAuth();
const navigate = useNavigate();
useEffect(() => {
if (!isAuthenticated) {
navigate("/");
}
}, [isAuthenticated])
const [openSettings, setOpenSettings] = useState(false);
const handleOpenSettings = () => {
setOpenSettings(true);
};
const handleCloseSettings = () => {
setOpenSettings(false);
};
const progress = Math.round(historyList.length / 100 * lessonsVisited);
const progressAnswer = 30;
const {cx, classes} = useStyles();
let achievementIconArray = [
EmojiEvents,
AnchorIcon,
CelebrationIcon,
RocketIcon,
MilitaryTechIcon,
StarIcon,
EmojiEvents,
EmojiEvents,
EmojiEvents,
]
const achievementActiveCount = 3;
const theme = useTheme();
const mdUp = useMediaQuery(theme.breakpoints.up('md'))
const smUp = useMediaQuery(theme.breakpoints.up('sm'))
const handleDeleteProfile = async () => {
if (window.confirm("Are you sure you want to delete your profile? This action cannot be undone.")) {
await deleteProfile();
}
};
return (
<Container className={"profile_container"}>
<Helmet>
<title>Профіль</title>
</Helmet>
{isLoading ? (
<Preloader/>
) :
<Grid spacing={mdUp ? 2 : 0} container direction={mdUp ? "row-reverse" : "row"}>
<Grid item xs={12} md={9} lg={9}>
<Paper className={"profile_block"} elevation={3}>
<Avatar className={"profile_block_avatar"} alt={username} src={avatar}
sx={{width: 100, height: 100, margin: 'auto'}}/>
<Typography variant={mdUp ? "h4" : "h5"} className={"username"}>
{username}
</Typography>
<Grid gap={2} className={"level_container"} container alignItems={"center"}
justifyContent={"center"}>
<Grid item>
{/*<KeyboardDoubleArrowUpIcon className={"block_icon"}/>*/}
<Avatar className={cx(classes.levelCounter)}> {lessonsVisited}</Avatar>
</Grid>
<Grid item>
<Typography variant="subtitle1" color="text.secondary">
Рівень
</Typography>
</Grid>
</Grid>
<Grid container alignItems={"center"} justifyContent={"center"}>
<Paper className={"time_location_container"}>
<Grid item container xs={"auto"} alignItems={"center"}>
<Grid item xs={"auto"} lg={"auto"}>
<Typography className={"time_label"}>Локація у часі:</Typography>
</Grid>
<Grid item xs={"auto"} lg={"auto"}>
<Typography className={"time"} variant={"h6"} color="text.secondary"
sx={{marginTop: '5px'}}>
{currentUserDate}
</Typography>
</Grid>
<Grid item xs={"auto"} lg={"auto"}>
<IconButton>
<ArrowForwardIosIcon/>
</IconButton>
</Grid>
</Grid>
</Paper>
</Grid>
<Grid className={"profile_progress_panel_container"} container alignItems={"center"}
justifyContent={"center"} spacing={mdUp ? 2 : 0}>
<Grid item xs={12} md={6} className={"profile_progress_item"}>
<Typography variant={mdUp ? "h6" : "subtitle1"}>Прогресс на поточному
рівні</Typography>
<Typography variant={mdUp ? "h6" : "body1"}
color="text.secondary">{progressAnswer + "%"}</Typography>
<LinearProgress
color={"primary"}
value={progressAnswer}
variant={"determinate"}
/>
</Grid>
<Grid item xs={12} md={6} className={"profile_progress_item"}>
<Typography variant={mdUp ? "h6" : "subtitle1"}>Загальний прогресс</Typography>
<Typography variant={mdUp ? "h6" : "body1"}
color="text.secondary">{progress + "%"}</Typography>
<LinearProgress
color={"primary"}
value={progress}
variant={"determinate"}
/>
</Grid>
</Grid>
<div className="achievement_container">
<Typography variant={"h5"}>
Ваші знахідки
</Typography>
<Grid container className={"achievement_icon_list"}>
{achievedList.map(({name, description}, index) => (
<AchievedItem key={index + "achievedList"} icon={achievementIconArray[index]}
name={name} description={description}
active={achievementActiveCount > index}/>
))}
</Grid>
</div>
<ResetAchievementsButton/>
</Paper>
</Grid>
<Grid item xs={12} md={3} lg={3}>
{(!mdUp && !openSettings) && <Button
className={"settings_button"}
fullWidth
variant="outlined"
color={"primary"}
onClick={handleOpenSettings}
startIcon={<SettingsIcon/>}
>
Налаштування
</Button>
}
{(openSettings || mdUp) && (
<Paper className={"profile_block profile_block_settings"} elevation={3}>
{!mdUp && <Grid container justifyContent={"flex-end"}>
<Grid item>
<Button onClick={handleCloseSettings}>Close Settings</Button>
</Grid>
</Grid>}
<UserProfileSettings/>
<ChangePasswordForm/>
</Paper>
)}
<Grid container justifyContent={"flex-end"}>
<Grid item lg={12}>
<Button
fullWidth
variant="outlined"
color="secondary"
onClick={handleDeleteProfile}
>
Видалити профіль
</Button>
</Grid>
</Grid>
</Grid>
</Grid>}
{/* Modal for Settings */}
</Container>
);
};
export default ProfilePage;