-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathOutputTemplate.tsx
106 lines (98 loc) · 2.88 KB
/
OutputTemplate.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
import type {
DeleteOutputTemplateMutation,
DeleteOutputTemplateMutationVariables,
FindOutputTemplateById,
} from 'types/graphql'
import { Link, routes, navigate } from '@redwoodjs/router'
import { useMutation } from '@redwoodjs/web'
import type { TypedDocumentNode } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'
import { timeTag } from 'src/lib/formatters'
const DELETE_OUTPUT_TEMPLATE_MUTATION: TypedDocumentNode<
DeleteOutputTemplateMutation,
DeleteOutputTemplateMutationVariables
> = gql`
mutation DeleteOutputTemplateMutation($id: Int!) {
deleteOutputTemplate(id: $id) {
id
}
}
`
interface Props {
outputTemplate: NonNullable<FindOutputTemplateById['outputTemplate']>
}
const OutputTemplate = ({ outputTemplate }: Props) => {
const [deleteOutputTemplate] = useMutation(DELETE_OUTPUT_TEMPLATE_MUTATION, {
onCompleted: () => {
toast.success('OutputTemplate deleted')
navigate(routes.outputTemplates())
},
onError: (error) => {
toast.error(error.message)
},
})
const onDeleteClick = (id: DeleteOutputTemplateMutationVariables['id']) => {
if (confirm('Are you sure you want to delete outputTemplate ' + id + '?')) {
deleteOutputTemplate({ variables: { id } })
}
}
return (
<>
<div className="rw-segment">
<header className="rw-segment-header">
<h2 className="rw-heading rw-heading-secondary">
OutputTemplate {outputTemplate.id} Detail
</h2>
</header>
<table className="rw-table">
<tbody>
<tr>
<th>Id</th>
<td>{outputTemplate.id}</td>
</tr>
<tr>
<th>Name</th>
<td>{outputTemplate.name}</td>
</tr>
<tr>
<th>Version</th>
<td>{outputTemplate.version}</td>
</tr>
<tr>
<th>Effective date</th>
<td>{timeTag(outputTemplate.effectiveDate)}</td>
</tr>
<tr>
<th>Rules generated at</th>
<td>{timeTag(outputTemplate.rulesGeneratedAt)}</td>
</tr>
<tr>
<th>Created at</th>
<td>{timeTag(outputTemplate.createdAt)}</td>
</tr>
<tr>
<th>Updated at</th>
<td>{timeTag(outputTemplate.updatedAt)}</td>
</tr>
</tbody>
</table>
</div>
<nav className="rw-button-group">
<Link
to={routes.editOutputTemplate({ id: outputTemplate.id })}
className="rw-button rw-button-blue"
>
Edit
</Link>
<button
type="button"
className="rw-button rw-button-red"
onClick={() => onDeleteClick(outputTemplate.id)}
>
Delete
</button>
</nav>
</>
)
}
export default OutputTemplate