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

add PageBulkExportResultModelNotification

Futa Arai 1 год назад
Родитель
Сommit
c1cbd2138e

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

@@ -1,12 +1,14 @@
-import React, { FC } from 'react';
+import type { FC } from 'react';
+import React from 'react';
 
 import type { HasObjectId } from '@growi/core';
 import { UserPicture } from '@growi/ui/dist/components';
 
 import { apiv3Post } from '~/client/util/apiv3-client';
-import { IInAppNotification, InAppNotificationStatuses } from '~/interfaces/in-app-notification';
+import type { IInAppNotification } from '~/interfaces/in-app-notification';
+import { InAppNotificationStatuses } from '~/interfaces/in-app-notification';
 
-import { useModelNotification } from './PageNotification';
+import { useModelNotification } from './ModelNotification';
 
 interface Props {
   notification: IInAppNotification & HasObjectId

+ 0 - 0
apps/app/src/components/InAppNotification/PageNotification/ModelNotification.tsx → apps/app/src/components/InAppNotification/ModelNotification/ModelNotification.tsx


+ 52 - 0
apps/app/src/components/InAppNotification/ModelNotification/PageBulkExportResultModelNotification.tsx

@@ -0,0 +1,52 @@
+import React from 'react';
+
+import type { HasObjectId } from '@growi/core';
+import { useRouter } from 'next/router';
+
+import type { IPageBulkExportResult } from '~/features/page-bulk-export/interfaces/page-bulk-export';
+import { SupportedTargetModel } from '~/interfaces/activity';
+import type { IInAppNotification } from '~/interfaces/in-app-notification';
+
+import { ModelNotification } from './ModelNotification';
+import type { ModelNotificationUtils } from './PageModelNotification';
+import { useActionMsgAndIconForModelNotification } from './useActionAndMsg';
+
+
+export const usePageBulkExportResultModelNotification = (notification: IInAppNotification & HasObjectId): ModelNotificationUtils | null => {
+
+  const { actionMsg, actionIcon } = useActionMsgAndIconForModelNotification(notification);
+  const router = useRouter();
+
+  const isPageBulkExportResultModelNotification = (
+      notification: IInAppNotification & HasObjectId,
+  ): notification is IInAppNotification<IPageBulkExportResult> & HasObjectId => {
+    return notification.targetModel === SupportedTargetModel.MODEL_PAGE_BULK_EXPORT_RESULT;
+  };
+
+  if (!isPageBulkExportResultModelNotification(notification)) {
+    return null;
+  }
+
+  const actionUsers = notification.user.username;
+
+  const Notification = () => {
+    return (
+      <ModelNotification
+        notification={notification}
+        actionMsg={actionMsg}
+        actionIcon={actionIcon}
+        actionUsers={actionUsers}
+      />
+    );
+  };
+
+  const publishOpen = () => {
+    router.push('/admin/users');
+  };
+
+  return {
+    Notification,
+    publishOpen,
+  };
+
+};

+ 2 - 3
apps/app/src/components/InAppNotification/PageNotification/PageModelNotification.tsx → apps/app/src/components/InAppNotification/ModelNotification/PageModelNotification.tsx

@@ -1,6 +1,5 @@
-import React, {
-  FC, useCallback,
-} from 'react';
+import type { FC } from 'react';
+import React, { useCallback } from 'react';
 
 import type { IPage, HasObjectId } from '@growi/core';
 import { useRouter } from 'next/router';

+ 1 - 1
apps/app/src/components/InAppNotification/PageNotification/UserModelNotification.tsx → apps/app/src/components/InAppNotification/ModelNotification/UserModelNotification.tsx

@@ -7,7 +7,7 @@ import { SupportedTargetModel } from '~/interfaces/activity';
 import type { IInAppNotification } from '~/interfaces/in-app-notification';
 
 import { ModelNotification } from './ModelNotification';
-import { ModelNotificationUtils } from './PageModelNotification';
+import type { ModelNotificationUtils } from './PageModelNotification';
 import { useActionMsgAndIconForModelNotification } from './useActionAndMsg';
 
 

+ 3 - 1
apps/app/src/components/InAppNotification/PageNotification/index.tsx → apps/app/src/components/InAppNotification/ModelNotification/index.tsx

@@ -3,6 +3,7 @@ import type { HasObjectId } from '@growi/core';
 import type { IInAppNotification } from '~/interfaces/in-app-notification';
 
 
+import { usePageBulkExportResultModelNotification } from './PageBulkExportResultModelNotification';
 import { usePageModelNotification, type ModelNotificationUtils } from './PageModelNotification';
 import { useUserModelNotification } from './UserModelNotification';
 
@@ -11,8 +12,9 @@ export const useModelNotification = (notification: IInAppNotification & HasObjec
 
   const pageModelNotificationUtils = usePageModelNotification(notification);
   const userModelNotificationUtils = useUserModelNotification(notification);
+  const pageBulkExportResultModelNotificationUtils = usePageBulkExportResultModelNotification(notification);
 
-  const modelNotificationUtils = pageModelNotificationUtils ?? userModelNotificationUtils;
+  const modelNotificationUtils = pageModelNotificationUtils ?? userModelNotificationUtils ?? pageBulkExportResultModelNotificationUtils;
 
 
   return modelNotificationUtils;

+ 0 - 0
apps/app/src/components/InAppNotification/PageNotification/useActionAndMsg.ts → apps/app/src/components/InAppNotification/ModelNotification/useActionAndMsg.ts


+ 2 - 0
apps/app/src/interfaces/activity.ts

@@ -4,6 +4,7 @@ import type { Ref, HasObjectId, IUser } from '@growi/core';
 const MODEL_PAGE = 'Page';
 const MODEL_USER = 'User';
 const MODEL_COMMENT = 'Comment';
+const MODEL_PAGE_BULK_EXPORT_RESULT = 'PageBulkExportResult';
 
 // Action
 const ACTION_UNSETTLED = 'UNSETTLED';
@@ -166,6 +167,7 @@ const ACTION_ADMIN_SEARCH_INDICES_REBUILD = 'ADMIN_SEARCH_INDICES_REBUILD';
 export const SupportedTargetModel = {
   MODEL_PAGE,
   MODEL_USER,
+  MODEL_PAGE_BULK_EXPORT_RESULT,
 } as const;
 
 export const SupportedEventModel = {

+ 1 - 1
apps/app/src/interfaces/in-app-notification.ts

@@ -1,6 +1,6 @@
 import type { IUser } from '@growi/core';
 
-import { SupportedTargetModelType, SupportedActionType } from './activity';
+import type { SupportedTargetModelType, SupportedActionType } from './activity';
 
 export enum InAppNotificationStatuses {
   STATUS_UNREAD = 'UNREAD',

+ 3 - 4
apps/app/src/server/models/in-app-notification.ts

@@ -1,6 +1,5 @@
-import {
-  Types, Document, Schema, Model,
-} from 'mongoose';
+import type { Types, Document, Model } from 'mongoose';
+import { Schema } from 'mongoose';
 import mongoosePaginate from 'mongoose-paginate-v2';
 
 import { AllSupportedTargetModels, AllSupportedActions } from '~/interfaces/activity';
@@ -8,7 +7,7 @@ import { InAppNotificationStatuses } from '~/interfaces/in-app-notification';
 
 import { getOrCreateModel } from '../util/mongoose-utils';
 
-import { ActivityDocument } from './activity';
+import type { ActivityDocument } from './activity';
 
 
 const { STATUS_UNREAD, STATUS_UNOPENED, STATUS_OPENED } = InAppNotificationStatuses;