-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcolumns.tsx
60 lines (54 loc) · 1.62 KB
/
columns.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
import { createColumnHelper } from '@tanstack/react-table'
import type { FindReportingPeriodsWithCertification } from 'types/graphql'
import { Link, routes } from '@redwoodjs/router'
import { formatDateString } from 'src/utils'
const columnHelper =
createColumnHelper<
FindReportingPeriodsWithCertification['reportingPeriodsWithCertification']
>()
export const columnDefs = ({ certificationDisplay, canEdit, isUSDRAdmin }) => {
const columns = [
columnHelper.accessor('id', {
header: 'ID',
enableSorting: true,
}),
columnHelper.accessor('name', {
header: 'Name',
enableSorting: false,
}),
columnHelper.accessor('startDate', {
cell: (info) => formatDateString(info.getValue()),
header: 'Start Date',
}),
columnHelper.accessor('endDate', {
cell: (info) => formatDateString(info.getValue()),
header: 'End Date',
}),
columnHelper.accessor((row) => certificationDisplay(row), {
id: 'certification',
cell: (info) => info.getValue(),
header: 'Certified At',
enableSorting: false,
}),
]
if (isUSDRAdmin) {
columns.push(
columnHelper.accessor('id', {
id: 'actions',
cell: (info) =>
canEdit(info.row.original) ? (
<Link
to={routes.editReportingPeriod({ id: info.row.original.id })}
title={'Edit reportingPeriod ' + info.row.original.id}
className="btn btn-secondary btn-sm"
>
Edit
</Link>
) : null,
header: 'Actions',
enableSorting: false,
})
)
}
return columns
}