diff --git a/front/src/applications/stdcm/components/StdcmForm/StdcmDestination.tsx b/front/src/applications/stdcm/components/StdcmForm/StdcmDestination.tsx
index 4f46570a04f..5da7ce58cfc 100644
--- a/front/src/applications/stdcm/components/StdcmForm/StdcmDestination.tsx
+++ b/front/src/applications/stdcm/components/StdcmForm/StdcmDestination.tsx
@@ -1,9 +1,6 @@
-import { useMemo } from 'react';
-
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
-import { getTimesInfoFromDate } from 'applications/stdcm/utils';
import DestinationIcon from 'assets/pictures/mapMarkers/destination.svg';
import { useOsrdConfSelectors } from 'common/osrdContext';
import type { StdcmConfSelectors } from 'reducers/osrdconf/stdcmConf/selectors';
@@ -20,13 +17,6 @@ const StdcmDestination = ({ disabled = false }: StdcmConfigCardProps) => {
const destination = useSelector(getStdcmDestination);
- const { destinationArrival } = useMemo(
- () => ({
- destinationArrival: getTimesInfoFromDate(destination.arrival),
- }),
- [destination]
- );
-
return (
{
pathStepId={destination.id}
disabled={disabled}
/>
-
+
);
};
diff --git a/front/src/applications/stdcm/components/StdcmForm/StdcmOpSchedule.tsx b/front/src/applications/stdcm/components/StdcmForm/StdcmOpSchedule.tsx
index 717becb169e..fd88053265c 100644
--- a/front/src/applications/stdcm/components/StdcmForm/StdcmOpSchedule.tsx
+++ b/front/src/applications/stdcm/components/StdcmForm/StdcmOpSchedule.tsx
@@ -8,7 +8,7 @@ import { useOsrdConfActions, useOsrdConfSelectors } from 'common/osrdContext';
import type { StdcmConfSliceActions } from 'reducers/osrdconf/stdcmConf';
import type { StdcmPathStep } from 'reducers/osrdconf/types';
import { useAppDispatch } from 'store';
-import { formatDateString, isArrivalDateInSearchTimeWindow } from 'utils/date';
+import { dateToHHMMSS, formatDateString } from 'utils/date';
import { createStringSelectOptions } from 'utils/uiCoreHelpers';
import type { ArrivalTimeTypes, ScheduleConstraint } from '../../types';
@@ -16,30 +16,11 @@ import type { ArrivalTimeTypes, ScheduleConstraint } from '../../types';
type StdcmOpScheduleProps = {
disabled: boolean;
pathStep: Extract;
- opTimingData?: {
- date: Date;
- arrivalDate: string;
- arrivalTime: string;
- arrivalTimeHours: number;
- arrivalTimeMinutes: number;
- };
opId: string;
isOrigin?: boolean;
};
-const defaultDate = (date?: Date) => {
- const newDate = date ? new Date(date) : new Date();
- newDate.setHours(0, 0, 0);
- return newDate;
-};
-
-const StdcmOpSchedule = ({
- disabled,
- pathStep,
- opTimingData,
- opId,
- isOrigin = false,
-}: StdcmOpScheduleProps) => {
+const StdcmOpSchedule = ({ disabled, pathStep, opId, isOrigin = false }: StdcmOpScheduleProps) => {
const { t } = useTranslation('stdcm');
const dispatch = useAppDispatch();
@@ -47,21 +28,20 @@ const StdcmOpSchedule = ({
const { getSearchDatetimeWindow } = useOsrdConfSelectors();
const searchDatetimeWindow = useSelector(getSearchDatetimeWindow);
- const { arrivalDate, arrivalTime, arrivalTimeHours, arrivalTimeMinutes } = useMemo(() => {
- const isArrivalDateValid =
- opTimingData?.arrivalDate &&
- isArrivalDateInSearchTimeWindow(opTimingData.date, searchDatetimeWindow);
-
+ const { arrivalTime, arrivalTimeHours, arrivalTimeMinutes } = useMemo(() => {
+ if (!pathStep.arrival) {
+ return {
+ arrivalTime: undefined,
+ arrivalTimeHours: undefined,
+ arrivalTimeMinutes: undefined,
+ };
+ }
return {
- arrivalDate:
- opTimingData && isArrivalDateValid
- ? opTimingData.date
- : defaultDate(searchDatetimeWindow?.begin),
- arrivalTime: opTimingData?.arrivalTime,
- arrivalTimeHours: opTimingData?.arrivalTimeHours,
- arrivalTimeMinutes: opTimingData?.arrivalTimeMinutes,
+ arrivalTime: dateToHHMMSS(pathStep.arrival, { withoutSeconds: true }),
+ arrivalTimeHours: pathStep.arrival.getHours(),
+ arrivalTimeMinutes: pathStep.arrival.getMinutes(),
};
- }, [opTimingData, searchDatetimeWindow]);
+ }, [pathStep.arrival]);
const tolerances = useMemo(
() => ({
@@ -137,7 +117,7 @@ const StdcmOpSchedule = ({
disabled,
}}
selectableSlot={selectableSlot}
- value={arrivalDate}
+ value={pathStep.arrival}
onDateChange={(e) => {
onArrivalChange({
date: e,
@@ -153,7 +133,11 @@ const StdcmOpSchedule = ({
hours={arrivalTimeHours}
minutes={arrivalTimeMinutes}
onTimeChange={({ hours, minutes }) => {
- onArrivalChange({ date: arrivalDate, hours, minutes });
+ onArrivalChange({
+ date: pathStep.arrival || searchDatetimeWindow!.begin,
+ hours,
+ minutes,
+ });
}}
disabled={disabled}
value={arrivalTime}
diff --git a/front/src/applications/stdcm/components/StdcmForm/StdcmOrigin.tsx b/front/src/applications/stdcm/components/StdcmForm/StdcmOrigin.tsx
index 8623b65fe84..63b760c2bac 100644
--- a/front/src/applications/stdcm/components/StdcmForm/StdcmOrigin.tsx
+++ b/front/src/applications/stdcm/components/StdcmForm/StdcmOrigin.tsx
@@ -1,9 +1,6 @@
-import { useMemo } from 'react';
-
import { useTranslation } from 'react-i18next';
import { useSelector } from 'react-redux';
-import { getTimesInfoFromDate } from 'applications/stdcm/utils';
import OriginIcon from 'assets/pictures/mapMarkers/start.svg';
import { useOsrdConfSelectors } from 'common/osrdContext';
import type { StdcmConfSelectors } from 'reducers/osrdconf/stdcmConf/selectors';
@@ -19,13 +16,6 @@ const StdcmOrigin = ({ disabled = false }: StdcmConfigCardProps) => {
const { getStdcmOrigin } = useOsrdConfSelectors() as StdcmConfSelectors;
const origin = useSelector(getStdcmOrigin);
- const { originArrival } = useMemo(
- () => ({
- originArrival: getTimesInfoFromDate(origin.arrival),
- }),
- [origin]
- );
-
return (
{
pathStepId={origin.id}
disabled={disabled}
/>
-
+
);
};