Skip to content

Commit

Permalink
Merge pull request #286 from systemli/fix-message-delete-modal-close
Browse files Browse the repository at this point in the history
🐛 Fix closing modal after message deleted
  • Loading branch information
0x46616c6b authored Jul 9, 2022
2 parents 315ba75 + 3fee12f commit 2ef7401
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
16 changes: 8 additions & 8 deletions src/api/Message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,14 @@ export function useMessageApi(token: string) {
}).then(response => response.json())
}

const deleteMessage = (
ticker: string,
message: string
): Promise<Response<any>> => {
return fetch(`${ApiUrl}/admin/tickers/${ticker}/messages/${message}`, {
headers: headers,
method: 'delete',
}).then(response => response.json())
const deleteMessage = (message: Message): Promise<Response<any>> => {
return fetch(
`${ApiUrl}/admin/tickers/${message.ticker}/messages/${message.id}`,
{
headers: headers,
method: 'delete',
}
).then(response => response.json())
}

return { deleteMessage, getMessages, postMessage }
Expand Down
15 changes: 9 additions & 6 deletions src/components/MessageModalDelete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,21 @@ const MessageModalDelete: FC<Props> = props => {
const { deleteMessage } = useMessageApi(token)
const [open, setOpen] = useState<boolean>(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)
Expand Down

0 comments on commit 2ef7401

Please sign in to comment.