useActionAndMsg.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. import type { HasObjectId } from '@growi/core';
  2. import { SupportedAction } from '~/interfaces/activity';
  3. import type { IInAppNotification } from '~/interfaces/in-app-notification';
  4. export type ActionMsgAndIconType = {
  5. actionMsg: string
  6. actionIcon: string
  7. }
  8. export const useActionMsgAndIconForPageModelNotification = (notification: IInAppNotification & HasObjectId): ActionMsgAndIconType => {
  9. const actionType: string = notification.action;
  10. let actionMsg: string;
  11. let actionIcon: string;
  12. switch (actionType) {
  13. case SupportedAction.ACTION_PAGE_LIKE:
  14. actionMsg = 'liked';
  15. actionIcon = 'icon-like';
  16. break;
  17. case SupportedAction.ACTION_PAGE_BOOKMARK:
  18. actionMsg = 'bookmarked on';
  19. actionIcon = 'icon-star';
  20. break;
  21. case SupportedAction.ACTION_PAGE_UPDATE:
  22. actionMsg = 'updated on';
  23. actionIcon = 'ti ti-agenda';
  24. break;
  25. case SupportedAction.ACTION_PAGE_RENAME:
  26. actionMsg = 'renamed';
  27. actionIcon = 'icon-action-redo';
  28. break;
  29. case SupportedAction.ACTION_PAGE_DUPLICATE:
  30. actionMsg = 'duplicated';
  31. actionIcon = 'icon-docs';
  32. break;
  33. case SupportedAction.ACTION_PAGE_DELETE:
  34. actionMsg = 'deleted';
  35. actionIcon = 'icon-trash';
  36. break;
  37. case SupportedAction.ACTION_PAGE_DELETE_COMPLETELY:
  38. actionMsg = 'completely deleted';
  39. actionIcon = 'icon-fire';
  40. break;
  41. case SupportedAction.ACTION_PAGE_REVERT:
  42. actionMsg = 'reverted';
  43. actionIcon = 'icon-action-undo';
  44. break;
  45. case SupportedAction.ACTION_PAGE_RECURSIVELY_RENAME:
  46. actionMsg = 'renamed under';
  47. actionIcon = 'icon-action-redo';
  48. break;
  49. case SupportedAction.ACTION_PAGE_RECURSIVELY_DELETE:
  50. actionMsg = 'deleted under';
  51. actionIcon = 'icon-trash';
  52. break;
  53. case SupportedAction.ACTION_PAGE_RECURSIVELY_DELETE_COMPLETELY:
  54. actionMsg = 'deleted completely under';
  55. actionIcon = 'icon-fire';
  56. break;
  57. case SupportedAction.ACTION_PAGE_RECURSIVELY_REVERT:
  58. actionMsg = 'reverted under';
  59. actionIcon = 'icon-action-undo';
  60. break;
  61. case SupportedAction.ACTION_COMMENT_CREATE:
  62. actionMsg = 'commented on';
  63. actionIcon = 'icon-bubble';
  64. break;
  65. default:
  66. actionMsg = '';
  67. actionIcon = '';
  68. }
  69. return {
  70. actionMsg,
  71. actionIcon,
  72. };
  73. };
  74. export const useActionMsgAndIconForUserModelNotification = (notification: IInAppNotification & HasObjectId): ActionMsgAndIconType => {
  75. const actionType: string = notification.action;
  76. let actionMsg: string;
  77. let actionIcon: string;
  78. switch (actionType) {
  79. case SupportedAction.ACTION_USER_REGISTRATION_APPROVAL_REQUEST:
  80. actionMsg = 'requested registration approval';
  81. actionIcon = 'icon-bubble';
  82. break;
  83. default:
  84. actionMsg = '';
  85. actionIcon = '';
  86. }
  87. return {
  88. actionMsg,
  89. actionIcon,
  90. };
  91. };