-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathOutputTemplates.tsx
108 lines (101 loc) · 3.62 KB
/
OutputTemplates.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
104
105
106
107
108
import type {
DeleteOutputTemplateMutation,
DeleteOutputTemplateMutationVariables,
FindOutputTemplates,
} from 'types/graphql'
import { Link, routes } from '@redwoodjs/router'
import { useMutation } from '@redwoodjs/web'
import type { TypedDocumentNode } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'
import { QUERY } from 'src/components/OutputTemplate/OutputTemplatesCell'
import { timeTag, truncate } from 'src/lib/formatters'
const DELETE_OUTPUT_TEMPLATE_MUTATION: TypedDocumentNode<
DeleteOutputTemplateMutation,
DeleteOutputTemplateMutationVariables
> = gql`
mutation DeleteOutputTemplateMutation($id: Int!) {
deleteOutputTemplate(id: $id) {
id
}
}
`
const OutputTemplatesList = ({ outputTemplates }: FindOutputTemplates) => {
const [deleteOutputTemplate] = useMutation(DELETE_OUTPUT_TEMPLATE_MUTATION, {
onCompleted: () => {
toast.success('OutputTemplate deleted')
},
onError: (error) => {
toast.error(error.message)
},
// This refetches the query on the list page. Read more about other ways to
// update the cache over here:
// https://www.apollographql.com/docs/react/data/mutations/#making-all-other-cache-updates
refetchQueries: [{ query: QUERY }],
awaitRefetchQueries: true,
})
const onDeleteClick = (id: DeleteOutputTemplateMutationVariables['id']) => {
if (confirm('Are you sure you want to delete outputTemplate ' + id + '?')) {
deleteOutputTemplate({ variables: { id } })
}
}
return (
<div className="rw-segment rw-table-wrapper-responsive">
<table className="rw-table">
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Version</th>
<th>Effective date</th>
<th>Rules generated at</th>
<th>Created at</th>
<th>Updated at</th>
<th> </th>
</tr>
</thead>
<tbody>
{outputTemplates.map((outputTemplate) => (
<tr key={outputTemplate.id}>
<td>{truncate(outputTemplate.id)}</td>
<td>{truncate(outputTemplate.name)}</td>
<td>{truncate(outputTemplate.version)}</td>
<td>{timeTag(outputTemplate.effectiveDate)}</td>
<td>{timeTag(outputTemplate.rulesGeneratedAt)}</td>
<td>{timeTag(outputTemplate.createdAt)}</td>
<td>{timeTag(outputTemplate.updatedAt)}</td>
<td>
<nav className="rw-table-actions">
<Link
to={routes.outputTemplate({ id: outputTemplate.id })}
title={
'Show outputTemplate ' + outputTemplate.id + ' detail'
}
className="rw-button rw-button-small"
>
Show
</Link>
<Link
to={routes.editOutputTemplate({ id: outputTemplate.id })}
title={'Edit outputTemplate ' + outputTemplate.id}
className="rw-button rw-button-small rw-button-blue"
>
Edit
</Link>
<button
type="button"
title={'Delete outputTemplate ' + outputTemplate.id}
className="rw-button rw-button-small rw-button-red"
onClick={() => onDeleteClick(outputTemplate.id)}
>
Delete
</button>
</nav>
</td>
</tr>
))}
</tbody>
</table>
</div>
)
}
export default OutputTemplatesList