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

Merge branch 'feat/137966-show-notifications-in-sidebar' into feat/138055-implementation-of-the-only-unread-switch

Shun Miyazawa 2 лет назад
Родитель
Сommit
057d381afb

+ 1 - 1
apps/app/src/components/InAppNotification/InAppNotificationDropdown.tsx

@@ -91,7 +91,7 @@ export const InAppNotificationDropdown = (): JSX.Element => {
           // no items
           // no items
           ? <DropdownItem disabled>{t('in_app_notification.mark_all_as_read')}</DropdownItem>
           ? <DropdownItem disabled>{t('in_app_notification.mark_all_as_read')}</DropdownItem>
           // render DropdownItem
           // render DropdownItem
-          : <InAppNotificationList type="list" inAppNotificationData={inAppNotificationData} />
+          : <InAppNotificationList inAppNotificationData={inAppNotificationData} />
         }
         }
         <DropdownItem divider />
         <DropdownItem divider />
         <DropdownItem tag="a" href="/me/all-in-app-notifications">
         <DropdownItem tag="a" href="/me/all-in-app-notifications">

+ 3 - 19
apps/app/src/components/InAppNotification/InAppNotificationElm.tsx

@@ -10,11 +10,8 @@ import { useModelNotification } from './PageNotification';
 
 
 interface Props {
 interface Props {
   notification: IInAppNotification & HasObjectId
   notification: IInAppNotification & HasObjectId
-  elemClassName?: string,
-  type?: 'button' | 'list',
 }
 }
 
 
-
 const InAppNotificationElm: FC<Props> = (props: Props) => {
 const InAppNotificationElm: FC<Props> = (props: Props) => {
 
 
   const { notification } = props;
   const { notification } = props;
@@ -56,22 +53,8 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
     );
     );
   };
   };
 
 
-  const isListItem = props.type === 'list';
-
-  // determine tag
-  const TagElem = isListItem
-    ? props => (
-      <div {...props} style={{ cursor: 'pointer' }}>
-        {/* eslint-disable-next-line react/prop-types */}
-        {props.children}
-        <div className="border-top" />
-      </div>
-    )
-    // eslint-disable-next-line react/prop-types
-    : props => <button type="button" {...props}>{props.children}</button>;
-
   return (
   return (
-    <TagElem className={props.elemClassName} onClick={() => clickHandler(notification)}>
+    <div className="list-group-item list-group-item-action" onClick={() => clickHandler(notification)} style={{ cursor: 'pointer' }}>
       <div className="d-flex align-items-center">
       <div className="d-flex align-items-center">
         <span
         <span
           className={`${notification.status === InAppNotificationStatuses.STATUS_UNOPENED
           className={`${notification.status === InAppNotificationStatuses.STATUS_UNOPENED
@@ -80,12 +63,13 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
           } rounded-circle me-3`}
           } rounded-circle me-3`}
         >
         >
         </span>
         </span>
+
         {renderActionUserPictures()}
         {renderActionUserPictures()}
 
 
         <Notification />
         <Notification />
 
 
       </div>
       </div>
-    </TagElem>
+    </div>
   );
   );
 };
 };
 
 

+ 3 - 5
apps/app/src/components/InAppNotification/InAppNotificationList.tsx

