import React from 'react'; import { isPopulated, type HasObjectId } from '@growi/core'; import { useTranslation } from 'react-i18next'; import type { IPageBulkExportJobHasId } from '~/features/page-bulk-export/interfaces/page-bulk-export'; import { SupportedAction, SupportedTargetModel } from '~/interfaces/activity'; import type { IInAppNotification } from '~/interfaces/in-app-notification'; import * as pageBulkExportJobSerializers from '~/models/serializers/in-app-notification-snapshot/page-bulk-export-job'; import { ModelNotification } from './ModelNotification'; import { useActionMsgAndIconForModelNotification } from './useActionAndMsg'; import type { ModelNotificationUtils } from '.'; export const usePageBulkExportJobModelNotification = (notification: IInAppNotification & HasObjectId): ModelNotificationUtils | null => { const { t } = useTranslation(); const { actionMsg, actionIcon } = useActionMsgAndIconForModelNotification(notification); const isPageBulkExportJobModelNotification = ( notification: IInAppNotification & HasObjectId, ): notification is IInAppNotification & HasObjectId => { return notification.targetModel === SupportedTargetModel.MODEL_PAGE_BULK_EXPORT_JOB; }; if (!isPageBulkExportJobModelNotification(notification)) { return null; } const actionUsers = notification.user.username; notification.parsedSnapshot = pageBulkExportJobSerializers.parseSnapshot(notification.snapshot); const getSubMsg = (): React.ReactElement => { if (notification.action === SupportedAction.ACTION_PAGE_BULK_EXPORT_COMPLETED && notification.target == null) { return
{t('page_export.bulk_export_download_expired')}
; } if (notification.action === SupportedAction.ACTION_PAGE_BULK_EXPORT_JOB_EXPIRED) { return
{t('page_export.bulk_export_job_expired')}
; } return <>; }; const Notification = () => { return ( ); }; const clickLink = (notification.action === SupportedAction.ACTION_PAGE_BULK_EXPORT_COMPLETED && notification.target?.attachment != null && isPopulated(notification.target?.attachment)) ? notification.target.attachment.downloadPathProxied : undefined; return { Notification, clickLink, isDisabled: notification.target == null, }; };