import React, { forwardRef, ForwardRefRenderFunction, useImperativeHandle, } from 'react'; import type { HasObjectId } from '@growi/core'; import { PagePathLabel } from '@growi/ui/dist/components/PagePath'; import { useRouter } from 'next/router'; import type { IInAppNotificationOpenable } from '~/client/interfaces/in-app-notification-openable'; import type { IInAppNotification } from '~/interfaces/in-app-notification'; import FormattedDistanceDate from '../../FormattedDistanceDate'; interface Props { notification: IInAppNotification & HasObjectId actionMsg: string actionIcon: string actionUsers: string } const PageModelNotification: ForwardRefRenderFunction = (props: Props, ref) => { const { notification, actionMsg, actionIcon, actionUsers, } = props; const router = useRouter(); // publish open() useImperativeHandle(ref, () => ({ open() { if (notification.target != null) { // jump to target page const targetPagePath = notification.target.path; if (targetPagePath != null) { router.push(targetPagePath); } } }, })); return (
{actionUsers} {actionMsg}
); }; export default forwardRef(PageModelNotification);