Skip to content

Commit

Permalink
Draft
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasbrunvoll committed Nov 6, 2024
1 parent a13ee5f commit c8b30e1
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 64 deletions.
1 change: 1 addition & 0 deletions src/page-modules/contact/components/form/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export { default as Radio } from './radio';
export { default as Select } from './select';
export { default as Textarea } from './textarea';
export { default as DateSelector } from './date-selector';
export { default as TimeSelector } from './time-selector';
export {
SearchableSelect,
getLineOptions,
Expand Down
47 changes: 47 additions & 0 deletions src/page-modules/contact/components/form/time-selector.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import style from './form.module.css';
import { TranslatedString, useTranslation } from '@atb/translations';
import { parseTime } from '@internationalized/date';
import {
DateInput,
DateSegment,
Label,
TimeField,
} from 'react-aria-components';

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

return (
<div className={style.time_field_container}>
<Label>{t(label)}</Label>
<TimeField
value={parsedValue}
onChange={(change) => onChange(change.toString())}
hourCycle={24}
shouldForceLeadingZeros
className={style.timeSelector}
data-testid="searchTimeSelector-time"
granularity="minute"
>
<DateInput className={style.timeSelectorInput}>
{(segment) => (
<DateSegment
className={style.timeSelectorSegment}
segment={segment}
/>
)}
</DateInput>
</TimeField>
</div>
);
}
1 change: 1 addition & 0 deletions src/page-modules/contact/components/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ export {
getLineOptions,
getStopOptions,
DateSelector,
TimeSelector,
} from './form';
export { SectionCard } from './section-card';
14 changes: 5 additions & 9 deletions src/page-modules/contact/means-of-transport/forms/delayForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getLineOptions,
getStopOptions,
DateSelector,
TimeSelector,
} from '../../components';

