Skip to content

Commit

Permalink
chore: added a toast in Book and other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Franqsanz committed Jan 26, 2024
1 parent 1beab2f commit 4a2f967
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
2 changes: 2 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"prefer-const": 0,
"func-style": [1, "declaration", { "allowArrowFunctions": false }],
"n/handle-callback-err": 0,
"camelcase": 0,
"prettier/prettier": [
2,
{
Expand All @@ -60,6 +61,7 @@
"@typescript-eslint/no-non-null-assertion": 0,
"@typescript-eslint/adjacent-overload-signatures": 0,
"@typescript-eslint/no-explicit-any": 0,
"@typescript-eslint/no-unnecessary-condition": 0,
"react/no-unescaped-entities": 0,
"react-hooks/exhaustive-deps": 0
}
Expand Down
9 changes: 2 additions & 7 deletions src/components/forms/FormEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,13 @@ export function FormEdit({
pathUrl,
image,
}: BookType) {
const {
url,
// eslint-disable-next-line camelcase
public_id,
} = image;
const {
handleSubmit,
register,
formState: { errors },
} = useForm<BookType>();
const { url, public_id } = image;
const navigate = useNavigate();
let previewImgUI;
const { isOpen, onOpen, onClose } = useDisclosure();
const toast = useToast();
const bgColorInput = useColorModeValue('gray.100', 'gray.800');
Expand All @@ -78,10 +73,10 @@ export function FormEdit({
pathUrl,
image: {
url,
// eslint-disable-next-line camelcase
public_id,
},
});
let previewImgUI;
const fileInputRef = useRef<HTMLInputElement>(null);
const { mutate, isPending, isSuccess, error } = useUpdateBook(books);

Expand Down
12 changes: 6 additions & 6 deletions src/hooks/querys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,12 @@ function useDeleteBook() {
return useMutation({
mutationKey: [keys.deleteBook],
mutationFn: (id: string | undefined) => deleteBook(id),
onSuccess: (data) => {
if (data) {
// return navigate(`/profile/${data.info.user.uid}`, { replace: true });
return navigate('/explore', { replace: true });
}
},
// 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();
Expand Down
18 changes: 17 additions & 1 deletion src/pages/Book.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
Button,
useDisclosure,
Icon,
useToast,
} from '@chakra-ui/react';
import {
FiArrowLeft,
Expand Down Expand Up @@ -52,6 +53,7 @@ export default function Book() {
const infoTextColor = useColorModeValue('gray.600', 'gray.400');
const bgButton = useColorModeValue('white', 'black');
const navigate = useNavigate();
const toast = useToast();
const {
isOpen: isOpenOptions,
onOpen: onOpenOptions,
Expand All @@ -76,7 +78,7 @@ export default function Book() {
let btnMoreOptions;

const { data } = useBook(pathUrl);
const { mutate, isPending } = useDeleteBook();
const { mutate, isSuccess, isPending } = useDeleteBook();

const isCurrentUserAuthor = currentUser && currentUser.uid === data.userId;

Expand All @@ -96,6 +98,20 @@ export default function Book() {
);
}

if (isSuccess) {
toast({
title: 'Libro eliminado',
description: 'Se ha eliminado exitosamente.',
position: 'top-right',
isClosable: true,
containerStyle: {
fontFamily: 'sans-serif',
},
});

navigate('/explore', { replace: true });
}

function handleDeleteBook() {
mutate(data.id);
}
Expand Down

1 comment on commit 4a2f967

@vercel
Copy link

@vercel vercel bot commented on 4a2f967 Jan 26, 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-franqsanz.vercel.app
xbu-git-main-franqsanz.vercel.app
xbu.vercel.app

Please sign in to comment.