2
0

UserModelNotification.tsx 1.4 KB

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