From 1c407e35a446c67487f1a8ab9e5e3f1f18e18029 Mon Sep 17 00:00:00 2001 From: vinit717 Date: Fri, 4 Oct 2024 22:49:11 +0530 Subject: [PATCH] fix url create and delete api --- __tests__/components/Dashhboard/UrlListItem.test.tsx | 2 +- src/components/Dashboard/UrlListItem.tsx | 4 +--- src/services/api.tsx | 7 ++----- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/__tests__/components/Dashhboard/UrlListItem.test.tsx b/__tests__/components/Dashhboard/UrlListItem.test.tsx index 626e86d..952600f 100644 --- a/__tests__/components/Dashhboard/UrlListItem.test.tsx +++ b/__tests__/components/Dashhboard/UrlListItem.test.tsx @@ -71,7 +71,7 @@ describe('UrlListItem', () => { fireEvent.click(deleteButtons[0]); await waitFor(() => { - expect(deleteUrlApi).toHaveBeenCalledWith({ id: url.id, userId: 123 }); + expect(deleteUrlApi).toHaveBeenCalledWith({ id: url.id }); }); }); diff --git a/src/components/Dashboard/UrlListItem.tsx b/src/components/Dashboard/UrlListItem.tsx index c95090d..f285f60 100644 --- a/src/components/Dashboard/UrlListItem.tsx +++ b/src/components/Dashboard/UrlListItem.tsx @@ -5,7 +5,6 @@ import { TbTrash } from 'react-icons/tb'; import { useMutation } from 'react-query'; import { TINY_SITE } from '@/constants/url'; -import useAuthenticated from '@/hooks/useAuthenticated'; import { queryClient } from '@/pages/_app'; import { deleteUrlApi } from '@/services/api'; import { UrlType } from '@/types/url.types'; @@ -42,7 +41,6 @@ interface UrlListItemProps { } const UrlListItem: React.FC = ({ url, copyButtonHandler }) => { - const { userData } = useAuthenticated(); const deleteMutation = useMutation({ mutationFn: deleteUrlApi, onSuccess: () => queryClient.invalidateQueries(['urls']), @@ -53,7 +51,7 @@ const UrlListItem: React.FC = ({ url, copyButtonHandler }) => }); const handleCopy = () => copyButtonHandler(`${TINY_SITE}/${url.shortUrl}`); - const handleDelete = () => deleteMutation.mutate({ id: url.id, userId: Number(userData?.data?.id) }); + const handleDelete = () => deleteMutation.mutate({ id: url.id }); return (
diff --git a/src/services/api.tsx b/src/services/api.tsx index 1fc930c..b3b2c62 100644 --- a/src/services/api.tsx +++ b/src/services/api.tsx @@ -73,14 +73,12 @@ const useShortenUrlMutation = ({ onSuccess, onError }: useShortenUrlMutationArgs MutationParams > => { return useMutation( - async ({ originalUrl, userData }: MutationParams) => { + async ({ originalUrl }: MutationParams) => { const response = await axios.post( `${TINY_API_URL}/tinyurl`, { OriginalUrl: originalUrl, Comment: '', - CreatedBy: userData?.data?.userName, - UserId: userData?.data?.id, } as ShortenUrlRequest, { withCredentials: true, @@ -95,10 +93,9 @@ const useShortenUrlMutation = ({ onSuccess, onError }: useShortenUrlMutationArgs } ); }; -const deleteUrlApi = async ({ id, userId }: { id: number; userId: number }) => { +const deleteUrlApi = async ({ id }: { id: number }) => { const { data } = await axios.delete(`${TINY_API_URL}/urls/${id}`, { withCredentials: true, - data: { user_id: userId }, }); return data; };