Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
baynt1 committed Oct 7, 2024
1 parent ca69b3d commit 9c03a32
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 25 deletions.
16 changes: 12 additions & 4 deletions src/features/auth/auth-form/auth-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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('Что-то пошло не так')
}
Expand Down
28 changes: 19 additions & 9 deletions src/features/settings/new-post/new-post.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,19 +64,29 @@ export const NewPost: FC<INewPostProps> = ({ 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,
})
Expand Down
38 changes: 26 additions & 12 deletions src/features/settings/new-user/new-user.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,34 @@ export const NewUser: FC<INewUserProps> = ({ 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('Что-то пошло не так')
Expand Down

0 comments on commit 9c03a32

Please sign in to comment.