Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 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 | import { Avatar, Box, Button, Card, Chip, Divider, Skeleton, Stack, Typography } from "@mui/material";
import "./AccountSettings.scss";
import { useSelector } from "react-redux";
import { useState } from "react";
import ChangePhoto from "@/app/teacher-page/components/settings/ChangePhoto";
import ChangeName from "@/app/teacher-page/components/settings/ChangeName";
import ChangePassword from "@/app/teacher-page/components/settings/ChangePassword";
import { useTheme } from "@mui/material/styles";
import { getTimeZoneName } from "@/utils/helpers/getTimeZoneName";
import { formatProfileDisplayName } from "@/utils/helpers/organizationDisplay";
import OrganizationSettingsFields from "@/utils/components/profile/OrganizationSettingsFields";
function AccountSettingsSkeleton() {
return (
<div className="teacher-account-settings">
<Card variant="outlined" elevation={0} sx={{ borderRadius: "16px", p: 3 }}>
<Stack
direction={{ xs: "column", sm: "row" }}
spacing={2.5}
alignItems={{ xs: "flex-start", sm: "center" }}
>
<Skeleton variant="circular" width={85} height={85} animation="wave" />
<Box sx={{ flex: 1, minWidth: 0 }}>
<Skeleton variant="text" width="40%" height={28} animation="wave" />
<Skeleton variant="rounded" width={70} height={22} animation="wave" sx={{ mt: 0.5 }} />
</Box>
<Skeleton variant="rounded" width={140} height={36} animation="wave" />
</Stack>
</Card>
<Card variant="outlined" elevation={0} sx={{ borderRadius: "16px" }}>
{[0, 1, 2, 3].map((i) => (
<Box key={i}>
<div className="settings-item">
<div className="item-content">
<Skeleton variant="text" width={90} animation="wave" />
<Skeleton variant="text" width={160} animation="wave" />
</div>
<div className="item-actions">
<Skeleton variant="rounded" width={130} height={36} animation="wave" />
</div>
</div>
{i < 3 && <Divider />}
</Box>
))}
</Card>
</div>
);
}
const AccountSettings = () => {
const theme = useTheme();
const { teacherData, isLoading } = useSelector((state) => state.TeacherData);
const [photoDialog, setPhotoDialog] = useState(false);
const [localPhotoUrl, setLocalPhotoUrl] = useState(null);
const [nameDialog, setNameDialog] = useState(false);
const [passwordDialog, setPasswordDialog] = useState(false);
const fullName = teacherData
? formatProfileDisplayName(
`${teacherData.first_name} ${teacherData.middle_name ?? ""} ${teacherData.last_name}`
.replace(/\s+/g, " ")
.trim()
)
: "";
return (
<div>
{isLoading && <AccountSettingsSkeleton />}
{teacherData && (
<div className="teacher-account-settings">
<ChangePhoto
showDialog={photoDialog}
setShowDialog={setPhotoDialog}
onPhotoUpdated={setLocalPhotoUrl}
/>
<ChangeName showDialog={nameDialog} setShowDialog={setNameDialog} />
<ChangePassword showDialog={passwordDialog} setShowDialog={setPasswordDialog} />
<Card variant="outlined" elevation={0} sx={{ borderRadius: "16px", p: 3 }}>
<Stack
direction={{ xs: "column", sm: "row" }}
spacing={2.5}
alignItems={{ xs: "flex-start", sm: "center" }}
>
{localPhotoUrl || teacherData.profile_picture ? (
<Box
component="img"
src={localPhotoUrl || teacherData.profile_picture}
alt=""
sx={{ width: 85, height: 85, objectFit: "cover", borderRadius: "50%" }}
/>
) : (
<Avatar
sx={{
width: 85,
height: 85,
bgcolor: theme.palette.primary.main,
color: theme.palette.primary.contrastText,
}}
>
{(teacherData.first_name?.charAt(0) ?? "") +
(teacherData.last_name?.charAt(0) ?? "")}
</Avatar>
)}
<Box sx={{ flex: 1, minWidth: 0 }}>
<Typography noWrap title={fullName}>
{fullName}
</Typography>
<Chip label="Teacher" size="small" variant="soft" color="primary" sx={{ mt: 0.5 }} />
</Box>
<Button
id="teacher-settings-btn-change-photo"
variant="outlined"
color="primary"
onClick={() => setPhotoDialog(true)}
>
Edit Photo
</Button>
</Stack>
</Card>
<Card variant="outlined" elevation={0} sx={{ borderRadius: "16px" }}>
<div className="settings-item">
<div className="item-content">
<Typography color="text.secondary">Name:</Typography>
<Typography color="text.primary">{fullName}</Typography>
</div>
<div className="item-actions">
<Button variant="outlined" color="primary" onClick={() => setNameDialog(true)}>
Change Name
</Button>
</div>
</div>
<Divider />
<OrganizationSettingsFields userData={teacherData} userType="teacher" />
<div className="settings-item">
<div className="item-content">
<Typography color="text.secondary">Email:</Typography>
<Typography color="text.primary">{teacherData.email}</Typography>
</div>
<div className="item-actions"></div>
</div>
<Divider />
<div className="settings-item">
<div className="item-content">
<Typography color="text.secondary">Password:</Typography>
<Typography color="text.primary">••••••</Typography>
</div>
<div className="item-actions">
<Button
id="teacher-settings-btn-change-password"
variant="outlined"
color="primary"
onClick={() => setPasswordDialog(true)}
>
Change Password
</Button>
</div>
</div>
<Divider />
<div className="settings-item">
<div className="item-content">
<Typography variant="subtitle2" color="text.secondary">
Time Zone:
</Typography>
<Typography color="text.primary">{getTimeZoneName()}</Typography>
</div>
<div className="item-actions"></div>
</div>
</Card>
</div>
)}
</div>
);
};
export default AccountSettings;
|