itizawa 5 ani în urmă
părinte
comite
6e8dab5297

+ 2 - 4
src/client/js/components/EmptyTrashModal.jsx

@@ -16,7 +16,6 @@ const EmptyTrashModal = (props) => {
     t, isOpen, onClose, appContainer,
     t, isOpen, onClose, appContainer,
   } = props;
   } = props;
 
 
-  // errors:array
   const [errors, setErrors] = useState(null);
   const [errors, setErrors] = useState(null);
 
 
   async function emptyTrash() {
   async function emptyTrash() {
@@ -26,9 +25,8 @@ const EmptyTrashModal = (props) => {
       await appContainer.apiv3Delete('/pages/empty-trash');
       await appContainer.apiv3Delete('/pages/empty-trash');
       window.location.reload();
       window.location.reload();
     }
     }
-    catch (errors) {
-      setErrors(errors);
-
+    catch (err) {
+      setErrors(err);
     }
     }
   }
   }
 
 

+ 2 - 3
src/client/js/components/PageDeleteModal.jsx

@@ -33,7 +33,6 @@ const PageDeleteModal = (props) => {
   const [isDeleteCompletely, setIsDeleteCompletely] = useState(isDeleteCompletelyModal && isAbleToDeleteCompletely);
   const [isDeleteCompletely, setIsDeleteCompletely] = useState(isDeleteCompletelyModal && isAbleToDeleteCompletely);
   const deleteMode = isDeleteCompletely ? 'completely' : 'temporary';
   const deleteMode = isDeleteCompletely ? 'completely' : 'temporary';
 
 
-  // errors:array
   const [errors, setErrors] = useState(null);
   const [errors, setErrors] = useState(null);
 
 
   function changeIsDeleteRecursivelyHandler() {
   function changeIsDeleteRecursivelyHandler() {
@@ -55,8 +54,8 @@ const PageDeleteModal = (props) => {
       const trashPagePath = response.page.path;
       const trashPagePath = response.page.path;
       window.location.href = encodeURI(trashPagePath);
       window.location.href = encodeURI(trashPagePath);
     }
     }
-    catch (errors) {
-      setErrors(errors);
+    catch (err) {
+      setErrors(err);
     }
     }
   }
   }
 
 

+ 2 - 3
src/client/js/components/PageDuplicateModal.jsx

@@ -76,9 +76,8 @@ const PageDuplicateModal = (props) => {
       const { page } = res;
       const { page } = res;
       window.location.href = encodeURI(`${page.path}?duplicated=${path}`);
       window.location.href = encodeURI(`${page.path}?duplicated=${path}`);
     }
     }
-    catch (errors) {
-      // TODO GW-3316 set errors
-      // setErrors(errors);
+    catch (err) {
+      setErrors(err);
     }
     }
   }
   }
 
 

+ 5 - 2
src/client/js/components/PageManagement/ApiErrorMessage.jsx

@@ -2,6 +2,7 @@ import React from 'react';
 import PropTypes from 'prop-types';
 import PropTypes from 'prop-types';
 
 
 import { withTranslation } from 'react-i18next';
 import { withTranslation } from 'react-i18next';
+import toArrayIfNot from '../../../../lib/util/toArrayIfNot';
 
 
 const ApiErrorMessage = (props) => {
 const ApiErrorMessage = (props) => {
   const {
   const {
@@ -16,6 +17,8 @@ const ApiErrorMessage = (props) => {
     return null;
     return null;
   }
   }
 
 
+  const errArray = toArrayIfNot(errors);
+
   function renderMessage(err) {
   function renderMessage(err) {
 
 
     function renderMessageByErrorCode() {
     function renderMessageByErrorCode() {
@@ -67,7 +70,7 @@ const ApiErrorMessage = (props) => {
 
 
   return (
   return (
     <>
     <>
-      {errors.map((error) => {
+      {errArray.map((error) => {
         return (
         return (
           <span key={error.message} className="text-danger">
           <span key={error.message} className="text-danger">
             {renderMessage(error)}
             {renderMessage(error)}
@@ -82,7 +85,7 @@ const ApiErrorMessage = (props) => {
 ApiErrorMessage.propTypes = {
 ApiErrorMessage.propTypes = {
   t:            PropTypes.func.isRequired, //  i18next
   t:            PropTypes.func.isRequired, //  i18next
 
 
-  errors:       PropTypes.array,
+  errors:       PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
   targetPath:   PropTypes.string,
   targetPath:   PropTypes.string,
 };
 };
 
 

+ 4 - 5
src/client/js/components/PageRenameModal.jsx

@@ -24,7 +24,6 @@ const PageRenameModal = (props) => {
 
 
   const [pageNameInput, setPageNameInput] = useState(path);
   const [pageNameInput, setPageNameInput] = useState(path);
 
 
-  // errors:array
   const [errors, setErrors] = useState(null);
   const [errors, setErrors] = useState(null);
 
 
   const [isRenameRecursively, SetIsRenameRecursively] = useState(true);
   const [isRenameRecursively, SetIsRenameRecursively] = useState(true);
@@ -52,9 +51,9 @@ const PageRenameModal = (props) => {
   }
   }
 
 
   async function rename() {
   async function rename() {
-    try {
-      setErrors(null);
+    setErrors(null);
 
 
+    try {
       const response = await pageContainer.rename(
       const response = await pageContainer.rename(
         pageNameInput,
         pageNameInput,
         isRenameRecursively,
         isRenameRecursively,
@@ -71,8 +70,8 @@ const PageRenameModal = (props) => {
 
 
       window.location.href = `${url.pathname}${url.search}`;
       window.location.href = `${url.pathname}${url.search}`;
     }
     }
-    catch (errors) {
-      setErrors(errors);
+    catch (err) {
+      setErrors(err);
     }
     }
   }
   }
 
 

+ 2 - 3
src/client/js/components/PutbackPageModal.jsx

@@ -18,7 +18,6 @@ const PutBackPageModal = (props) => {
     t, isOpen, onClose, pageContainer, path,
     t, isOpen, onClose, pageContainer, path,
   } = props;
   } = props;
 
 
-  // errors:array
   const [errors, setErrors] = useState(null);
   const [errors, setErrors] = useState(null);
 
 
   const [isPutbackRecursively, setIsPutbackRecursively] = useState(true);
   const [isPutbackRecursively, setIsPutbackRecursively] = useState(true);
@@ -35,8 +34,8 @@ const PutBackPageModal = (props) => {
       const putbackPagePath = response.page.path;
       const putbackPagePath = response.page.path;
       window.location.href = encodeURI(putbackPagePath);
       window.location.href = encodeURI(putbackPagePath);
     }
     }
-    catch (errors) {
-      setErrors(errors);
+    catch (err) {
+      setErrors(err);
     }
     }
   }
   }