Merge branch 'develop' of https://gitlab.com/witel-front-end/rms into develop
This commit is contained in:
@@ -52,6 +52,7 @@ const Form = ({ handleCloseForm, setLoading }) => {
|
|||||||
const request = useRequest();
|
const request = useRequest();
|
||||||
const { user, getUser } = useAuth();
|
const { user, getUser } = useAuth();
|
||||||
const [uploadBackDrop, setUploadBackDrop] = useState(false);
|
const [uploadBackDrop, setUploadBackDrop] = useState(false);
|
||||||
|
const [avatarUrl, setAvatarUrl] = useState(user?.avatar || "");
|
||||||
const defaultValues = {
|
const defaultValues = {
|
||||||
first_name: user.first_name,
|
first_name: user.first_name,
|
||||||
last_name: user.last_name,
|
last_name: user.last_name,
|
||||||
@@ -70,6 +71,15 @@ const Form = ({ handleCloseForm, setLoading }) => {
|
|||||||
formState: { isSubmitting, errors },
|
formState: { isSubmitting, errors },
|
||||||
} = useForm({ defaultValues, resolver: yupResolver(validationSchema) });
|
} = useForm({ defaultValues, resolver: yupResolver(validationSchema) });
|
||||||
|
|
||||||
|
const handleFileChange = (event) => {
|
||||||
|
const file = event.target.files[0];
|
||||||
|
if (file) {
|
||||||
|
const objectUrl = URL.createObjectURL(file);
|
||||||
|
setAvatarUrl(objectUrl);
|
||||||
|
setValue("avatar", file);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setLoading(isSubmitting);
|
setLoading(isSubmitting);
|
||||||
}, [isSubmitting]);
|
}, [isSubmitting]);
|
||||||
@@ -124,7 +134,7 @@ const Form = ({ handleCloseForm, setLoading }) => {
|
|||||||
onMouseEnter={() => setUploadBackDrop(true)}
|
onMouseEnter={() => setUploadBackDrop(true)}
|
||||||
onMouseLeave={() => setUploadBackDrop(false)}
|
onMouseLeave={() => setUploadBackDrop(false)}
|
||||||
>
|
>
|
||||||
<Avatar src={user?.avatar} sx={{ width: 120, height: 120, border: "1px solid #e1e1e1" }} />
|
<Avatar src={avatarUrl} sx={{ width: 120, height: 120, border: "1px solid #e1e1e1" }} />
|
||||||
<Backdrop
|
<Backdrop
|
||||||
sx={{
|
sx={{
|
||||||
color: "#fff",
|
color: "#fff",
|
||||||
@@ -144,7 +154,7 @@ const Form = ({ handleCloseForm, setLoading }) => {
|
|||||||
<VisuallyHiddenInput
|
<VisuallyHiddenInput
|
||||||
type="file"
|
type="file"
|
||||||
accept="image/*"
|
accept="image/*"
|
||||||
onChange={(event) => setValue("avatar", event.target.files[0])}
|
onChange={handleFileChange}
|
||||||
/>
|
/>
|
||||||
</Button>
|
</Button>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
Reference in New Issue
Block a user