|
8 | 8 | StopRegistryShelterCondition,
|
9 | 9 | StopRegistryShelterElectricity,
|
10 | 10 | StopRegistryShelterType,
|
| 11 | + StopRegistryStopPlaceInput, |
11 | 12 | useUpdateStopPlaceMutation,
|
12 | 13 | } from '../../generated/graphql';
|
13 | 14 | import {
|
@@ -57,55 +58,53 @@ const mapShelterFormToInput = (shelter: ShelterState) => {
|
57 | 58 | };
|
58 | 59 | };
|
59 | 60 |
|
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; |
63 | 68 |
|
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); |
71 | 73 |
|
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], |
94 | 90 | },
|
95 |
| - ], |
96 |
| - }; |
97 |
| - |
98 |
| - return input; |
| 91 | + }, |
| 92 | + ], |
99 | 93 | };
|
| 94 | +} |
100 | 95 |
|
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 | + }), |
108 | 102 | };
|
| 103 | +} |
| 104 | + |
| 105 | +export const useEditStopShelters = () => { |
| 106 | + const { t } = useTranslation(); |
| 107 | + const [updateStopPlaceMutation] = useUpdateStopPlaceMutation(); |
109 | 108 |
|
110 | 109 | const updateTiamatStopPlace = async (editParams: EditTiamatParams) => {
|
111 | 110 | const changesToTiamatDb = prepareEditForTiamatDb(editParams);
|
|
0 commit comments