-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add control unit dialogs on map [WIP]
- Loading branch information
1 parent
b01be8d
commit 3e3f7d3
Showing
74 changed files
with
2,476 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { monitorenvApi } from '.' | ||
import { FrontendApiError } from '../libs/FrontendApiError' | ||
|
||
import type { Administration } from '@mtes-mct/monitor-ui' | ||
|
||
export const ARCHIVE_ADMINISTRATION_ERROR_MESSAGE = [ | ||
'Certaines unités de cette administration ne sont pas archivées.', | ||
'Veuillez les archiver pour pouvoir archiver cette administration.' | ||
].join(' ') | ||
export const DELETE_ADMINISTRATION_ERROR_MESSAGE = [ | ||
'Des unités sont encore rattachées à cette administration.', | ||
'Veuillez les supprimer avant de pouvoir supprimer cette administration.' | ||
].join(' ') | ||
const GET_ADMINISTRATION_ERROR_MESSAGE = "Nous n'avons pas pu récupérer cette administration." | ||
const GET_ADMINISTRATIONS_ERROR_MESSAGE = "Nous n'avons pas pu récupérer la liste des administrations." | ||
|
||
export const monitorenvAdministrationApi = monitorenvApi.injectEndpoints({ | ||
endpoints: builder => ({ | ||
getAdministration: builder.query<Administration.Administration, number>({ | ||
providesTags: () => [{ type: 'Administrations' }], | ||
query: administrationId => `/v1/administrations/${administrationId}`, | ||
transformErrorResponse: response => new FrontendApiError(GET_ADMINISTRATION_ERROR_MESSAGE, response) | ||
}), | ||
|
||
getAdministrations: builder.query<Administration.Administration[], void>({ | ||
providesTags: () => [{ type: 'Administrations' }], | ||
query: () => `/v1/administrations`, | ||
transformErrorResponse: response => new FrontendApiError(GET_ADMINISTRATIONS_ERROR_MESSAGE, response) | ||
}) | ||
}) | ||
}) | ||
|
||
export const { useGetAdministrationQuery, useGetAdministrationsQuery } = monitorenvAdministrationApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,37 @@ | ||
import { monitorenvApi } from '.' | ||
import { FrontendApiError } from '../libs/FrontendApiError' | ||
|
||
import type { ControlUnit } from '../domain/types/controlUnit' | ||
import type { ControlUnit } from '@mtes-mct/monitor-ui' | ||
|
||
export const controlUnitApi = monitorenvApi.injectEndpoints({ | ||
const GET_CONTROL_UNIT_ERROR_MESSAGE = "Nous n'avons pas pu récupérer cette unité de contrôle." | ||
const GET_CONTROL_UNITS_ERROR_MESSAGE = "Nous n'avons pas pu récupérer la liste des unités de contrôle." | ||
const UPDATE_CONTROL_UNIT_ERROR_MESSAGE = "Nous n'avons pas pu mettre à jour cette unité de contrôle." | ||
|
||
export const monitorenvControlUnitApi = monitorenvApi.injectEndpoints({ | ||
endpoints: builder => ({ | ||
getControlUnit: builder.query<ControlUnit.ControlUnit, number>({ | ||
providesTags: () => [{ type: 'ControlUnits' }], | ||
query: controlUnitId => `/v2/control_units/${controlUnitId}`, | ||
transformErrorResponse: response => new FrontendApiError(GET_CONTROL_UNIT_ERROR_MESSAGE, response) | ||
}), | ||
|
||
getControlUnits: builder.query<ControlUnit.ControlUnit[], void>({ | ||
providesTags: () => [{ type: 'ControlUnits' }], | ||
query: () => `/control_units` | ||
query: () => `/v2/control_units`, | ||
transformErrorResponse: response => new FrontendApiError(GET_CONTROL_UNITS_ERROR_MESSAGE, response) | ||
}), | ||
|
||
updateControlUnit: builder.mutation<void, ControlUnit.ControlUnitData>({ | ||
invalidatesTags: () => [{ type: 'Administrations' }, { type: 'ControlUnits' }], | ||
query: nextControlUnitData => ({ | ||
body: nextControlUnitData, | ||
method: 'PUT', | ||
url: `/v2/control_units/${nextControlUnitData.id}` | ||
}), | ||
transformErrorResponse: response => new FrontendApiError(UPDATE_CONTROL_UNIT_ERROR_MESSAGE, response) | ||
}) | ||
}) | ||
}) | ||
|
||
export const { useGetControlUnitsQuery } = controlUnitApi | ||
export const { useGetControlUnitQuery, useGetControlUnitsQuery, useUpdateControlUnitMutation } = | ||
monitorenvControlUnitApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { monitorenvApi } from '.' | ||
import { FrontendApiError } from '../libs/FrontendApiError' | ||
|
||
import type { ControlUnit } from '@mtes-mct/monitor-ui' | ||
|
||
const GET_CONTROL_UNIT_CONTACT_ERROR_MESSAGE = "Nous n'avons pas pu récupérer cette contact." | ||
const GET_CONTROL_UNIT_CONTACTS_ERROR_MESSAGE = "Nous n'avons pas pu récupérer la liste des contacts." | ||
|
||
export const monitorenvControlUnitContactApi = monitorenvApi.injectEndpoints({ | ||
endpoints: builder => ({ | ||
createControlUnitContact: builder.mutation<void, ControlUnit.NewControlUnitContactData>({ | ||
invalidatesTags: () => [{ type: 'ControlUnits' }], | ||
query: newControlUnitContactData => ({ | ||
body: newControlUnitContactData, | ||
method: 'POST', | ||
url: `/v1/control_unit_contacts` | ||
}) | ||
}), | ||
|
||
deleteControlUnitContact: builder.mutation<void, number>({ | ||
invalidatesTags: () => [{ type: 'ControlUnits' }], | ||
query: controlUnitContactId => ({ | ||
method: 'DELETE', | ||
url: `/v1/control_unit_contacts/${controlUnitContactId}` | ||
}) | ||
}), | ||
|
||
getControlUnitContact: builder.query<ControlUnit.ControlUnitContact, number>({ | ||
providesTags: () => [{ type: 'ControlUnits' }], | ||
query: controlUnitContactId => `/v1/control_unit_contacts/${controlUnitContactId}`, | ||
transformErrorResponse: response => new FrontendApiError(GET_CONTROL_UNIT_CONTACT_ERROR_MESSAGE, response) | ||
}), | ||
|
||
getControlUnitContacts: builder.query<ControlUnit.ControlUnitContact[], void>({ | ||
providesTags: () => [{ type: 'ControlUnits' }], | ||
query: () => `/v1/control_unit_contacts`, | ||
transformErrorResponse: response => new FrontendApiError(GET_CONTROL_UNIT_CONTACTS_ERROR_MESSAGE, response) | ||
}), | ||
|
||
updateControlUnitContact: builder.mutation<void, ControlUnit.ControlUnitContactData>({ | ||
invalidatesTags: () => [{ type: 'ControlUnits' }], | ||
query: nextControlUnitContactData => ({ | ||
body: nextControlUnitContactData, | ||
method: 'PUT', | ||
url: `/v1/control_unit_contacts/${nextControlUnitContactData.id}` | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
export const { | ||
useCreateControlUnitContactMutation, | ||
useDeleteControlUnitContactMutation, | ||
useGetControlUnitContactQuery, | ||
useGetControlUnitContactsQuery, | ||
useUpdateControlUnitContactMutation | ||
} = monitorenvControlUnitContactApi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import { monitorenvApi } from '.' | ||
import { ARCHIVE_GENERIC_ERROR_MESSAGE } from './constants' | ||
import { ApiErrorCode, type BackendApiBooleanResponse } from './types' | ||
import { FrontendApiError } from '../libs/FrontendApiError' | ||
import { newUserError } from '../libs/UserError' | ||
|
||
import type { ControlUnit } from '@mtes-mct/monitor-ui' | ||
|
||
export const ARCHIVE_CONTROL_UNITE_RESOURCE_ERROR_MESSAGE = "Nous n'avons pas pu archiver ce moyen." | ||
const CAN_DELETE_CONTROL_UNIT_RESOURCE_ERROR_MESSAGE = "Nous n'avons pas pu vérifier si ce moyen est supprimable." | ||
export const DELETE_CONTROL_UNIT_RESOURCE_ERROR_MESSAGE = | ||
"Ce moyen est rattaché à des missions. Veuillez l'en détacher avant de le supprimer." | ||
const GET_CONTROL_UNIT_RESOURCE_ERROR_MESSAGE = "Nous n'avons pas pu récupérer ce moyen." | ||
const GET_CONTROL_UNIT_RESOURCES_ERROR_MESSAGE = "Nous n'avons pas pu récupérer la liste des moyens." | ||
|
||
export const monitorenvControlUnitResourceApi = monitorenvApi.injectEndpoints({ | ||
endpoints: builder => ({ | ||
archiveControlUnitResource: builder.mutation<void, number>({ | ||
invalidatesTags: () => [{ type: 'ControlUnits' }, { type: 'Stations' }], | ||
query: controlUnitResourceId => ({ | ||
method: 'PUT', | ||
url: `/v1/control_unit_resources/${controlUnitResourceId}/archive` | ||
}), | ||
transformErrorResponse: response => { | ||
if (response.data.type === ApiErrorCode.UNARCHIVED_CHILD) { | ||
return newUserError(ARCHIVE_CONTROL_UNITE_RESOURCE_ERROR_MESSAGE) | ||
} | ||
|
||
return new FrontendApiError(ARCHIVE_GENERIC_ERROR_MESSAGE, response) | ||
} | ||
}), | ||
|
||
canDeleteControlUnitResource: builder.query<boolean, number>({ | ||
query: controlUnitResourceId => `/v1/control_unit_resources/${controlUnitResourceId}/can_delete`, | ||
transformErrorResponse: response => | ||
new FrontendApiError(CAN_DELETE_CONTROL_UNIT_RESOURCE_ERROR_MESSAGE, response), | ||
transformResponse: (response: BackendApiBooleanResponse) => response.value | ||
}), | ||
|
||
createControlUnitResource: builder.mutation<void, ControlUnit.NewControlUnitResourceData>({ | ||
invalidatesTags: () => [{ type: 'ControlUnits' }, { type: 'Stations' }], | ||
query: newControlUnitResourceData => ({ | ||
body: newControlUnitResourceData, | ||
method: 'POST', | ||
url: `/v1/control_unit_resources` | ||
}) | ||
}), | ||
|
||
deleteControlUnitResource: builder.mutation<void, number>({ | ||
invalidatesTags: () => [{ type: 'ControlUnits' }, { type: 'Stations' }], | ||
query: controlUnitResourceId => ({ | ||
method: 'DELETE', | ||
url: `/v1/control_unit_resources/${controlUnitResourceId}` | ||
}), | ||
transformErrorResponse: response => { | ||
if (response.data.type === ApiErrorCode.FOREIGN_KEY_CONSTRAINT) { | ||
return newUserError(DELETE_CONTROL_UNIT_RESOURCE_ERROR_MESSAGE) | ||
} | ||
|
||
return new FrontendApiError(DELETE_CONTROL_UNIT_RESOURCE_ERROR_MESSAGE, response) | ||
} | ||
}), | ||
|
||
getControlUnitResource: builder.query<ControlUnit.ControlUnitResource, number>({ | ||
providesTags: () => [{ type: 'ControlUnits' }], | ||
query: controlUnitResourceId => `/v1/control_unit_resources/${controlUnitResourceId}`, | ||
transformErrorResponse: response => new FrontendApiError(GET_CONTROL_UNIT_RESOURCE_ERROR_MESSAGE, response) | ||
}), | ||
|
||
getControlUnitResources: builder.query<ControlUnit.ControlUnitResource[], void>({ | ||
providesTags: () => [{ type: 'ControlUnits' }], | ||
query: () => `/v1/control_unit_resources`, | ||
transformErrorResponse: response => new FrontendApiError(GET_CONTROL_UNIT_RESOURCES_ERROR_MESSAGE, response) | ||
}), | ||
|
||
updateControlUnitResource: builder.mutation<void, ControlUnit.ControlUnitResourceData>({ | ||
invalidatesTags: () => [{ type: 'ControlUnits' }, { type: 'Stations' }], | ||
query: nextControlUnitResourceData => ({ | ||
body: nextControlUnitResourceData, | ||
method: 'PUT', | ||
url: `/v1/control_unit_resources/${nextControlUnitResourceData.id}` | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
export const { | ||
useArchiveControlUnitResourceMutation, | ||
useCanDeleteControlUnitResourceQuery, | ||
useCreateControlUnitResourceMutation, | ||
useDeleteControlUnitResourceMutation, | ||
useGetControlUnitResourceQuery, | ||
useGetControlUnitResourcesQuery, | ||
useUpdateControlUnitResourceMutation | ||
} = monitorenvControlUnitResourceApi |
Oops, something went wrong.