1- import { forwardRef , useImperativeHandle , useMemo } from 'react' ;
1+ import { DateTime } from 'luxon' ;
2+ import { forwardRef , useImperativeHandle , useMemo , useState } from 'react' ;
23import { MapLayerMouseEvent } from 'react-map-gl/maplibre' ;
34import { useDispatch } from 'react-redux' ;
45import { ReusableComponentsVehicleModeEnum } from '../../../generated/graphql' ;
78 MapEntityEditorViewState ,
89 Operation ,
910 closeTimingPlaceModalAction ,
11+ isCopyMode ,
1012 isModalOpen ,
13+ selectCopyStopId ,
1114 selectEditedStopAreaData ,
1215 selectMapStopViewState ,
1316 setCopyStopIdAction ,
@@ -29,6 +32,8 @@ import {
2932 mapStopToCommonConflictItem ,
3033} from '../../routes-and-lines/common/ConflictResolverModal' ;
3134import { EditStoplayerRef } from '../refTypes' ;
35+ import { CopyStopConfirmationDialog } from './CopyStopConfirmationDialog' ;
36+ import { CopyStopModal } from './CopyStopModal' ;
3237import { DeleteStopConfirmationDialog } from './DeleteStopConfirmationDialog' ;
3338import { EditStopConfirmationDialog } from './EditStopConfirmationDialog' ;
3439import { EditStopModal } from './EditStopModal' ;
@@ -40,6 +45,7 @@ import {
4045 useDeleteStopUtils ,
4146 useEditStopUtils ,
4247} from './hooks' ;
48+ import { useMapCopyStopUtils } from './hooks/useMapCopyStopUtils' ;
4349import { LineToActiveStopArea } from './LineToActiveStopArea' ;
4450import { LineToClosestInfraLink } from './LineToClosestInfraLink' ;
4551import { Stop } from './Stop' ;
@@ -107,27 +113,46 @@ function useDefaultValues(
107113type EditStopLayerProps = {
108114 readonly draftLocation : Point | null ;
109115 readonly onEditingFinished : ( netexId : string | null ) => void ;
116+ readonly onCopyFinished : (
117+ netexId : string ,
118+ validityStart : DateTime ,
119+ validityEnd ?: DateTime ,
120+ ) => void ;
110121 readonly onPopupClose : ( ) => void ;
111122 readonly selectedStopId : string | null ;
112123} ;
113124
114125export const EditStopLayer = forwardRef < EditStoplayerRef , EditStopLayerProps > (
115- ( { draftLocation, onEditingFinished, onPopupClose, selectedStopId } , ref ) => {
116- const { stopInfo, loading } = useGetStopInfoForEditingOnMap ( selectedStopId ) ;
117- useMapDataLayerLoader (
118- Operation . FetchStopInfo ,
119- ! ! stopInfo || ! selectedStopId ,
120- loading ,
121- ) ;
122-
126+ (
127+ {
128+ draftLocation,
129+ onEditingFinished,
130+ onCopyFinished,
131+ onPopupClose,
132+ selectedStopId,
133+ } ,
134+ ref ,
135+ ) => {
123136 const dispatch = useDispatch ( ) ;
124137
138+ const copyStopId = useAppSelector ( selectCopyStopId ) ;
125139 const mapStopViewState = useAppSelector ( selectMapStopViewState ) ;
126140 const setMapStopViewState = useAppAction ( setMapStopViewStateAction ) ;
127141 const setCopyStopId = useAppAction ( setCopyStopIdAction ) ;
128142
143+ const { stopInfo, loading } = useGetStopInfoForEditingOnMap (
144+ selectedStopId ?? copyStopId ,
145+ ) ;
146+ useMapDataLayerLoader (
147+ Operation . FetchStopInfo ,
148+ ! ! stopInfo || ( ! selectedStopId && ! copyStopId ) ,
149+ loading ,
150+ ) ;
151+
129152 const defaultValues = useDefaultValues ( draftLocation , stopInfo ) ;
130153
154+ const [ copyDialogOpen , setCopyDialogOpen ] = useState ( false ) ;
155+
131156 const onCloseEditors = ( ) => {
132157 setMapStopViewState ( MapEntityEditorViewState . NONE ) ;
133158 dispatch ( closeTimingPlaceModalAction ( ) ) ;
@@ -154,6 +179,19 @@ export const EditStopLayer = forwardRef<EditStoplayerRef, EditStopLayerProps>(
154179 const { deleteChanges, onDeleteStop, onConfirmDelete, onCancelDelete } =
155180 useDeleteStopUtils ( stopInfo , onFinishEditing ) ;
156181
182+ const {
183+ defaultStopFormValues,
184+ onStartCopyStop,
185+ onCancelCopyStop,
186+ onCloseCopyModal,
187+ onCopyStopFormSubmit,
188+ } = useMapCopyStopUtils (
189+ stopInfo ,
190+ onCopyFinished ,
191+ onPopupClose ,
192+ setCopyDialogOpen ,
193+ ) ;
194+
157195 if ( createChanges && editChanges ) {
158196 throw new Error ( 'Undefined state' ) ;
159197 }
@@ -184,9 +222,10 @@ export const EditStopLayer = forwardRef<EditStoplayerRef, EditStopLayerProps>(
184222 dispatch ( setSelectedRouteIdAction ( undefined ) ) ;
185223 } ;
186224
187- const onStartCopyStop = ( ) => {
225+ const onInitCopyStop = ( ) => {
188226 if ( selectedStopId ) {
189227 setCopyStopId ( selectedStopId ) ;
228+ setCopyDialogOpen ( true ) ;
190229 }
191230 } ;
192231
@@ -215,7 +254,7 @@ export const EditStopLayer = forwardRef<EditStoplayerRef, EditStopLayerProps>(
215254 onMove = { onStartMoveStop }
216255 onDelete = { onDeleteStop }
217256 onClose = { onCloseEditors }
218- onCopy = { onStartCopyStop }
257+ onCopy = { onInitCopyStop }
219258 />
220259 ) }
221260
@@ -256,6 +295,21 @@ export const EditStopLayer = forwardRef<EditStoplayerRef, EditStopLayerProps>(
256295 deleteChanges = { deleteChanges }
257296 />
258297 ) }
298+
299+ < CopyStopConfirmationDialog
300+ isOpen = { copyDialogOpen }
301+ onConfirm = { onStartCopyStop }
302+ onCancel = { onCancelCopyStop }
303+ />
304+
305+ { isCopyMode ( mapStopViewState ) && ! ! defaultStopFormValues && (
306+ < CopyStopModal
307+ defaultValues = { defaultStopFormValues }
308+ onCancel = { onCloseCopyModal }
309+ onClose = { onCloseCopyModal }
310+ onSubmit = { onCopyStopFormSubmit }
311+ />
312+ ) }
259313 </ >
260314 ) ;
261315 } ,
0 commit comments