mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 17:19:37 +02:00
- Replace free-text license input with a select box - Improve visual presentation of modals and enhance keyboard interaction
49 lines
1.4 KiB
TypeScript
49 lines
1.4 KiB
TypeScript
import { useState } from 'react'
|
|
import { useTranslation } from 'react-i18next'
|
|
import useIsMounted from '@/shared/hooks/use-is-mounted'
|
|
import OLButton from '@/features/ui/components/ol/ol-button'
|
|
import DeleteTemplateModal from './modals/delete-template-modal'
|
|
import { useTemplateContext } from '../context/template-context'
|
|
import { deleteTemplate } from '../util/api'
|
|
import type { Template } from '../../../../../types/template'
|
|
|
|
function DeleteTemplateButton() {
|
|
const { t } = useTranslation()
|
|
const [showModal, setShowModal] = useState(false)
|
|
const isMounted = useIsMounted()
|
|
const { template, setTemplate } = useTemplateContext()
|
|
|
|
const handleOpenModal = () => {
|
|
setShowModal(true)
|
|
}
|
|
|
|
const handleCloseModal = () => {
|
|
if (isMounted.current) {
|
|
setShowModal(false)
|
|
}
|
|
}
|
|
|
|
const handleDeleteTemplate = async (template: Template) => {
|
|
await deleteTemplate(template)
|
|
handleCloseModal()
|
|
const previousPage = document.referrer || '/templates'
|
|
window.location.href = previousPage
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<OLButton variant="danger" onClick={handleOpenModal}>
|
|
{t('delete')}
|
|
</OLButton>
|
|
<DeleteTemplateModal
|
|
template={template}
|
|
actionHandler={handleDeleteTemplate}
|
|
showModal={showModal}
|
|
handleCloseModal={handleCloseModal}
|
|
/>
|
|
</>
|
|
)
|
|
}
|
|
|
|
export default DeleteTemplateButton
|