Skip to content

Commit

Permalink
Ensure that users must manually set the date of the incident
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbrunvoll committed Nov 14, 2024
1 parent 71ce965 commit b2dd017
Show file tree
Hide file tree
Showing 13 changed files with 17 additions and 16 deletions.
11 changes: 9 additions & 2 deletions src/page-modules/contact/components/form/date-selector.tsx
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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 (
<div className={style.dateSelectorContainer}>
<Label>{t(label)}</Label>
<DatePicker
granularity="day"
value={fromDate(new Date(value || ''), 'Europe/Oslo')}
value={zonedDateTime}
onChange={(e) => onChange(e.toString().slice(0, 10))}
className={style.dateSelector}
shouldForceLeadingZeros
Expand Down Expand Up @@ -78,6 +84,7 @@ export default function DateSelector({
</Dialog>
</Popover>
</DatePicker>
{errorMessage && <ErrorMessage message={t(errorMessage)} />}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -137,9 +136,6 @@ export const groupTravelStateMachine = setup({
initial: 'selectTravelType',
context: {
travelType: null,
formData: {
dateOfTravel: getCurrentDateString(),
},
errors: defaultErrors,
} as GroupTravelContextType,
on: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export const DelayForm = ({ state, send }: DelayFormProps) => {
value: date,
})
}
errorMessage={state.context?.errorMessages['date']?.[0]}
/>

<TimeSelector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ export const DriverForm = ({ state, send }: DriverFormProps) => {
value: date,
})
}
errorMessage={state.context?.errorMessages['date']?.[0]}
/>

<TimeSelector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ export const InjuryForm = ({ state, send }: InjuryFormProps) => {
value: date,
})
}
errorMessage={state.context?.errorMessages['date']?.[0]}
/>

<TimeSelector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ export const TransportationForm = ({
value: date,
})
}
errorMessage={state.context?.errorMessages['date']?.[0]}
/>

<TimeSelector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { Line } from '../server/journey-planner/validators';
import { commonInputValidator, InputErrorMessages } from '../validation';
import {
convertFilesToBase64,
getCurrentDateString,
setLineAndResetStops,
setTransportModeAndResetLineAndStops,
} from '../utils';
Expand Down Expand Up @@ -248,7 +247,6 @@ export const meansOfTransportFormMachine = setup({
/** @xstate-layout N4IgpgJg5mDOIC5QAoC2BDAxgCwJYDswBKAOlwgBswBiAZQFUAhAWQEkAVAbQAYBdRUAAcA9rFwAXXMPwCQAD0QBGAGzcSAZgCsATnXLlAJi2rN6gDQgAnkoDsmktxsAObstN7FN5eoC+Pi2hYeISk5FTU7ADyAOLRADIAojz8SCAiYpLSsgoIACyKJNpFxSUlFtYIRvZO6rUqBg3c3Fp+ARg4BMRklDTsAIIAGqzJsukSUjKpOSpqWrr6VSbmVojqueoaBk6K3AbOqjYGyq0ggR0hJJDj+FB0TGxcfKOi41lTiJqaBdyKmoaKTmcTkB2nKtnsjhcblqyk83hOZ2CXSukhudAS7AA+uwAEp9ABytAACpEcVjmJEACJJJ6pMaZSagHJ2NSKXKudnqGw7TSAsGVdTaEhOYpOTQ2ZqmZS5BHtJGkCjCdAQAi3CDSMBkfAAN2EAGtNYjOgqlSqbggCLrMOgGckRnSXgzsh8vg5fv9AcCQfztiRcsVnHpuO4bLKgsaSIrlarqGAAE5x4RxkiCCg2gBmSdQJCNFyjZqgFp1wmttr49qEjomzoQn2+7oMAKB3pWlQM9nF20cn20nj8-hA+GEEDgslzxGeGWr7wQAFplA4mkvl8ubPz52Hzl0wmBJ69GfIPkLcgZtMpudovmze6DW7UbH7FGzT9wnA12TKB+PSCjVXunTO2wPq47anmK3DaGKuT8msBS5M4EFit4Ng2OoBifm04Z5qaf4OlObxMqsmi5H6TjrGRhwoV4wb8r8BgOAh5FNCo56bvKJCwAArpgmBwPAeH7jWQEOIYmhgZoiHEbRzQkKY2jBl83C5GKnihv2QA */
initial: 'editing',
context: {
date: getCurrentDateString(),
isResponseWanted: false,
errorMessages: {},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ export const FeedbackForm = ({ state, send }: FeedbackFormProps) => {
value: date,
})
}
errorMessage={state.context?.errorMessages['date']?.[0]}
/>

<TimeSelector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { assign, fromPromise, setup } from 'xstate';
import { ticketControlFormEvents } from './events';
import {
convertFilesToBase64,
getCurrentDateString,
setBankAccountStatusAndResetBankInformation,
setLineAndResetStops,
setTransportModeAndResetLineAndStops,
Expand Down Expand Up @@ -325,7 +324,6 @@ export const ticketControlFormMachine = setup({
id: 'ticketControlForm',
initial: 'editing',
context: {
date: getCurrentDateString(),
agreesFirstAgreement: false,
agreesSecondAgreement: false,
hasInternationalBankAccount: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export const RefundCarForm = ({ state, send }: RefundCarFormProps) => {
value: date,
})
}
errorMessage={state.context?.errorMessages['date']?.[0]}
/>
<TimeSelector
label={PageText.Contact.input.plannedDepartureTime.label}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ export const RefundTaxiForm = ({ state, send }: RefundTaxiFormProps) => {
value: date,
})
}
errorMessage={state.context?.errorMessages['date']?.[0]}
/>

<TimeSelector
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ReasonForTransportFailure } from './events';
import { commonInputValidator, InputErrorMessages } from '../validation';
import {
convertFilesToBase64,
getCurrentDateString,
setBankAccountStatusAndResetBankInformation,
setLineAndResetStops,
setTransportModeAndResetLineAndStops,
Expand Down Expand Up @@ -61,7 +60,7 @@ export type ContextProps = {
line?: Line | undefined;
fromStop?: Line['quays'][0] | undefined;
toStop?: Line['quays'][0] | undefined;
date: string;
date?: string;
plannedDepartureTime?: string;
kilometersDriven?: string;
fromAddress?: string;
Expand Down Expand Up @@ -293,7 +292,6 @@ export const fetchMachine = setup({
context: {
isIntialAgreementChecked: false,
hasInternationalBankAccount: false,
date: getCurrentDateString(),
errorMessages: {},
},
states: {
Expand Down
3 changes: 0 additions & 3 deletions src/page-modules/contact/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ export const convertFilesToBase64 = (
return Promise.all(filePromises);
};

export const getCurrentDateString = (): string =>
new Date().toISOString().split('T')[0];

export const setTransportModeAndResetLineAndStops = (
context: any,
transporMode: TransportModeType,
Expand Down

0 comments on commit b2dd017

Please sign in to comment.