From 3fee12f4db7996b633baa10584f8d5c1fb1b081b Mon Sep 17 00:00:00 2001 From: louis Date: Sat, 9 Jul 2022 18:16:33 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix=20closing=20modal=20after=20?= =?UTF-8?q?message=20deleted?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/Message.ts | 16 ++++++++-------- src/components/MessageModalDelete.tsx | 15 +++++++++------ 2 files changed, 17 insertions(+), 14 deletions(-) diff --git a/src/api/Message.ts b/src/api/Message.ts index 06c2589b..666dd897 100644 --- a/src/api/Message.ts +++ b/src/api/Message.ts @@ -53,14 +53,14 @@ export function useMessageApi(token: string) { }).then(response => response.json()) } - const deleteMessage = ( - ticker: string, - message: string - ): Promise> => { - return fetch(`${ApiUrl}/admin/tickers/${ticker}/messages/${message}`, { - headers: headers, - method: 'delete', - }).then(response => response.json()) + const deleteMessage = (message: Message): Promise> => { + return fetch( + `${ApiUrl}/admin/tickers/${message.ticker}/messages/${message.id}`, + { + headers: headers, + method: 'delete', + } + ).then(response => response.json()) } return { deleteMessage, getMessages, postMessage } diff --git a/src/components/MessageModalDelete.tsx b/src/components/MessageModalDelete.tsx index 33b1645a..86ba27b2 100644 --- a/src/components/MessageModalDelete.tsx +++ b/src/components/MessageModalDelete.tsx @@ -14,18 +14,21 @@ const MessageModalDelete: FC = props => { const { deleteMessage } = useMessageApi(token) const [open, setOpen] = useState(false) const queryClient = useQueryClient() - const tickerId = props.message.ticker.toString() - const messageId = props.message.id.toString() + const message = props.message const handleCancel = useCallback(() => { setOpen(false) }, []) const handleConfirm = useCallback(() => { - deleteMessage(tickerId, messageId).finally(() => { - queryClient.invalidateQueries(['messages', tickerId]) - }) - }, [deleteMessage, tickerId, messageId, queryClient]) + deleteMessage(message) + .then(() => { + queryClient.invalidateQueries(['messages', message.ticker]) + }) + .finally(() => { + setOpen(false) + }) + }, [deleteMessage, message, queryClient]) const handleOpen = useCallback(() => { setOpen(true)