compelete design of edit profile and change password components
This commit is contained in:
65
src/core/components/Profile/ChangePass/Form.jsx
Normal file
65
src/core/components/Profile/ChangePass/Form.jsx
Normal file
@@ -0,0 +1,65 @@
|
|||||||
|
"use client";
|
||||||
|
|
||||||
|
import { Chip, Divider, Grid, TextField } from "@mui/material";
|
||||||
|
import StyledForm from "@/core/components/StyledForm";
|
||||||
|
import { useForm } from "react-hook-form";
|
||||||
|
|
||||||
|
const Form = () => {
|
||||||
|
const defaultValues = {
|
||||||
|
old_password: "",
|
||||||
|
new_password: "",
|
||||||
|
repeat_new_password: "",
|
||||||
|
};
|
||||||
|
|
||||||
|
const {
|
||||||
|
control,
|
||||||
|
watch,
|
||||||
|
register,
|
||||||
|
handleSubmit,
|
||||||
|
setValue,
|
||||||
|
formState: { isSubmitting },
|
||||||
|
} = useForm({ defaultValues: defaultValues });
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Divider sx={{ mb: 3 }}>
|
||||||
|
<Chip color="primary" variant="outlined" label="تغییر رمز عبور" />
|
||||||
|
</Divider>
|
||||||
|
<StyledForm id={"ChangePassword"}>
|
||||||
|
<Grid container columns={{ xs: 1, sm: 3 }} spacing={2}>
|
||||||
|
<Grid item xs={1}>
|
||||||
|
<TextField
|
||||||
|
autoComplete="off"
|
||||||
|
{...register("old_password")}
|
||||||
|
label="رمز عبور فعلی"
|
||||||
|
size="small"
|
||||||
|
fullWidth
|
||||||
|
type="text"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={1}>
|
||||||
|
<TextField
|
||||||
|
autoComplete="off"
|
||||||
|
{...register("new_password")}
|
||||||
|
label="رمز عبور جدید"
|
||||||
|
size="small"
|
||||||
|
fullWidth
|
||||||
|
type="text"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={1}>
|
||||||
|
<TextField
|
||||||
|
autoComplete="off"
|
||||||
|
{...register("repeat_new_password")}
|
||||||
|
label="تکرار رمز عبور جدید"
|
||||||
|
size="small"
|
||||||
|
fullWidth
|
||||||
|
type="text"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
</Grid>
|
||||||
|
</StyledForm>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
export default Form;
|
||||||
@@ -1,46 +1,27 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import {
|
import { Button, Dialog, DialogActions, DialogContent } from "@mui/material";
|
||||||
Box,
|
|
||||||
Button,
|
|
||||||
Dialog,
|
|
||||||
DialogActions,
|
|
||||||
DialogContent,
|
|
||||||
DialogTitle,
|
|
||||||
IconButton,
|
|
||||||
useMediaQuery,
|
|
||||||
} from "@mui/material";
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import CloseIcon from "@mui/icons-material/Close";
|
import Form from "./Form";
|
||||||
|
|
||||||
const ChangePass = ({ open, setOpen }) => {
|
const ChangePass = ({ open, setOpen }) => {
|
||||||
const theme = useTheme();
|
const theme = useTheme();
|
||||||
const fullScreen = useMediaQuery(theme.breakpoints.down("sm"));
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog fullScreen={fullScreen} maxWidth="sm" fullWidth={true} open={open}
|
<Dialog maxWidth="sm" fullWidth={true} open={open}
|
||||||
onClose={() => {
|
onClose={() => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
}}>
|
}}>
|
||||||
<Box sx={{ display: "flex", alignItems: "center", justifyContent: "space-between", mx: 1 }}>
|
|
||||||
<DialogTitle sx={{ py: 2, px: 1 }}>
|
|
||||||
تغییر رمز عبور
|
|
||||||
</DialogTitle>
|
|
||||||
<IconButton
|
|
||||||
aria-label="بستن تغییر رمز عبور"
|
|
||||||
onClick={() => {
|
|
||||||
setOpen(false);
|
|
||||||
}}
|
|
||||||
sx={{ color: (theme) => theme.palette.grey[500] }}
|
|
||||||
>
|
|
||||||
<CloseIcon />
|
|
||||||
</IconButton>
|
|
||||||
</Box>
|
|
||||||
<DialogContent dividers>
|
<DialogContent dividers>
|
||||||
تست
|
<Form />
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button autoFocus variant="outlined" onClick={() => {
|
<Button autoFocus variant="outlined" color="error" onClick={() => {
|
||||||
|
setOpen(false);
|
||||||
|
}}>
|
||||||
|
بستن
|
||||||
|
</Button>
|
||||||
|
<Button autoFocus variant="contained" onClick={() => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
}}>
|
}}>
|
||||||
ثبت
|
ثبت
|
||||||
|
|||||||
@@ -1,14 +1,26 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { Autocomplete, Avatar, Backdrop, Badge, Box, Grid, TextField } from "@mui/material";
|
import { Autocomplete, Avatar, Backdrop, Box, Button, Chip, Divider, Grid, TextField } from "@mui/material";
|
||||||
import StyledForm from "@/core/components/StyledForm";
|
import StyledForm from "@/core/components/StyledForm";
|
||||||
import useRequest from "@/lib/hooks/useRequest";
|
import useRequest from "@/lib/hooks/useRequest";
|
||||||
import { Controller, useForm } from "react-hook-form";
|
import { Controller, useForm } from "react-hook-form";
|
||||||
import { useAuth } from "@/lib/contexts/auth";
|
import { useAuth } from "@/lib/contexts/auth";
|
||||||
import AddCircleIcon from "@mui/icons-material/AddCircle";
|
import CloudUploadIcon from "@mui/icons-material/CloudUpload";
|
||||||
import DataSAverOn from "@mui/icons-material/DataSAverOn";
|
import { styled } from "@mui/material/styles";
|
||||||
import { useState } from "react";
|
import { useState } from "react";
|
||||||
|
|
||||||
|
const VisuallyHiddenInput = styled("input")({
|
||||||
|
clip: "rect(0 0 0 0)",
|
||||||
|
clipPath: "inset(50%)",
|
||||||
|
height: 1,
|
||||||
|
overflow: "hidden",
|
||||||
|
position: "absolute",
|
||||||
|
bottom: 0,
|
||||||
|
left: 0,
|
||||||
|
whiteSpace: "nowrap",
|
||||||
|
width: 1,
|
||||||
|
});
|
||||||
|
|
||||||
const degreeItems = ["دیپلم", "کارشناسی", "کارشناسی ارشد", "دکترا"];
|
const degreeItems = ["دیپلم", "کارشناسی", "کارشناسی ارشد", "دکترا"];
|
||||||
|
|
||||||
const Form = () => {
|
const Form = () => {
|
||||||
@@ -24,8 +36,6 @@ const Form = () => {
|
|||||||
avatar: user.data.avatar,
|
avatar: user.data.avatar,
|
||||||
};
|
};
|
||||||
|
|
||||||
console.log("defaultValues", defaultValues);
|
|
||||||
|
|
||||||
const {
|
const {
|
||||||
control,
|
control,
|
||||||
watch,
|
watch,
|
||||||
@@ -36,96 +46,120 @@ const Form = () => {
|
|||||||
} = useForm({ defaultValues: defaultValues });
|
} = useForm({ defaultValues: defaultValues });
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<StyledForm id={"UpdateProfileForm"}>
|
<>
|
||||||
<Box sx={{ display: "flex", alignItems: "center", justifyContent: "center", mb: 4, position: "relative" }}>
|
<Divider sx={{ mb: 3 }}>
|
||||||
<Badge
|
<Chip color="success" variant="outlined" label="ویرایش پروفایل" />
|
||||||
overlap="circular"
|
</Divider>
|
||||||
anchorOrigin={{ vertical: "bottom", horizontal: "left" }}
|
<StyledForm id={"UpdateProfileForm"}>
|
||||||
badgeContent={<AddCircleIcon sx={{ fontSize: "2rem" }} color="primary" />}
|
<Box sx={{
|
||||||
>
|
display: "flex",
|
||||||
<Avatar
|
flexDirection: "column",
|
||||||
onMouseEnter={() => setUploadBackDrop(true)}
|
alignItems: "center",
|
||||||
onMouseLeave={() => setUploadBackDrop(false)}
|
justifyContent: "center",
|
||||||
alt={watch("first_name")}
|
mb: 4,
|
||||||
src={`${process.env.NEXT_PUBLIC_API_URL}/${watch("avatar")}`}
|
position: "relative",
|
||||||
sx={{ width: 150, height: 150, border: "1px solid #e1e1e1", cursor: "pointer" }}
|
borderRadius: "50%",
|
||||||
/>
|
}}>
|
||||||
</Badge>
|
<Button
|
||||||
<Backdrop
|
component="label"
|
||||||
sx={{
|
role={undefined}
|
||||||
color: "#fff", zIndex: (theme) => theme.zIndex.drawer + 1,
|
tabIndex={-1}
|
||||||
position: "absolute", width: 150, height: 150,
|
sx={{
|
||||||
marginLeft: "auto", marginRight: "auto",
|
borderRadius: "50%",
|
||||||
borderRadius: "50%",
|
padding: "unset",
|
||||||
}}
|
"&:hover": {
|
||||||
open={uploadBackDrop}
|
backgroundColor: "unset",
|
||||||
>
|
},
|
||||||
<DataSAverOn sx={{ fontSize: "4rem" }} color="inherit" />
|
}}
|
||||||
</Backdrop>
|
>
|
||||||
</Box>
|
<Box
|
||||||
<Grid container columns={{ xs: 1, sm: 2 }} spacing={2}>
|
onMouseEnter={() => setUploadBackDrop(true)}
|
||||||
<Grid item xs={1}>
|
onMouseLeave={() => setUploadBackDrop(false)}
|
||||||
<TextField
|
>
|
||||||
autoComplete="off"
|
<Avatar
|
||||||
{...register("first_name")}
|
alt={watch("first_name")}
|
||||||
label="نام"
|
src={`${process.env.NEXT_PUBLIC_API_URL}/${watch("avatar")}`}
|
||||||
size="small"
|
sx={{ width: 120, height: 120, border: "1px solid #e1e1e1" }}
|
||||||
fullWidth
|
|
||||||
type="text"
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
<Grid item xs={1}>
|
|
||||||
<TextField
|
|
||||||
autoComplete="off"
|
|
||||||
{...register("last_name")}
|
|
||||||
label="نام خانوادگی"
|
|
||||||
size="small"
|
|
||||||
fullWidth
|
|
||||||
type="text"
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
<Grid item xs={1}>
|
|
||||||
<TextField
|
|
||||||
autoComplete="off"
|
|
||||||
{...register("major")}
|
|
||||||
label="رشته تحصیلی"
|
|
||||||
size="small"
|
|
||||||
fullWidth
|
|
||||||
type="text"
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
<Grid item xs={1}>
|
|
||||||
<Controller
|
|
||||||
name="degree"
|
|
||||||
control={control}
|
|
||||||
render={({ field: { onChange, value } }) => (
|
|
||||||
<Autocomplete
|
|
||||||
size="small"
|
|
||||||
disablePortal
|
|
||||||
value={value}
|
|
||||||
onChange={(event, newValue) => {
|
|
||||||
onChange(newValue);
|
|
||||||
}}
|
|
||||||
options={degreeItems}
|
|
||||||
renderInput={(params) => (
|
|
||||||
<TextField autoComplete="off" fullWidth {...params} label="مدرک تحصیلی" />
|
|
||||||
)}
|
|
||||||
/>
|
/>
|
||||||
)}
|
<Backdrop
|
||||||
/>
|
sx={{
|
||||||
|
color: "#fff", zIndex: (theme) => theme.zIndex.drawer + 1,
|
||||||
|
position: "absolute", width: 120, height: 120,
|
||||||
|
marginLeft: "auto", marginRight: "auto",
|
||||||
|
borderRadius: "50%",
|
||||||
|
}}
|
||||||
|
open={uploadBackDrop}
|
||||||
|
>
|
||||||
|
<CloudUploadIcon sx={{ fontSize: "2rem" }} color="inherit" />
|
||||||
|
</Backdrop>
|
||||||
|
</Box>
|
||||||
|
<VisuallyHiddenInput type="file" />
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
<Grid container columns={{ xs: 1, sm: 2 }} spacing={2}>
|
||||||
|
<Grid item xs={1}>
|
||||||
|
<TextField
|
||||||
|
autoComplete="off"
|
||||||
|
{...register("first_name")}
|
||||||
|
label="نام"
|
||||||
|
size="small"
|
||||||
|
fullWidth
|
||||||
|
type="text"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={1}>
|
||||||
|
<TextField
|
||||||
|
autoComplete="off"
|
||||||
|
{...register("last_name")}
|
||||||
|
label="نام خانوادگی"
|
||||||
|
size="small"
|
||||||
|
fullWidth
|
||||||
|
type="text"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={1}>
|
||||||
|
<TextField
|
||||||
|
autoComplete="off"
|
||||||
|
{...register("major")}
|
||||||
|
label="رشته تحصیلی"
|
||||||
|
size="small"
|
||||||
|
fullWidth
|
||||||
|
type="text"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={1}>
|
||||||
|
<Controller
|
||||||
|
name="degree"
|
||||||
|
control={control}
|
||||||
|
render={({ field: { onChange, value } }) => (
|
||||||
|
<Autocomplete
|
||||||
|
size="small"
|
||||||
|
disablePortal
|
||||||
|
value={value}
|
||||||
|
onChange={(event, newValue) => {
|
||||||
|
onChange(newValue);
|
||||||
|
}}
|
||||||
|
options={degreeItems}
|
||||||
|
renderInput={(params) => (
|
||||||
|
<TextField autoComplete="off" fullWidth {...params} label="مدرک تحصیلی" />
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
|
<Grid item xs={2}>
|
||||||
|
<TextField
|
||||||
|
autoComplete="off"
|
||||||
|
{...register("mobile")}
|
||||||
|
label="موبایل"
|
||||||
|
size="small"
|
||||||
|
fullWidth
|
||||||
|
type="text"
|
||||||
|
/>
|
||||||
|
</Grid>
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={2}>
|
</StyledForm>
|
||||||
<TextField
|
</>
|
||||||
autoComplete="off"
|
|
||||||
{...register("mobile")}
|
|
||||||
label="موبایل"
|
|
||||||
size="small"
|
|
||||||
fullWidth
|
|
||||||
type="text"
|
|
||||||
/>
|
|
||||||
</Grid>
|
|
||||||
</Grid>
|
|
||||||
</StyledForm>
|
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
export default Form;
|
export default Form;
|
||||||
@@ -1,17 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import {
|
import { Button, Dialog, DialogActions, DialogContent, useMediaQuery } from "@mui/material";
|
||||||
Box,
|
|
||||||
Button,
|
|
||||||
Dialog,
|
|
||||||
DialogActions,
|
|
||||||
DialogContent,
|
|
||||||
DialogTitle,
|
|
||||||
IconButton,
|
|
||||||
useMediaQuery,
|
|
||||||
} from "@mui/material";
|
|
||||||
import { useTheme } from "@mui/material/styles";
|
import { useTheme } from "@mui/material/styles";
|
||||||
import CloseIcon from "@mui/icons-material/Close";
|
|
||||||
import Form from "./form";
|
import Form from "./form";
|
||||||
|
|
||||||
const Update = ({ open, setOpen }) => {
|
const Update = ({ open, setOpen }) => {
|
||||||
@@ -23,25 +13,16 @@ const Update = ({ open, setOpen }) => {
|
|||||||
onClose={() => {
|
onClose={() => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
}}>
|
}}>
|
||||||
<Box sx={{ display: "flex", alignItems: "center", justifyContent: "space-between", mx: 1 }}>
|
|
||||||
<DialogTitle sx={{ py: 2, px: 1 }}>
|
|
||||||
ویرایش پروفایل
|
|
||||||
</DialogTitle>
|
|
||||||
<IconButton
|
|
||||||
aria-label="بستن ویرایش پروفایل"
|
|
||||||
onClick={() => {
|
|
||||||
setOpen(false);
|
|
||||||
}}
|
|
||||||
sx={{ color: (theme) => theme.palette.grey[500] }}
|
|
||||||
>
|
|
||||||
<CloseIcon />
|
|
||||||
</IconButton>
|
|
||||||
</Box>
|
|
||||||
<DialogContent dividers>
|
<DialogContent dividers>
|
||||||
<Form />
|
<Form />
|
||||||
</DialogContent>
|
</DialogContent>
|
||||||
<DialogActions>
|
<DialogActions>
|
||||||
<Button autoFocus variant="outlined" onClick={() => {
|
<Button autoFocus variant="outlined" color="error" onClick={() => {
|
||||||
|
setOpen(false);
|
||||||
|
}}>
|
||||||
|
بستن
|
||||||
|
</Button>
|
||||||
|
<Button autoFocus variant="contained" onClick={() => {
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
}}>
|
}}>
|
||||||
ثبت
|
ثبت
|
||||||
|
|||||||
Reference in New Issue
Block a user