Просмотр исходного кода

change some and able to click checkbox

ryuichi-e 5 лет назад
Родитель
Сommit
2242a7a1f6
2 измененных файлов с 39 добавлено и 6 удалено
  1. 38 5
      src/client/js/components/PutbackPageModal.jsx
  2. 1 1
      src/server/views/modal/put_back.html

+ 38 - 5
src/client/js/components/PutbackPageModal.jsx

@@ -1,4 +1,4 @@
-import React from 'react';
+import React, { useState } from 'react';
 import PropTypes from 'prop-types';
 import PropTypes from 'prop-types';
 
 
 import {
 import {
@@ -10,13 +10,39 @@ import { withTranslation } from 'react-i18next';
 import { createSubscribedElement } from './UnstatedUtils';
 import { createSubscribedElement } from './UnstatedUtils';
 import PageContainer from '../services/PageContainer';
 import PageContainer from '../services/PageContainer';
 
 
+import ApiErrorMessage from './PageManagement/ApiErrorMessage';
+
 const PutBackPageModal = (props) => {
 const PutBackPageModal = (props) => {
   const {
   const {
-    t, isOpen, toggle, onClickSubmit, pageContainer,
+    t, isOpen, toggle, pageContainer,
   } = props;
   } = props;
 
 
   const { path } = pageContainer.state;
   const { path } = pageContainer.state;
 
 
+  const [errorCode, setErrorCode] = useState(null);
+  const [errorMessage, setErrorMessage] = useState(null);
+
+  const [isPutbackRecursively, setIsPutbackRecursively] = useState(true);
+
+  function changeIsPutbackRecursivelyHandler() {
+    setIsPutbackRecursively(!isPutbackRecursively);
+  }
+
+  async function clickPutbackButtonHandler() {
+    setErrorCode(null);
+    setErrorMessage(null);
+
+    try {
+      const res = await pageContainer.deletePage(isPutbackRecursively);
+      const { page } = res.page.path;
+      window.location.href = encodeURI(page);
+    }
+    catch (err) {
+      setErrorCode(err.code);
+      setErrorMessage(err.message);
+    }
+  }
+
   return (
   return (
     <Modal isOpen={isOpen} toggle={toggle} className="grw-create-page">
     <Modal isOpen={isOpen} toggle={toggle} className="grw-create-page">
       <ModalHeader tag="h4" toggle={toggle} className="bg-info text-light">
       <ModalHeader tag="h4" toggle={toggle} className="bg-info text-light">
@@ -28,15 +54,22 @@ const PutBackPageModal = (props) => {
           <code>{path}</code>
           <code>{path}</code>
         </div>
         </div>
         <div className="custom-control custom-checkbox custom-checkbox-warning">
         <div className="custom-control custom-checkbox custom-checkbox-warning">
-          <input type="checkbox" className="custom-control-input" name="recursively" id="cbPutbackRecursively" value="1" checked />
-          <label htmlFor="cbPutbackRecursively" className="custom-control-label">
+          <input
+            className="custom-control-input"
+            id="cbPutBackRecursively"
+            type="checkbox"
+            checked={isPutbackRecursively}
+            onChange={changeIsPutbackRecursivelyHandler}
+          />
+          <label htmlFor="cbPutBackRecursively" className="custom-control-label">
             { t('modal_putback.label.recursively') }
             { t('modal_putback.label.recursively') }
           </label>
           </label>
           <p className="form-text text-muted mt-0">{ t('modal_putback.help.recursively') }<code>{ path }</code>{ t('modal_putback.help.recursively2') }</p>
           <p className="form-text text-muted mt-0">{ t('modal_putback.help.recursively') }<code>{ path }</code>{ t('modal_putback.help.recursively2') }</p>
         </div>
         </div>
       </ModalBody>
       </ModalBody>
       <ModalFooter>
       <ModalFooter>
-        <button type="button" className="btn btn-info" onClick={onClickSubmit}>
+        <ApiErrorMessage errorCode={errorCode} errorMessage={errorMessage} linkPath={path} />
+        <button type="button" className="btn btn-info" onClick={clickPutbackButtonHandler}>
           <i className="icon-action-undo mr-2" aria-hidden="true"></i> { t('Put Back') }
           <i className="icon-action-undo mr-2" aria-hidden="true"></i> { t('Put Back') }
         </button>
         </button>
       </ModalFooter>
       </ModalFooter>

+ 1 - 1
src/server/views/modal/put_back.html

@@ -14,7 +14,7 @@
             <code>{{ page.path }}</code>
             <code>{{ page.path }}</code>
           </div>
           </div>
           <div class="custom-control custom-checkbox custom-checkbox-warning">
           <div class="custom-control custom-checkbox custom-checkbox-warning">
-            <input class="custom-control-input" name="recursively"  value="1" type="checkbox" checked>
+            <input class="custom-control-input" name="recursively" id="cbPutbackRecursively" value="1" type="checkbox" checked>
             <label class="custom-control-label" for="cbPutbackRecursively">
             <label class="custom-control-label" for="cbPutbackRecursively">
               {{ t('modal_putback.label.recursively') }}
               {{ t('modal_putback.label.recursively') }}
               <p class="form-text text-muted mt-0">{{ t('modal_putback.help.recursively', page.path) }}</p>
               <p class="form-text text-muted mt-0">{{ t('modal_putback.help.recursively', page.path) }}</p>