import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { Modal, ModalHeader, ModalBody, ModalFooter, } from 'reactstrap'; import { withTranslation } from 'react-i18next'; import { apiPost } from '~/client/util/apiv1-client'; import ApiErrorMessageList from './PageManagement/ApiErrorMessageList'; const deleteIconAndKey = { completely: { color: 'danger', icon: 'fire', translationKey: 'completely', }, temporary: { color: 'primary', icon: 'trash', translationKey: 'page', }, }; const PageDeleteModal = (props) => { const { t, isOpen, onClose, isDeleteCompletelyModal, pageId, revisionId, path, isAbleToDeleteCompletely, } = props; const [isDeleteRecursively, setIsDeleteRecursively] = useState(true); const [isDeleteCompletely, setIsDeleteCompletely] = useState(isDeleteCompletelyModal && isAbleToDeleteCompletely); const deleteMode = isDeleteCompletely ? 'completely' : 'temporary'; const [errs, setErrs] = useState(null); function changeIsDeleteRecursivelyHandler() { setIsDeleteRecursively(!isDeleteRecursively); } function changeIsDeleteCompletelyHandler() { if (!isAbleToDeleteCompletely) { return; } setIsDeleteCompletely(!isDeleteCompletely); } async function deletePage() { setErrs(null); try { // control flag // If is it not true, Request value must be `null`. const recursively = isDeleteRecursively ? true : null; const completely = isDeleteCompletely ? true : null; const response = await apiPost('/pages.remove', { page_id: pageId, revision_id: revisionId, recursively, completely, }); const trashPagePath = response.page.path; window.location.href = encodeURI(trashPagePath); } catch (err) { setErrs(err); } } async function deleteButtonHandler() { deletePage(); } function renderDeleteRecursivelyForm() { return (
{ t('modal_delete.delete_completely_restriction') }
)}{ path }