Browse Source

set default type for iinappnotification

WNomunomu 2 years ago
parent
commit
4333cb4a1f

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

@@ -16,7 +16,7 @@ import PageModelNotification from './PageNotification/PageModelNotification';
 import UserModelNotification from './PageNotification/UserModelNotification';
 
 interface Props {
-  notification: IInAppNotification<IUser | IPage> & HasObjectId
+  notification: IInAppNotification & HasObjectId
   elemClassName?: string,
   type?: 'button' | 'dropdown-item',
 }
@@ -28,7 +28,7 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
 
   const notificationRef = useRef<IInAppNotificationOpenable>(null);
 
-  const clickHandler = async(notification: IInAppNotification<IUser | IPage> & HasObjectId): Promise<void> => {
+  const clickHandler = async(notification: IInAppNotification & HasObjectId): Promise<void> => {
     if (notification.status === InAppNotificationStatuses.STATUS_UNOPENED) {
       // set notification status "OPEND"
       await apiv3Post('/in-app-notification/open', { id: notification._id });
@@ -61,11 +61,11 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
 
   const isDropdownItem = props.type === 'dropdown-item';
 
-  const isPageNotification = (notification: IInAppNotification<IUser | IPage>): notification is IInAppNotification<IPage> => {
+  const isPageNotification = (notification: IInAppNotification): notification is IInAppNotification<IPage> => {
     return notification.targetModel === SupportedTargetModel.MODEL_PAGE;
   };
 
-  const isUserNotification = (notification: IInAppNotification<IUser | IPage>): notification is IInAppNotification<IUser> => {
+  const isUserNotification = (notification: IInAppNotification): notification is IInAppNotification<IUser> => {
     return notification.targetModel === SupportedTargetModel.MODEL_USER;
   };
 

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

@@ -1,6 +1,6 @@
 import React, { FC } from 'react';
 
-import type { IUser, IPage, HasObjectId } from '@growi/core';
+import type { HasObjectId } from '@growi/core';
 
 import type { IInAppNotification, PaginateResult } from '~/interfaces/in-app-notification';
 
@@ -8,7 +8,7 @@ import InAppNotificationElm from './InAppNotificationElm';
 
 
 type Props = {
-  inAppNotificationData?: PaginateResult<IInAppNotification<IUser | IPage>>,
+  inAppNotificationData?: PaginateResult<IInAppNotification>,
   elemClassName?: string,
   type?: 'button' | 'dropdown-item',
 };
@@ -30,7 +30,7 @@ const InAppNotificationList: FC<Props> = (props: Props) => {
 
   return (
     <>
-      { notifications.map((notification: IInAppNotification<IUser | IPage> & HasObjectId) => {
+      { notifications.map((notification: IInAppNotification & HasObjectId) => {
         return (
           <InAppNotificationElm key={notification._id} notification={notification} type={props.type} elemClassName={props.elemClassName} />
         );

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

@@ -1,6 +1,6 @@
 import React, { FC, useImperativeHandle } from 'react';
 
-import type { IUser, IPage, HasObjectId } from '@growi/core';
+import type { HasObjectId } from '@growi/core';
 import { PagePathLabel } from '@growi/ui/dist/components';
 
 import type { IInAppNotificationOpenable } from '~/client/interfaces/in-app-notification-openable';
@@ -9,7 +9,7 @@ import type { IInAppNotification } from '~/interfaces/in-app-notification';
 import FormattedDistanceDate from '../../FormattedDistanceDate';
 
 type Props = {
-  notification: IInAppNotification<IUser | IPage> & HasObjectId
+  notification: IInAppNotification & HasObjectId
   actionMsg: string
   actionIcon: string
   actionUsers: string

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

@@ -10,7 +10,7 @@ export enum InAppNotificationStatuses {
 
 // TODO: do not use any type
 // https://redmine.weseek.co.jp/issues/120632
-export interface IInAppNotification<T> {
+export interface IInAppNotification<T = unknown> {
   user: IUser
   targetModel: SupportedTargetModelType
   target: T

+ 2 - 4
apps/app/src/server/routes/apiv3/in-app-notification.ts

@@ -1,5 +1,3 @@
-import type { IUser, IPage } from '@growi/core';
-
 import { SupportedAction } from '~/interfaces/activity';
 import { generateAddActivityMiddleware } from '~/server/middlewares/add-activity';
 
@@ -51,12 +49,12 @@ module.exports = (crowi) => {
       return activities.map(({ user }) => user).filter((user, i, self) => self.indexOf(user) === i);
     };
 
-    const serializedDocs: Array<IInAppNotification<IUser | IPage>> = paginationResult.docs.map((doc) => {
+    const serializedDocs: Array<IInAppNotification> = paginationResult.docs.map((doc) => {
       if (doc.user != null && doc.user instanceof User) {
         doc.user = serializeUserSecurely(doc.user);
       }
       // To add a new property into mongoose doc, need to change the format of doc to an object
-      const docObj: IInAppNotification<IUser | IPage> = doc.toObject();
+      const docObj: IInAppNotification = doc.toObject();
       const actionUsersNew = getActionUsersFromActivities(doc.activities);
 
       const serializedActionUsers = actionUsersNew.map((actionUser) => {

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

@@ -1,4 +1,3 @@
-import type { IUser, IPage } from '@growi/core';
 import useSWR, { SWRConfiguration, SWRResponse } from 'swr';
 
 
@@ -11,14 +10,14 @@ import { apiv3Get } from '../client/util/apiv3-client';
 
 const logger = loggerFactory('growi:cli:InAppNotification');
 
-type inAppNotificationPaginateResult = PaginateResult<IInAppNotification<IUser | IPage>>
+type inAppNotificationPaginateResult = PaginateResult<IInAppNotification>
 
 export const useSWRxInAppNotifications = (
     limit: number,
     offset?: number,
     status?: InAppNotificationStatuses,
     config?: SWRConfiguration,
-): SWRResponse<PaginateResult<IInAppNotification<IUser | IPage>>, Error> => {
+): SWRResponse<PaginateResult<IInAppNotification>, Error> => {
   return useSWR(
     ['/in-app-notification/list', limit, offset, status],
     ([endpoint]) => apiv3Get(endpoint, { limit, offset, status }).then((response) => {