Browse Source

fix InAppNotification merge

Futa Arai 1 year ago
parent
commit
9a1ee27308

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


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


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


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


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


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


+ 0 - 19
apps/app/src/client/components/InAppNotification/PageNotification/index.tsx

@@ -1,19 +0,0 @@
-import type { HasObjectId } from '@growi/core';
-
-import type { IInAppNotification } from '~/interfaces/in-app-notification';
-
-
-import { usePageModelNotification, type ModelNotificationUtils } from './PageModelNotification';
-import { useUserModelNotification } from './UserModelNotification';
-
-
-export const useModelNotification = (notification: IInAppNotification & HasObjectId): ModelNotificationUtils | null => {
-
-  const pageModelNotificationUtils = usePageModelNotification(notification);
-  const userModelNotificationUtils = useUserModelNotification(notification);
-
-  const modelNotificationUtils = pageModelNotificationUtils ?? userModelNotificationUtils;
-
-
-  return modelNotificationUtils;
-};

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

@@ -1,46 +0,0 @@
-import type { FC } from 'react';
-import React from 'react';
-
-import type { HasObjectId } from '@growi/core';
-import { PagePathLabel } from '@growi/ui/dist/components';
-
-import type { IInAppNotification } from '~/interfaces/in-app-notification';
-
-import FormattedDistanceDate from '../../FormattedDistanceDate';
-
-type Props = {
-  notification: IInAppNotification & HasObjectId
-  actionMsg: string
-  actionIcon: string
-  actionUsers: string
-  hideActionUsers?: boolean
-  subMsg?: JSX.Element
-};
-
-export const ModelNotification: FC<Props> = ({
-  notification,
-  actionMsg,
-  actionIcon,
-  actionUsers,
-  hideActionUsers = false,
-  subMsg,
-}: Props) => {
-
-  return (
-    <div className="p-2 overflow-hidden">
-      <div className="text-truncate">
-        {hideActionUsers ? <></> : <b>{actionUsers}</b>}
-        {` ${actionMsg}`}
-        <PagePathLabel path={notification.parsedSnapshot?.path ?? ''} />
-      </div>
-      { subMsg }
-      <span className="material-symbols-outlined me-2">{actionIcon}</span>
-      <FormattedDistanceDate
-        id={notification._id}
-        date={notification.createdAt}
-        isShowTooltip={false}
-        differenceForAvoidingFormat={Number.POSITIVE_INFINITY}
-      />
-    </div>
-  );
-};

+ 0 - 79
apps/app/src/components/InAppNotification/ModelNotification/PageModelNotification.tsx

@@ -1,79 +0,0 @@
-import React, { useCallback } from 'react';
-
-import type { IPage, HasObjectId } from '@growi/core';
-import { useRouter } from 'next/router';
-
-import { SupportedTargetModel } from '~/interfaces/activity';
-import type { IInAppNotification } from '~/interfaces/in-app-notification';
-import * as pageSerializers from '~/models/serializers/in-app-notification-snapshot/page';
-
-import { ModelNotification } from './ModelNotification';
-import { useActionMsgAndIconForModelNotification } from './useActionAndMsg';
-
-import type { ModelNotificationUtils } from '.';
-
-export const usePageModelNotification = (notification: IInAppNotification & HasObjectId): ModelNotificationUtils | null => {
-
-  const router = useRouter();
-  const { actionMsg, actionIcon } = useActionMsgAndIconForModelNotification(notification);
-
-  const getActionUsers = useCallback(() => {
-    const latestActionUsers = notification.actionUsers.slice(0, 3);
-    const latestUsers = latestActionUsers.map((user) => {
-      return `@${user.name}`;
-    });
-
-    let actionedUsers = '';
-    const latestUsersCount = latestUsers.length;
-    if (latestUsersCount === 1) {
-      actionedUsers = latestUsers[0];
-    }
-    else if (notification.actionUsers.length >= 4) {
-      actionedUsers = `${latestUsers.slice(0, 2).join(', ')} and ${notification.actionUsers.length - 2} others`;
-    }
-    else {
-      actionedUsers = latestUsers.join(', ');
-    }
-
-    return actionedUsers;
-  }, [notification.actionUsers]);
-
-  const isPageModelNotification = (notification: IInAppNotification & HasObjectId): notification is IInAppNotification<IPage> & HasObjectId => {
-    return notification.targetModel === SupportedTargetModel.MODEL_PAGE;
-  };
-
-  if (!isPageModelNotification(notification)) {
-    return null;
-  }
-
-  const actionUsers = getActionUsers();
-
-  notification.parsedSnapshot = pageSerializers.parseSnapshot(notification.snapshot);
-
-  const Notification = () => {
-    return (
-      <ModelNotification
-        notification={notification}
-        actionMsg={actionMsg}
-        actionIcon={actionIcon}
-        actionUsers={actionUsers}
-      />
-    );
-  };
-
-  const publishOpen = () => {
-    if (notification.target != null) {
-      // jump to target page
-      const targetPagePath = (notification.target as IPage).path;
-      if (targetPagePath != null) {
-        router.push(targetPagePath);
-      }
-    }
-  };
-
-  return {
-    Notification,
-    publishOpen,
-  };
-
-};

