PageBulkExportJobModelNotification.tsx 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import React from 'react';
  2. import { isPopulated, type HasObjectId } from '@growi/core';
  3. import { useTranslation } from 'react-i18next';
  4. import type { IPageBulkExportJobHasId } from '~/features/page-bulk-export/interfaces/page-bulk-export';
  5. import { SupportedTargetModel } from '~/interfaces/activity';
  6. import type { IInAppNotification } from '~/interfaces/in-app-notification';
  7. import * as pageBulkExportJobSerializers from '~/models/serializers/in-app-notification-snapshot/page-bulk-export-job';
  8. import { ModelNotification } from './ModelNotification';
  9. import { useActionMsgAndIconForModelNotification } from './useActionAndMsg';
  10. import type { ModelNotificationUtils } from '.';
  11. export const usePageBulkExportJobModelNotification = (notification: IInAppNotification & HasObjectId): ModelNotificationUtils | null => {
  12. const { actionMsg, actionIcon } = useActionMsgAndIconForModelNotification(notification);
  13. const { t } = useTranslation();
  14. const isPageBulkExportJobModelNotification = (
  15. notification: IInAppNotification & HasObjectId,
  16. ): notification is IInAppNotification<IPageBulkExportJobHasId> & HasObjectId => {
  17. return notification.targetModel === SupportedTargetModel.MODEL_PAGE_BULK_EXPORT_JOB;
  18. };
  19. if (!isPageBulkExportJobModelNotification(notification)) {
  20. return null;
  21. }
  22. const actionUsers = notification.user.username;
  23. notification.parsedSnapshot = pageBulkExportJobSerializers.parseSnapshot(notification.snapshot);
  24. const Notification = () => {
  25. return (
  26. <ModelNotification
  27. notification={notification}
  28. actionMsg={actionMsg}
  29. actionIcon={actionIcon}
  30. actionUsers={actionUsers}
  31. />
  32. );
  33. };
  34. const clickLink = notification.target?.attachment != null && isPopulated(notification.target?.attachment)
  35. ? notification.target.attachment.downloadPathProxied : undefined;
  36. return {
  37. Notification,
  38. clickLink,
  39. };
  40. };