Browse Source

use supported targe model

ryoji-s 3 years ago
parent
commit
33452f63fa

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

@@ -8,6 +8,7 @@ import { DropdownItem } from 'reactstrap';
 
 import { IInAppNotificationOpenable } from '~/client/interfaces/in-app-notification-openable';
 import { apiv3Post } from '~/client/util/apiv3-client';
+import { SupportedTargetModel } from '~/interfaces/activity';
 import { IInAppNotification, InAppNotificationStatuses } from '~/interfaces/in-app-notification';
 
 // Change the display for each targetmodel
@@ -40,7 +41,7 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
   };
 
   const getActionUsers = () => {
-    if (notification.targetModel === 'User') {
+    if (notification.targetModel === SupportedTargetModel.MODEL_USER) {
       return notification.target.username;
     }
 
@@ -170,7 +171,7 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
         >
         </span>
         {renderActionUserPictures()}
-        {notification.targetModel === 'Page' && (
+        {notification.targetModel === SupportedTargetModel.MODEL_PAGE && (
           <PageModelNotification
             ref={notificationRef}
             notification={notification}
@@ -179,7 +180,7 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
             actionUsers={actionUsers}
           />
         )}
-        {notification.targetModel === 'User' && (
+        {notification.targetModel === SupportedTargetModel.MODEL_USER && (
           <UserModelNotification
             ref={notificationRef}
             notification={notification}

+ 2 - 2
apps/app/src/server/routes/login.js

@@ -1,4 +1,4 @@
-import { SupportedAction } from '~/interfaces/activity';
+import { SupportedAction, SupportedTargetModel } from '~/interfaces/activity';
 import loggerFactory from '~/utils/logger';
 
 // disable all of linting
@@ -47,7 +47,7 @@ module.exports = function(crowi, app) {
     const activity = await activityService.createActivity({
       action: SupportedAction.ACTION_USER_REGISTRATION_APPROVAL_REQUEST,
       target: user,
-      targetModel: 'User',
+      targetModel: SupportedTargetModel.MODEL_USER,
     });
     await activityEvent.emit('updated', activity, user, adminUsers);
     return;

+ 3 - 2
apps/app/src/stores/in-app-notification.ts

@@ -1,5 +1,6 @@
 import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
 
+import { SupportedTargetModel } from '~/interfaces/activity';
 import type { InAppNotificationStatuses, IInAppNotification, PaginateResult } from '~/interfaces/in-app-notification';
 import * as pageSerializers from '~/models/serializers/in-app-notification-snapshot/page';
 import * as userSerializers from '~/models/serializers/in-app-notification-snapshot/user';
@@ -25,10 +26,10 @@ export const useSWRxInAppNotifications = <Data, Error>(
       inAppNotificationPaginateResult.docs.forEach((doc) => {
         try {
           switch (doc.targetModel) {
-            case 'Page':
+            case SupportedTargetModel.MODEL_PAGE:
               doc.parsedSnapshot = pageSerializers.parseSnapshot(doc.snapshot);
               break;
-            case 'User':
+            case SupportedTargetModel.MODEL_USER:
               doc.parsedSnapshot = userSerializers.parseSnapshot(doc.snapshot);
               break;
             default: