-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathAgency.tsx
87 lines (80 loc) · 2.04 KB
/
Agency.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
import type {
DeleteAgencyMutationVariables,
FindAgencyById,
} from 'types/graphql'
import { Link, routes, navigate } from '@redwoodjs/router'
import { useMutation } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'
const DELETE_AGENCY_MUTATION = gql`
mutation DeleteAgencyMutation($id: Int!) {
deleteAgency(id: $id) {
id
}
}
`
interface Props {
agency: NonNullable<FindAgencyById['agency']>
}
const Agency = ({ agency }: Props) => {
const [deleteAgency] = useMutation(DELETE_AGENCY_MUTATION, {
onCompleted: () => {
toast.success('Agency deleted')
navigate(routes.agencies())
},
onError: (error) => {
toast.error(error.message)
},
})
const onDeleteClick = (id: DeleteAgencyMutationVariables['id']) => {
if (confirm('Are you sure you want to delete agency ' + id + '?')) {
deleteAgency({ variables: { id } })
}
}
return (
<>
<div className="rw-segment">
<header className="rw-segment-header">
<h2 className="rw-heading rw-heading-secondary">
Agency {agency.id} Detail
</h2>
</header>
<table className="rw-table">
<tbody>
<tr>
<th>Id</th>
<td>{agency.id}</td>
</tr>
<tr>
<th>Name</th>
<td>{agency.name}</td>
</tr>
<tr>
<th>Abbreviation</th>
<td>{agency.abbreviation}</td>
</tr>
<tr>
<th>Code</th>
<td>{agency.code}</td>
</tr>
</tbody>
</table>
</div>
<nav className="rw-button-group">
<Link
to={routes.editAgency({ id: agency.id })}
className="rw-button rw-button-blue"
>
Edit
</Link>
<button
type="button"
className="rw-button rw-button-red"
onClick={() => onDeleteClick(agency.id)}
>
Delete
</button>
</nav>
</>
)
}
export default Agency