Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update means of transport state machine and forms #373

Merged
merged 6 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/page-modules/contact/means-of-transport/events.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { TranslatedString } from '@atb/translations';
import { commonEvents } from '../commoneEvents';
import { Line } from '..';

export type Area = { id: string; name: TranslatedString };

const meansOfTransportSpecificFormEvents = {} as {
type: 'ON_INPUT_CHANGE';
inputName: 'area' | 'formType' | 'wantsToBeContacted';
value: Area | string | boolean;
inputName: 'area' | 'formType' | 'isResponseWanted' | 'stop';
value: Area | string | boolean | Line['quays'][0];
};

export const meansOfTransportFormEvents = {} as
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ export const DelayForm = ({ state, send }: DelayFormProps) => {
{t(PageText.Contact.input.feedback.description)}
</Typo.p>
<Textarea
value={state.context.feedback}
value={state.context.feedback || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
Expand Down Expand Up @@ -203,7 +203,7 @@ export const DelayForm = ({ state, send }: DelayFormProps) => {
label={PageText.Contact.input.firstName.label}
type="text"
name="firstName"
value={state.context.firstName}
value={state.context.firstName || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
Expand All @@ -217,7 +217,7 @@ export const DelayForm = ({ state, send }: DelayFormProps) => {
label={PageText.Contact.input.lastName.label}
type="text"
name="lastName"
value={state.context.lastName}
value={state.context.lastName || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
Expand All @@ -231,7 +231,7 @@ export const DelayForm = ({ state, send }: DelayFormProps) => {
label={PageText.Contact.input.email.label}
type="email"
name="email"
value={state.context.email}
value={state.context.email || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
Expand Down
53 changes: 11 additions & 42 deletions src/page-modules/contact/means-of-transport/forms/driverForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { TransportModeType } from '@atb-as/config-specs';
import { Line } from '../..';
import { FileInput } from '../../components/input/file';
import { Textarea } from '../../components/input/textarea';
import { RadioInput } from '../../components/input/radio';
import { meansOfTransportFormEvents } from '../events';

type DriverFormProps = {
Expand Down Expand Up @@ -195,7 +194,7 @@ export const DriverForm = ({ state, send }: DriverFormProps) => {
{t(PageText.Contact.input.feedback.description)}
</Typo.p>
<Textarea
value={state.context.feedback}
value={state.context.feedback || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
Expand Down Expand Up @@ -226,7 +225,7 @@ export const DriverForm = ({ state, send }: DriverFormProps) => {
label={PageText.Contact.input.firstName.label}
type="text"
name="firstName"
value={state.context.firstName}
value={state.context.firstName || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
Expand All @@ -240,7 +239,7 @@ export const DriverForm = ({ state, send }: DriverFormProps) => {
label={PageText.Contact.input.lastName.label}
type="text"
name="lastName"
value={state.context.lastName}
value={state.context.lastName || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
Expand All @@ -250,49 +249,19 @@ export const DriverForm = ({ state, send }: DriverFormProps) => {
}
/>

<Typo.p textType="body__primary">
{t(PageText.Contact.input.email.wantsToBeContacted.question)}
</Typo.p>

<RadioInput
label={t(PageText.Contact.input.email.wantsToBeContacted.yes)}
name="wantsToBeContacted"
checked={state.context.wantsToBeContacted}
onChange={() =>
send({
type: 'ON_INPUT_CHANGE',
inputName: 'wantsToBeContacted',
value: !state.context.wantsToBeContacted,
})
}
/>
<RadioInput
label={t(PageText.Contact.input.email.wantsToBeContacted.no)}
name="wantsToBeContacted"
checked={!state.context.wantsToBeContacted}
onChange={() =>
<Input
label={PageText.Contact.input.email.label}
type="email"
name="email"
value={state.context.email || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
inputName: 'wantsToBeContacted',
value: !state.context.wantsToBeContacted,
inputName: 'email',
value: e.target.value,
})
}
/>
{state.context.wantsToBeContacted && (
<Input
label={PageText.Contact.input.email.wantsToBeContacted.label}
type="email"
name="email"
value={state.context.email}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
inputName: 'email',
value: e.target.value,
})
}
/>
)}
</SectionCard>
</div>
);
Expand Down
53 changes: 11 additions & 42 deletions src/page-modules/contact/means-of-transport/forms/injuryForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import { TransportModeType } from '@atb-as/config-specs';
import { Line } from '../..';
import { FileInput } from '../../components/input/file';
import { Textarea } from '../../components/input/textarea';
import { RadioInput } from '../../components/input/radio';
import { meansOfTransportFormEvents } from '../events';

type InjuryFormProps = {
Expand Down Expand Up @@ -194,7 +193,7 @@ export const InjuryForm = ({ state, send }: InjuryFormProps) => {
{t(PageText.Contact.input.feedback.description)}
</Typo.p>
<Textarea
value={state.context.feedback}
value={state.context.feedback || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
Expand Down Expand Up @@ -225,7 +224,7 @@ export const InjuryForm = ({ state, send }: InjuryFormProps) => {
label={PageText.Contact.input.firstName.label}
type="text"
name="firstName"
value={state.context.firstName}
value={state.context.firstName || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
Expand All @@ -239,7 +238,7 @@ export const InjuryForm = ({ state, send }: InjuryFormProps) => {
label={PageText.Contact.input.lastName.label}
type="text"
name="lastName"
value={state.context.lastName}
value={state.context.lastName || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
Expand All @@ -249,49 +248,19 @@ export const InjuryForm = ({ state, send }: InjuryFormProps) => {
}
/>

<Typo.p textType="body__primary">
{t(PageText.Contact.input.email.wantsToBeContacted.question)}
</Typo.p>

<RadioInput
label={t(PageText.Contact.input.email.wantsToBeContacted.yes)}
name="wantsToBeContacted"
checked={state.context.wantsToBeContacted}
onChange={() =>
send({
type: 'ON_INPUT_CHANGE',
inputName: 'wantsToBeContacted',
value: !state.context.wantsToBeContacted,
})
}
/>
<RadioInput
label={t(PageText.Contact.input.email.wantsToBeContacted.no)}
name="wantsToBeContacted"
checked={!state.context.wantsToBeContacted}
onChange={() =>
<Input
label={PageText.Contact.input.email.label}
type="email"
name="email"
value={state.context.email || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
inputName: 'wantsToBeContacted',
value: !state.context.wantsToBeContacted,
inputName: 'email',
value: e.target.value,
})
}
/>
{state.context.wantsToBeContacted && (
<Input
label={PageText.Contact.input.email.wantsToBeContacted.label}
type="email"
name="email"
value={state.context.email}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
inputName: 'email',
value: e.target.value,
})
}
/>
)}
</SectionCard>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const ServiceOfferingForm = ({
send,
}: ServiceOfferingFormProps) => {
const { t } = useTranslation();
const { getLinesByMode, getQuaysByLine } = useLines();
const { getLinesByMode } = useLines();

return (
<div>
Expand Down Expand Up @@ -117,7 +117,7 @@ export const ServiceOfferingForm = ({
{t(PageText.Contact.input.feedback.description)}
</Typo.p>
<Textarea
value={state.context.feedback}
value={state.context.feedback || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
Expand Down Expand Up @@ -148,7 +148,7 @@ export const ServiceOfferingForm = ({
label={PageText.Contact.input.firstName.label}
type="text"
name="firstName"
value={state.context.firstName}
value={state.context.firstName || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
Expand All @@ -162,7 +162,7 @@ export const ServiceOfferingForm = ({
label={PageText.Contact.input.lastName.label}
type="text"
name="lastName"
value={state.context.lastName}
value={state.context.lastName || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
Expand Down
14 changes: 7 additions & 7 deletions src/page-modules/contact/means-of-transport/forms/stopForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,14 @@ export const StopForm = ({ state, send }: StopFormProps) => {
/>

<Select
label={t(PageText.Contact.input.fromStop.labelWhitoutSpecification)}
value={state.context.fromStop}
label={t(PageText.Contact.input.stop.label)}
value={state.context.stop}
disabled={!state.context.line}
onChange={(value) => {
if (!value) return;
send({
type: 'ON_INPUT_CHANGE',
inputName: 'fromStop',
inputName: 'stop',
value: value,
});
}}
Expand Down Expand Up @@ -126,7 +126,7 @@ export const StopForm = ({ state, send }: StopFormProps) => {
{t(PageText.Contact.input.feedback.description)}
</Typo.p>
<Textarea
value={state.context.feedback}
value={state.context.feedback || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
Expand Down Expand Up @@ -157,7 +157,7 @@ export const StopForm = ({ state, send }: StopFormProps) => {
label={PageText.Contact.input.firstName.label}
type="text"
name="firstName"
value={state.context.firstName}
value={state.context.firstName || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
Expand All @@ -171,7 +171,7 @@ export const StopForm = ({ state, send }: StopFormProps) => {
label={PageText.Contact.input.lastName.label}
type="text"
name="lastName"
value={state.context.lastName}
value={state.context.lastName || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
Expand All @@ -185,7 +185,7 @@ export const StopForm = ({ state, send }: StopFormProps) => {
label={PageText.Contact.input.email.label}
type="email"
name="email"
value={state.context.email}
value={state.context.email || ''}
onChange={(e) =>
send({
type: 'ON_INPUT_CHANGE',
Expand Down
Loading
Loading