Skip to content

Commit 8ad614e

Browse files
committed
ShelterEditing: Send [null] list when all removed
1 parent 14aa833 commit 8ad614e

File tree

1 file changed

+42
-43
lines changed

1 file changed

+42
-43
lines changed

ui/src/hooks/stop-registry/useEditStopShelters.ts

+42-43
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
StopRegistryShelterCondition,
99
StopRegistryShelterElectricity,
1010
StopRegistryShelterType,
11+
StopRegistryStopPlaceInput,
1112
useUpdateStopPlaceMutation,
1213
} from '../../generated/graphql';
1314
import {
@@ -57,55 +58,53 @@ const mapShelterFormToInput = (shelter: ShelterState) => {
5758
};
5859
};
5960

60-
export const useEditStopShelters = () => {
61-
const { t } = useTranslation();
62-
const [updateStopPlaceMutation] = useUpdateStopPlaceMutation();
61+
function mapStopEditChangesToTiamatDbInput({
62+
state,
63+
stop,
64+
}: EditTiamatParams): StopRegistryStopPlaceInput {
65+
const stopPlaceId = stop.stop_place?.id;
66+
const quay = stop.stop_place?.quays?.[0];
67+
const stopPlaceQuayId = quay?.id;
6368

64-
const mapStopEditChangesToTiamatDbInput = ({
65-
state,
66-
stop,
67-
}: EditTiamatParams) => {
68-
const stopPlaceId = stop.stop_place?.id;
69-
const quay = stop.stop_place?.quays?.[0];
70-
const stopPlaceQuayId = quay?.id;
69+
const sheltersInput = state.shelters
70+
.filter((s) => !s.toBeDeleted)
71+
.map(mapShelterFormToInput);
72+
const hasBicycleParking = sheltersInput.some((s) => s.bicycleParking);
7173

72-
const sheltersInput = state.shelters
73-
.filter((s) => !s.toBeDeleted)
74-
.map(mapShelterFormToInput);
75-
const hasBicycleParking = sheltersInput.some((s) => s.bicycleParking);
76-
77-
const input = {
78-
...getRequiredStopPlaceMutationProperties(stop.stop_place),
79-
id: stopPlaceId,
80-
quays: [
81-
{
82-
id: stopPlaceQuayId,
83-
placeEquipments: {
84-
shelterEquipment: sheltersInput.length ? sheltersInput : null,
85-
cycleStorageEquipment: hasBicycleParking
86-
? [
87-
{
88-
// Use "Other" since we don't know the specific type
89-
cycleStorageType: StopRegistryCycleStorageType.Other,
90-
},
91-
]
92-
: null,
93-
},
74+
return {
75+
...getRequiredStopPlaceMutationProperties(stop.stop_place),
76+
id: stopPlaceId,
77+
quays: [
78+
{
79+
id: stopPlaceQuayId,
80+
placeEquipments: {
81+
shelterEquipment: sheltersInput.length ? sheltersInput : [null],
82+
cycleStorageEquipment: hasBicycleParking
83+
? [
84+
{
85+
// Use "Other" since we don't know the specific type
86+
cycleStorageType: StopRegistryCycleStorageType.Other,
87+
},
88+
]
89+
: [null],
9490
},
95-
],
96-
};
97-
98-
return input;
91+
},
92+
],
9993
};
94+
}
10095

101-
const prepareEditForTiamatDb = ({ state, stop }: EditTiamatParams) => {
102-
return {
103-
input: mapStopEditChangesToTiamatDbInput({
104-
state,
105-
stop,
106-
}),
107-
};
96+
function prepareEditForTiamatDb({ state, stop }: EditTiamatParams) {
97+
return {
98+
input: mapStopEditChangesToTiamatDbInput({
99+
state,
100+
stop,
101+
}),
108102
};
103+
}
104+
105+
export const useEditStopShelters = () => {
106+
const { t } = useTranslation();
107+
const [updateStopPlaceMutation] = useUpdateStopPlaceMutation();
109108

110109
const updateTiamatStopPlace = async (editParams: EditTiamatParams) => {
111110
const changesToTiamatDb = prepareEditForTiamatDb(editParams);

0 commit comments

Comments
 (0)