Implemented redux integration - profile panel
This commit is contained in:
1 parent
ee08bac389
commit
4edc18a9f4
4 files changed
+63
-22
No files matched your search
@@ -23,18 +23,20 @@ const ProfilePanel = () => {
|
||||
const theme = useTheme();
|
||||
const dispatch = useDispatch();
|
||||
|
||||
const { user, isLoading } = useSelector((state) => state.auth);
|
||||
console.log(user);
|
||||
const { user, authToken, isLoading } = useSelector((state) => state.auth);
|
||||
const idToName = {
|
||||
"edit-first-name": "firstname",
|
||||
"edit-last-name": "lastname",
|
||||
"edit-email": "email",
|
||||
//Disabled for now, will revisit in the future
|
||||
// "edit-email": "email",
|
||||
};
|
||||
const [localData, setLocalData] = useState({
|
||||
firstname: user.firstname,
|
||||
lastname: user.lastname,
|
||||
email: user.email,
|
||||
profilePicUrl: ""
|
||||
//Disabled for now, will revisit in the future
|
||||
// email: user.email,
|
||||
//TODO - upload picture
|
||||
profilePicUrl: "placeholder",
|
||||
});
|
||||
const [errors, setErrors] = useState({});
|
||||
const [isOpen, setIsOpen] = useState(false);
|
||||
@@ -73,13 +75,25 @@ const ProfilePanel = () => {
|
||||
}, 2000);
|
||||
};
|
||||
//TODO - implement update profile function
|
||||
const handleUpdatePicture = () => {};
|
||||
const handleUpdatePicture = () => {
|
||||
setLocalData((prev) => ({ ...prev, profilePicUrl: file }));
|
||||
console.log(localData);
|
||||
};
|
||||
//TODO - implement delete account function
|
||||
const handleDeleteAccount = () => {};
|
||||
//TODO - implement save profile function
|
||||
const handleSaveProfile = (event) => {
|
||||
event.preventDefault();
|
||||
dispatch(update(user._id, localData));
|
||||
if (
|
||||
localData.firstname === user.firstname &&
|
||||
localData.lastname === user.lastname &&
|
||||
localData.profilePicUrl === user.profilePicUrl
|
||||
) {
|
||||
//TODO - add toast(profile data is unchanged) and maybe disable button
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(update({ authToken, localData }));
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -141,18 +155,19 @@ const ProfilePanel = () => {
|
||||
Email
|
||||
</Typography>
|
||||
<Typography variant="h5" component="p">
|
||||
After updating, you'll receive a confirmation email.
|
||||
This is your current email address — it cannot be changed.
|
||||
</Typography>
|
||||
</Stack>
|
||||
<Stack>
|
||||
<EmailTextField
|
||||
id="edit-email"
|
||||
label={null}
|
||||
value={localData.email}
|
||||
value={user.email}
|
||||
placeholder="Enter your email"
|
||||
autoComplete="email"
|
||||
onChange={handleChange}
|
||||
error={errors[idToName["edit-email"]] ? true : false}
|
||||
// onChange={handleChange}
|
||||
// error={errors[idToName["edit-email"]] ? true : false}
|
||||
disabled={true}
|
||||
/>
|
||||
{errors[idToName["edit-email"]] ? (
|
||||
<Typography variant="h5" component="p" className="input-error">
|
||||
@@ -214,7 +229,7 @@ const ProfilePanel = () => {
|
||||
level="primary"
|
||||
label="Save"
|
||||
onClick={handleSaveProfile}
|
||||
isLoading={false}
|
||||
isLoading={isLoading}
|
||||
loadingText="Saving..."
|
||||
disabled={Object.keys(errors).length !== 0 && true}
|
||||
sx={{
|
||||
|
||||
@@ -19,7 +19,8 @@ import { useTheme } from "@mui/material";
|
||||
* @param {React.Element} props.icon - The icon to be displayed in the text field.
|
||||
* @param {string} props.helperText - The helper text to be displayed below the text field.
|
||||
* @param {boolean} props.error - If true, the text field will indicate an error state.
|
||||
*
|
||||
* @param {boolean} props.disabled - If true, the text field will be disabled and cannot be interacted with.
|
||||
*
|
||||
* @example
|
||||
* // To use this component, import it and use it in your JSX like this:
|
||||
* <EmailTextField id="email" variant="outlined" placeholder="Enter your email" />
|
||||
@@ -38,6 +39,7 @@ const EmailTextField = ({
|
||||
icon,
|
||||
helperText,
|
||||
error,
|
||||
disabled
|
||||
}) => {
|
||||
const theme = useTheme();
|
||||
|
||||
@@ -65,6 +67,7 @@ const EmailTextField = ({
|
||||
variant={variant}
|
||||
placeholder={placeholder}
|
||||
autoComplete={autoComplete}
|
||||
disabled={disabled}
|
||||
InputProps={{
|
||||
endAdornment: (
|
||||
<InputAdornment position="end">
|
||||
@@ -81,7 +84,7 @@ const EmailTextField = ({
|
||||
style={{ fill: "red", width: "16px", height: "16px" }}
|
||||
/>
|
||||
)}
|
||||
{!error && showIcon && (
|
||||
{!error && showIcon && !disabled && (
|
||||
<HelpOutlineIcon
|
||||
className="text-field-icon"
|
||||
style={{ width: "16px", height: "16px" }}
|
||||
|
||||
Reference in new issue
Block a user