mirror of https://github.com/gabehf/Koito.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
40 lines
1.1 KiB
40 lines
1.1 KiB
import { deleteItem } from "api/api"
|
|
import { AsyncButton } from "../AsyncButton"
|
|
import { Modal } from "./Modal"
|
|
import { useNavigate } from "react-router"
|
|
import { useState } from "react"
|
|
|
|
interface Props {
|
|
open: boolean
|
|
setOpen: Function
|
|
title: string,
|
|
id: number,
|
|
type: string
|
|
}
|
|
|
|
export default function DeleteModal({ open, setOpen, title, id, type }: Props) {
|
|
const [loading, setLoading] = useState(false)
|
|
const navigate = useNavigate()
|
|
|
|
const doDelete = () => {
|
|
setLoading(true)
|
|
deleteItem(type.toLowerCase(), id)
|
|
.then(r => {
|
|
if (r.ok) {
|
|
navigate('/')
|
|
} else {
|
|
console.log(r)
|
|
}
|
|
})
|
|
}
|
|
|
|
return (
|
|
<Modal isOpen={open} onClose={() => setOpen(false)}>
|
|
<h2>Delete "{title}"?</h2>
|
|
<p>This action is irreversible!</p>
|
|
<div className="flex flex-col mt-3 items-center">
|
|
<AsyncButton loading={loading} onClick={doDelete}>Yes, Delete It</AsyncButton>
|
|
</div>
|
|
</Modal>
|
|
)
|
|
} |