-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathUploadSeriesTable.tsx
67 lines (60 loc) · 2.04 KB
/
UploadSeriesTable.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import type { FindUploadById } from 'types/graphql'
import TableBuilder from 'src/components/TableBuilder/TableBuilder'
import { columnDefs } from 'src/components/Upload/UploadSeriesTable/columns'
export type UploadSeriesRow =
FindUploadById['upload']['seriesUploads'][number] & {
_isCurrentUpload: boolean
_isFirstValid: boolean
}
interface UploadSeriesTableProps {
upload: FindUploadById['upload']
seriesUploads: FindUploadById['upload']['seriesUploads']
}
const UploadSeriesTable = ({
upload,
seriesUploads,
}: UploadSeriesTableProps) => {
const ecCode = upload.expenditureCategory?.code || 'Not set'
const firstValid = seriesUploads.find(
(upload) => upload.latestValidation?.passed
)
const formattedRows: UploadSeriesRow[] = seriesUploads.map((seriesUpload) => {
return {
...seriesUpload,
_isCurrentUpload: seriesUpload.id === upload.id,
_isFirstValid: seriesUpload.id === firstValid?.id,
}
})
return (
<div>
<h3 className="mb-2">
Upload Series from{' '}
<span className="text-primary">{upload.agency.code}</span>, EC Code{' '}
<span className="text-primary">{ecCode}</span> in period{' '}
<span className="text-primary">{upload.reportingPeriod?.name}</span>
</h3>
<div className="mb-2">
{firstValid ? (
'The upload highlighted in green will be used for Treasury Reporting.'
) : (
<span>
Agency <span className="text-primary">{upload.agency.code}</span>{' '}
does not have a valid upload with code{' '}
<span className="text-primary">{ecCode}</span> to use in Treasury
reporting for{' '}
<span className="text-primary">{upload.reportingPeriod?.name}</span>
</span>
)}
</div>
<div className="row">
<div className="col-lg-6">
<TableBuilder<UploadSeriesRow>
data={formattedRows}
columns={columnDefs}
/>
</div>
</div>
</div>
)
}
export default UploadSeriesTable