Skip to content

Commit

Permalink
chore: started to implement the update function and other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Franqsanz committed Jan 10, 2024
1 parent 8aaf689 commit e3a3216
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 13 deletions.
8 changes: 0 additions & 8 deletions src/components/ModalOptions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,12 @@ export function ModalOptions({
>
Editar
</Button>
<Button
fontWeight='normal'
fontSize='sm'
_hover={{ color: 'none' }}
>
Copiar enlace
</Button>
</Flex>
</ModalBody>
<ModalFooter justifyContent='center'>
<Button
w='full'
onClick={onClose}
// fontWeight='normal'
fontSize='sm'
_hover={{ color: 'none' }}
>
Expand Down
10 changes: 6 additions & 4 deletions src/components/skeletons/SkeletonDBook.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,21 @@ import { Skeleton, SkeletonText, Flex, Box } from '@chakra-ui/react';
export function SkeletonDetailsBook() {
return (
<>
<Box
<Flex
w='full'
maxW='1234px'
maxW='1255px'
m='auto'
px={{ base: 5, xl: 0 }}
pt='10'
pb='3'
justify='space-between'
>
<Skeleton w='100px' h='30px' rounded='lg'></Skeleton>
</Box>
<Skeleton w='40px' h='30px' rounded='lg'></Skeleton>
</Flex>
<Flex
w='full'
maxW='1255px'
maxW='1300px'
m='auto'
mb='300px'
align='flex-start'
Expand Down
23 changes: 22 additions & 1 deletion src/hooks/querys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
postBook,
postRegister,
getUserAndBooks,
updateBook,
deleteBook,
} from '../services/api';
import { logOut } from '../services/firebase/auth';
Expand Down Expand Up @@ -181,7 +182,7 @@ function useDeleteBook() {
const navigate = useNavigate();

return useMutation({
mutationKey: ['deleteBook'],
mutationKey: [keys.deleteBook],
mutationFn: (id: string | undefined) => deleteBook(id),
onSuccess: (data) => {
if (data) {
Expand All @@ -196,6 +197,25 @@ function useDeleteBook() {
});
}

function useUpdateBook(book: any) {
const navigate = useNavigate();

return useMutation({
mutationKey: [keys.updateBook],
mutationFn: (id: string | undefined) => updateBook(id, book),
onSuccess: (data) => {
if (data) {
// return navigate(`/profile/${data.info.user.uid}`, { replace: true });
return navigate('/explore', { replace: true });
}
},
onError: async (error) => {
console.error('Error en el servidor:', error);
await logOut();
},
});
}

export {
useMutatePost,
useAllFilterOptions,
Expand All @@ -209,5 +229,6 @@ export {
useMoreBooksAuthors,
useUserRegister,
useProfile,
useUpdateBook,
useDeleteBook,
};
11 changes: 11 additions & 0 deletions src/services/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ async function getAllFilterOptions() {
return data;
}

async function updateBook(id: string | undefined, books: any) {
const data = await fetchData(`${API_URL}/book/update/${id}`, {
method: 'PATCH',
headers: { 'content-type': 'application/json' },
body: JSON.stringify(books),
});

return data;
}

async function deleteBook(id: string | undefined) {
const data = await fetchData(`${API_URL}/book/delete/${id}`, {
method: 'DELETE',
Expand Down Expand Up @@ -112,6 +122,7 @@ export {
getMoreBooksAuthors,
postBook,
deleteBook,
updateBook,
// Usuarios
postRegister,
getUserAndBooks,
Expand Down
2 changes: 2 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ const keys = {
relatedBooks: 'RelatedBooks',
moreBooksAuthors: 'MoreBooksAuthors',
userRegister: 'UserRegister',
updateBook: 'UpdateBook',
deleteBook: 'DeleteBook',
profile: 'Profile',
};

Expand Down

1 comment on commit e3a3216

@vercel
Copy link

@vercel vercel bot commented on e3a3216 Jan 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

xbu – ./

xbu-git-main-franqsanz.vercel.app
xbu-franqsanz.vercel.app
xbu.vercel.app

Please sign in to comment.