import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { Modal, ModalHeader, ModalBody, ModalFooter, } from 'reactstrap'; import { withTranslation } from 'react-i18next'; import { withUnstatedContainers } from './UnstatedUtils'; import PageContainer from '../services/PageContainer'; import ApiErrorMessage from './PageManagement/ApiErrorMessage'; const deleteIconAndKey = { completely: { color: 'danger', icon: 'fire', translationKey: 'completely', }, temporary: { color: 'primary', icon: 'trash', translationKey: 'page', }, }; const PageDeleteModal = (props) => { const { t, pageContainer, isOpen, onClose, isDeleteCompletelyModal, path, isAbleToDeleteCompletely, } = props; const [isDeleteRecursively, setIsDeleteRecursively] = useState(true); const [isDeleteCompletely, setIsDeleteCompletely] = useState(isDeleteCompletelyModal && isAbleToDeleteCompletely); const deleteMode = isDeleteCompletely ? 'completely' : 'temporary'; const [errorCode, setErrorCode] = useState(null); const [errorMessage, setErrorMessage] = useState(null); function changeIsDeleteRecursivelyHandler() { setIsDeleteRecursively(!isDeleteRecursively); } function changeIsDeleteCompletelyHandler() { if (!isAbleToDeleteCompletely) { return; } setIsDeleteCompletely(!isDeleteCompletely); } async function deletePage() { setErrorCode(null); setErrorMessage(null); try { const response = await pageContainer.deletePage(isDeleteRecursively, isDeleteCompletely); const trashPagePath = response.page.path; window.location.href = encodeURI(trashPagePath); } catch (err) { setErrorCode(err.code); setErrorMessage(err.message); } } async function deleteButtonHandler() { deletePage(); } function renderDeleteRecursivelyForm() { return (
{ t('modal_delete.delete_completely_restriction') }
)}{ path }