/* * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. * SPDX-License-Identifier: Apache-2.0 */ import { CaseStatus } from '@aws/dea-app/lib/models/case-status'; import { Button, ColumnLayout, Container, ContentLayout, Header, SpaceBetween, Spinner, StatusIndicator, TextContent, } from '@cloudscape-design/components'; import { useRouter } from 'next/router'; import { useState } from 'react'; import { getCaseAuditCSV, useGetCaseActions, useGetCaseById } from '../../api/cases'; import { DeaCaseDTO } from '../../api/models/case'; import { auditLogLabels, caseDetailLabels, caseStatusLabels, commonLabels } from '../../common/labels'; import { useNotifications } from '../../context/NotificationsContext'; import { canDownloadCaseAudit, canUpdateCaseDetails } from '../../helpers/userActionSupport'; import CaseDetailsTabs from './CaseDetailsTabs'; export interface CaseDetailsBodyProps { readonly caseId: string; } function CaseDetailsBody(props: CaseDetailsBodyProps): JSX.Element { const router = useRouter(); const [downloadInProgress, setDownloadInProgress] = useState(false); const userActions = useGetCaseActions(props.caseId); const { data, isLoading } = useGetCaseById(props.caseId); const { pushNotification } = useNotifications(); function getStatusIcon(status: CaseStatus) { if (status == CaseStatus.ACTIVE) { return {caseStatusLabels.active}; } else { return {caseStatusLabels.inactive}; } } function editCaseHandler() { return router.push(`/edit-case?caseId=${props.caseId}`); } if (isLoading) { return

{commonLabels.loadingLabel}

; } else { if (!data) { return

{commonLabels.notFoundLabel}

; } return (
{data.name}
} > } > {caseDetailLabels.caseDetailsLabel} } >
{commonLabels.creationDate}

{new Date(data.created).toLocaleString([], { year: 'numeric', month: 'long', day: 'numeric', })}

{commonLabels.description}

{data.description ?? '-'}

{commonLabels.statusLabel}

{getStatusIcon(data.status)}

); } } const downloadCaseAudit = async (deaCase: DeaCaseDTO) => { const csv = await getCaseAuditCSV(deaCase.ulid); const blob = new Blob([csv], { type: 'text/csv' }); const fileUrl = window.URL.createObjectURL(blob); const alink = document.createElement('a'); alink.href = fileUrl; alink.download = `${deaCase.name}_Audit_${new Date().toLocaleString()}`; alink.click(); }; export default CaseDetailsBody;