Skip to content

Commit

Permalink
Merge pull request #55 from Sokilskill/fix/profileForm
Browse files Browse the repository at this point in the history
fix
  • Loading branch information
Sokilskill committed Jan 20, 2024
2 parents ab9dfb9 + 1073cf3 commit b57aed0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 32 deletions.
48 changes: 19 additions & 29 deletions src/components/UserForm/UserForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import {
getUserProfile,
updateUserName,
} from '../../redux/profileSettings/operations';
import { useEffect } from 'react';

import {
selectProfileEmail,
selectProfileName,
selectUserProfile,
} from '../../redux/profileSettings/selectors';
import { selectUser } from '../../redux/auth/auth-selectors';
import { useEffect } from 'react';

// import 'react-toastify/dist/ReactToastify.css';

Expand Down Expand Up @@ -299,33 +300,21 @@ export const UserForm = () => {
levelActivity,
} = useSelector(selectUserProfile);
const userName = useSelector(selectProfileName);
const userEmail = useSelector(selectProfileEmail);
// const userEmail = useSelector(selectProfileEmail);
const userCurrent = useSelector(selectUser);

useEffect(() => {
// const fetchData = () => {
// dispatch(getUserProfile());
// };
// fetchData();
dispatch(getUserProfile());

// console.log('userData', userData);
}, [dispatch]);

// const validationSchema = Yup.object().shape({
// name: Yup.string().required('Name is required'),
// email: Yup.string().required('email is required'),
// height: Yup.number().required('height is required'),
// currentWeight: Yup.number().required('currentWeight is required'),
// desiredWeight: Yup.number().required('desiredWeight is required'),
// birthday: Yup.number().required('birthday is required'),
// blood: Yup.number().required('blood is required'),
// sex: Yup.string().required('gender is required'),
// levelActivity: Yup.number().required('levelActivity is required'),
// });
if (userName) {
dispatch(getUserProfile());
}
}, [dispatch, userName]);

const currentName = userName ? userName : userCurrent.name;
console.log('currentName', currentName);

const initialValues = {
name: userName || '',
email: userEmail || '',
name: currentName || '',
email: userCurrent.email || '',
height: height || '',
currentWeight: currentWeight || '',
desiredWeight: desiredWeight || '',
Expand All @@ -342,16 +331,18 @@ export const UserForm = () => {
console.log('DATA', data);
const { name, email, ...profileData } = data;
const updateNameResult = await dispatch(updateUserName({ name }));
console.log('PROFILEDATA]', profileData);
const updateProfileDataResult = await dispatch(addUserData(profileData));

// console.log('PROFILEDATA]', profileData);
const updateProfileDataResult = await dispatch(addUserData(profileData));
// console.log('updateNameResult', updateNameResult);
// console.log('updateProfileDataResult', updateProfileDataResult);

if (
updateNameResult.meta.requestStatus === 'fulfilled' &&
updateProfileDataResult.meta.requestStatus === 'fulfilled'
) {
await dispatch(getUserProfile());

toast.success('Дані оброблюються, створюється план тренувань');
} else {
console.log('Помилка оновлення даних');
Expand All @@ -363,8 +354,7 @@ export const UserForm = () => {
};

return (
userName &&
userEmail && (
currentName && (
<Formik
initialValues={initialValues}
validationSchema={ProfileSchema}
Expand Down
6 changes: 3 additions & 3 deletions src/redux/profileSettings/slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,14 @@ const handleRejected = (state, action) => {
state.error = action.payload;
};

const handleAddUserDataFulfilled = (state, action) => {
const handleAddUserDataFulfilled = (state) => {
// console.log('actionUPDATE++++++++', action.payload);
// state = { ...state, ...action.payload.profile };
state.isLoading = false;
state.error = null;
};

const handleUpdateUserNameFulfilled = (state, action) => {
const handleUpdateUserNameFulfilled = (state) => {
// console.log('actionUPDATE NAMEEE++++++++', action);
// state.profile.owner.name = action.payload.name;
state.isLoading = false;
Expand All @@ -60,7 +60,7 @@ const handleUpdateAvatarFulfilled = (state, action) => {

const handleGetUserProfileFulfilled = (state, action) => {
// console.log('action.payload.result', action.payload.result);
state.profile = { ...state, ...action.payload.result };
state.profile = { ...action.payload.result };
state.isLoading = false;
state.error = null;
};
Expand Down

0 comments on commit b57aed0

Please sign in to comment.