From b2dd017298f5b62506fa57d9812bd0d907a99b7f Mon Sep 17 00:00:00 2001 From: Jonas Brunvoll Larsson Date: Thu, 14 Nov 2024 12:53:09 +0100 Subject: [PATCH] Ensure that users must manually set the date of the incident --- .../contact/components/form/date-selector.tsx | 11 +++++++++-- .../group-travel/group-travel-state-machine.ts | 4 ---- .../contact/means-of-transport/forms/delayForm.tsx | 1 + .../contact/means-of-transport/forms/driverForm.tsx | 1 + .../contact/means-of-transport/forms/injuryForm.tsx | 1 + .../means-of-transport/forms/transportationForm.tsx | 1 + .../means-of-transport-form-machine.ts | 2 -- .../contact/ticket-control/forms/feedbackForm.tsx | 1 + .../ticket-control/ticket-control-form-machine.ts | 2 -- .../contact/travel-guarantee/forms/refundCarForm.tsx | 1 + .../contact/travel-guarantee/forms/refundTaxiForm.tsx | 1 + .../travel-guarantee/travelGuaranteeFormMachine.ts | 4 +--- src/page-modules/contact/utils.ts | 3 --- 13 files changed, 17 insertions(+), 16 deletions(-) diff --git a/src/page-modules/contact/components/form/date-selector.tsx b/src/page-modules/contact/components/form/date-selector.tsx index d05eb1f3..0be25369 100644 --- a/src/page-modules/contact/components/form/date-selector.tsx +++ b/src/page-modules/contact/components/form/date-selector.tsx @@ -1,7 +1,7 @@ import style from './form.module.css'; import { MonoIcon } from '@atb/components/icon'; import { TranslatedString, useTranslation } from '@atb/translations'; -import { fromDate, parseDate } from '@internationalized/date'; +import { fromDate } from '@internationalized/date'; import { Button, Calendar, @@ -16,26 +16,32 @@ import { Label, Popover, } from 'react-aria-components'; +import ErrorMessage from './error-message'; export type DateSelectorProps = { label: TranslatedString; value?: string; + errorMessage?: TranslatedString; onChange: (value: string) => void; }; export default function DateSelector({ label, value, + errorMessage, onChange, }: DateSelectorProps) { const { t } = useTranslation(); + const zonedDateTime = value + ? fromDate(new Date(value || ''), 'Europe/Oslo') + : undefined; return (
onChange(e.toString().slice(0, 10))} className={style.dateSelector} shouldForceLeadingZeros @@ -78,6 +84,7 @@ export default function DateSelector({ + {errorMessage && }
); } diff --git a/src/page-modules/contact/group-travel/group-travel-state-machine.ts b/src/page-modules/contact/group-travel/group-travel-state-machine.ts index 31296285..513c1605 100644 --- a/src/page-modules/contact/group-travel/group-travel-state-machine.ts +++ b/src/page-modules/contact/group-travel/group-travel-state-machine.ts @@ -1,6 +1,5 @@ import { assign, fromPromise, setup } from 'xstate'; import { Line } from '../server/journey-planner/validators'; -import { getCurrentDateString } from '../utils'; export type GroupTravelContextType = { travelType: 'bus' | 'boat' | null; @@ -137,9 +136,6 @@ export const groupTravelStateMachine = setup({ initial: 'selectTravelType', context: { travelType: null, - formData: { - dateOfTravel: getCurrentDateString(), - }, errors: defaultErrors, } as GroupTravelContextType, on: { diff --git a/src/page-modules/contact/means-of-transport/forms/delayForm.tsx b/src/page-modules/contact/means-of-transport/forms/delayForm.tsx index 25c0dae1..7d73a6fe 100644 --- a/src/page-modules/contact/means-of-transport/forms/delayForm.tsx +++ b/src/page-modules/contact/means-of-transport/forms/delayForm.tsx @@ -140,6 +140,7 @@ export const DelayForm = ({ state, send }: DelayFormProps) => { value: date, }) } + errorMessage={state.context?.errorMessages['date']?.[0]} /> { value: date, }) } + errorMessage={state.context?.errorMessages['date']?.[0]} /> { value: date, }) } + errorMessage={state.context?.errorMessages['date']?.[0]} /> { value: date, }) } + errorMessage={state.context?.errorMessages['date']?.[0]} /> { value: date, }) } + errorMessage={state.context?.errorMessages['date']?.[0]} /> { value: date, }) } + errorMessage={state.context?.errorMessages['date']?.[0]} /> - new Date().toISOString().split('T')[0]; - export const setTransportModeAndResetLineAndStops = ( context: any, transporMode: TransportModeType,