|
@@ -2,7 +2,7 @@ import React, {
|
|
|
forwardRef, ForwardRefRenderFunction,
|
|
forwardRef, ForwardRefRenderFunction,
|
|
|
} from 'react';
|
|
} from 'react';
|
|
|
|
|
|
|
|
-import type { HasObjectId } from '@growi/core';
|
|
|
|
|
|
|
+import type { IPage, HasObjectId } from '@growi/core';
|
|
|
import { useRouter } from 'next/router';
|
|
import { useRouter } from 'next/router';
|
|
|
|
|
|
|
|
import type { IInAppNotificationOpenable } from '~/client/interfaces/in-app-notification-openable';
|
|
import type { IInAppNotificationOpenable } from '~/client/interfaces/in-app-notification-openable';
|
|
@@ -13,20 +13,40 @@ import { useActionMsgAndIconForPageModelNotification } from './useActionAndMsg';
|
|
|
|
|
|
|
|
|
|
|
|
|
interface Props {
|
|
interface Props {
|
|
|
- notification: IInAppNotification & HasObjectId
|
|
|
|
|
- actionUsers: string
|
|
|
|
|
|
|
+ notification: IInAppNotification<IPage> & HasObjectId
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const PageModelNotification: ForwardRefRenderFunction<IInAppNotificationOpenable, Props> = (props: Props, ref) => {
|
|
const PageModelNotification: ForwardRefRenderFunction<IInAppNotificationOpenable, Props> = (props: Props, ref) => {
|
|
|
|
|
|
|
|
- const {
|
|
|
|
|
- notification, actionUsers,
|
|
|
|
|
- } = props;
|
|
|
|
|
|
|
+ const { notification } = props;
|
|
|
|
|
|
|
|
const { actionMsg, actionIcon } = useActionMsgAndIconForPageModelNotification(notification);
|
|
const { actionMsg, actionIcon } = useActionMsgAndIconForPageModelNotification(notification);
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
|
|
+ const getActionUsers = () => {
|
|
|
|
|
+ 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;
|
|
|
|
|
+ };
|
|
|
|
|
+
|
|
|
|
|
+ const actionUsers = getActionUsers();
|
|
|
|
|
+
|
|
|
// publish open()
|
|
// publish open()
|
|
|
const publishOpen = () => {
|
|
const publishOpen = () => {
|
|
|
if (notification.target != null) {
|
|
if (notification.target != null) {
|