From c9d84a49476d55138a95430ca4f927ab3d4ab042 Mon Sep 17 00:00:00 2001 From: Fedor Katurov Date: Wed, 26 Aug 2020 16:35:24 +0700 Subject: [PATCH] fixed calculation of empty fields on frontend --- src/components/profile/ProfileSettings/index.tsx | 14 +++++++------- src/constants/errors.ts | 2 ++ src/redux/auth/sagas.ts | 16 ++++++++-------- 3 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/components/profile/ProfileSettings/index.tsx b/src/components/profile/ProfileSettings/index.tsx index e1f3b724..df8482a1 100644 --- a/src/components/profile/ProfileSettings/index.tsx +++ b/src/components/profile/ProfileSettings/index.tsx @@ -48,13 +48,13 @@ const ProfileSettingsUnconnected: FC = ({ event => { event.preventDefault(); - const fields = reject(el => !el)({ - email: data.email !== user.email && data.email, - fullname: data.fullname !== user.fullname && data.fullname, - username: data.username !== user.username && data.username, - password: password.length > 0 && password, - new_password: new_password.length > 0 && new_password, - description: data.description !== user.description && data.description, + const fields = reject(el => typeof el === 'undefined')({ + email: data.email !== user.email && data.email ? data.email : undefined, + fullname: data.fullname !== user.fullname ? data.fullname : undefined, + username: data.username !== user.username && data.username ? data.username : undefined, + password: password.length > 0 && password ? password : undefined, + new_password: new_password.length > 0 && new_password ? new_password : undefined, + description: data.description !== user.description ? data.description : undefined, }); if (Object.values(fields).length === 0) return; diff --git a/src/constants/errors.ts b/src/constants/errors.ts index 421f7fdd..5d614efd 100644 --- a/src/constants/errors.ts +++ b/src/constants/errors.ts @@ -37,6 +37,7 @@ export const ERRORS = { CANT_SAVE_COMMENT: 'CantSaveComment', CANT_SAVE_NODE: 'CantSaveNode', INPUT_TOO_SHIRT: 'InputTooShirt', + CANT_SAVE_USER: 'CantSaveUser', }; export const ERROR_LITERAL = { @@ -79,4 +80,5 @@ export const ERROR_LITERAL = { [ERRORS.CANT_SAVE_COMMENT]: 'Не удалось сохранить коммент', [ERRORS.CANT_SAVE_NODE]: 'Не удалось сохранить пост', [ERRORS.INPUT_TOO_SHIRT]: 'Должно быть длиннее', + [ERRORS.CANT_SAVE_USER]: 'Не удалось сохранить пользователя', }; diff --git a/src/redux/auth/sagas.ts b/src/redux/auth/sagas.ts index d83d3d57..8b20c40c 100644 --- a/src/redux/auth/sagas.ts +++ b/src/redux/auth/sagas.ts @@ -508,14 +508,14 @@ function* authRegisterSocial({ username, password }: ReturnType> = yield call(apiLoginWithSocial, { - token, - username, - password, - }); + const { data, error }: Unwrap> = yield call( + apiLoginWithSocial, + { + token, + username, + password, + } + ); if (data?.errors) { yield put(authSetRegisterSocialErrors(data.errors));