UserModelNotification.tsx 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import React from 'react';
  2. import type { IUser, HasObjectId } from '@growi/core';
  3. import { useRouter } from 'next/router';
  4. import { SupportedTargetModel } from '~/interfaces/activity';
  5. import type { IInAppNotification } from '~/interfaces/in-app-notification';
  6. import { ModelNotification } from './ModelNotification';
  7. import { useActionMsgAndIconForModelNotification } from './useActionAndMsg';
  8. import type { ModelNotificationUtils } from '.';
  9. export const useUserModelNotification = (notification: IInAppNotification & HasObjectId): ModelNotificationUtils | null => {
  10. const { actionMsg, actionIcon } = useActionMsgAndIconForModelNotification(notification);
  11. const router = useRouter();
  12. const isUserModelNotification = (notification: IInAppNotification & HasObjectId): notification is IInAppNotification<IUser> & HasObjectId => {
  13. return notification.targetModel === SupportedTargetModel.MODEL_USER;
  14. };
  15. if (!isUserModelNotification(notification)) {
  16. return null;
  17. }
  18. const actionUsers = notification.target.username;
  19. const Notification = () => {
  20. return (
  21. <ModelNotification
  22. notification={notification}
  23. actionMsg={actionMsg}
  24. actionIcon={actionIcon}
  25. actionUsers={actionUsers}
  26. />
  27. );
  28. };
  29. const publishOpen = () => {
  30. router.push('/admin/users');
  31. };
  32. return {
  33. Notification,
  34. publishOpen,
  35. };
  36. };