Skip to content

Commit c4c3664

Browse files
committed
Refactor code
1 parent 34dd2ff commit c4c3664

File tree

17 files changed

+80
-195
lines changed

17 files changed

+80
-195
lines changed

frontend/package-lock.json

Lines changed: 0 additions & 140 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
"markdown-to-jsx": "^7.5.0",
2626
"react": "^18.3.1",
2727
"react-dom": "^18.3.1",
28-
"react-loader-spinner": "^6.1.6",
2928
"react-router-dom": "^6.26.2",
3029
"react-toastify": "^10.0.5",
3130
"vite-plugin-svgr": "^4.2.0"

frontend/src/components/AppMargin/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Box } from "@mui/material";
2-
import { ToastContainer } from "react-toastify";
32

43
type AppMarginProps = { classname?: string; children: React.ReactNode };
54

@@ -14,7 +13,6 @@ const AppMargin: React.FC<AppMarginProps> = (props) => {
1413
})}
1514
>
1615
{children}
17-
<ToastContainer position="bottom-right" />
1816
</Box>
1917
);
2018
};

frontend/src/components/CustomTextField/index.tsx

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
11
import { Visibility, VisibilityOff } from "@mui/icons-material";
2-
import { IconButton, InputAdornment, TextField, TextFieldPropsSizeOverrides, TextFieldVariants } from "@mui/material";
2+
import { IconButton, InputAdornment, TextField, TextFieldPropsSizeOverrides, TextFieldVariants, Tooltip } from "@mui/material";
33
import { OverridableStringUnion } from '@mui/types';
44
import { useState } from "react";
55

6+
const passwordRequirements = (
7+
<ul style={{ paddingLeft: "12px", margin: 0 }}>
8+
<li>At least 8 characters long</li>
9+
<li>At least 1 lowercase letter</li>
10+
<li>At least 1 uppercase letter</li>
11+
<li>At least 1 digit</li>
12+
<li>At least 1 special character</li>
13+
</ul>
14+
);
15+
616
// Adapted from https://muhimasri.com/blogs/mui-validation/
717
type CustomTextFieldProps = {
818
label: string;
@@ -41,27 +51,30 @@ const CustomTextField: React.FC<CustomTextFieldProps> = ({
4151
};
4252

4353
return (
44-
<TextField
45-
label={label}
46-
variant={variant}
47-
size={size}
48-
required={required}
49-
onChange={handleChange}
50-
error={(required && emptyField) || !!error}
51-
helperText={error}
52-
type={showPassword ? "text" : "password"}
53-
slotProps={{
54-
input: {
55-
endAdornment: isPasswordField && (
56-
<InputAdornment position="end">
57-
<IconButton onClick={() => setShowPassword(!showPassword)} edge="end">
58-
{showPassword ? <VisibilityOff /> : <Visibility />}
59-
</IconButton>
60-
</InputAdornment>
61-
),
62-
}
63-
}}
64-
/>
54+
<Tooltip title={isPasswordField && passwordRequirements} placement="right" arrow>
55+
<TextField
56+
label={label}
57+
variant={variant}
58+
size={size}
59+
fullWidth
60+
required={required}
61+
onChange={handleChange}
62+
error={(required && emptyField) || !!error}
63+
helperText={error}
64+
type={showPassword ? "text" : "password"}
65+
slotProps={{
66+
input: {
67+
endAdornment: isPasswordField && (
68+
<InputAdornment position="end">
69+
<IconButton onClick={() => setShowPassword(!showPassword)} edge="end">
70+
{showPassword ? <VisibilityOff /> : <Visibility />}
71+
</IconButton>
72+
</InputAdornment>
73+
),
74+
}
75+
}}
76+
/>
77+
</Tooltip>
6578
);
6679
};
6780

frontend/src/components/Layout/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import { Box } from "@mui/material";
22
import { Outlet } from "react-router-dom";
33
import Navbar from "../Navbar";
4+
import { ToastContainer } from "react-toastify";
5+
import 'react-toastify/dist/ReactToastify.css';
46

57
const Layout: React.FC = () => {
68
return (
@@ -15,6 +17,7 @@ const Layout: React.FC = () => {
1517
>
1618
<Navbar />
1719
<Outlet />
20+
<ToastContainer position="bottom-right" />
1821
</Box>
1922
);
2023
};

frontend/src/components/Loader/index.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Box, Typography } from "@mui/material";
2-
import { Oval } from "react-loader-spinner";
1+
import { Box, CircularProgress, Typography } from "@mui/material";
32

43
const Loader: React.FC = () => {
54
return (
@@ -13,12 +12,7 @@ const Loader: React.FC = () => {
1312
justifyContent: "center",
1413
}}
1514
>
16-
<Oval
17-
height="80"
18-
width="80"
19-
color="#8FB8ED"
20-
secondaryColor="#9E9E9E"
21-
/>
15+
<CircularProgress color="primary" size="80px" />
2216
<Typography
2317
variant="h4"
2418
sx={(theme) => ({ marginTop: theme.spacing(2) })}

frontend/src/components/QuestionImage/index.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { Box, ImageListItem, IconButton } from "@mui/material";
22
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
33
import FullscreenIcon from "@mui/icons-material/Fullscreen";
4-
54
import { toast } from "react-toastify";
6-
import "react-toastify/dist/ReactToastify.css";
75

86
interface QuestionImageProps {
97
url: string;

frontend/src/components/QuestionImageContainer/index.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { toast } from "react-toastify";
88
import { createImageUrls } from "../../reducers/questionReducer";
99
import QuestionImage from "../QuestionImage";
1010
import QuestionImageDialog from "../QuestionImageDialog";
11+
import { FAILED_FILE_UPLOAD, SUCCESS_FILE_UPLOAD } from "../../utils/constants";
1112

1213
interface QuestionImageContainerProps {
1314
uploadedImagesUrl: string[];
@@ -69,9 +70,9 @@ const QuestionImageContainer: React.FC<QuestionImageContainerProps> = ({
6970
for (const imageUrl of res.imageUrls) {
7071
setUploadedImagesUrl((prev) => [...prev, imageUrl]);
7172
}
72-
toast.success("File uploaded successfully");
73+
toast.success(SUCCESS_FILE_UPLOAD);
7374
} else {
74-
toast.error("Error uploading file");
75+
toast.error(FAILED_FILE_UPLOAD);
7576
}
7677
});
7778
};

frontend/src/contexts/AuthContext.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { userClient } from "../utils/api";
55
import { useNavigate } from "react-router-dom";
66
import { toast } from "react-toastify";
77
import Loader from "../components/Loader";
8+
import { SUCCESS_LOG_OUT } from "../utils/constants";
89

910
type User = {
1011
id: string;
@@ -100,7 +101,7 @@ const AuthProvider: React.FC<{ children?: React.ReactNode }> = (props) => {
100101
localStorage.removeItem("token");
101102
setUser(null);
102103
navigate("/");
103-
toast.success("Logged out successfully!");
104+
toast.success(SUCCESS_LOG_OUT);
104105
};
105106

106107
if (loading) {

frontend/src/pages/LogIn/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useAuth } from "../../contexts/AuthContext";
66
import CustomTextField from "../../components/CustomTextField";
77
import { emailValidator } from "../../utils/validators";
88
import { ToastContainer } from "react-toastify";
9+
import 'react-toastify/dist/ReactToastify.css';
910

1011
const LogIn: React.FC = () => {
1112
const navigate = useNavigate();

0 commit comments

Comments
 (0)