PageBulkExportJobModelNotification.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 { SupportedAction, 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 { t } = useTranslation();
  13. const { actionMsg, actionIcon } = useActionMsgAndIconForModelNotification(notification);
  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 subMsg = (notification.action === SupportedAction.ACTION_PAGE_BULK_EXPORT_COMPLETED && notification.target == null)
  25. ? <div className="text-danger"><small>{t('page_export.bulk_export_download_expired')}</small></div> : <></>;
  26. const Notification = () => {
  27. return (
  28. <ModelNotification
  29. notification={notification}
  30. actionMsg={actionMsg}
  31. actionIcon={actionIcon}
  32. actionUsers={actionUsers}
  33. hideActionUsers
  34. subMsg={subMsg}
  35. />
  36. );
  37. };
  38. const clickLink = (notification.action === SupportedAction.ACTION_PAGE_BULK_EXPORT_COMPLETED
  39. && notification.target?.attachment != null && isPopulated(notification.target?.attachment))
  40. ? notification.target.attachment.downloadPathProxied : undefined;
  41. return {
  42. Notification,
  43. clickLink,
  44. isDisabled: notification.target == null,
  45. };
  46. };