@ -1,10 +1,11 @@
import { Box , Stack , Typography } from "@mui/material"
import { Box , Stack } from "@mui/material"
import UserService from "../services/UserService"
import { useAuthStore } from "../store/auth"
import { setUserData , useAuthStore } from "../store/auth"
import { useEffect , useState } from "react"
import { CreateField } from "../interfaces/create"
import { IUser } from "../interfaces/user"
import FormFields from "../components/FormFields"
import AuthService from "../services/AuthService"
export default function Settings() {
const { token } = useAuthStore ( )
@ -25,8 +26,8 @@ export default function Settings() {
} , [ token ] )
const profileFields : CreateField [ ] = [
{ key : 'email' , headerName : 'E-mail' , type : 'string' , required : true } ,
{ key : 'login' , headerName : 'Логин' , type : 'string' , required : true } ,
//{ key: 'email', headerName: 'E-mail', type: 'string', required: true },
//{ key: 'login', headerName: 'Логин', type: 'string', required: true },
{ key : 'phone' , headerName : 'Телефон' , type : 'string' , required : false } ,
{ key : 'name' , headerName : 'Имя' , type : 'string' , required : true } ,
{ key : 'surname' , headerName : 'Фамилия' , type : 'string' , required : true } ,
@ -34,16 +35,17 @@ export default function Settings() {
const passwordFields : CreateField [ ] = [
{ key : 'password' , headerName : 'Новый пароль' , type : 'string' , required : true , inputType : 'password' } ,
{ key : 'password_confirm' , headerName : 'Подтверждение пароля' , type : 'string' , required : true , inputType : 'password' , watch : 'password' , watchMessage : 'Пароли не совпадают' } ,
{ key : 'password_confirm' , headerName : 'Подтверждение пароля' , type : 'string' , required : true , inputType : 'password' , watch : 'password' , watchMessage : 'Пароли не совпадают' , include : false } ,
]
return (
< Box sx = { {
display : "flex" ,
flexDirection : "column" ,
alignItems : "flex-start" ,
gap : "16px" ,
} }
< Box
sx = { {
display : "flex" ,
flexDirection : "column" ,
alignItems : "flex-start" ,
gap : "16px" ,
} }
>
{ currentUser &&
< Stack spacing = { 2 } width = '100%' >
@ -51,21 +53,22 @@ export default function Settings() {
< FormFields
fields = { profileFields }
defaultValues = { currentUser }
//submitHandler={RoleService.createRole}
mutateHandler = { ( data : any ) = > {
setUserData ( data )
} }
submitHandler = { ( data ) = > UserService . updateUser ( { id : currentUser.id , . . . data } ) }
title = "Пользователь"
/ >
< / Stack >
< Stack width = '100%' >
< FormFields
fields = { passwordFields }
defaultValues = { currentUser }
watchValues = { [ 'password, password_confirm' ] }
//submitHandler={RoleService.createRole}
submitHandler = { ( data ) = > AuthService . updatePassword ( { id : currentUser.id , . . . data } ) }
title = "Смена пароля"
/ >
< / Stack >
< / Stack >
}
< / Box >
)