File tree 3 files changed +11
-4
lines changed
3 files changed +11
-4
lines changed Original file line number Diff line number Diff line change 1
1
import { useRef } from "react" ;
2
2
import { useDispatch } from "react-redux" ;
3
+ import { useSelector } from "react-redux" ;
4
+ import { selectUser } from "../../redux/auth/selectror" ;
3
5
import { Field , Form , Formik } from "formik" ;
4
6
import { ErrorMessage } from "formik" ;
5
7
import PasswordField from "../PasswordField/PasswordField" ;
@@ -21,6 +23,7 @@ const ValidationSchema = Yup.object().shape({
21
23
} ) ;
22
24
23
25
export default function UserEditModal ( { onClose } ) {
26
+ const user = useSelector ( selectUser ) ;
24
27
const dispatch = useDispatch ( ) ;
25
28
26
29
const fileInputRef = useRef ( null ) ;
@@ -84,8 +87,8 @@ export default function UserEditModal({ onClose }) {
84
87
< div >
85
88
< Formik
86
89
initialValues = { {
87
- name : "" ,
88
- email : "" ,
90
+ name : user . name || "" ,
91
+ email : user . email || "" ,
89
92
password : "" ,
90
93
} }
91
94
onSubmit = { handleSubmit }
Original file line number Diff line number Diff line change @@ -15,7 +15,6 @@ export const register = createAsyncThunk(
15
15
"/auth/register" ,
16
16
async ( userInfo , thunkAPI ) => {
17
17
try {
18
-
19
18
const response = await axios . post ( "/auth/register" , userInfo ) ;
20
19
setAuthHeader ( response . data . token ) ;
21
20
return response . data ;
@@ -31,6 +30,7 @@ export const logIn = createAsyncThunk(
31
30
try {
32
31
const response = await axios . post ( "/auth/login" , userInfo ) ;
33
32
setAuthHeader ( response . data . token ) ;
33
+ await thunkAPI . dispatch ( getUserInfo ( ) ) ;
34
34
return response . data ;
35
35
} catch ( error ) {
36
36
return thunkAPI . rejectWithValue ( error . message ) ;
Original file line number Diff line number Diff line change @@ -71,7 +71,11 @@ const authSlice = createSlice({
71
71
} )
72
72
. addCase ( getUserInfo . fulfilled , ( state , action ) => {
73
73
state . loading = false ;
74
- state . user = action . payload ;
74
+ // state.user = action.payload;
75
+ state . user . name = action . payload . name ;
76
+ state . user . email = action . payload . email ;
77
+ state . user . theme = action . payload . theme ;
78
+ state . user . avatarURL = action . payload . avatarURL ;
75
79
state . isLoggedIn = true ;
76
80
} )
77
81
. addCase ( getUserInfo . rejected , ( state , action ) => {
You can’t perform that action at this time.
0 commit comments