From 136d8c943f1b446300d3fe2e510e47ab3858fbf8 Mon Sep 17 00:00:00 2001 From: Jonas Brunvoll Larsson <59939294+jonasbrunvoll@users.noreply.github.com> Date: Tue, 24 Sep 2024 15:20:57 +0200 Subject: [PATCH] feat: add page with forms for means of transport (#348) * Save progress * Update translations. * Update machineEvents * Update mode of transport form selector. * Update form view an state machine. * Add rule to avoid having to provide email if the user dont want to e contacted. * Update to use correct validation and add validation roule to routeArea. * Spliting the form into multiple forms. One for each option. * Add prop types to pass state and send as params. * Add formtype as API param. * Remove console.log() * Update translations and make personal info opional. * rename from mods-of-transport to means-of-transport. * rename from routeArea to area * Update src/translations/pages/contact.ts Co-authored-by: Morten Nordseth <43166974+mortennordseth@users.noreply.github.com> * Update src/translations/pages/contact.ts Co-authored-by: Morten Nordseth <43166974+mortennordseth@users.noreply.github.com> * Update src/translations/pages/contact.ts Co-authored-by: Morten Nordseth <43166974+mortennordseth@users.noreply.github.com> * Update src/translations/pages/contact.ts Co-authored-by: Morten Nordseth <43166974+mortennordseth@users.noreply.github.com> * Update src/translations/pages/contact.ts Co-authored-by: Morten Nordseth <43166974+mortennordseth@users.noreply.github.com> * Move button to index.ts * Set initial date and plannedDepartureTime with global functions from utils.ts. * Move form and onSumbit functions to /means-of-transport/index.ts * Fix copy-paste error. * Remove console.log * Change from using hasTags to chech to using context.formType in radio buttons. * remove unused import. * Simplify validation logic and update when to clean up error messages. * Fix typo and translation errors * Ensure that inly string values are submitet to the api. --------- Co-authored-by: Morten Nordseth <43166974+mortennordseth@users.noreply.github.com> --- src/page-modules/contact/contact.module.css | 4 + src/page-modules/contact/index.ts | 1 + .../contact/layouts/contact-page-layout.tsx | 2 +- src/page-modules/contact/machineEvents.ts | 19 +- .../means-of-transport/forms/delayForm.tsx | 247 +++++++++++++++ .../means-of-transport/forms/driverForm.tsx | 298 ++++++++++++++++++ .../contact/means-of-transport/forms/index.ts | 6 + .../means-of-transport/forms/injuryForm.tsx | 297 +++++++++++++++++ .../forms/serviceOfferingForm.tsx | 186 +++++++++++ .../means-of-transport/forms/stopForm.tsx | 210 ++++++++++++ .../forms/transportationForm.tsx | 283 +++++++++++++++++ .../contact/means-of-transport/index.tsx | 93 ++++++ .../means-of-transport-form-machine.ts | 252 +++++++++++++++ .../feedback/feedbackformMachine.ts | 10 +- .../travelGuaranteeFormMachine.ts | 5 +- src/page-modules/contact/utils.ts | 6 + .../validation/commonFieldValidator.ts | 12 +- .../contact/means-of-transport/index.tsx | 24 ++ src/translations/pages/contact.ts | 260 ++++++++++++++- 19 files changed, 2195 insertions(+), 20 deletions(-) create mode 100644 src/page-modules/contact/means-of-transport/forms/delayForm.tsx create mode 100644 src/page-modules/contact/means-of-transport/forms/driverForm.tsx create mode 100644 src/page-modules/contact/means-of-transport/forms/index.ts create mode 100644 src/page-modules/contact/means-of-transport/forms/injuryForm.tsx create mode 100644 src/page-modules/contact/means-of-transport/forms/serviceOfferingForm.tsx create mode 100644 src/page-modules/contact/means-of-transport/forms/stopForm.tsx create mode 100644 src/page-modules/contact/means-of-transport/forms/transportationForm.tsx create mode 100644 src/page-modules/contact/means-of-transport/index.tsx create mode 100644 src/page-modules/contact/means-of-transport/means-of-transport-form-machine.ts create mode 100644 src/pages/contact/means-of-transport/index.tsx diff --git a/src/page-modules/contact/contact.module.css b/src/page-modules/contact/contact.module.css index 6c33e48e..6c575bec 100644 --- a/src/page-modules/contact/contact.module.css +++ b/src/page-modules/contact/contact.module.css @@ -1,5 +1,9 @@ @value typo-body__secondary from "@atb/theme/typography.module.css"; +.form_options__list { + list-style-type: none; +} + .rules__list { padding: var(--spacings-medium); padding-left: var(--spacings-xLarge); diff --git a/src/page-modules/contact/index.ts b/src/page-modules/contact/index.ts index 093b5542..e28c6868 100644 --- a/src/page-modules/contact/index.ts +++ b/src/page-modules/contact/index.ts @@ -11,3 +11,4 @@ export { FeeComplaintForm } from './ticket-control/complaint'; export { type Line } from './server/journey-planner/validators'; export { shouldShowContactPage } from './utils'; export { FeedbackForm } from './ticket-control/feedback'; +export { MeansOfTransportContent } from './means-of-transport'; diff --git a/src/page-modules/contact/layouts/contact-page-layout.tsx b/src/page-modules/contact/layouts/contact-page-layout.tsx index 20fe5e1e..ca90c609 100644 --- a/src/page-modules/contact/layouts/contact-page-layout.tsx +++ b/src/page-modules/contact/layouts/contact-page-layout.tsx @@ -26,7 +26,7 @@ export const contactPages: ContactPage[] = [ }, { title: PageText.Contact.modeOfTransport.title, - href: '/contact/mode-of-transport', + href: '/contact/means-of-transport', icon: 'transportation/Bus', }, { diff --git a/src/page-modules/contact/machineEvents.ts b/src/page-modules/contact/machineEvents.ts index 84e3f019..43fb27b5 100644 --- a/src/page-modules/contact/machineEvents.ts +++ b/src/page-modules/contact/machineEvents.ts @@ -3,6 +3,7 @@ import { Line } from './server/journey-planner/validators'; import { TranslatedString } from '@atb/translations'; export type ReasonForTransportFailure = { id: string; name: TranslatedString }; +export type Area = { id: string; name: TranslatedString }; export const machineEvents = {} as | { type: 'VALIDATE' } @@ -13,7 +14,8 @@ export const machineEvents = {} as | 'isAppTicketStorageMode' | 'agreesFirstAgreement' | 'agreesSecondAgreement' - | 'hasInternationalBankAccount'; + | 'hasInternationalBankAccount' + | 'wantsToBeContacted'; } | { type: 'UPDATE_FIELD'; @@ -43,7 +45,9 @@ export const machineEvents = {} as | 'appPhoneNumber' | 'customerNumber' | 'travelCardNumber' - | 'isAppTicketStorageMode'; + | 'isAppTicketStorageMode' + | 'formType' + | 'area'; value: | string | number @@ -51,6 +55,7 @@ export const machineEvents = {} as | Line['quays'][0] | TransportModeType | ReasonForTransportFailure + | Area | File[]; } @@ -58,4 +63,12 @@ export const machineEvents = {} as | { type: 'TAXI' } | { type: 'CAR' } | { type: 'OTHER' } - | { type: 'SET_STATE_SUBMITTED'; stateSubmitted: string | undefined }; + | { type: 'SET_STATE_SUBMITTED'; stateSubmitted: string | undefined } + + // mode-of-transport + | { type: 'DRIVER_FORM' } + | { type: 'TRANSPORTATION_FORM' } + | { type: 'DELAY_FORM' } + | { type: 'STOP_FORM' } + | { type: 'SERVICE_OFFERING_FORM' } + | { type: 'INJURY_FORM' }; diff --git a/src/page-modules/contact/means-of-transport/forms/delayForm.tsx b/src/page-modules/contact/means-of-transport/forms/delayForm.tsx new file mode 100644 index 00000000..3ddb502a --- /dev/null +++ b/src/page-modules/contact/means-of-transport/forms/delayForm.tsx @@ -0,0 +1,247 @@ +import { PageText, useTranslation } from '@atb/translations'; +import { useLines } from '../../lines/use-lines'; +import { SectionCard } from '../../components/section-card'; +import { Typo } from '@atb/components/typography'; +import Select from '../../components/input/select'; +import { ComponentText } from '@atb/translations'; +import { Input } from '../../components/input'; +import { TransportModeType } from '@atb-as/config-specs'; +import { Line } from '../..'; +import { FileInput } from '../../components/input/file'; +import { Textarea } from '../../components/input/textarea'; +import { ContextProps } from '../means-of-transport-form-machine'; +import { machineEvents } from '../../machineEvents'; + +type DelayFormProps = { + state: { + hasTag(arg0: string): boolean | undefined; + context: ContextProps; + }; + send: (event: typeof machineEvents) => void; +}; + +export const DelayForm = ({ state, send }: DelayFormProps) => { + const { t } = useTranslation(); + const { getLinesByMode, getQuaysByLine } = useLines(); + + return ( +
+ + + {t(PageText.Contact.modeOfTransport.delay.info)} + + + + + + {t(PageText.Contact.modeOfTransport.delay.about.description)} + + + { + if (!value) return; + send({ + type: 'UPDATE_FIELD', + field: 'line', + value: value, + }); + }} + options={getLinesByMode( + state.context.transportMode as TransportModeType, + )} + valueToId={(line: Line) => line.id} + valueToText={(line: Line) => line.name} + placeholder={t(PageText.Contact.inputFields.line.optionLabel)} + error={ + state.context?.errorMessages['line']?.[0] + ? t(state.context?.errorMessages['line']?.[0]) + : undefined + } + /> + + { + if (!value) return; + send({ + type: 'UPDATE_FIELD', + field: 'toStop', + value: value, + }); + }} + placeholder={t(PageText.Contact.inputFields.toStop.optionLabel)} + options={ + state.context.line?.id ? getQuaysByLine(state.context.line.id) : [] + } + error={ + state.context?.errorMessages['toStop']?.[0] + ? t(state.context?.errorMessages['toStop']?.[0]) + : undefined + } + valueToId={(quay: Line['quays'][0]) => quay.id} + valueToText={(quay: Line['quays'][0]) => quay.name} + /> + + + send({ + type: 'UPDATE_FIELD', + field: 'date', + value: e.target.value, + }) + } + /> + + + send({ + type: 'UPDATE_FIELD', + field: 'plannedDepartureTime', + value: e.target.value, + }) + } + /> + + + + + {t(PageText.Contact.inputFields.feedback.description)} + +