-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcolumns.tsx
103 lines (95 loc) · 3.33 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
import { createColumnHelper, ColumnDef } from '@tanstack/react-table'
import { ParsedSubrecipient, FindSubrecipients } from 'types/graphql'
import SubrecipientTableUploadLinksDisplay from 'src/components/Subrecipient/SubrecipientTableUploadLinksDisplay/SubrecipientTableUploadLinksDisplay'
import { formatDateString, formatPhoneNumber } from 'src/utils'
const columnHelper =
createColumnHelper<FindSubrecipients['subrecipients'][number]>()
function formatDetails(
parsedSubrecipient: ParsedSubrecipient | null | undefined
) {
if (!parsedSubrecipient) return 'No details available'
const fields = [
{ label: 'Name', value: parsedSubrecipient.name },
{ label: 'Recipient ID', value: parsedSubrecipient.recipientId },
{ label: 'POC Name', value: parsedSubrecipient.pocName },
{
label: 'POC Phone Number',
value:
formatPhoneNumber(parsedSubrecipient.pocPhoneNumber) ||
parsedSubrecipient.pocPhoneNumber,
},
{ label: 'POC Email Address', value: parsedSubrecipient.pocEmailAddress },
{ label: 'Zip5', value: parsedSubrecipient.zip5 },
{ label: 'Zip4', value: parsedSubrecipient.zip4 },
{ label: 'Address Line 1', value: parsedSubrecipient.addressLine1 },
{ label: 'Address Line 2', value: parsedSubrecipient.addressLine2 },
{ label: 'Address Line 3', value: parsedSubrecipient.addressLine3 },
{ label: 'City', value: parsedSubrecipient.city },
{ label: 'State', value: parsedSubrecipient.state },
]
return (
<ul className="list-unstyled">
{fields.map(({ label, value }) => (
<li key={label}>
<strong>{label}:</strong> {value || ''}
</li>
))}
</ul>
)
}
const getUEI = (ueiTinCombo: string) => ueiTinCombo.split('_')[0]
const getTIN = (ueiTinCombo: string) => ueiTinCombo.split('_')[1]
export const columnDefs: ColumnDef<
FindSubrecipients['subrecipients'][number]
>[] = [
columnHelper.accessor((row) => getUEI(row.ueiTinCombo), {
id: 'uei',
cell: (info) => info.getValue() ?? '',
header: 'UEI',
enableSorting: false,
}),
columnHelper.accessor((row) => getTIN(row.ueiTinCombo), {
id: 'tin',
cell: (info) => info.getValue() ?? '',
header: 'TIN',
enableSorting: false,
}),
columnHelper.accessor('validSubrecipientUploads', {
id: 'details',
header: 'Details',
cell: (info) => {
const uploads = info.getValue()
if (uploads && uploads.length > 0 && uploads[0].parsedSubrecipient) {
return formatDetails(uploads[0].parsedSubrecipient)
}
return 'No details available'
},
enableSorting: false,
}),
columnHelper.accessor('createdAt', {
cell: (info) => formatDateString(info.getValue()),
header: 'Created Date',
}),
columnHelper.accessor('validSubrecipientUploads', {
id: 'lastUpdatedDate',
header: 'Last Updated Date',
cell: (info) => {
const uploads = info.getValue()
if (uploads && uploads.length > 0 && uploads[0].updatedAt) {
return formatDateString(uploads[0].updatedAt)
}
return 'N/A'
},
}),
{
id: 'links',
header: 'Upload Links',
cell: ({ row }) => (
<SubrecipientTableUploadLinksDisplay
validSubrecipientUploads={row.original.validSubrecipientUploads}
invalidSubrecipientUploads={row.original.invalidSubrecipientUploads}
/>
),
enableSorting: false,
},
]