Browse Source

imprv apiNotification utility

mizozobu 6 years ago
parent
commit
0bbed577f6

+ 2 - 2
src/client/js/components/Admin/UserGroup/UserGroupCreateForm.jsx

@@ -42,10 +42,10 @@ class UserGroupCreateForm extends React.Component {
         const { userGroup, userGroupRelation } = res;
         this.props.onCreate(userGroup, userGroupRelation);
         this.setState({ name: '' });
-        apiSuccessHandler({ body: `Created ${this.xss.process(userGroup.name)}` });
+        apiSuccessHandler(`Created a user group "${this.xss.process(userGroup.name)}"`);
       }
       else {
-        throw new Error('Unable to create a group');
+        throw new Error(`Unable to create a group "${this.xss.process(this.state.name)}"`);
       }
     }
     catch (err) {

+ 2 - 2
src/client/js/components/Admin/UserGroup/UserGroupPage.jsx

@@ -79,10 +79,10 @@ class UserGroupPage extends React.Component {
           };
         });
 
-        apiSuccessHandler({ body: `Deleted ${this.xss.process(res.userGroup.name)}` });
+        apiSuccessHandler(`Deleted a group "${this.xss.process(res.userGroup.name)}"`);
       }
       else {
-        throw new Error('Unable to create a group');
+        throw new Error(`Unable to delete a group "${this.xss.process(res.userGroup.name)}"`);
       }
     }
     catch (err) {

+ 2 - 1
src/client/js/components/Admin/UserGroup/UserGroupTable.jsx

@@ -1,6 +1,7 @@
 import React, { Fragment } from 'react';
 import PropTypes from 'prop-types';
 import { withTranslation } from 'react-i18next';
+import dateFnsFormat from 'date-fns/format';
 
 class UserGroupTable extends React.Component {
 
@@ -57,7 +58,7 @@ class UserGroupTable extends React.Component {
                       })}
                     </ul>
                   </td>
-                  <td>{group.createdAt}</td>{/* formatdate */}
+                  <td>{dateFnsFormat(new Date(group.createdAt), 'YYYY-MM-DD')}</td>
                   {this.props.isAclEnabled
                     ? (
                       <td>

+ 3 - 3
src/client/js/util/apiNotification.js

@@ -2,10 +2,10 @@ import * as toastr from 'toastr';
 
 const logger = require('@alias/logger')('growi');
 
-export const apiErrorHandler = (err) => {
+export const apiErrorHandler = (err, header = 'Error') => {
   logger.error(err);
 
-  toastr.error(err, 'Error', {
+  toastr.error(err, header, {
     closeButton: true,
     progressBar: true,
     newestOnTop: false,
@@ -15,7 +15,7 @@ export const apiErrorHandler = (err) => {
   });
 };
 
-export const apiSuccessHandler = ({ header, body }) => {
+export const apiSuccessHandler = (body, header = '') => {
   toastr.success(body, header, {
     closeButton: true,
     progressBar: true,