Skip to content

Commit

Permalink
feat: set the time of the incident manually (#432)
Browse files Browse the repository at this point in the history
* Ensure that users must manually set the time of the incident

* Remove exessive undefined fallback.
  • Loading branch information
jonasbrunvoll authored Nov 14, 2024
1 parent e432159 commit 71ce965
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 14 deletions.
8 changes: 6 additions & 2 deletions src/page-modules/contact/components/form/time-selector.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import style from './form.module.css';
import { TranslatedString, useTranslation } from '@atb/translations';
import { parseTime } from '@internationalized/date';
import ErrorMessage from './error-message';
import {
DateInput,
DateSegment,
Expand All @@ -10,16 +11,18 @@ import {

export type TimeSelectorProps = {
label: TranslatedString;
value: string;
value?: string;
errorMessage?: TranslatedString;
onChange: (value: string) => void;
};
export default function TimeSelector({
label,
value,
errorMessage,
onChange,
}: TimeSelectorProps) {
const { t } = useTranslation();
const parsedValue = parseTime(value);
const parsedValue = value ? parseTime(value) : undefined;

return (
<div className={style.timeSelectorContainer}>
Expand All @@ -42,6 +45,7 @@ export default function TimeSelector({
)}
</DateInput>
</TimeField>
{errorMessage && <ErrorMessage message={t(errorMessage)} />}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { assign, fromPromise, setup } from 'xstate';
import { Line } from '../server/journey-planner/validators';
import { getCurrentDateString, getCurrentTimeString } from '../utils';
import { getCurrentDateString } from '../utils';

export type GroupTravelContextType = {
travelType: 'bus' | 'boat' | null;
Expand Down Expand Up @@ -139,7 +139,6 @@ export const groupTravelStateMachine = setup({
travelType: null,
formData: {
dateOfTravel: getCurrentDateString(),
departureTime: getCurrentTimeString(),
},
errors: defaultErrors,
} as GroupTravelContextType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ export const DelayForm = ({ state, send }: DelayFormProps) => {
value: time,
})
}
errorMessage={
state.context?.errorMessages['plannedDepartureTime']?.[0]
}
/>
</SectionCard>

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

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

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { commonInputValidator, InputErrorMessages } from '../validation';
import {
convertFilesToBase64,
getCurrentDateString,
getCurrentTimeString,
setLineAndResetStops,
setTransportModeAndResetLineAndStops,
} from '../utils';
Expand Down Expand Up @@ -250,7 +249,6 @@ export const meansOfTransportFormMachine = setup({
initial: 'editing',
context: {
date: getCurrentDateString(),
plannedDepartureTime: getCurrentTimeString(),
isResponseWanted: false,
errorMessages: {},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ export const FeedbackForm = ({ state, send }: FeedbackFormProps) => {
value: time,
})
}
errorMessage={
state.context?.errorMessages['plannedDepartureTime']?.[0]
}
/>
</SectionCard>
<SectionCard title={t(PageText.Contact.input.feedback.title)}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { ticketControlFormEvents } from './events';
import {
convertFilesToBase64,
getCurrentDateString,
getCurrentTimeString,
setBankAccountStatusAndResetBankInformation,
setLineAndResetStops,
setTransportModeAndResetLineAndStops,
Expand Down Expand Up @@ -327,7 +326,6 @@ export const ticketControlFormMachine = setup({
initial: 'editing',
context: {
date: getCurrentDateString(),
plannedDepartureTime: getCurrentTimeString(),
agreesFirstAgreement: false,
agreesSecondAgreement: false,
hasInternationalBankAccount: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,9 @@ export const RefundCarForm = ({ state, send }: RefundCarFormProps) => {
value: time,
})
}
errorMessage={
state.context?.errorMessages['plannedDepartureTime']?.[0]
}
/>

<Select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ export const RefundTaxiForm = ({ state, send }: RefundTaxiFormProps) => {
value: time,
})
}
errorMessage={
state.context?.errorMessages['plannedDepartureTime']?.[0]
}
/>

<Select
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { commonInputValidator, InputErrorMessages } from '../validation';
import {
convertFilesToBase64,
getCurrentDateString,
getCurrentTimeString,
setBankAccountStatusAndResetBankInformation,
setLineAndResetStops,
setTransportModeAndResetLineAndStops,
Expand Down Expand Up @@ -63,7 +62,7 @@ export type ContextProps = {
fromStop?: Line['quays'][0] | undefined;
toStop?: Line['quays'][0] | undefined;
date: string;
plannedDepartureTime: string;
plannedDepartureTime?: string;
kilometersDriven?: string;
fromAddress?: string;
toAddress?: string;
Expand Down Expand Up @@ -295,7 +294,6 @@ export const fetchMachine = setup({
isIntialAgreementChecked: false,
hasInternationalBankAccount: false,
date: getCurrentDateString(),
plannedDepartureTime: getCurrentTimeString(),
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 @@ -37,9 +37,6 @@ export const convertFilesToBase64 = (
export const getCurrentDateString = (): string =>
new Date().toISOString().split('T')[0];

export const getCurrentTimeString = (): string =>
`${String(new Date().getHours()).padStart(2, '0')}:${String(new Date().getMinutes()).padStart(2, '0')}`;

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

0 comments on commit 71ce965

Please sign in to comment.