|
@@ -1,19 +1,13 @@
|
|
|
-import React, {
|
|
|
|
|
- FC, useRef,
|
|
|
|
|
-} from 'react';
|
|
|
|
|
|
|
+import React, { FC } from 'react';
|
|
|
|
|
|
|
|
-import type { IUser, IPage, HasObjectId } from '@growi/core';
|
|
|
|
|
|
|
+import type { HasObjectId } from '@growi/core';
|
|
|
import { UserPicture } from '@growi/ui/dist/components';
|
|
import { UserPicture } from '@growi/ui/dist/components';
|
|
|
import { DropdownItem } from 'reactstrap';
|
|
import { DropdownItem } from 'reactstrap';
|
|
|
|
|
|
|
|
-import { IInAppNotificationOpenable } from '~/client/interfaces/in-app-notification-openable';
|
|
|
|
|
import { apiv3Post } from '~/client/util/apiv3-client';
|
|
import { apiv3Post } from '~/client/util/apiv3-client';
|
|
|
-import { SupportedTargetModel } from '~/interfaces/activity';
|
|
|
|
|
import { IInAppNotification, InAppNotificationStatuses } from '~/interfaces/in-app-notification';
|
|
import { IInAppNotification, InAppNotificationStatuses } from '~/interfaces/in-app-notification';
|
|
|
|
|
|
|
|
-// Change the display for each targetmodel
|
|
|
|
|
-import PageModelNotification from './PageNotification/PageModelNotification';
|
|
|
|
|
-import UserModelNotification from './PageNotification/UserModelNotification';
|
|
|
|
|
|
|
+import { useModelNotification } from './PageNotification';
|
|
|
|
|
|
|
|
interface Props {
|
|
interface Props {
|
|
|
notification: IInAppNotification & HasObjectId
|
|
notification: IInAppNotification & HasObjectId
|
|
@@ -26,7 +20,7 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
|
|
|
|
|
|
|
|
const { notification } = props;
|
|
const { notification } = props;
|
|
|
|
|
|
|
|
- const notificationRef = useRef<IInAppNotificationOpenable>(null);
|
|
|
|
|
|
|
+ const { Notification, publishOpen } = useModelNotification(notification, notification.targetModel);
|
|
|
|
|
|
|
|
const clickHandler = async(notification: IInAppNotification & HasObjectId): Promise<void> => {
|
|
const clickHandler = async(notification: IInAppNotification & HasObjectId): Promise<void> => {
|
|
|
if (notification.status === InAppNotificationStatuses.STATUS_UNOPENED) {
|
|
if (notification.status === InAppNotificationStatuses.STATUS_UNOPENED) {
|
|
@@ -34,10 +28,7 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
|
|
|
await apiv3Post('/in-app-notification/open', { id: notification._id });
|
|
await apiv3Post('/in-app-notification/open', { id: notification._id });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- const currentInstance = notificationRef.current;
|
|
|
|
|
- if (currentInstance != null) {
|
|
|
|
|
- currentInstance.open();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ publishOpen();
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
const renderActionUserPictures = (): JSX.Element => {
|
|
const renderActionUserPictures = (): JSX.Element => {
|
|
@@ -61,14 +52,6 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
|
|
|
|
|
|
|
|
const isDropdownItem = props.type === 'dropdown-item';
|
|
const isDropdownItem = props.type === 'dropdown-item';
|
|
|
|
|
|
|
|
- const isPageNotification = (notification: IInAppNotification): notification is IInAppNotification<IPage> => {
|
|
|
|
|
- return notification.targetModel === SupportedTargetModel.MODEL_PAGE;
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- const isUserNotification = (notification: IInAppNotification): notification is IInAppNotification<IUser> => {
|
|
|
|
|
- return notification.targetModel === SupportedTargetModel.MODEL_USER;
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
// determine tag
|
|
// determine tag
|
|
|
const TagElem = isDropdownItem
|
|
const TagElem = isDropdownItem
|
|
|
? DropdownItem
|
|
? DropdownItem
|
|
@@ -86,18 +69,9 @@ const InAppNotificationElm: FC<Props> = (props: Props) => {
|
|
|
>
|
|
>
|
|
|
</span>
|
|
</span>
|
|
|
{renderActionUserPictures()}
|
|
{renderActionUserPictures()}
|
|
|
- {isPageNotification(notification) && (
|
|
|
|
|
- <PageModelNotification
|
|
|
|
|
- ref={notificationRef}
|
|
|
|
|
- notification={notification}
|
|
|
|
|
- />
|
|
|
|
|
- )}
|
|
|
|
|
- {isUserNotification(notification) && (
|
|
|
|
|
- <UserModelNotification
|
|
|
|
|
- ref={notificationRef}
|
|
|
|
|
- notification={notification}
|
|
|
|
|
- />
|
|
|
|
|
- )}
|
|
|
|
|
|
|
+
|
|
|
|
|
+ <Notification />
|
|
|
|
|
+
|
|
|
</div>
|
|
</div>
|
|
|
</TagElem>
|
|
</TagElem>
|
|
|
);
|
|
);
|