+ 0 - 50
apps/app/src/components/InAppNotification/ModelNotification/UserModelNotification.tsx

@@ -1,50 +0,0 @@
-import React from 'react';
-
-import type { IUser, HasObjectId } from '@growi/core';
-import { useRouter } from 'next/router';
-
-import { SupportedTargetModel } from '~/interfaces/activity';
-import type { IInAppNotification } from '~/interfaces/in-app-notification';
-
-import { ModelNotification } from './ModelNotification';
-import { useActionMsgAndIconForModelNotification } from './useActionAndMsg';
-
-import type { ModelNotificationUtils } from '.';
-
-
-export const useUserModelNotification = (notification: IInAppNotification & HasObjectId): ModelNotificationUtils | null => {
-
-  const { actionMsg, actionIcon } = useActionMsgAndIconForModelNotification(notification);
-  const router = useRouter();
-
-  const isUserModelNotification = (notification: IInAppNotification & HasObjectId): notification is IInAppNotification<IUser> & HasObjectId => {
-    return notification.targetModel === SupportedTargetModel.MODEL_USER;
-  };
-
-  if (!isUserModelNotification(notification)) {
-    return null;
-  }
-
-  const actionUsers = notification.target.username;
-
-  const Notification = () => {
-    return (
-      <ModelNotification
-        notification={notification}
-        actionMsg={actionMsg}
-        actionIcon={actionIcon}
-        actionUsers={actionUsers}
-      />
-    );
-  };
-
-  const publishOpen = () => {
-    router.push('/admin/users');
-  };
-
-  return {
-    Notification,
-    publishOpen,
-  };
-
-};

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

@@ -1,90 +0,0 @@
-import type { HasObjectId } from '@growi/core';
-
-import { SupportedAction } from '~/interfaces/activity';
-import type { IInAppNotification } from '~/interfaces/in-app-notification';
-
-export type ActionMsgAndIconType = {
-  actionMsg: string
-  actionIcon: string
-}
-
-export const useActionMsgAndIconForModelNotification = (notification: IInAppNotification & HasObjectId): ActionMsgAndIconType => {
-  const actionType: string = notification.action;
-  let actionMsg: string;
-  let actionIcon: string;
-
-  switch (actionType) {
-    case SupportedAction.ACTION_PAGE_LIKE:
-      actionMsg = 'liked';
-      actionIcon = 'favorite';
-      break;
-    case SupportedAction.ACTION_PAGE_BOOKMARK:
-      actionMsg = 'bookmarked on';
-      actionIcon = 'bookmark_add';
-      break;
-    case SupportedAction.ACTION_PAGE_UPDATE:
-      actionMsg = 'updated on';
-      actionIcon = 'update';
-      break;
-    case SupportedAction.ACTION_PAGE_RENAME:
-      actionMsg = 'renamed';
-      actionIcon = 'redo';
-      break;
-    case SupportedAction.ACTION_PAGE_DUPLICATE:
-      actionMsg = 'duplicated';
-      actionIcon = 'file_copy';
-      break;
-    case SupportedAction.ACTION_PAGE_DELETE:
-      actionMsg = 'deleted';
-      actionIcon = 'delete';
-      break;
-    case SupportedAction.ACTION_PAGE_DELETE_COMPLETELY:
-      actionMsg = 'completely deleted';
-      actionIcon = 'delete_forever';
-      break;
-    case SupportedAction.ACTION_PAGE_REVERT:
-      actionMsg = 'reverted';
-      actionIcon = 'undo';
-      break;
-    case SupportedAction.ACTION_PAGE_RECURSIVELY_RENAME:
-      actionMsg = 'renamed under';
-      actionIcon = 'redo';
-      break;
-    case SupportedAction.ACTION_PAGE_RECURSIVELY_DELETE:
-      actionMsg = 'deleted under';
-      actionIcon = 'delete_forever';
-      break;
-    case SupportedAction.ACTION_PAGE_RECURSIVELY_DELETE_COMPLETELY:
-      actionMsg = 'deleted completely under';
-      actionIcon = 'delete_forever';
-      break;
-    case SupportedAction.ACTION_PAGE_RECURSIVELY_REVERT:
-      actionMsg = 'reverted under';
-      actionIcon = 'undo';
-      break;
-    case SupportedAction.ACTION_COMMENT_CREATE:
-      actionMsg = 'commented on';
-      actionIcon = 'comment';
-      break;
-    case SupportedAction.ACTION_USER_REGISTRATION_APPROVAL_REQUEST:
-      actionMsg = 'requested registration approval';
-      actionIcon = 'add_comment';
-      break;
-    case SupportedAction.ACTION_PAGE_BULK_EXPORT_COMPLETED:
-      actionMsg = 'export completed for';
-      actionIcon = 'download';
-      break;
-    case SupportedAction.ACTION_PAGE_BULK_EXPORT_FAILED:
-      actionMsg = 'export failed for';
-      actionIcon = 'error';
-      break;
-    default:
-      actionMsg = '';
-      actionIcon = '';
-  }
-
-  return {
-    actionMsg,
-    actionIcon,
-  };
-};