Refactored code to make it more reusable

This commit is contained in:
Daniel Cojocea committed 2024-06-16 18:45:21 -04:00
1 parent fd4c5436bd
commit f9852c19d5
2 files changed
+61 -96

No files matched your search

+10 -4
View File
@@ -1,7 +1,11 @@
.edit-profile-form, .delete-profile-form{ .edit-profile-form,
.edit-password-form,
.delete-profile-form {
width: inherit; width: inherit;
} }
.edit-profile-form__wrapper, .delete-profile-form__wrapper{ .edit-profile-form__wrapper,
.delete-profile-form__wrapper,
.edit-password-form__wrapper {
width: 90%; width: 90%;
display: flex; display: flex;
@@ -9,10 +13,12 @@
justify-content: space-between; justify-content: space-between;
align-items: flex-start; align-items: flex-start;
} }
.edit-profile-form__wrapper:not(:first-of-type){ .edit-profile-form__wrapper:not(:first-of-type),
.edit-password-form__wrapper:not(:first-of-type) {
margin-top: 40px; margin-top: 40px;
} }
.edit-profile-form__wrapper input{ .edit-profile-form__wrapper input,
.edit-password-form__wrapper input {
font-size: 13px; font-size: 13px;
padding: 10px; padding: 10px;
} }
+51 -92
View File
@@ -20,6 +20,30 @@ import ButtonSpinner from "../../Components/ButtonSpinner";
import Button from "../../Components/Button"; import Button from "../../Components/Button";
const tabList = ["Profile", "Password", "Team"]; const tabList = ["Profile", "Password", "Team"];
const profileConfig = {
firstName: {
id: "edit-first-name",
label: "First name",
type: "input",
},
lastName: {
id: "edit-last-name",
label: "Last name",
type: "input",
},
email: {
id: "edit-email",
label: "Email",
description: "After updating, you'll receive a confirmation email.",
type: "input",
},
photo: {
id: "edit-photo",
label: "Your photo",
description: "This photo will be displayed in your profile page.",
type: "photo",
},
};
const Settings = () => { const Settings = () => {
//(tab) 0 - Profile //(tab) 0 - Profile
@@ -95,94 +119,8 @@ const Settings = () => {
sx={{ padding: "0", marginTop: theme.spacing(6.25), width: "100%" }} sx={{ padding: "0", marginTop: theme.spacing(6.25), width: "100%" }}
> >
<form className="edit-profile-form" noValidate spellCheck="false"> <form className="edit-profile-form" noValidate spellCheck="false">
<div className="edit-profile-form__wrapper"> {Object.entries(profileConfig).map(([key, field]) => (
<Typography <div className="edit-profile-form__wrapper" key={key}>
variant="h4"
component="h1"
sx={{
flex: 1,
color: theme.palette.secondary.main,
fontSize: "13px",
fontWeight: "600",
marginRight: "10px",
}}
>
First name
</Typography>
<TextField
id="edit-first-name"
placeholder="Enter your first name"
sx={{
flex: 1,
minWidth: theme.spacing(30),
}}
></TextField>
</div>
<div className="edit-profile-form__wrapper">
<Typography
variant="h4"
component="h1"
sx={{
flex: 1,
color: theme.palette.secondary.main,
fontSize: "13px",
fontWeight: "600",
marginRight: "10px",
}}
>
Last name
</Typography>
<TextField
id="edit-last-name"
placeholder="Enter your last name"
sx={{
flex: 1,
minWidth: theme.spacing(30),
}}
></TextField>
</div>
<div className="edit-profile-form__wrapper">
<Stack
direction="column"
gap="8px"
sx={{
flex: 1,
marginRight: "10px",
}}
>
<Typography
variant="h4"
component="h1"
sx={{
color: theme.palette.secondary.main,
fontSize: "13px",
fontWeight: "600",
}}
>
Email
</Typography>
<Typography
variant="h4"
component="p"
sx={{
color: theme.palette.secondary.main,
opacity: 0.6,
fontSize: "13px",
}}
>
After updating, you'll receive a confirmation email.
</Typography>
</Stack>
<TextField
id="edit-email"
placeholder="Enter your email"
sx={{
flex: 1,
minWidth: theme.spacing(30),
}}
></TextField>
</div>
<div className="edit-profile-form__wrapper">
<Stack <Stack
direction="column" direction="column"
gap="8px" gap="8px"
@@ -197,10 +135,11 @@ const Settings = () => {
fontWeight: "600", fontWeight: "600",
}} }}
> >
Your photo {field.label}
</Typography> </Typography>
{field ? (
<Typography <Typography
variant="h4" variant="h5"
component="p" component="p"
sx={{ sx={{
color: theme.palette.secondary.main, color: theme.palette.secondary.main,
@@ -208,9 +147,22 @@ const Settings = () => {
fontSize: "13px", fontSize: "13px",
}} }}
> >
This photo will be displayed in your profile page. {field.description}
</Typography> </Typography>
) : (
""
)}
</Stack> </Stack>
{field.type === "input" ? (
<TextField
id={field.id}
placeholder={`Enter your ${field.label.toLowerCase()}`}
sx={{
flex: 1,
minWidth: theme.spacing(30),
}}
></TextField>
) : field.type === "photo" ? (
<Stack direction="row" alignItems="center" sx={{ flex: 1 }}> <Stack direction="row" alignItems="center" sx={{ flex: 1 }}>
{/* TODO - Use Avatar component instead of @mui */} {/* TODO - Use Avatar component instead of @mui */}
<Avatar <Avatar
@@ -247,7 +199,11 @@ const Settings = () => {
}} }}
/> />
</Stack> </Stack>
) : (
""
)}
</div> </div>
))}
</form> </form>
<Divider sx={{ marginY: theme.spacing(6.25) }} /> <Divider sx={{ marginY: theme.spacing(6.25) }} />
<form className="delete-profile-form" noValidate spellCheck="false"> <form className="delete-profile-form" noValidate spellCheck="false">
@@ -293,7 +249,10 @@ const Settings = () => {
</div> </div>
</form> </form>
</TabPanel> </TabPanel>
<TabPanel value="1">Password</TabPanel> <TabPanel
value="1"
sx={{ padding: "0", marginTop: theme.spacing(6.25), width: "100%" }}
></TabPanel>
<TabPanel value="2">Team</TabPanel> <TabPanel value="2">Team</TabPanel>
</TabContext> </TabContext>
{/* TODO - Update ModalPopup Component with @mui for reusability */} {/* TODO - Update ModalPopup Component with @mui for reusability */}