-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathOrganization.tsx
79 lines (72 loc) · 1.97 KB
/
Organization.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
import type {
DeleteOrganizationMutationVariables,
FindOrganizationById,
} from 'types/graphql'
import { Link, routes, navigate } from '@redwoodjs/router'
import { useMutation } from '@redwoodjs/web'
import { toast } from '@redwoodjs/web/toast'
const DELETE_ORGANIZATION_MUTATION = gql`
mutation DeleteOrganizationMutation($id: Int!) {
deleteOrganization(id: $id) {
id
}
}
`
interface Props {
organization: NonNullable<FindOrganizationById['organization']>
}
const Organization = ({ organization }: Props) => {
const [deleteOrganization] = useMutation(DELETE_ORGANIZATION_MUTATION, {
onCompleted: () => {
toast.success('Organization deleted')
navigate(routes.organizations())
},
onError: (error) => {
toast.error(error.message)
},
})
const onDeleteClick = (id: DeleteOrganizationMutationVariables['id']) => {
if (confirm('Are you sure you want to delete organization ' + id + '?')) {
deleteOrganization({ variables: { id } })
}
}
return (
<>
<div className="rw-segment">
<header className="rw-segment-header">
<h2 className="rw-heading rw-heading-secondary">
Organization {organization.id} Detail
</h2>
</header>
<table className="rw-table">
<tbody>
<tr>
<th>Id</th>
<td>{organization.id}</td>
</tr>
<tr>
<th>Name</th>
<td>{organization.name}</td>
</tr>
</tbody>
</table>
</div>
<nav className="rw-button-group">
<Link
to={routes.editOrganization({ id: organization.id })}
className="rw-button rw-button-blue"
>
Edit
</Link>
<button
type="button"
className="rw-button rw-button-red"
onClick={() => onDeleteClick(organization.id)}
>
Delete
</button>
</nav>
</>
)
}
export default Organization