Przeglądaj źródła

WIP: add NotAvailableForGuest HoC

Yuki Takei 5 lat temu
rodzic
commit
61984f1465

+ 1 - 1
src/client/js/app.jsx

@@ -87,6 +87,7 @@ Object.assign(componentMappings, {
 if (pageContainer.state.pageId != null) {
 if (pageContainer.state.pageId != null) {
   Object.assign(componentMappings, {
   Object.assign(componentMappings, {
     'page-comments-list': <PageComments />,
     'page-comments-list': <PageComments />,
+    'page-comment-write': <CommentEditorLazyRenderer />,
     'page-attachment': <PageAttachment />,
     'page-attachment': <PageAttachment />,
     'page-management': <PageManagement />,
     'page-management': <PageManagement />,
 
 
@@ -117,7 +118,6 @@ if (appContainer.currentUser != null) {
   if (pageContainer.state.pageId != null) {
   if (pageContainer.state.pageId != null) {
     Object.assign(componentMappings, {
     Object.assign(componentMappings, {
       'page-editor-with-hackmd': <PageEditorByHackmd />,
       'page-editor-with-hackmd': <PageEditorByHackmd />,
-      'page-comment-write': <CommentEditorLazyRenderer />,
     });
     });
   }
   }
 }
 }

+ 32 - 0
src/client/js/components/NotAvailableForGuest.jsx

@@ -0,0 +1,32 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+
+import { UncontrolledTooltip } from 'reactstrap';
+
+const NotAvailableForGuest = ({ children }) => {
+
+  const id = `not-available-for-guest-${Math.random().toString(32).substring(2)}`;
+
+  // clone and add className
+  const clonedChildren = React.Children.map(children, child => (
+    React.cloneElement(child, {
+      id,
+      className: `${child.props.className} grw-not-available-for-guest`,
+      onClick: () => { /* do nothing */ },
+    })
+  ));
+
+  return (
+    <>
+      { clonedChildren }
+      {/* <UncontrolledTooltip placement="bottom" fade={false} target={id}>Not available for guest</UncontrolledTooltip> */}
+    </>
+  );
+
+};
+
+NotAvailableForGuest.propTypes = {
+  children: PropTypes.array.length(1).isRequired,
+};
+
+export default NotAvailableForGuest;

+ 10 - 7
src/client/js/components/PageComment/CommentEditor.jsx

@@ -20,6 +20,7 @@ import Editor from '../PageEditor/Editor';
 import SlackNotification from '../SlackNotification';
 import SlackNotification from '../SlackNotification';
 
 
 import CommentPreview from './CommentPreview';
 import CommentPreview from './CommentPreview';
+import NotAvailableForGuest from '../NotAvailableForGuest';
 
 
 /**
 /**
  *
  *
@@ -242,13 +243,15 @@ class CommentEditor extends React.Component {
   renderBeforeReady() {
   renderBeforeReady() {
     return (
     return (
       <div className="text-center">
       <div className="text-center">
-        <button
-          type="button"
-          className="btn btn-lg btn-link"
-          onClick={() => this.setState({ isReadyToUse: true })}
-        >
-          <i className="icon-bubble"></i> Add Comment
-        </button>
+        <NotAvailableForGuest>
+          <button
+            type="button"
+            className="btn btn-lg btn-link"
+            onClick={() => this.setState({ isReadyToUse: true })}
+          >
+            <i className="icon-bubble"></i> Add Comment
+          </button>
+        </NotAvailableForGuest>
       </div>
       </div>
     );
     );
   }
   }

+ 1 - 1
src/client/js/components/PageComments.jsx

@@ -174,7 +174,7 @@ class PageComments extends React.Component {
             </Button>
             </Button>
           </div>
           </div>
         )}
         )}
-        { showEditor && isLoggedIn && (
+        { showEditor && (
           <div className="page-comment-reply-form ml-4 ml-sm-5 mr-3">
           <div className="page-comment-reply-form ml-4 ml-sm-5 mr-3">
             <CommentEditor
             <CommentEditor
               growiRenderer={this.growiRenderer}
               growiRenderer={this.growiRenderer}

+ 6 - 0
src/client/styles/scss/style-app.scss

@@ -63,14 +63,20 @@
 /*
 /*
  * for Guest User Mode
  * for Guest User Mode
  */
  */
+// TODO: reactify and replace with `grw-not-available-for-guest`
 .dropdown-toggle.dropdown-toggle-disabled {
 .dropdown-toggle.dropdown-toggle-disabled {
   cursor: not-allowed;
   cursor: not-allowed;
 }
 }
 
 
+// TODO: reactify and replace with `grw-not-available-for-guest`
 .edit-button.edit-button-disabled {
 .edit-button.edit-button-disabled {
   cursor: not-allowed;
   cursor: not-allowed;
 }
 }
 
 
+.grw-not-available-for-guest {
+  cursor: not-allowed !important;
+}
+
 /*
 /*
  * Helper Classes
  * Helper Classes
  */
  */