type DelayFormProps = {
Expand Down Expand Up @@ -141,19 +142,14 @@ export const DelayForm = ({ state, send }: DelayFormProps) => {
}
/>

<Input
<TimeSelector
label={PageText.Contact.input.plannedDepartureTime.label}
type="time"
name="time"
value={state.context.plannedDepartureTime}
errorMessage={
state.context?.errorMessages['plannedDepartureTime']?.[0]
}
onChange={(e) =>
value={state.context.plannedDepartureTime || ''}
onChange={(time: string) =>
send({
type: 'ON_INPUT_CHANGE',
inputName: 'plannedDepartureTime',
value: e.target.value,
value: time,
})
}
/>
Expand Down
14 changes: 5 additions & 9 deletions src/page-modules/contact/means-of-transport/forms/driverForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getLineOptions,
getStopOptions,
DateSelector,
TimeSelector,
} from '../../components';

type DriverFormProps = {
Expand Down Expand Up @@ -163,19 +164,14 @@ export const DriverForm = ({ state, send }: DriverFormProps) => {
}
/>

<Input
<TimeSelector
label={PageText.Contact.input.plannedDepartureTime.label}
type="time"
name="time"
value={state.context.plannedDepartureTime}
errorMessage={
state.context?.errorMessages['plannedDepartureTime']?.[0]
}
onChange={(e) =>
value={state.context.plannedDepartureTime || ''}
onChange={(time: string) =>
send({
type: 'ON_INPUT_CHANGE',
inputName: 'plannedDepartureTime',
value: e.target.value,
value: time,
})
}
/>
Expand Down
14 changes: 5 additions & 9 deletions src/page-modules/contact/means-of-transport/forms/injuryForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getLineOptions,
getStopOptions,
DateSelector,
TimeSelector,
} from '../../components';

type InjuryFormProps = {
Expand Down Expand Up @@ -162,19 +163,14 @@ export const InjuryForm = ({ state, send }: InjuryFormProps) => {
}
/>

<Input
<TimeSelector
label={PageText.Contact.input.plannedDepartureTime.label}
type="time"
name="time"
value={state.context.plannedDepartureTime}
errorMessage={
state.context?.errorMessages['plannedDepartureTime']?.[0]
}
onChange={(e) =>
value={state.context.plannedDepartureTime || ''}
onChange={(time: string) =>
send({
type: 'ON_INPUT_CHANGE',
inputName: 'plannedDepartureTime',
value: e.target.value,
value: time,
})
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getLineOptions,
getStopOptions,
DateSelector,
TimeSelector,
} from '../../components';

type TransportationFormProps = {
Expand Down Expand Up @@ -145,19 +146,14 @@ export const TransportationForm = ({
}
/>

<Input
<TimeSelector
label={PageText.Contact.input.plannedDepartureTime.label}
type="time"
name="time"
value={state.context.plannedDepartureTime}
errorMessage={
state.context?.errorMessages['plannedDepartureTime']?.[0]
}
onChange={(e) =>
value={state.context.plannedDepartureTime || ''}
onChange={(time: string) =>
send({
type: 'ON_INPUT_CHANGE',
inputName: 'plannedDepartureTime',
value: e.target.value,
value: time,
})
}
/>
Expand Down
14 changes: 5 additions & 9 deletions src/page-modules/contact/ticket-control/forms/feedbackForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getLineOptions,
getStopOptions,
DateSelector,
TimeSelector,
} from '../../components';

type FeedbackFormProps = {
Expand Down Expand Up @@ -131,19 +132,14 @@ export const FeedbackForm = ({ state, send }: FeedbackFormProps) => {
}
/>

<Input
<TimeSelector
label={PageText.Contact.input.plannedDepartureTime.label}
type="time"
name="time"
value={state.context.plannedDepartureTime}
errorMessage={
state.context?.errorMessages['plannedDepartureTime']?.[0]
}
onChange={(e) =>
value={state.context.plannedDepartureTime || ''}
onChange={(time: string) =>
send({
type: 'ON_INPUT_CHANGE',
inputName: 'plannedDepartureTime',
value: e.target.value,
value: time,
})
}
/>
Expand Down
15 changes: 5 additions & 10 deletions src/page-modules/contact/travel-guarantee/forms/refundCarForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
getLineOptions,
getStopOptions,
DateSelector,
TimeSelector,
} from '../../components';

type RefundCarFormProps = {
Expand Down Expand Up @@ -182,20 +183,14 @@ export const RefundCarForm = ({ state, send }: RefundCarFormProps) => {
})
}
/>

<Input
<TimeSelector
label={PageText.Contact.input.plannedDepartureTime.label}
type="time"
name="time"
value={state.context.plannedDepartureTime}
errorMessage={
state.context?.errorMessages['plannedDepartureTime']?.[0]
}
onChange={(e) =>
value={state.context.plannedDepartureTime || ''}
onChange={(time: string) =>
send({
type: 'ON_INPUT_CHANGE',
inputName: 'plannedDepartureTime',
value: e.target.value,
value: time,
})
}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
getLineOptions,
getStopOptions,
DateSelector,
TimeSelector,
} from '../../components';

type RefundTaxiFormProps = {
Expand Down Expand Up @@ -169,19 +170,14 @@ export const RefundTaxiForm = ({ state, send }: RefundTaxiFormProps) => {
}
/>

<Input
<TimeSelector
label={PageText.Contact.input.plannedDepartureTime.label}
type="time"
name="time"
value={state.context.plannedDepartureTime}
errorMessage={
state.context?.errorMessages['plannedDepartureTime']?.[0]
}
onChange={(e) =>
value={state.context.plannedDepartureTime || ''}
onChange={(time: string) =>
send({
type: 'ON_INPUT_CHANGE',
inputName: 'plannedDepartureTime',
value: e.target.value,
value: time,
})
}
/>
Expand Down

0 comments on commit c8b30e1

Please sign in to comment.