@@ -9,8 +9,6 @@ import InAppNotificationElm from './InAppNotificationElm';
 
 
 type Props = {
 type Props = {
   inAppNotificationData?: PaginateResult<IInAppNotification>,
   inAppNotificationData?: PaginateResult<IInAppNotification>,
-  elemClassName?: string,
-  type?: 'button' | 'list',
 };
 };
 
 
 const InAppNotificationList: FC<Props> = (props: Props) => {
 const InAppNotificationList: FC<Props> = (props: Props) => {
@@ -29,13 +27,13 @@ const InAppNotificationList: FC<Props> = (props: Props) => {
   const notifications = inAppNotificationData.docs;
   const notifications = inAppNotificationData.docs;
 
 
   return (
   return (
-    <>
+    <div className="list-group">
       { notifications.map((notification: IInAppNotification & HasObjectId) => {
       { notifications.map((notification: IInAppNotification & HasObjectId) => {
         return (
         return (
-          <InAppNotificationElm key={notification._id} notification={notification} type={props.type} elemClassName={props.elemClassName} />
+          <InAppNotificationElm key={notification._id} notification={notification} />
         );
         );
       }) }
       }) }
-    </>
+    </div>
   );
   );
 };
 };
 
 

+ 1 - 3
apps/app/src/components/InAppNotification/InAppNotificationPage.tsx

@@ -100,9 +100,7 @@ export const InAppNotificationPage: FC = () => {
           ? t('in_app_notification.mark_all_as_read')
           ? t('in_app_notification.mark_all_as_read')
           // render list-group
           // render list-group
           : (
           : (
-            <div className="list-group">
-              <InAppNotificationList inAppNotificationData={notificationData} type="button" elemClassName="list-group-item list-group-item-action" />
-            </div>
+            <InAppNotificationList inAppNotificationData={notificationData} />
           )
           )
         }
         }
 
 

+ 12 - 2
apps/app/src/components/Sidebar/InAppNotification/InAppNotificationSubstance.tsx

@@ -1,5 +1,7 @@
 import React from 'react';
 import React from 'react';
 
 
+import { useTranslation } from 'next-i18next';
+
 import InAppNotificationList from '~/components/InAppNotification/InAppNotificationList';
 import InAppNotificationList from '~/components/InAppNotification/InAppNotificationList';
 import { InAppNotificationStatuses } from '~/interfaces/in-app-notification';
 import { InAppNotificationStatuses } from '~/interfaces/in-app-notification';
 import { useSWRxInAppNotifications } from '~/stores/in-app-notification';
 import { useSWRxInAppNotifications } from '~/stores/in-app-notification';
@@ -12,7 +14,7 @@ export const InAppNotificationForms = (props: InAppNotificationFormsProps): JSX.
   const { onChangeUnreadNotificationsVisible } = props;
   const { onChangeUnreadNotificationsVisible } = props;
 
 
   return (
   return (
-    <div className="px-4 my-2">
+    <div className="my-2">
       <div className="form-check form-switch">
       <div className="form-check form-switch">
         <label className="form-check-label" htmlFor="flexSwitchCheckDefault">Only unread</label>
         <label className="form-check-label" htmlFor="flexSwitchCheckDefault">Only unread</label>
         <input
         <input
@@ -33,6 +35,7 @@ type InAppNotificationContentProps = {
 }
 }
 export const InAppNotificationContent = (props: InAppNotificationContentProps): JSX.Element => {
 export const InAppNotificationContent = (props: InAppNotificationContentProps): JSX.Element => {
   const { isUnreadNotificationsVisible } = props;
   const { isUnreadNotificationsVisible } = props;
+  const { t } = useTranslation('commons');
 
 
   // TODO: Infinite scroll implemented (https://redmine.weseek.co.jp/issues/138057)
   // TODO: Infinite scroll implemented (https://redmine.weseek.co.jp/issues/138057)
   const { data: inAppNotificationData } = useSWRxInAppNotifications(
   const { data: inAppNotificationData } = useSWRxInAppNotifications(
@@ -44,7 +47,14 @@ export const InAppNotificationContent = (props: InAppNotificationContentProps):
 
 
   return (
   return (
     <>
     <>
-      <InAppNotificationList type="list" inAppNotificationData={inAppNotificationData} />
+      {inAppNotificationData != null && inAppNotificationData.docs.length === 0
+      // no items
+        ? t('in_app_notification.mark_all_as_read')
+      // render list-group
+        : (
+          <InAppNotificationList inAppNotificationData={inAppNotificationData} />
+        )
+      }
     </>
     </>
   );
   );
 };
 };