From 9c03a326c87b6b0889e9de7ea8aa8bbd3e9adfa8 Mon Sep 17 00:00:00 2001 From: algafur Date: Mon, 7 Oct 2024 11:22:03 +0500 Subject: [PATCH] fix --- src/features/auth/auth-form/auth-form.tsx | 16 ++++++--- src/features/settings/new-post/new-post.tsx | 28 ++++++++++----- src/features/settings/new-user/new-user.tsx | 38 ++++++++++++++------- 3 files changed, 57 insertions(+), 25 deletions(-) diff --git a/src/features/auth/auth-form/auth-form.tsx b/src/features/auth/auth-form/auth-form.tsx index 2fc5692..337ad1b 100644 --- a/src/features/auth/auth-form/auth-form.tsx +++ b/src/features/auth/auth-form/auth-form.tsx @@ -24,10 +24,18 @@ export const AuthForm: FC = () => { try { const axiosInstance = await getAxiosInstance() - await axiosInstance.post('/auth/registration', { ...data, confirm: undefined }).then(() => { - openNotification('Регистрация прошла успешно', 'success') - handleAuth() - }) + await axiosInstance + .post('/auth/registration', { + ...data, + name: data.name?.trim(), + confirm: undefined, + password: data.password.trim(), + email: data.email.trim(), + }) + .then(() => { + openNotification('Регистрация прошла успешно', 'success') + handleAuth() + }) } catch (error) { openNotification('Что-то пошло не так') } diff --git a/src/features/settings/new-post/new-post.tsx b/src/features/settings/new-post/new-post.tsx index fb64f9a..e6c714b 100644 --- a/src/features/settings/new-post/new-post.tsx +++ b/src/features/settings/new-post/new-post.tsx @@ -64,19 +64,29 @@ export const NewPost: FC = ({ open, handeOpen, item, refetch }) = const axiosInstance = await getAxiosInstance() if (item && item.id) { - const users = data.users - ? data.users.map((user) => ({ - post: item.id, - user: user, - })) - : [] - await axiosInstance.patch(`/posts/${item.id}`, data) + // const users = data.users + // ? data.users.map((user) => ({ + // post: item.id, + // user: user, + // })) + // : [] + await axiosInstance.patch(`/posts/${item.id}`, { + ...data, + name: data.name.trim(), + bin: data.bin.trim(), + address: data.address.trim(), + }) openNotification('Пост изменен', 'success') handeOpen() refetch() - await axiosInstance.patch(`/posts-users-access/post/${item.id}`, users) + await axiosInstance.patch(`/posts-users-access/post/${item.id}`, { users: data.users }) } else { - const res = await axiosInstance.post('/posts', data) + const res = await axiosInstance.post('/posts', { + ...data, + name: data.name.trim(), + bin: data.bin.trim(), + address: data.address.trim(), + }) await axiosInstance.patch(`/posts-users-access/post/${res.data.id}`, { users: data.users, }) diff --git a/src/features/settings/new-user/new-user.tsx b/src/features/settings/new-user/new-user.tsx index 23df119..594cb1b 100644 --- a/src/features/settings/new-user/new-user.tsx +++ b/src/features/settings/new-user/new-user.tsx @@ -30,20 +30,34 @@ export const NewUser: FC = ({ open, handleModal, item, refetch }) }) : [] - await axiosInstance.patch(`/users/${item.id}`, data).then(() => { - openNotification('Пользователь изменен', 'success') - handleModal() - refetch() - setLoading(false) - }) + await axiosInstance + .patch(`/users/${item.id}`, { + ...data, + name: data.name.trim(), + email: data.email.trim(), + password: data.password.trim(), + }) + .then(() => { + openNotification('Пользователь изменен', 'success') + handleModal() + refetch() + setLoading(false) + }) await axiosInstance.post('/posts-users-access', posts) } else { - await axiosInstance.post('/users', data).then(() => { - openNotification('Пользователь создан', 'success') - handleModal() - refetch() - setLoading(false) - }) + await axiosInstance + .post('/users', { + ...data, + name: data.name.trim(), + email: data.email.trim(), + password: data.password.trim(), + }) + .then(() => { + openNotification('Пользователь создан', 'success') + handleModal() + refetch() + setLoading(false) + }) } } catch (error) { openNotification('Что-то пошло не так')