diff --git a/src/components/line-chip/index.tsx b/src/components/line-chip/index.tsx index d884ffd53..dc7bc3218 100644 --- a/src/components/line-chip/index.tsx +++ b/src/components/line-chip/index.tsx @@ -1,13 +1,11 @@ +import { Typo } from '@atb/components/typography'; +import style from './line-chip.module.css'; import { TransportIcon, - useTransportationThemeColor, -} from '@atb/components/transport-mode/transport-icon'; -import { TransportModeType, TransportSubmodeType, -} from '@atb/components/transport-mode/types'; -import { Typo } from '@atb/components/typography'; -import style from './line-chip.module.css'; + useTransportationThemeColor, +} from '@atb/modules/transport-mode'; export type LineChipProps = { transportMode: TransportModeType; diff --git a/src/components/map/map-header.tsx b/src/components/map/map-header.tsx index d193fe80b..1f032dcc4 100644 --- a/src/components/map/map-header.tsx +++ b/src/components/map/map-header.tsx @@ -1,12 +1,13 @@ import style from './map.module.css'; - import { ButtonLink } from '@atb/components/button'; import { ComponentText, useTranslation } from '@atb/translations'; import { and } from '@atb/utils/css'; import { MonoIcon } from '@atb/components/icon'; -import { transportModeToTranslatedString } from '@atb/components/transport-mode'; -import { getTransportModeIcon } from '@atb/components/transport-mode/transport-icon'; -import { TransportModeType } from '@atb/components/transport-mode/types'; +import { + type TransportModeType, + transportModeToTranslatedString, + getTransportModeIcon, +} from '@atb/modules/transport-mode'; export type MapHeaderProps = { id: string; diff --git a/src/components/search/index.ts b/src/components/search/index.ts new file mode 100644 index 000000000..dd78d06aa --- /dev/null +++ b/src/components/search/index.ts @@ -0,0 +1,3 @@ +export { default } from './search'; +export { default as GeolocationButton } from './geolocation-button'; +export { default as SwapButton } from './swap-button'; diff --git a/src/components/search/index.tsx b/src/components/search/search.tsx similarity index 100% rename from src/components/search/index.tsx rename to src/components/search/search.tsx diff --git a/src/components/transport-mode-filter/types.ts b/src/components/transport-mode-filter/types.ts deleted file mode 100644 index 8bd288bd6..000000000 --- a/src/components/transport-mode-filter/types.ts +++ /dev/null @@ -1,17 +0,0 @@ -export const transportModeFilterOptions = [ - 'bus', - 'rail', - 'expressboat', - 'ferry', - 'airportbus', - 'air', - 'other', -] as const; - -export type TransportModeFilterOption = - (typeof transportModeFilterOptions)[number]; - -export type TransportModeFilterState = Record< - TransportModeFilterOption, - boolean ->; diff --git a/src/components/transport-mode/index.ts b/src/components/transport-mode/index.ts deleted file mode 100644 index 4e1cac9c0..000000000 --- a/src/components/transport-mode/index.ts +++ /dev/null @@ -1,11 +0,0 @@ -export { - TransportIcons, - TransportIcon, - TransportMonoIcon, -} from './transport-icon'; -export type { TransportIconsProps, TransportIconProps } from './transport-icon'; - -export { - severalTransportModesToTranslatedStrings, - transportModeToTranslatedString, -} from './utils'; diff --git a/src/components/transport-mode/types.ts b/src/components/transport-mode/types.ts deleted file mode 100644 index d69785ac0..000000000 --- a/src/components/transport-mode/types.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { TransportSubmodeType } from '@atb-as/config-specs'; -import { z } from 'zod'; - -export const TransportModeType = z.union([ - z.literal('air'), - z.literal('bus'), - z.literal('foot'), - z.literal('bicycle'), - z.literal('cableway'), - z.literal('coach'), - z.literal('funicular'), - z.literal('lift'), - z.literal('metro'), - z.literal('monorail'), - z.literal('rail'), - z.literal('taxi'), - z.literal('tram'), - z.literal('trolleybus'), - z.literal('unknown'), - z.literal('water'), -]); -export type TransportModeType = z.infer; - -export { TransportSubmodeType }; - -export type TransportModeGroup = { - mode: TransportModeType; - subMode?: TransportSubmodeType; -}; diff --git a/src/components/transport-mode/utils.ts b/src/components/transport-mode/utils.ts deleted file mode 100644 index a68835bc0..000000000 --- a/src/components/transport-mode/utils.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { ComponentText } from '@atb/translations'; -import { TransportModeGroup } from './types'; - -export function transportModeToTranslatedString(mode: TransportModeGroup) { - if (!ComponentText.TransportMode.modes[mode.mode]) { - return ComponentText.TransportMode.modes.unknown; - } - return ComponentText.TransportMode.modes[mode.mode]; -} -export function severalTransportModesToTranslatedStrings( - modes: TransportModeGroup[], -) { - return modes - .map((mode) => ComponentText.TransportMode.modes[mode.mode]) - .filter(Boolean); -} diff --git a/src/modules/search-time/index.ts b/src/modules/search-time/index.ts index 8afb4fded..05f10e14c 100644 --- a/src/modules/search-time/index.ts +++ b/src/modules/search-time/index.ts @@ -1,3 +1,5 @@ export { default as SearchTimeSelector } from './selector'; export * from './types'; + +export { parseSearchTimeQuery, searchTimeToQueryString } from './utils'; diff --git a/src/modules/search-time/utils.ts b/src/modules/search-time/utils.ts index 736ff2760..f5eded78e 100644 --- a/src/modules/search-time/utils.ts +++ b/src/modules/search-time/utils.ts @@ -15,3 +15,9 @@ export function parseSearchTimeQuery( return { mode: 'now' }; } + +export function searchTimeToQueryString(searchTime: SearchTime) { + return searchTime.mode !== 'now' + ? { searchMode: searchTime.mode, searchTime: searchTime.dateTime } + : { searchMode: searchTime.mode }; +} diff --git a/src/components/transport-mode-filter/__tests__/transport-mode-filter.test.tsx b/src/modules/transport-mode/filter/__tests__/filter.test.tsx similarity index 93% rename from src/components/transport-mode-filter/__tests__/transport-mode-filter.test.tsx rename to src/modules/transport-mode/filter/__tests__/filter.test.tsx index eeab648a4..4f73f0aca 100644 --- a/src/components/transport-mode-filter/__tests__/transport-mode-filter.test.tsx +++ b/src/modules/transport-mode/filter/__tests__/filter.test.tsx @@ -1,9 +1,9 @@ import { cleanup, render, screen } from '@testing-library/react'; import { afterEach, describe, expect, it, vi } from 'vitest'; -import TransportModeFilter from '@atb/components/transport-mode-filter'; -import { getInitialTransportModeFilter } from '@atb/components/transport-mode-filter/utils'; import userEvent from '@testing-library/user-event'; -import { TransportModeFilterState } from '@atb/components/transport-mode-filter/types'; +import TransportModeFilter from '../filter'; +import { getInitialTransportModeFilter } from '../utils'; +import { TransportModeFilterState } from '../types'; afterEach(() => cleanup()); diff --git a/src/components/transport-mode-filter/transport-mode-filter.module.css b/src/modules/transport-mode/filter/filter.module.css similarity index 100% rename from src/components/transport-mode-filter/transport-mode-filter.module.css rename to src/modules/transport-mode/filter/filter.module.css diff --git a/src/components/transport-mode-filter/index.tsx b/src/modules/transport-mode/filter/filter.tsx similarity index 88% rename from src/components/transport-mode-filter/index.tsx rename to src/modules/transport-mode/filter/filter.tsx index 0a23430b1..348d87937 100644 --- a/src/components/transport-mode-filter/index.tsx +++ b/src/modules/transport-mode/filter/filter.tsx @@ -1,17 +1,11 @@ import { getTextForLanguage } from '@atb/translations/utils'; import { useTranslation, ComponentText } from '@atb/translations'; -import style from './transport-mode-filter.module.css'; +import style from './filter.module.css'; import { MonoIcon } from '@atb/components/icon'; -import { - TransportModeFilterOption, - TransportModeFilterState, -} from '@atb/components/transport-mode-filter/types'; +import { TransportModeFilterOption, TransportModeFilterState } from './types'; import { Typo } from '@atb/components/typography'; -import { getTransportModeIcon } from '@atb/components/transport-mode/transport-icon'; -import { - filterOptionsWithTransportModes, - setAllValues, -} from '@atb/components/transport-mode-filter/utils'; +import { getTransportModeIcon } from '../icon'; +import { filterOptionsWithTransportModes, setAllValues } from './utils'; type TransportModeFilterProps = { filterState: TransportModeFilterState; diff --git a/src/modules/transport-mode/filter/index.ts b/src/modules/transport-mode/filter/index.ts new file mode 100644 index 000000000..b12b55ed0 --- /dev/null +++ b/src/modules/transport-mode/filter/index.ts @@ -0,0 +1,13 @@ +export { default as TransportModeFilter } from './filter'; + +export { + type TransportModeFilterOption, + type TransportModeFilterState, +} from './types'; + +export { + getAllTransportModesFromFilterOptions, + getInitialTransportModeFilter, + parseFilterQuery, + filterToQueryString, +} from './utils'; diff --git a/src/modules/transport-mode/filter/types.ts b/src/modules/transport-mode/filter/types.ts new file mode 100644 index 000000000..0c055d1c0 --- /dev/null +++ b/src/modules/transport-mode/filter/types.ts @@ -0,0 +1,22 @@ +import { z } from 'zod'; + +export const transportModeFilterSchema = z.union([ + z.literal('bus'), + z.literal('rail'), + z.literal('expressboat'), + z.literal('ferry'), + z.literal('airportbus'), + z.literal('air'), + z.literal('other'), +]); + +export type TransportModeFilterOption = z.infer< + typeof transportModeFilterSchema +>; + +export type TransportModeFilterState = Record< + TransportModeFilterOption, + boolean +>; + +export { TransportModeFilterOptionType } from '@atb-as/config-specs'; diff --git a/src/components/transport-mode-filter/utils.ts b/src/modules/transport-mode/filter/utils.ts similarity index 94% rename from src/components/transport-mode-filter/utils.ts rename to src/modules/transport-mode/filter/utils.ts index ec61ac1e3..45bd3fb70 100644 --- a/src/components/transport-mode-filter/utils.ts +++ b/src/modules/transport-mode/filter/utils.ts @@ -1,13 +1,20 @@ +import { uniq } from 'lodash'; import { TransportModeFilterOption, - transportModeFilterOptions, - TransportModeFilterState, -} from '@atb/components/transport-mode-filter/types'; -import { TransportModeFilterOptionType, - TransportModeType, -} from '@atb-as/config-specs'; -import { uniq } from 'lodash'; + TransportModeFilterState, +} from './types'; +import { TransportModeType } from '../types'; + +const transportModeFilterOptions: TransportModeFilterOption[] = [ + 'bus', + 'rail', + 'expressboat', + 'ferry', + 'airportbus', + 'air', + 'other', +]; export function getInitialTransportModeFilter( initialSelected?: TransportModeFilterOption[] | null, @@ -50,8 +57,10 @@ export function parseFilterQuery( } export function getAllTransportModesFromFilterOptions( - filterOptions: TransportModeFilterOption[], + filterOptions: TransportModeFilterOption[] | null, ): TransportModeType[] { + if (!filterOptions) return []; + const transportModes: TransportModeType[] = []; filterOptions.forEach((filterOption) => { diff --git a/src/components/transport-mode/transport-icon/transport-icon.module.css b/src/modules/transport-mode/icon/icon.module.css similarity index 72% rename from src/components/transport-mode/transport-icon/transport-icon.module.css rename to src/modules/transport-mode/icon/icon.module.css index 499d9841e..04ce1dc18 100644 --- a/src/components/transport-mode/transport-icon/transport-icon.module.css +++ b/src/modules/transport-mode/icon/icon.module.css @@ -1,17 +1,11 @@ .transportIcons { display: flex; - - /* Specialized sizing. */ - /* @TODO investigate generic way to handle this */ gap: 0.125rem; } .transportIcon, .transportIconWithLabel { display: inline-block; - - /* Specialized sizing. */ - /* @TODO investigate generic way to handle this */ border-radius: var(--border-radius-small); padding: var(--spacings-xSmall); } diff --git a/src/components/transport-mode/transport-icon/index.tsx b/src/modules/transport-mode/icon/index.tsx similarity index 98% rename from src/components/transport-mode/transport-icon/index.tsx rename to src/modules/transport-mode/icon/index.tsx index 63eb0995c..d43a614ea 100644 --- a/src/components/transport-mode/transport-icon/index.tsx +++ b/src/modules/transport-mode/icon/index.tsx @@ -6,7 +6,7 @@ import { useTheme } from '@atb/modules/theme'; import { useTranslation } from '@atb/translations'; import { transportModeToTranslatedString } from '../utils'; -import style from './transport-icon.module.css'; +import style from './icon.module.css'; import { colorToOverrideMode } from '@atb/utils/color'; export type TransportIconsProps = { diff --git a/src/modules/transport-mode/index.ts b/src/modules/transport-mode/index.ts new file mode 100644 index 000000000..8dbd529d1 --- /dev/null +++ b/src/modules/transport-mode/index.ts @@ -0,0 +1,18 @@ +export { + type TransportModeType, + type TransportSubmodeType, + type TransportModeGroup, + transportModeSchema, + transportSubmodeSchema, +} from './types'; + +export { + transportModeToTranslatedString, + severalTransportModesToTranslatedStrings, + isTransportModeType, + isTransportSubmodeType, + filterGraphQlTransportModes, +} from './utils'; + +export * from './icon'; +export * from './filter'; diff --git a/src/modules/transport-mode/types.ts b/src/modules/transport-mode/types.ts new file mode 100644 index 000000000..606b36acc --- /dev/null +++ b/src/modules/transport-mode/types.ts @@ -0,0 +1,145 @@ +import { z } from 'zod'; + +export const transportModeSchema = z.union([ + z.literal('air'), + z.literal('bus'), + z.literal('foot'), + z.literal('bicycle'), + z.literal('cableway'), + z.literal('car'), + z.literal('coach'), + z.literal('funicular'), + z.literal('lift'), + z.literal('metro'), + z.literal('monorail'), + z.literal('rail'), + z.literal('scooter'), + z.literal('taxi'), + z.literal('tram'), + z.literal('trolleybus'), + z.literal('unknown'), + z.literal('water'), +]); +export type TransportModeType = z.infer; + +export const transportSubmodeSchema = z.union([ + z.literal('SchengenAreaFlight'), + z.literal('airportBoatLink'), + z.literal('airportLinkBus'), + z.literal('airportLinkRail'), + z.literal('airshipService'), + z.literal('allFunicularServices'), + z.literal('allHireVehicles'), + z.literal('allTaxiServices'), + z.literal('bikeTaxi'), + z.literal('blackCab'), + z.literal('cableCar'), + z.literal('cableFerry'), + z.literal('canalBarge'), + z.literal('carTransportRailService'), + z.literal('chairLift'), + z.literal('charterTaxi'), + z.literal('cityTram'), + z.literal('communalTaxi'), + z.literal('commuterCoach'), + z.literal('crossCountryRail'), + z.literal('dedicatedLaneBus'), + z.literal('demandAndResponseBus'), + z.literal('domesticCharterFlight'), + z.literal('domesticFlight'), + z.literal('domesticScheduledFlight'), + z.literal('dragLift'), + z.literal('expressBus'), + z.literal('funicular'), + z.literal('helicopterService'), + z.literal('highFrequencyBus'), + z.literal('highSpeedPassengerService'), + z.literal('highSpeedRail'), + z.literal('highSpeedVehicleService'), + z.literal('hireCar'), + z.literal('hireCycle'), + z.literal('hireMotorbike'), + z.literal('hireVan'), + z.literal('intercontinentalCharterFlight'), + z.literal('intercontinentalFlight'), + z.literal('international'), + z.literal('internationalCarFerry'), + z.literal('internationalCharterFlight'), + z.literal('internationalCoach'), + z.literal('internationalFlight'), + z.literal('internationalPassengerFerry'), + z.literal('interregionalRail'), + z.literal('lift'), + z.literal('local'), + z.literal('localBus'), + z.literal('localCarFerry'), + z.literal('localPassengerFerry'), + z.literal('localTram'), + z.literal('longDistance'), + z.literal('metro'), + z.literal('miniCab'), + z.literal('mobilityBus'), + z.literal('mobilityBusForRegisteredDisabled'), + z.literal('nationalCarFerry'), + z.literal('nationalCoach'), + z.literal('nationalPassengerFerry'), + z.literal('nightBus'), + z.literal('nightRail'), + z.literal('postBoat'), + z.literal('postBus'), + z.literal('rackAndPinionRailway'), + z.literal('railReplacementBus'), + z.literal('railShuttle'), + z.literal('railTaxi'), + z.literal('regionalBus'), + z.literal('regionalCarFerry'), + z.literal('regionalCoach'), + z.literal('regionalPassengerFerry'), + z.literal('regionalRail'), + z.literal('regionalTram'), + z.literal('replacementRailService'), + z.literal('riverBus'), + z.literal('roadFerryLink'), + z.literal('roundTripCharterFlight'), + z.literal('scheduledFerry'), + z.literal('schoolAndPublicServiceBus'), + z.literal('schoolBoat'), + z.literal('schoolBus'), + z.literal('schoolCoach'), + z.literal('shortHaulInternationalFlight'), + z.literal('shuttleBus'), + z.literal('shuttleCoach'), + z.literal('shuttleFerryService'), + z.literal('shuttleFlight'), + z.literal('shuttleTram'), + z.literal('sightseeingBus'), + z.literal('sightseeingCoach'), + z.literal('sightseeingFlight'), + z.literal('sightseeingService'), + z.literal('sightseeingTram'), + z.literal('sleeperRailService'), + z.literal('specialCoach'), + z.literal('specialNeedsBus'), + z.literal('specialTrain'), + z.literal('streetCableCar'), + z.literal('suburbanRailway'), + z.literal('telecabin'), + z.literal('telecabinLink'), + z.literal('touristCoach'), + z.literal('touristRailway'), + z.literal('trainFerry'), + z.literal('trainTram'), + z.literal('tube'), + z.literal('undefined'), + z.literal('undefinedFunicular'), + z.literal('unknown'), + z.literal('urbanRailway'), + z.literal('waterTaxi'), +]); + +export type TransportSubmodeType = z.infer; + +export type TransportModeGroup = { + mode: TransportModeType; + subMode?: TransportSubmodeType; +}; diff --git a/src/modules/transport-mode/utils.ts b/src/modules/transport-mode/utils.ts new file mode 100644 index 000000000..4d17305a7 --- /dev/null +++ b/src/modules/transport-mode/utils.ts @@ -0,0 +1,43 @@ +import { ComponentText } from '@atb/translations'; +import { + TransportModeGroup, + transportModeSchema, + TransportModeType, + transportSubmodeSchema, + TransportSubmodeType, +} from './types'; +import { TransportMode as GraphQlTransportMode } from '@atb/modules/graphql-types'; + +export function transportModeToTranslatedString(mode: TransportModeGroup) { + if (!ComponentText.TransportMode.modes[mode.mode]) { + return ComponentText.TransportMode.modes.unknown; + } + return ComponentText.TransportMode.modes[mode.mode]; +} +export function severalTransportModesToTranslatedStrings( + modes: TransportModeGroup[], +) { + return modes + .map((mode) => ComponentText.TransportMode.modes[mode.mode]) + .filter(Boolean); +} + +export function isTransportModeType(a: any): a is TransportModeType { + return transportModeSchema.safeParse(a).success; +} + +export function isTransportSubmodeType(a: any): a is TransportSubmodeType { + return transportSubmodeSchema.safeParse(a).success; +} + +export function filterGraphQlTransportModes( + modes: GraphQlTransportMode[] | undefined, +): TransportModeType[] | undefined { + if (!modes) return undefined; + const transportModes: TransportModeType[] = []; + modes.forEach((transportMode) => { + if (isTransportModeType(transportMode)) transportModes.push(transportMode); + }); + if (transportModes.length === 0) return undefined; + return transportModes; +} diff --git a/src/page-modules/assistant/__tests__/assistant.test.tsx b/src/page-modules/assistant/__tests__/assistant.test.tsx index 70fc14ac6..eb61f57b9 100644 --- a/src/page-modules/assistant/__tests__/assistant.test.tsx +++ b/src/page-modules/assistant/__tests__/assistant.test.tsx @@ -2,7 +2,7 @@ import { cleanup, render, screen } from '@testing-library/react'; import mockRouter from 'next-router-mock'; import { afterEach, describe, expect, it, vi } from 'vitest'; import { ExternalClient } from '@atb/modules/api-server'; -import { JourneyPlannerApi } from '@atb/page-modules/assistant/server/journey-planner'; +import { JourneyPlannerApi } from '../server/journey-planner'; import { getServerSideProps } from '@atb/pages/assistant'; import { expectProps } from '@atb/tests/utils'; import { createDynamicRouteParser } from 'next-router-mock/dynamic-routes'; diff --git a/src/page-modules/assistant/client/journey-planner/index.ts b/src/page-modules/assistant/client/journey-planner/index.ts index 391a852ae..6d59978dd 100644 --- a/src/page-modules/assistant/client/journey-planner/index.ts +++ b/src/page-modules/assistant/client/journey-planner/index.ts @@ -1,5 +1,5 @@ -import { TripData } from '@atb/page-modules/assistant/server/journey-planner/validators'; -import { TripQuery } from '@atb/page-modules/assistant/'; +import { TripData } from '../../server/journey-planner/validators'; +import { TripQuery } from '../../types'; export type TripApiReturnType = TripData; diff --git a/src/page-modules/assistant/index.ts b/src/page-modules/assistant/index.ts index 341fb32a6..91b37dc6e 100644 --- a/src/page-modules/assistant/index.ts +++ b/src/page-modules/assistant/index.ts @@ -2,3 +2,7 @@ export * from './types'; export { parseTripQuery, createTripQuery } from './utils'; export type { AssistantLayoutProps } from './layout'; export { default as AssistantLayout } from './layout'; + +export { default as Trip, type TripProps } from './trip'; + +export { type TripApiReturnType } from './client/journey-planner'; diff --git a/src/page-modules/assistant/layout.tsx b/src/page-modules/assistant/layout.tsx index 49c079a7a..f736386cf 100644 --- a/src/page-modules/assistant/layout.tsx +++ b/src/page-modules/assistant/layout.tsx @@ -1,23 +1,22 @@ import type { GeocoderFeature } from '@atb/page-modules/departures'; import { PageText, useTranslation } from '@atb/translations'; -import { FormEventHandler, PropsWithChildren, useState } from 'react'; -import Search from '@atb/components/search'; +import React, { FormEventHandler, PropsWithChildren, useState } from 'react'; +import Search, { GeolocationButton, SwapButton } from '@atb/components/search'; import { Button } from '@atb/components/button'; import style from './assistant.module.css'; import { useRouter } from 'next/router'; -import TransportModeFilter from '@atb/components/transport-mode-filter'; import { Typo } from '@atb/components/typography'; -import { getInitialTransportModeFilter } from '@atb/components/transport-mode-filter/utils'; -import { TransportModeFilterOption } from '@atb/components/transport-mode-filter/types'; import { MonoIcon } from '@atb/components/icon'; import { FocusScope } from '@react-aria/focus'; import { createTripQuery } from './utils'; -import SwapButton from '@atb/components/search/swap-button'; -import GeolocationButton from '@atb/components/search/geolocation-button'; import { AnimatePresence, motion } from 'framer-motion'; -import React from 'react'; import SearchTimeSelector from '@atb/modules/search-time/selector'; -import { SearchTime } from '@atb/modules/search-time'; +import type { SearchTime } from '@atb/modules/search-time'; +import { + getInitialTransportModeFilter, + TransportModeFilter, + type TransportModeFilterOption, +} from '@atb/modules/transport-mode'; export type AssistantLayoutProps = PropsWithChildren<{ initialFromFeature?: GeocoderFeature; diff --git a/src/page-modules/assistant/non-transit-pill/index.tsx b/src/page-modules/assistant/non-transit-pill/index.tsx index b0388637d..12e372b47 100644 --- a/src/page-modules/assistant/non-transit-pill/index.tsx +++ b/src/page-modules/assistant/non-transit-pill/index.tsx @@ -1,7 +1,9 @@ import { ButtonLink } from '@atb/components/button'; import { MonoIcon } from '@atb/components/icon'; -import { TransportMonoIcon } from '@atb/components/transport-mode'; -import { TransportModeType } from '@atb/components/transport-mode/types'; +import { + TransportMonoIcon, + type TransportModeType, +} from '@atb/modules/transport-mode'; import { PageText, TranslateFunction, useTranslation } from '@atb/translations'; import { secondsToDurationShort } from '@atb/utils/date'; diff --git a/src/page-modules/assistant/server/journey-planner/index.ts b/src/page-modules/assistant/server/journey-planner/index.ts index ffb9863a1..4ba97479e 100644 --- a/src/page-modules/assistant/server/journey-planner/index.ts +++ b/src/page-modules/assistant/server/journey-planner/index.ts @@ -1,5 +1,5 @@ import { GraphQlRequester } from '@atb/modules/api-server'; -import { StreetMode } from '@atb/modules/graphql-types'; +import { StreetMode, TransportMode } from '@atb/modules/graphql-types'; import { TripsDocument, TripsNonTransitDocument, @@ -21,12 +21,11 @@ import type { NonTransitTripInput, TripInput, } from '../../types'; +import { filterOutDuplicates, getCursorBySearchMode } from '../../utils'; import { - getTransportModesEnums, isTransportModeType, isTransportSubmodeType, -} from '@atb/page-modules/departures/server/journey-planner'; -import { filterOutDuplicates, getCursorBySearchMode } from '../../utils'; +} from '@atb/modules/transport-mode'; const MIN_NUMBER_OF_TRIP_PATTERNS = 8; const MAX_NUMBER_OF_SEARCH_ATTEMPTS = 5; @@ -109,11 +108,10 @@ export function createJourneyApi( // Show specific non-transit suggestions through separate API call directMode: undefined, egressMode: StreetMode.Foot, - transportModes: input.transportModes - ? getTransportModesEnums(input.transportModes)?.map((mode) => ({ - transportMode: mode, - })) - : undefined, + transportModes: + input.transportModes?.map((mode) => ({ + transportMode: mode as TransportMode, + })) ?? undefined, }; const from = inputToLocation(input, 'from'); diff --git a/src/page-modules/assistant/server/journey-planner/validators.ts b/src/page-modules/assistant/server/journey-planner/validators.ts index b53823dda..46f581e90 100644 --- a/src/page-modules/assistant/server/journey-planner/validators.ts +++ b/src/page-modules/assistant/server/journey-planner/validators.ts @@ -1,8 +1,9 @@ -import { - TransportModeType, - TransportSubmodeType, -} from '@atb/components/transport-mode/types'; import { z } from 'zod'; +import { + transportModeSchema, + transportSubmodeSchema, +} from '@atb/modules/transport-mode'; + export const noticeSchema = z.object({ id: z.string(), text: z.string().nullable(), @@ -92,14 +93,14 @@ export const fromEstimatedCallSchema = z.object({ export const lineSchema = z.object({ id: z.string(), name: z.string().nullable(), - transportSubmode: TransportSubmodeType.nullable(), + transportSubmode: transportSubmodeSchema.nullable().optional(), publicCode: z.string().nullable(), flexibleLineType: z.string().nullable(), notices: z.array(noticeSchema), }); export const legSchema = z.object({ - mode: TransportModeType.nullable(), + mode: transportModeSchema.nullable(), distance: z.number(), duration: z.number(), aimedStartTime: z.string(), @@ -107,7 +108,7 @@ export const legSchema = z.object({ expectedEndTime: z.string(), expectedStartTime: z.string(), realtime: z.boolean(), - transportSubmode: TransportSubmodeType.nullable(), + transportSubmode: transportSubmodeSchema.nullable().optional(), line: lineSchema.nullable(), fromEstimatedCall: fromEstimatedCallSchema.nullable(), situations: z.array(situationSchema), @@ -162,7 +163,7 @@ export const tripSchema = z.object({ }); export const nonTransitSchema = z.object({ - mode: TransportModeType, + mode: transportModeSchema, rentedBike: z.boolean(), duration: z.number(), }); diff --git a/src/page-modules/assistant/trip/index.tsx b/src/page-modules/assistant/trip/index.tsx index b0d8e14e4..b1b62ed28 100644 --- a/src/page-modules/assistant/trip/index.tsx +++ b/src/page-modules/assistant/trip/index.tsx @@ -11,7 +11,6 @@ import style from './trip.module.css'; import { PageText, useTranslation } from '@atb/translations'; import { Typo } from '@atb/components/typography'; import { GeocoderFeature } from '@atb/page-modules/departures'; -import { TransportModeFilterOption } from '@atb/components/transport-mode-filter/types'; import { nextTripPatterns } from '../client'; import { NonTransitTripData } from '../types'; import { @@ -20,7 +19,6 @@ import { getCursorBySearchMode, } from '../utils'; import { useEffect, useState } from 'react'; -import { getInitialTransportModeFilter } from '@atb/components/transport-mode-filter/utils'; import { Button } from '@atb/components/button'; import { NonTransitTrip } from '../non-transit-pill'; import { isSameDay } from 'date-fns'; @@ -28,6 +26,10 @@ import { capitalize } from 'lodash'; import EmptySearchResults from '@atb/components/empty-search-results'; import TripPattern from './trip-pattern'; import { SearchTime } from '@atb/modules/search-time'; +import { + getInitialTransportModeFilter, + type TransportModeFilterOption, +} from '@atb/modules/transport-mode'; export type TripProps = { initialFromFeature: GeocoderFeature; diff --git a/src/page-modules/assistant/trip/trip-pattern/index.tsx b/src/page-modules/assistant/trip/trip-pattern/index.tsx index a4be3ca60..1dc29a4be 100644 --- a/src/page-modules/assistant/trip/trip-pattern/index.tsx +++ b/src/page-modules/assistant/trip/trip-pattern/index.tsx @@ -7,9 +7,9 @@ import { type TripPattern as TripPatternType } from '../../server/journey-planne import style from './trip-pattern.module.css'; import { formatLocaleTime, isInPast } from '@atb/utils/date'; import { TripPatternHeader } from './trip-pattern-header'; -import { TransportIconWithLabel } from '@atb/components/transport-mode/transport-icon'; import { MonoIcon } from '@atb/components/icon'; import { Typo } from '@atb/components/typography'; +import { TransportIconWithLabel } from '@atb/modules/transport-mode'; const LAST_LEG_PADDING = 20; diff --git a/src/page-modules/assistant/trip/trip-pattern/trip-pattern-header/index.tsx b/src/page-modules/assistant/trip/trip-pattern/trip-pattern-header/index.tsx index 4254e2802..5215df262 100644 --- a/src/page-modules/assistant/trip/trip-pattern/trip-pattern-header/index.tsx +++ b/src/page-modules/assistant/trip/trip-pattern/trip-pattern-header/index.tsx @@ -1,13 +1,10 @@ -import { - TripPattern, - Quay, -} from '@atb/page-modules/assistant/server/journey-planner/validators'; +import { TripPattern, Quay } from '../../../server/journey-planner/validators'; import style from './trip-pattern-header.module.css'; import { Typo } from '@atb/components/typography'; import { useTranslation, PageText } from '@atb/translations'; import { secondsToDuration } from '@atb/utils/date'; import { flatMap } from 'lodash'; -import { getNoticesForLeg } from '@atb/page-modules/assistant/trip/trip-pattern/trip-pattern-header/utils'; +import { getNoticesForLeg } from './utils'; import { RailReplacementBusMessage } from './rail-replacement-bus'; import { SituationOrNoticeIcon } from '@atb/modules/situations'; diff --git a/src/page-modules/assistant/trip/trip-pattern/utils.ts b/src/page-modules/assistant/trip/trip-pattern/utils.ts index a41577277..35c5449a4 100644 --- a/src/page-modules/assistant/trip/trip-pattern/utils.ts +++ b/src/page-modules/assistant/trip/trip-pattern/utils.ts @@ -8,7 +8,7 @@ import { getQuayName } from './trip-pattern-header'; import { Language, TranslateFunction, PageText } from '@atb/translations'; import dictionary from '@atb/translations/dictionary'; import { screenReaderPause } from '@atb/components/typography/utils'; -import { transportModeToTranslatedString } from '@atb/components/transport-mode'; +import { transportModeToTranslatedString } from '@atb/modules/transport-mode'; import { getTimeRepresentationType } from '@atb/modules/time-representation'; export const tripSummary = ( diff --git a/src/page-modules/assistant/types.ts b/src/page-modules/assistant/types.ts index 90c0c2c9d..0998ea44b 100644 --- a/src/page-modules/assistant/types.ts +++ b/src/page-modules/assistant/types.ts @@ -1,20 +1,11 @@ -import { TransportModeFilterOption } from '@atb/components/transport-mode-filter/types'; import { GeocoderFeature } from '@atb/page-modules/departures'; import { z } from 'zod'; import type { NonTransitData, TripData, } from './server/journey-planner/validators'; -import { - SEARCH_MODES, - searchModeSchema, - SearchTime, -} from '@atb/modules/search-time'; - -export enum DepartureMode { - DepartBy = 'departBy', - ArriveBy = 'arriveBy', -} +import { searchModeSchema, type SearchTime } from '@atb/modules/search-time'; +import { type TransportModeFilterOption } from '@atb/modules/transport-mode'; export type TripInput = { from: GeocoderFeature; diff --git a/src/page-modules/assistant/utils.ts b/src/page-modules/assistant/utils.ts index 182735e56..807f0608b 100644 --- a/src/page-modules/assistant/utils.ts +++ b/src/page-modules/assistant/utils.ts @@ -1,12 +1,15 @@ -import { TransportModeFilterState } from '@atb/components/transport-mode-filter/types'; -import { filterToQueryString } from '@atb/components/transport-mode-filter/utils'; import { GeocoderFeature } from '@atb/page-modules/departures'; import { - TripData, - TripQuery, + type TripData, + type TripQuery, TripQuerySchema, } from '@atb/page-modules/assistant'; -import { SearchMode, SearchTime } from '@atb/modules/search-time'; +import type { SearchMode, SearchTime } from '@atb/modules/search-time'; +import { + filterToQueryString, + type TransportModeFilterState, +} from '@atb/modules/transport-mode'; +import { searchTimeToQueryString } from '@atb/modules/search-time'; export function filterOutDuplicates( arrayToFilter: TripData['tripPatterns'], @@ -56,10 +59,7 @@ export function createTripQuery( } } - const searchTimeQuery = - searchTime.mode !== 'now' - ? { searchMode: searchTime.mode, searchTime: searchTime.dateTime } - : { searchMode: searchTime.mode }; + const searchTimeQuery = searchTimeToQueryString(searchTime); const cursorQuery = cursor ? { cursor } : {}; const fromToQuery = featuresToFromToQuery(fromFeature, toFeature); diff --git a/src/page-modules/departures/__tests__/departure-data.fixture.ts b/src/page-modules/departures/__tests__/departure-data.fixture.ts index bfafcd1db..d9fd48455 100644 --- a/src/page-modules/departures/__tests__/departure-data.fixture.ts +++ b/src/page-modules/departures/__tests__/departure-data.fixture.ts @@ -1,4 +1,4 @@ -import { DepartureData } from '@atb/page-modules/departures/'; +import { DepartureData } from '../server/journey-planner'; export const departureDataFixture: DepartureData = { stopPlace: { diff --git a/src/page-modules/departures/__tests__/departure.test.tsx b/src/page-modules/departures/__tests__/departure.test.tsx index b78c2075b..a6898c885 100644 --- a/src/page-modules/departures/__tests__/departure.test.tsx +++ b/src/page-modules/departures/__tests__/departure.test.tsx @@ -1,12 +1,8 @@ import { cleanup, render, screen, within } from '@testing-library/react'; import mockRouter from 'next-router-mock'; import { afterEach, describe, expect, it, vi } from 'vitest'; - import { ExternalClient } from '@atb/modules/api-server'; -import { - DepartureData, - JourneyPlannerApi, -} from '@atb/page-modules/departures/server/journey-planner'; +import { DepartureData, JourneyPlannerApi } from '../server/journey-planner'; import { getServerSideProps } from '@atb/pages/departures/[[...id]]'; import { expectProps } from '@atb/tests/utils'; import { createDynamicRouteParser } from 'next-router-mock/dynamic-routes'; @@ -14,6 +10,7 @@ import { departureDataFixture } from './departure-data.fixture'; import { StopPlace } from '../stop-place'; import userEvent from '@testing-library/user-event'; import { NearestStopPlaces } from '..'; + afterEach(function () { cleanup(); }); diff --git a/src/page-modules/departures/__tests__/service-journey-data.fixture.ts b/src/page-modules/departures/__tests__/service-journey-data.fixture.ts index 91f592959..c4b02bbf6 100644 --- a/src/page-modules/departures/__tests__/service-journey-data.fixture.ts +++ b/src/page-modules/departures/__tests__/service-journey-data.fixture.ts @@ -1,8 +1,8 @@ import { ServiceJourneyData } from '../server/journey-planner/validators'; -import { +import type { TransportModeType, TransportSubmodeType, -} from '@atb/components/transport-mode/types'; +} from '@atb/modules/transport-mode'; export const serviceJourneyFixture: ServiceJourneyData = { id: 'ATB:ServiceJourney:22_230306097862461_113', diff --git a/src/page-modules/departures/details/estimated-call-rows.tsx b/src/page-modules/departures/details/estimated-call-rows.tsx index 50a53115f..bc104b2f1 100644 --- a/src/page-modules/departures/details/estimated-call-rows.tsx +++ b/src/page-modules/departures/details/estimated-call-rows.tsx @@ -1,10 +1,8 @@ -import { TransportModeType } from '@atb/components/transport-mode/types'; import { EstimatedCallWithMetadata } from '../types'; import { PageText, useTranslation } from '@atb/translations'; import { PropsWithChildren, useState } from 'react'; import style from './details.module.css'; import { motion } from 'framer-motion'; -import { useTransportationThemeColor } from '@atb/components/transport-mode/transport-icon'; import { Typo } from '@atb/components/typography'; import { MonoIcon } from '@atb/components/icon'; import { Button } from '@atb/components/button'; @@ -12,6 +10,10 @@ import Link from 'next/link'; import DepartureTime from './departure-time'; import DecorationLine from './decoration-line'; import { and } from '@atb/utils/css'; +import { + type TransportModeType, + useTransportationThemeColor, +} from '@atb/modules/transport-mode'; export type EstimatedCallRowsProps = { calls: EstimatedCallWithMetadata[]; diff --git a/src/page-modules/departures/index.ts b/src/page-modules/departures/index.ts index 55c18c6f5..bf05b2948 100644 --- a/src/page-modules/departures/index.ts +++ b/src/page-modules/departures/index.ts @@ -7,3 +7,8 @@ export type { } from './server/journey-planner'; export * from './nearest-stop-places'; +export { StopPlace } from './stop-place'; +export { + default as DeparturesLayout, + type DeparturesLayoutProps, +} from './layout'; diff --git a/src/page-modules/departures/layout.tsx b/src/page-modules/departures/layout.tsx index 2a541e12a..6cf749265 100644 --- a/src/page-modules/departures/layout.tsx +++ b/src/page-modules/departures/layout.tsx @@ -5,19 +5,23 @@ import Search from '@atb/components/search'; import { Button } from '@atb/components/button'; import style from './departures.module.css'; import { useRouter } from 'next/router'; -import TransportModeFilter from '@atb/components/transport-mode-filter'; import { Typo } from '@atb/components/typography'; import { + TransportModeFilter, filterToQueryString, getInitialTransportModeFilter, -} from '@atb/components/transport-mode-filter/utils'; -import { TransportModeFilterOption } from '@atb/components/transport-mode-filter/types'; + TransportModeFilterOption, +} from '@atb/modules/transport-mode'; import { MonoIcon } from '@atb/components/icon'; import { FocusScope } from '@react-aria/focus'; import GeolocationButton from '@atb/components/search/geolocation-button'; import { AnimatePresence, motion } from 'framer-motion'; import React from 'react'; -import { SearchTime, SearchTimeSelector } from '@atb/modules/search-time'; +import { + SearchTime, + SearchTimeSelector, + searchTimeToQueryString, +} from '@atb/modules/search-time'; export type DeparturesLayoutProps = PropsWithChildren<{ initialTransportModesFilter?: TransportModeFilterOption[] | null; diff --git a/src/page-modules/departures/nearest-stop-places/index.tsx b/src/page-modules/departures/nearest-stop-places/index.tsx index 3a9c2b8e3..2ae287dc7 100644 --- a/src/page-modules/departures/nearest-stop-places/index.tsx +++ b/src/page-modules/departures/nearest-stop-places/index.tsx @@ -1,11 +1,10 @@ import { MapWithHeader } from '@atb/components/map'; -import type { - GeocoderFeature, +import { GeocoderFeature } from '../types'; +import { NearestStopPlacesData, -} from '@atb/page-modules/departures'; + StopPlaceWithDistance, +} from '../server/journey-planner'; import Link from 'next/link'; -import type { StopPlaceWithDistance } from '..'; - import style from './nearest-stop-places.module.css'; import { Typo } from '@atb/components/typography'; import { useRouter } from 'next/router'; diff --git a/src/page-modules/departures/server/journey-planner/index.ts b/src/page-modules/departures/server/journey-planner/index.ts index 8f8f8eda1..fa554c0d9 100644 --- a/src/page-modules/departures/server/journey-planner/index.ts +++ b/src/page-modules/departures/server/journey-planner/index.ts @@ -34,17 +34,12 @@ import { ServiceJourneyData, serviceJourneySchema, } from './validators'; +import { TransportMode as GraphQlTransportMode } from '@atb/modules/graphql-types'; import { - TransportMode, - TransportMode as GraphqlTransportMode, -} from '@atb/modules/graphql-types'; -import { TransportModeFilterOption } from '@atb/components/transport-mode-filter/types'; -import { getAllTransportModesFromFilterOptions } from '@atb/components/transport-mode-filter/utils'; -import { enumFromString } from '@atb/utils/enum-from-string'; -import { - TransportModeType, - TransportSubmodeType, -} from '@atb/components/transport-mode/types'; + type TransportModeType, + isTransportModeType, + filterGraphQlTransportModes, +} from '@atb/modules/transport-mode'; import { ServiceJourneyWithEstimatedCallsDocument, ServiceJourneyWithEstimatedCallsQuery, @@ -54,7 +49,7 @@ import { formatISO } from 'date-fns'; export type DepartureInput = { id: string; - transportModes: TransportModeFilterOption[] | null; + transportModes: TransportModeType[] | null; }; export type { DepartureData, Quay, Departure }; @@ -65,7 +60,7 @@ export type StopPlaceInput = { export type NearestStopPlacesInput = { lat: number; lon: number; - transportModes: TransportModeFilterOption[] | null; + transportModes: TransportModeType[] | null; }; export type EstimatedCallsInput = { @@ -104,7 +99,8 @@ export function createJourneyApi( id: input.id, startTime: new Date(), numberOfDepartures: 10, - transportModes: getTransportModesEnums(input.transportModes), + transportModes: + (input.transportModes as GraphQlTransportMode[]) ?? null, }, }); @@ -120,7 +116,7 @@ export function createJourneyApi( lat: result.data.stopPlace?.latitude, lon: result.data.stopPlace?.longitude, }, - transportMode: filterTransportModes( + transportMode: filterGraphQlTransportModes( result.data.stopPlace?.transportMode, ), transportSubmode: result.data.stopPlace?.transportSubmode, @@ -199,7 +195,8 @@ export function createJourneyApi( variables: { // Max distance in meters distance: 900, - transportModes: getTransportModesEnums(input.transportModes), + transportModes: + (input.transportModes as GraphQlTransportMode[]) ?? null, latitude: input.lat, longitude: input.lon, @@ -358,36 +355,3 @@ type RecursivePartial = { ? RecursivePartial : T[P]; }; - -const filterTransportModes = ( - modes: GraphqlTransportMode[] | undefined, -): TransportModeType[] | undefined => { - if (!modes) return undefined; - const transportModes: TransportModeType[] = []; - modes.forEach((transportMode) => { - if (isTransportModeType(transportMode)) transportModes.push(transportMode); - }); - if (transportModes.length === 0) return undefined; - return transportModes; -}; - -export const isTransportModeType = (a: any): a is TransportModeType => { - return TransportModeType.safeParse(a).success; -}; - -export const isTransportSubmodeType = (a: any): a is TransportSubmodeType => { - return TransportSubmodeType.safeParse(a).success; -}; - -export const getTransportModesEnums = ( - transportModes: TransportModeFilterOption[] | null, -): TransportMode[] | null => { - if (!transportModes) return null; - - const allTransportModes = - getAllTransportModesFromFilterOptions(transportModes); - - return allTransportModes - .map((mode) => enumFromString(TransportMode, mode)) - .filter(Boolean) as TransportMode[]; -}; diff --git a/src/page-modules/departures/server/journey-planner/validators.ts b/src/page-modules/departures/server/journey-planner/validators.ts index 6c5f1cbed..8f71aa2ea 100644 --- a/src/page-modules/departures/server/journey-planner/validators.ts +++ b/src/page-modules/departures/server/journey-planner/validators.ts @@ -1,7 +1,7 @@ import { - TransportModeType, - TransportSubmodeType, -} from '@atb/components/transport-mode/types'; + transportModeSchema, + transportSubmodeSchema, +} from '@atb/modules/transport-mode'; import { z } from 'zod'; export const locationSchema = z.object({ @@ -14,8 +14,8 @@ export const stopPlaceSchema = z.object({ name: z.string(), description: z.string().nullable(), position: locationSchema, - transportMode: TransportModeType.array().optional(), - transportSubmode: TransportSubmodeType.array().optional(), + transportMode: transportModeSchema.array().optional(), + transportSubmode: transportSubmodeSchema.array().optional(), }); export const departureSchema = z.object({ @@ -25,8 +25,8 @@ export const departureSchema = z.object({ date: z.string(), aimedDepartureTime: z.string(), expectedDepartureTime: z.string(), - transportMode: TransportModeType.optional(), - transportSubmode: TransportSubmodeType.optional(), + transportMode: transportModeSchema.optional(), + transportSubmode: transportSubmodeSchema.optional(), }); export const quaySchema = z.object({ @@ -54,8 +54,8 @@ export const estimatedCallsSchema = z.object({ export const serviceJourneySchema = z.object({ id: z.string(), - transportMode: TransportModeType, - transportSubmode: TransportSubmodeType.optional(), + transportMode: transportModeSchema, + transportSubmode: transportSubmodeSchema.optional(), line: z.object({ publicCode: z.string(), }), diff --git a/src/pages/api/assistant/trip.ts b/src/pages/api/assistant/trip.ts index e5c8cc29e..be30668b9 100644 --- a/src/pages/api/assistant/trip.ts +++ b/src/pages/api/assistant/trip.ts @@ -1,11 +1,13 @@ -import { parseFilterQuery } from '@atb/components/transport-mode-filter/utils'; import { errorResultAsJson, tryResult } from '@atb/modules/api-server'; -import { TripApiReturnType } from '@atb/page-modules/assistant/client/journey-planner'; import { handlerWithAssistantClient } from '@atb/page-modules/assistant/server'; -import { parseTripQuery } from '@atb/page-modules/assistant'; +import { + parseTripQuery, + type TripApiReturnType, +} from '@atb/page-modules/assistant'; import { ServerText } from '@atb/translations'; import { constants } from 'http2'; -import { parseSearchTimeQuery } from '@atb/modules/search-time/utils'; +import { parseSearchTimeQuery } from '@atb/modules/search-time'; +import { parseFilterQuery } from '@atb/modules/transport-mode'; export default handlerWithAssistantClient({ async GET(req, res, { client, ok }) { diff --git a/src/pages/assistant/index.tsx b/src/pages/assistant/index.tsx index e37f0cd76..885938b92 100644 --- a/src/pages/assistant/index.tsx +++ b/src/pages/assistant/index.tsx @@ -1,17 +1,18 @@ -import { parseFilterQuery } from '@atb/components/transport-mode-filter/utils'; import DefaultLayout from '@atb/layouts/default'; import { type WithGlobalData, withGlobalData } from '@atb/layouts/global-data'; import { withAssistantClient } from '@atb/page-modules/assistant/server'; -import Trip, { TripProps } from '@atb/page-modules/assistant/trip'; -import type { TripData } from '@atb/page-modules/assistant'; import { AssistantLayout, - AssistantLayoutProps, + type AssistantLayoutProps, parseTripQuery, StreetMode, + Trip, + type TripData, + type TripProps, } from '@atb/page-modules/assistant'; import type { NextPage } from 'next'; -import { parseSearchTimeQuery } from '@atb/modules/search-time/utils'; +import { parseSearchTimeQuery } from '@atb/modules/search-time'; +import { parseFilterQuery } from '@atb/modules/transport-mode'; type AssistantContentProps = { empty: true } | TripProps; diff --git a/src/pages/departures/[[...id]].tsx b/src/pages/departures/[[...id]].tsx index 94ca4390c..3e297208b 100644 --- a/src/pages/departures/[[...id]].tsx +++ b/src/pages/departures/[[...id]].tsx @@ -1,18 +1,20 @@ import DefaultLayout from '@atb/layouts/default'; -import type { WithGlobalData } from '@atb/layouts/global-data'; -import { withGlobalData } from '@atb/layouts/global-data'; +import { type WithGlobalData, withGlobalData } from '@atb/layouts/global-data'; import { - DepartureData, + type DepartureData, + DeparturesLayout, + type DeparturesLayoutProps, NearestStopPlaces, - NearestStopPlacesProps, + type NearestStopPlacesProps, + StopPlace, } from '@atb/page-modules/departures'; -import DeparturesLayout, { - DeparturesLayoutProps, -} from '@atb/page-modules/departures/layout'; import { withDepartureClient } from '@atb/page-modules/departures/server'; -import { StopPlace } from '@atb/page-modules/departures/stop-place'; import type { NextPage } from 'next'; -import { parseFilterQuery } from '@atb/components/transport-mode-filter/utils'; +import { + getAllTransportModesFromFilterOptions, + parseFilterQuery, +} from '@atb/modules/transport-mode'; + type DeparturesStopPlaceProps = { stopPlace: true; departures?: DepartureData; @@ -67,8 +69,10 @@ export const getServerSideProps = withGlobalData( if (id && stopPlace) { const departures = await client.departures({ id, - transportModes: transportModeFilter, + transportModes: + getAllTransportModesFromFilterOptions(transportModeFilter), }); + return { props: { stopPlace: true, @@ -83,7 +87,8 @@ export const getServerSideProps = withGlobalData( }; const nearestStopPlaces = await client.nearestStopPlaces({ ...position, - transportModes: transportModeFilter, + transportModes: + getAllTransportModesFromFilterOptions(transportModeFilter), }); const activeLocation = await client.reverse( diff --git a/src/translations/pages/assistant.ts b/src/translations/pages/assistant.ts index c5cd5e7b4..40029ce0b 100644 --- a/src/translations/pages/assistant.ts +++ b/src/translations/pages/assistant.ts @@ -1,5 +1,5 @@ import { translation as _ } from '@atb/translations/commons'; -import { TransportModeType } from '@atb/components/transport-mode/types'; +import { TransportModeType } from '@atb/modules/transport-mode'; export const Assistant = { title: _('Planlegg reisen', 'Plan travel', 'Planlegg reisa'),