PageModelNotification.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import React, {
  2. forwardRef, ForwardRefRenderFunction,
  3. } from 'react';
  4. import type { HasObjectId } from '@growi/core';
  5. import { useRouter } from 'next/router';
  6. import type { IInAppNotificationOpenable } from '~/client/interfaces/in-app-notification-openable';
  7. import type { IInAppNotification } from '~/interfaces/in-app-notification';
  8. import { ModelNotification } from './ModelNotification';
  9. import { useActionMsgAndIconForPageModelNotification } from './useActionAndMsg';
  10. interface Props {
  11. notification: IInAppNotification & HasObjectId
  12. actionUsers: string
  13. }
  14. const PageModelNotification: ForwardRefRenderFunction<IInAppNotificationOpenable, Props> = (props: Props, ref) => {
  15. const {
  16. notification, actionUsers,
  17. } = props;
  18. const { actionMsg, actionIcon } = useActionMsgAndIconForPageModelNotification(notification);
  19. const router = useRouter();
  20. // publish open()
  21. const publishOpen = () => {
  22. if (notification.target != null) {
  23. // jump to target page
  24. const targetPagePath = notification.target.path;
  25. if (targetPagePath != null) {
  26. router.push(targetPagePath);
  27. }
  28. }
  29. };
  30. return (
  31. <ModelNotification
  32. notification={notification}
  33. actionMsg={actionMsg}
  34. actionIcon={actionIcon}
  35. actionUsers={actionUsers}
  36. publishOpen={publishOpen}
  37. ref={ref}
  38. />
  39. );
  40. };
  41. export default forwardRef(PageModelNotification);