-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathuse-add-update-control.tsx
89 lines (79 loc) · 2.79 KB
/
use-add-update-control.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
import { gql, MutationTuple, useMutation } from '@apollo/client'
import { GET_MISSION_TIMELINE } from "../timeline/use-mission-timeline.tsx";
import { ActionControl } from "../../../types/action-types.ts";
import { useParams } from "react-router-dom";
import { ControlType } from "../../../types/control-types.ts";
import { GET_ACTION_BY_ID } from "../actions/use-action-by-id.tsx";
export const MUTATION_ADD_OR_UPDATE_CONTROL_GENS_DE_MER = gql`
mutation AddOrUpdateControlGensDeMer($control: ControlGensDeMerInput!) {
addOrUpdateControlGensDeMer(control: $control) {
id
amountOfControls
unitShouldConfirm
unitHasConfirmed
staffOutnumbered
upToDateMedicalCheck
knowledgeOfFrenchLawAndLanguage
observations
}
}
`
export const MUTATION_ADD_OR_UPDATE_CONTROL_NAVIGATION = gql`
mutation AddOrUpdateControlNavigation($control: ControlNavigationInput!) {
addOrUpdateControlNavigation(control: $control) {
id
amountOfControls
unitShouldConfirm
unitHasConfirmed
observations
}
}
`
export const MUTATION_ADD_OR_UPDATE_CONTROL_SECURITY = gql`
mutation AddOrUpdateControlSecurity($control: ControlSecurityInput!) {
addOrUpdateControlSecurity(control: $control) {
id
amountOfControls
unitShouldConfirm
unitHasConfirmed
observations
}
}
`
export const MUTATION_ADD_OR_UPDATE_CONTROL_ADMINISTRATIVE = gql`
mutation AddOrUpdateControlAdministrative($control: ControlAdministrativeInput!) {
addOrUpdateControlAdministrative(control: $control) {
id
amountOfControls
unitShouldConfirm
unitHasConfirmed
compliantOperatingPermit
upToDateNavigationPermit
compliantSecurityDocuments
observations
}
}
`
const mutations = {
[ControlType.ADMINISTRATIVE]: MUTATION_ADD_OR_UPDATE_CONTROL_ADMINISTRATIVE,
[ControlType.NAVIGATION]: MUTATION_ADD_OR_UPDATE_CONTROL_NAVIGATION,
[ControlType.SECURITY]: MUTATION_ADD_OR_UPDATE_CONTROL_SECURITY,
[ControlType.GENS_DE_MER]: MUTATION_ADD_OR_UPDATE_CONTROL_GENS_DE_MER,
}
export interface UseAddOrUpdateControlProps {
controlType: ControlType
}
const useAddOrUpdateControl = ({controlType}: UseAddOrUpdateControlProps): MutationTuple<ActionControl, Record<string, any>> => {
const {missionId} = useParams()
const mutation = useMutation(
mutations[controlType],
{
refetchQueries: [
{query: GET_MISSION_TIMELINE, variables: {missionId}},
GET_ACTION_BY_ID
]
}
)
return mutation
}
export default useAddOrUpdateControl