@mrfylke/contact-form 0.1.10 → 0.1.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (166) hide show
  1. package/README.md +393 -2
  2. package/lib/ContactFormRoot.d.ts +11 -1
  3. package/lib/ContactFormRoot.d.ts.map +1 -1
  4. package/lib/ContactFormRoot.js +2 -2
  5. package/lib/commoneEvents.d.ts +1 -1
  6. package/lib/commoneEvents.d.ts.map +1 -1
  7. package/lib/components/form/date-selector.d.ts.map +1 -1
  8. package/lib/components/form/date-selector.js +5 -4
  9. package/lib/components/form/departure-time-field.d.ts +16 -0
  10. package/lib/components/form/departure-time-field.d.ts.map +1 -0
  11. package/lib/components/form/departure-time-field.js +28 -0
  12. package/lib/components/form/description-modal.d.ts.map +1 -1
  13. package/lib/components/form/description-modal.js +2 -1
  14. package/lib/components/form/file-input.d.ts.map +1 -1
  15. package/lib/components/form/file-input.js +2 -1
  16. package/lib/components/form/index.d.ts +1 -0
  17. package/lib/components/form/index.d.ts.map +1 -1
  18. package/lib/components/form/index.js +3 -1
  19. package/lib/components/form/input.d.ts.map +1 -1
  20. package/lib/components/form/input.js +2 -1
  21. package/lib/components/form/searchable-select/utils.js +6 -1
  22. package/lib/components/index.d.ts +1 -1
  23. package/lib/components/index.d.ts.map +1 -1
  24. package/lib/components/index.js +2 -1
  25. package/lib/contact.module.css +9 -0
  26. package/lib/error-content/error-content.d.ts.map +1 -1
  27. package/lib/error-content/error-content.js +2 -1
  28. package/lib/group-travel/index.d.ts.map +1 -1
  29. package/lib/group-travel/index.js +3 -1
  30. package/lib/index.d.ts +16 -4
  31. package/lib/index.d.ts.map +1 -1
  32. package/lib/index.js +41 -1
  33. package/lib/journey-info/index.d.ts.map +1 -1
  34. package/lib/journey-info/index.js +14 -8
  35. package/lib/journey-info/journeyInfoStateMachine.d.ts +8 -8
  36. package/lib/layouts/contact-page-layout.d.ts +2 -2
  37. package/lib/layouts/contact-page-layout.d.ts.map +1 -1
  38. package/lib/layouts/contact-page-layout.js +29 -20
  39. package/lib/layouts/container.module.css +1 -1
  40. package/lib/layouts/layout.module.css +23 -2
  41. package/lib/lines/use-departures.d.ts +12 -0
  42. package/lib/lines/use-departures.d.ts.map +1 -0
  43. package/lib/lines/use-departures.js +35 -0
  44. package/lib/lines/use-lines.d.ts +5 -6
  45. package/lib/lines/use-lines.d.ts.map +1 -1
  46. package/lib/lines/use-lines.js +75 -42
  47. package/lib/lost-property/LostPropertyForm.d.ts +10 -0
  48. package/lib/lost-property/LostPropertyForm.d.ts.map +1 -0
  49. package/lib/lost-property/LostPropertyForm.js +65 -0
  50. package/lib/lost-property/LostPropertyMachine.d.ts +116 -0
  51. package/lib/lost-property/LostPropertyMachine.d.ts.map +1 -0
  52. package/lib/lost-property/LostPropertyMachine.js +187 -0
  53. package/lib/lost-property/index.d.ts.map +1 -1
  54. package/lib/lost-property/index.js +27 -3
  55. package/lib/means-of-transport/forms/delayForm.d.ts.map +1 -1
  56. package/lib/means-of-transport/forms/delayForm.js +26 -18
  57. package/lib/means-of-transport/forms/driverForm.d.ts.map +1 -1
  58. package/lib/means-of-transport/forms/driverForm.js +26 -18
  59. package/lib/means-of-transport/forms/injuryForm.d.ts.map +1 -1
  60. package/lib/means-of-transport/forms/injuryForm.js +26 -18
  61. package/lib/means-of-transport/forms/serviceOfferingForm.d.ts.map +1 -1
  62. package/lib/means-of-transport/forms/serviceOfferingForm.js +10 -10
  63. package/lib/means-of-transport/forms/stopForm.d.ts.map +1 -1
  64. package/lib/means-of-transport/forms/stopForm.js +13 -12
  65. package/lib/means-of-transport/forms/transportationForm.d.ts.map +1 -1
  66. package/lib/means-of-transport/forms/transportationForm.js +26 -18
  67. package/lib/means-of-transport/index.d.ts.map +1 -1
  68. package/lib/means-of-transport/index.js +13 -4
  69. package/lib/means-of-transport/means-of-transport-form-machine.d.ts +10 -8
  70. package/lib/means-of-transport/means-of-transport-form-machine.d.ts.map +1 -1
  71. package/lib/means-of-transport/means-of-transport-form-machine.js +6 -1
  72. package/lib/modules/config/types.d.ts +56 -1
  73. package/lib/modules/config/types.d.ts.map +1 -1
  74. package/lib/refund/events.d.ts +1 -1
  75. package/lib/refund/events.d.ts.map +1 -1
  76. package/lib/refund/forms/refund-and-travel-guarantee/index.d.ts.map +1 -1
  77. package/lib/refund/forms/refund-and-travel-guarantee/index.js +7 -5
  78. package/lib/refund/forms/refund-and-travel-guarantee/refundCarForm.d.ts.map +1 -1
  79. package/lib/refund/forms/refund-and-travel-guarantee/refundCarForm.js +39 -29
  80. package/lib/refund/forms/refund-and-travel-guarantee/refundTaxiForm.d.ts.map +1 -1
  81. package/lib/refund/forms/refund-and-travel-guarantee/refundTaxiForm.js +37 -28
  82. package/lib/refund/forms/refund-ticket/appTicketRefund.d.ts.map +1 -1
  83. package/lib/refund/forms/refund-ticket/appTicketRefund.js +46 -25
  84. package/lib/refund/forms/refund-ticket/index.d.ts.map +1 -1
  85. package/lib/refund/forms/refund-ticket/index.js +9 -6
  86. package/lib/refund/forms/refund-ticket/otherTicketRefund.d.ts.map +1 -1
  87. package/lib/refund/forms/refund-ticket/otherTicketRefund.js +56 -30
  88. package/lib/refund/forms/residualValueOnTravelCard/index.d.ts.map +1 -1
  89. package/lib/refund/forms/residualValueOnTravelCard/index.js +5 -3
  90. package/lib/refund/index.d.ts.map +1 -1
  91. package/lib/refund/index.js +39 -6
  92. package/lib/refund/refundFormMachine.d.ts +37 -13
  93. package/lib/refund/refundFormMachine.d.ts.map +1 -1
  94. package/lib/refund/refundFormMachine.js +107 -11
  95. package/lib/server/journey-planner/index.d.ts.map +1 -1
  96. package/lib/server/journey-planner/index.js +15 -6
  97. package/lib/server/journey-planner/validators.d.ts +2 -0
  98. package/lib/server/journey-planner/validators.d.ts.map +1 -1
  99. package/lib/server/journey-planner/validators.js +1 -0
  100. package/lib/success-content/success-content.d.ts.map +1 -1
  101. package/lib/success-content/success-content.js +2 -1
  102. package/lib/test-utils/setup.d.ts +2 -0
  103. package/lib/test-utils/setup.d.ts.map +1 -0
  104. package/lib/test-utils/setup.js +3 -0
  105. package/lib/ticket-control/events.d.ts +1 -1
  106. package/lib/ticket-control/events.d.ts.map +1 -1
  107. package/lib/ticket-control/forms/feeComplaintForm.d.ts.map +1 -1
  108. package/lib/ticket-control/forms/feeComplaintForm.js +39 -36
  109. package/lib/ticket-control/forms/feedbackForm.d.ts.map +1 -1
  110. package/lib/ticket-control/forms/feedbackForm.js +26 -14
  111. package/lib/ticket-control/forms/postponePayment.d.ts.map +1 -1
  112. package/lib/ticket-control/forms/postponePayment.js +8 -7
  113. package/lib/ticket-control/index.d.ts.map +1 -1
  114. package/lib/ticket-control/index.js +23 -8
  115. package/lib/ticket-control/ticket-control-form-machine.d.ts +19 -11
  116. package/lib/ticket-control/ticket-control-form-machine.d.ts.map +1 -1
  117. package/lib/ticket-control/ticket-control-form-machine.js +25 -5
  118. package/lib/ticketing/forms/app/appAccountForm.d.ts.map +1 -1
  119. package/lib/ticketing/forms/app/appAccountForm.js +9 -8
  120. package/lib/ticketing/forms/app/appTicketingForm.d.ts.map +1 -1
  121. package/lib/ticketing/forms/app/appTicketingForm.js +13 -12
  122. package/lib/ticketing/forms/app/appTravelSuggestionForm.d.ts.map +1 -1
  123. package/lib/ticketing/forms/app/appTravelSuggestionForm.js +6 -5
  124. package/lib/ticketing/forms/app/index.d.ts.map +1 -1
  125. package/lib/ticketing/forms/app/index.js +2 -1
  126. package/lib/ticketing/forms/priceAndTicketTypesForm.d.ts.map +1 -1
  127. package/lib/ticketing/forms/priceAndTicketTypesForm.js +6 -5
  128. package/lib/ticketing/forms/travel-card/index.d.ts.map +1 -1
  129. package/lib/ticketing/forms/travel-card/index.js +2 -1
  130. package/lib/ticketing/forms/travel-card/orderTravelCard.d.ts.map +1 -1
  131. package/lib/ticketing/forms/travel-card/orderTravelCard.js +2 -2
  132. package/lib/ticketing/forms/travel-card/travelCardQuestionForm.d.ts.map +1 -1
  133. package/lib/ticketing/forms/travel-card/travelCardQuestionForm.js +9 -8
  134. package/lib/ticketing/forms/webshop/index.d.ts.map +1 -1
  135. package/lib/ticketing/forms/webshop/index.js +2 -1
  136. package/lib/ticketing/forms/webshop/webshopAccountForm.d.ts.map +1 -1
  137. package/lib/ticketing/forms/webshop/webshopAccountForm.js +9 -8
  138. package/lib/ticketing/forms/webshop/webshopTicketingForm.d.ts.map +1 -1
  139. package/lib/ticketing/forms/webshop/webshopTicketingForm.js +12 -11
  140. package/lib/ticketing/index.d.ts.map +1 -1
  141. package/lib/ticketing/index.js +21 -6
  142. package/lib/ticketing/ticketingStateMachine.d.ts +12 -12
  143. package/lib/translations/index.d.ts +1 -1
  144. package/lib/translations/index.d.ts.map +1 -1
  145. package/lib/translations/index.js +2 -1
  146. package/lib/translations/merge-overrides.d.ts.map +1 -1
  147. package/lib/translations/merge-overrides.js +8 -1
  148. package/lib/translations/pages/contact.d.ts +61 -0
  149. package/lib/translations/pages/contact.d.ts.map +1 -1
  150. package/lib/translations/pages/contact.js +64 -2
  151. package/lib/translations/translations-context.d.ts +2 -0
  152. package/lib/translations/translations-context.d.ts.map +1 -1
  153. package/lib/translations/translations-context.js +39 -0
  154. package/lib/types/submit-payloads.d.ts +40 -11
  155. package/lib/types/submit-payloads.d.ts.map +1 -1
  156. package/lib/types/submit-payloads.js +1 -1
  157. package/lib/types.d.ts +1 -1
  158. package/lib/types.d.ts.map +1 -1
  159. package/lib/url-form-type.d.ts +6 -0
  160. package/lib/url-form-type.d.ts.map +1 -0
  161. package/lib/url-form-type.js +21 -0
  162. package/lib/utils.d.ts.map +1 -1
  163. package/lib/utils.js +10 -0
  164. package/lib/validation/validationRules.d.ts.map +1 -1
  165. package/lib/validation/validationRules.js +31 -0
  166. package/package.json +11 -3
@@ -1,20 +1,19 @@
1
1
  import { TransportModeType } from '../types';
2
2
  import { Line } from '../server/journey-planner/validators';
3
- /**
4
- * Get available transport modes based on config (ferry flag).
5
- * Returns the standard list ['bus', 'expressboat', 'ferry'] or ['bus', 'expressboat'] if ferry is disabled.
6
- */
3
+ export declare function getTransportModeOptions(includeFerry: boolean, includeBestillingstransport: boolean): TransportModeType[];
7
4
  export declare const useTransportModeOptions: () => TransportModeType[];
5
+ export declare function filterLinesByMode(lines: Line[], transportMode: TransportModeType, includeFerry: boolean): Line[];
8
6
  export declare const useLines: () => {
9
7
  lines: {
10
8
  id: string;
11
9
  name: string;
12
10
  publicCode: string | null;
13
- transportMode: "unknown" | "bus" | "coach" | "rail" | "tram" | "water" | "air" | "foot" | "metro" | "funicular" | "bicycle" | "cableway" | "car" | "lift" | "monorail" | "scooter" | "taxi" | "trolleybus" | "carpool" | "snowAndIce" | null;
14
- transportSubmode: "undefined" | "unknown" | "metro" | "funicular" | "lift" | "local" | "SchengenAreaFlight" | "airportBoatLink" | "airportLinkBus" | "airportLinkRail" | "airshipService" | "allFunicularServices" | "allHireVehicles" | "allTaxiServices" | "bikeTaxi" | "blackCab" | "cableCar" | "cableFerry" | "canalBarge" | "carTransportRailService" | "chairLift" | "charterTaxi" | "cityTram" | "communalTaxi" | "commuterCoach" | "crossCountryRail" | "dedicatedLaneBus" | "demandAndResponseBus" | "domesticCharterFlight" | "domesticFlight" | "domesticScheduledFlight" | "dragLift" | "escooter" | "expressBus" | "helicopterService" | "highFrequencyBus" | "highSpeedPassengerService" | "highSpeedRail" | "highSpeedVehicleService" | "hireCar" | "hireCycle" | "hireMotorbike" | "hireVan" | "intercontinentalCharterFlight" | "intercontinentalFlight" | "international" | "internationalCarFerry" | "internationalCharterFlight" | "internationalCoach" | "internationalFlight" | "internationalPassengerFerry" | "interregionalRail" | "localBus" | "localCarFerry" | "localPassengerFerry" | "localTram" | "longDistance" | "miniCab" | "mobilityBus" | "mobilityBusForRegisteredDisabled" | "nationalCarFerry" | "nationalCoach" | "nationalPassengerFerry" | "nightBus" | "nightRail" | "postBoat" | "postBus" | "rackAndPinionRailway" | "railReplacementBus" | "railShuttle" | "railTaxi" | "regionalBus" | "regionalCarFerry" | "regionalCoach" | "regionalPassengerFerry" | "regionalRail" | "regionalTram" | "replacementRailService" | "riverBus" | "roadFerryLink" | "roundTripCharterFlight" | "scheduledFerry" | "schoolAndPublicServiceBus" | "schoolBoat" | "schoolBus" | "schoolCoach" | "shortHaulInternationalFlight" | "shuttleBus" | "shuttleCoach" | "shuttleFerryService" | "shuttleFlight" | "shuttleTram" | "sightseeingBus" | "sightseeingCoach" | "sightseeingFlight" | "sightseeingService" | "sightseeingTram" | "sleeperRailService" | "specialCoach" | "specialNeedsBus" | "specialTrain" | "streetCableCar" | "suburbanRailway" | "telecabin" | "telecabinLink" | "touristCoach" | "touristRailway" | "trainFerry" | "trainTram" | "tube" | "undefinedFunicular" | "urbanRailway" | "waterTaxi" | null;
11
+ transportMode: "unknown" | "air" | "bus" | "foot" | "bicycle" | "cableway" | "car" | "carpool" | "coach" | "funicular" | "lift" | "metro" | "monorail" | "rail" | "scooter" | "taxi" | "tram" | "trolleybus" | "water" | "snowAndIce" | null;
12
+ transportSubmode: "undefined" | "unknown" | "funicular" | "lift" | "metro" | "SchengenAreaFlight" | "airportBoatLink" | "airportLinkBus" | "airportLinkRail" | "airshipService" | "allFunicularServices" | "allHireVehicles" | "allTaxiServices" | "bikeTaxi" | "blackCab" | "cableCar" | "cableFerry" | "canalBarge" | "carTransportRailService" | "chairLift" | "charterTaxi" | "cityTram" | "communalTaxi" | "commuterCoach" | "crossCountryRail" | "dedicatedLaneBus" | "demandAndResponseBus" | "domesticCharterFlight" | "domesticFlight" | "domesticScheduledFlight" | "dragLift" | "escooter" | "expressBus" | "helicopterService" | "highFrequencyBus" | "highSpeedPassengerService" | "highSpeedRail" | "highSpeedVehicleService" | "hireCar" | "hireCycle" | "hireMotorbike" | "hireVan" | "intercontinentalCharterFlight" | "intercontinentalFlight" | "international" | "internationalCarFerry" | "internationalCharterFlight" | "internationalCoach" | "internationalFlight" | "internationalPassengerFerry" | "interregionalRail" | "local" | "localBus" | "localCarFerry" | "localPassengerFerry" | "localTram" | "longDistance" | "miniCab" | "mobilityBus" | "mobilityBusForRegisteredDisabled" | "nationalCarFerry" | "nationalCoach" | "nationalPassengerFerry" | "nightBus" | "nightRail" | "postBoat" | "postBus" | "rackAndPinionRailway" | "railReplacementBus" | "railShuttle" | "railTaxi" | "regionalBus" | "regionalCarFerry" | "regionalCoach" | "regionalPassengerFerry" | "regionalRail" | "regionalTram" | "replacementRailService" | "riverBus" | "roadFerryLink" | "roundTripCharterFlight" | "scheduledFerry" | "schoolAndPublicServiceBus" | "schoolBoat" | "schoolBus" | "schoolCoach" | "shortHaulInternationalFlight" | "shuttleBus" | "shuttleCoach" | "shuttleFerryService" | "shuttleFlight" | "shuttleTram" | "sightseeingBus" | "sightseeingCoach" | "sightseeingFlight" | "sightseeingService" | "sightseeingTram" | "sleeperRailService" | "specialCoach" | "specialNeedsBus" | "specialTrain" | "streetCableCar" | "suburbanRailway" | "telecabin" | "telecabinLink" | "touristCoach" | "touristRailway" | "trainFerry" | "trainTram" | "tube" | "undefinedFunicular" | "urbanRailway" | "waterTaxi" | null;
15
13
  quays: {
16
14
  id: string;
17
15
  name: string;
16
+ description: string | null;
18
17
  }[];
19
18
  }[] | undefined;
20
19
  error: any;
@@ -1 +1 @@
1
- {"version":3,"file":"use-lines.d.ts","sourceRoot":"","sources":["../../src/lines/use-lines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,sCAAsC,CAAC;AAK5D;;;GAGG;AACH,eAAO,MAAM,uBAAuB,QAAO,iBAAiB,EAQ3D,CAAC;AAEF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;oCA0BoB,iBAAiB,KAAG,IAAI,EAAE;6BAkCjC,MAAM,KAAG,IAAI,CAAC,OAAO,CAAC;CAYvD,CAAC"}
1
+ {"version":3,"file":"use-lines.d.ts","sourceRoot":"","sources":["../../src/lines/use-lines.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC7C,OAAO,EAAE,IAAI,EAAE,MAAM,sCAAsC,CAAC;AAK5D,wBAAgB,uBAAuB,CACrC,YAAY,EAAE,OAAO,EACrB,2BAA2B,EAAE,OAAO,GACnC,iBAAiB,EAAE,CAKrB;AAED,eAAO,MAAM,uBAAuB,QAAO,iBAAiB,EAM3D,CAAC;AAsCF,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,IAAI,EAAE,EACb,aAAa,EAAE,iBAAiB,EAChC,YAAY,EAAE,OAAO,GACpB,IAAI,EAAE,CA6CR;AAED,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;oCAWoB,iBAAiB,KAAG,IAAI,EAAE;6BAUjC,MAAM,KAAG,IAAI,CAAC,OAAO,CAAC;CAYvD,CAAC"}
@@ -4,62 +4,95 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.useLines = exports.useTransportModeOptions = void 0;
7
+ exports.getTransportModeOptions = getTransportModeOptions;
8
+ exports.filterLinesByMode = filterLinesByMode;
7
9
  const immutable_1 = __importDefault(require("swr/immutable"));
8
10
  const api_browser_1 = require("../modules/api-browser");
9
11
  const config_1 = require("../modules/config");
10
- /**
11
- * Get available transport modes based on config (ferry flag).
12
- * Returns the standard list ['bus', 'expressboat', 'ferry'] or ['bus', 'expressboat'] if ferry is disabled.
13
- */
12
+ function getTransportModeOptions(includeFerry, includeBestillingstransport) {
13
+ const modes = ['bus'];
14
+ if (includeBestillingstransport)
15
+ modes.push('bestillingstransport');
16
+ if (includeFerry)
17
+ modes.push('expressboat', 'ferry');
18
+ return modes;
19
+ }
14
20
  const useTransportModeOptions = () => {
15
21
  const { features } = (0, config_1.useContactFormConfig)();
16
- const includeFerry = features?.includeFerry !== false; // Default true
17
- if (includeFerry) {
18
- return ['bus', 'expressboat', 'ferry'];
19
- }
20
- return ['bus', 'expressboat'];
22
+ return getTransportModeOptions(features?.includeFerry !== false, features?.includeBestillingstransport === true);
21
23
  };
22
24
  exports.useTransportModeOptions = useTransportModeOptions;
25
+ const subTransportModesExpressboat = [
26
+ 'highSpeedPassengerService',
27
+ 'highSpeedVehicleService',
28
+ 'sightseeingService',
29
+ 'localPassengerFerry',
30
+ 'internationalPassengerFerry',
31
+ ];
32
+ const subTransportModesFerry = [
33
+ 'highSpeedVehicleService',
34
+ 'internationalCarFerry',
35
+ 'localCarFerry',
36
+ 'nationalCarFerry',
37
+ ];
38
+ function sortLinesByCode(lines) {
39
+ return [...lines].sort((a, b) => {
40
+ if (a.publicCode === null && b.publicCode === null)
41
+ return a.name.localeCompare(b.name, undefined, {
42
+ numeric: true,
43
+ sensitivity: 'base',
44
+ });
45
+ if (a.publicCode === null)
46
+ return 1;
47
+ if (b.publicCode === null)
48
+ return -1;
49
+ const aNum = Number(a.publicCode);
50
+ const bNum = Number(b.publicCode);
51
+ if (!isNaN(aNum) && !isNaN(bNum))
52
+ return aNum - bNum;
53
+ return a.publicCode.localeCompare(b.publicCode, undefined, {
54
+ numeric: true,
55
+ sensitivity: 'base',
56
+ });
57
+ });
58
+ }
59
+ function filterLinesByMode(lines, transportMode, includeFerry) {
60
+ if ((transportMode === 'ferry' || transportMode === 'expressboat') &&
61
+ !includeFerry) {
62
+ return [];
63
+ }
64
+ switch (transportMode) {
65
+ case 'bus':
66
+ return sortLinesByCode(lines.filter((line) => line.transportMode === 'bus'));
67
+ case 'bestillingstransport':
68
+ return sortLinesByCode(lines.filter((line) => line.transportMode === 'taxi' ||
69
+ line.name.toLowerCase().includes('bestillingsrute')));
70
+ case 'expressboat':
71
+ return sortLinesByCode(lines.filter((line) => line.transportMode === 'water' &&
72
+ line.transportSubmode !== null &&
73
+ subTransportModesExpressboat.includes(line.transportSubmode)));
74
+ case 'ferry':
75
+ return sortLinesByCode(lines.filter((line) => line.transportMode === 'water' &&
76
+ line.transportSubmode !== null &&
77
+ subTransportModesFerry.includes(line.transportSubmode)));
78
+ default:
79
+ return [];
80
+ }
81
+ }
23
82
  const useLines = () => {
24
83
  const apiConfig = (0, config_1.useApiConfig)();
25
- const { features } = (0, config_1.useContactFormConfig)();
26
- const includeFerry = features?.includeFerry !== false; // Default true
84
+ const { features, lineFilters } = (0, config_1.useContactFormConfig)();
85
+ const includeFerry = features?.includeFerry !== false;
27
86
  const linesEndpoint = apiConfig.endpoints.lines || '/api/contact/lines';
28
87
  const { data: lines, error, isLoading, } = (0, immutable_1.default)(linesEndpoint, api_browser_1.swrFetcher);
29
- const subTransportModesExpressboat = [
30
- 'highSpeedPassengerService',
31
- 'highSpeedVehicleService',
32
- 'sightseeingService',
33
- 'localPassengerFerry',
34
- 'internationalPassengerFerry',
35
- ];
36
- const subTransportModesFerry = [
37
- 'highSpeedVehicleService',
38
- 'internationalCarFerry',
39
- 'localCarFerry',
40
- 'nationalCarFerry',
41
- ];
42
88
  const getLinesByMode = (transportMode) => {
43
89
  if (!lines)
44
90
  return [];
45
- // If ferry is disabled and mode is ferry, return empty array
46
- if (transportMode === 'ferry' && !includeFerry) {
47
- return [];
48
- }
49
- switch (transportMode) {
50
- case 'bus':
51
- return lines.filter((line) => line.transportMode === transportMode);
52
- case 'expressboat':
53
- return lines.filter((line) => line.transportMode === 'water' &&
54
- line.transportSubmode !== null &&
55
- subTransportModesExpressboat.includes(line.transportSubmode));
56
- case 'ferry':
57
- return lines.filter((line) => line.transportMode === 'water' &&
58
- line.transportSubmode !== null &&
59
- subTransportModesFerry.includes(line.transportSubmode));
60
- default:
61
- return [];
62
- }
91
+ const filteredLines = filterLinesByMode(lines, transportMode, includeFerry);
92
+ const additionalPredicate = lineFilters?.additionalPredicate;
93
+ if (!additionalPredicate)
94
+ return filteredLines;
95
+ return filteredLines.filter((line) => additionalPredicate(line, transportMode));
63
96
  };
64
97
  const getQuaysByLine = (lineId) => {
65
98
  if (!lines)
@@ -0,0 +1,10 @@
1
+ import type { LostPropertyContext, LostPropertyEvent } from './LostPropertyMachine';
2
+ type LostPropertyFormProps = {
3
+ state: {
4
+ context: LostPropertyContext;
5
+ };
6
+ send: (event: LostPropertyEvent) => void;
7
+ };
8
+ export default function LostPropertyForm({ state, send, }: LostPropertyFormProps): import("react/jsx-runtime").JSX.Element;
9
+ export {};
10
+ //# sourceMappingURL=LostPropertyForm.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LostPropertyForm.d.ts","sourceRoot":"","sources":["../../src/lost-property/LostPropertyForm.tsx"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,mBAAmB,EACnB,iBAAiB,EAClB,MAAM,uBAAuB,CAAC;AAE/B,KAAK,qBAAqB,GAAG;IAC3B,KAAK,EAAE;QAAE,OAAO,EAAE,mBAAmB,CAAA;KAAE,CAAC;IACxC,IAAI,EAAE,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,CAAC;CAC1C,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EACvC,KAAK,EACL,IAAI,GACL,EAAE,qBAAqB,2CAqOvB"}
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = LostPropertyForm;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const translations_1 = require("../translations");
6
+ const use_lines_1 = require("../lines/use-lines");
7
+ const components_1 = require("../components");
8
+ const typography_1 = require("../components/typography");
9
+ function LostPropertyForm({ state, send, }) {
10
+ const PageText = (0, translations_1.usePageText)();
11
+ const { t } = (0, translations_1.useTranslation)();
12
+ const { getLinesByMode, getQuaysByLine } = (0, use_lines_1.useLines)();
13
+ const transportModeOptions = (0, use_lines_1.useTransportModeOptions)();
14
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(typography_1.Typo.p, { textType: "body__m", children: t(PageText.Contact.lostAndFound.info) }), (0, jsx_runtime_1.jsxs)(components_1.Fieldset, { title: t(PageText.Contact.lostAndFound.about.title), children: [(0, jsx_runtime_1.jsx)(components_1.Select, { id: "transportMode", label: t(PageText.Contact.input.transportMode.label), value: state.context.transportMode || '', onChange: (value) => send({
15
+ type: 'ON_TRANSPORTMODE_CHANGE',
16
+ value: value,
17
+ }), isRequired: true, error: state.context.errorMessages['transportMode']?.[0]
18
+ ? t(state.context.errorMessages['transportMode']?.[0])
19
+ : undefined, valueToId: (val) => val, valueToText: (val) => t(PageText.Contact.input.transportMode.modes[val]), options: transportModeOptions, placeholder: t(PageText.Contact.input.transportMode.optionLabel) }), (0, jsx_runtime_1.jsx)(components_1.SearchableSelect, { id: "line", label: t(PageText.Contact.input.line.label), value: state.context.line, placeholder: t(PageText.Contact.input.line.optionLabel), isDisabled: !state.context.transportMode, options: (0, components_1.getLineOptions)(getLinesByMode(state.context.transportMode)), onChange: (value) => {
20
+ send({ type: 'ON_LINE_CHANGE', value });
21
+ }, isRequired: true, error: state.context.errorMessages['line']?.[0]
22
+ ? t(state.context.errorMessages['line']?.[0])
23
+ : undefined }), (0, jsx_runtime_1.jsx)(components_1.SearchableSelect, { id: "fromStop", label: t(PageText.Contact.input.fromStop.label), value: state.context.fromStop, isDisabled: !state.context.line, onChange: (value) => {
24
+ send({ type: 'ON_INPUT_CHANGE', inputName: 'fromStop', value });
25
+ }, options: (0, components_1.getStopOptions)(getQuaysByLine(state.context.line?.id ?? '')), placeholder: t(PageText.Contact.input.fromStop.optionLabel), isRequired: true, error: state.context.errorMessages['fromStop']?.[0]
26
+ ? t(state.context.errorMessages['fromStop']?.[0])
27
+ : undefined }), (0, jsx_runtime_1.jsx)(components_1.SearchableSelect, { id: "toStop", label: t(PageText.Contact.input.toStop.label), value: state.context.toStop, isDisabled: !state.context.line, onChange: (value) => {
28
+ send({ type: 'ON_INPUT_CHANGE', inputName: 'toStop', value });
29
+ }, options: (0, components_1.getStopOptions)(getQuaysByLine(state.context.line?.id ?? '')), placeholder: t(PageText.Contact.input.toStop.optionLabel), isRequired: true, error: state.context.errorMessages['toStop']?.[0]
30
+ ? t(state.context.errorMessages['toStop']?.[0])
31
+ : undefined }), (0, jsx_runtime_1.jsx)(components_1.DateSelector, { id: "date", label: t(PageText.Contact.input.date.label), isRequired: true, value: state.context.date, onChange: (date) => send({ type: 'ON_INPUT_CHANGE', inputName: 'date', value: date }), errorMessage: state.context.errorMessages['date']?.[0] }), (0, jsx_runtime_1.jsx)(components_1.DepartureTimeField, { date: state.context.date, lineId: state.context.line?.id, fromStopId: state.context.fromStop?.id, toStopId: state.context.toStop?.id, selectedTripId: state.context.tripId, plannedDepartureTime: state.context.plannedDepartureTime, onChange: (time, tripId) => {
32
+ send({
33
+ type: 'ON_INPUT_CHANGE',
34
+ inputName: 'plannedDepartureTime',
35
+ value: time,
36
+ });
37
+ send({
38
+ type: 'ON_INPUT_CHANGE',
39
+ inputName: 'tripId',
40
+ value: tripId,
41
+ });
42
+ }, isRequired: true, errorMessage: state.context.errorMessages['plannedDepartureTime']?.[0] })] }), (0, jsx_runtime_1.jsx)(components_1.Fieldset, { title: t(PageText.Contact.lostAndFound.itemDescription.title), isRequired: true, children: (0, jsx_runtime_1.jsx)(components_1.Textarea, { id: "feedback", value: state.context.feedback || '', onChange: (e) => send({
43
+ type: 'ON_INPUT_CHANGE',
44
+ inputName: 'feedback',
45
+ value: e.target.value,
46
+ }), error: state.context.errorMessages['feedback']?.[0]
47
+ ? t(state.context.errorMessages['feedback']?.[0])
48
+ : undefined }) }), (0, jsx_runtime_1.jsxs)(components_1.Fieldset, { title: t(PageText.Contact.lostAndFound.contactInfo.title), isRequired: true, children: [(0, jsx_runtime_1.jsx)(components_1.Input, { id: "firstName", label: t(PageText.Contact.input.firstName.label), type: "text", name: "firstName", isRequired: true, value: state.context.firstName || '', errorMessage: state.context.errorMessages['firstName']?.[0], onChange: (e) => send({
49
+ type: 'ON_INPUT_CHANGE',
50
+ inputName: 'firstName',
51
+ value: e.target.value,
52
+ }) }), (0, jsx_runtime_1.jsx)(components_1.Input, { id: "lastName", label: t(PageText.Contact.input.lastName.label), type: "text", name: "lastName", isRequired: true, value: state.context.lastName || '', errorMessage: state.context.errorMessages['lastName']?.[0], onChange: (e) => send({
53
+ type: 'ON_INPUT_CHANGE',
54
+ inputName: 'lastName',
55
+ value: e.target.value,
56
+ }) }), (0, jsx_runtime_1.jsx)(components_1.Input, { id: "email", label: t(PageText.Contact.input.email.label), type: "email", name: "email", isRequired: true, value: state.context.email || '', errorMessage: state.context.errorMessages['email']?.[0], onChange: (e) => send({
57
+ type: 'ON_INPUT_CHANGE',
58
+ inputName: 'email',
59
+ value: e.target.value,
60
+ }) }), (0, jsx_runtime_1.jsx)(components_1.Input, { id: "phoneNumber", label: t(PageText.Contact.input.phoneNumber.label), type: "tel", name: "phoneNumber", isRequired: true, value: state.context.phoneNumber || '', errorMessage: state.context.errorMessages['phoneNumber']?.[0], onChange: (e) => send({
61
+ type: 'ON_INPUT_CHANGE',
62
+ inputName: 'phoneNumber',
63
+ value: e.target.value,
64
+ }) })] })] }));
65
+ }
@@ -0,0 +1,116 @@
1
+ import { InputErrorMessages } from '../validation';
2
+ import type { TransportModeType } from '../types';
3
+ import type { Line } from '../server/journey-planner/validators';
4
+ import type { FormSchemaName } from '../modules/config/types';
5
+ export type LostPropertyContext = {
6
+ transportMode?: TransportModeType;
7
+ line?: Line;
8
+ fromStop?: Line['quays'][0];
9
+ toStop?: Line['quays'][0];
10
+ date?: string;
11
+ plannedDepartureTime?: string;
12
+ tripId?: string;
13
+ feedback?: string;
14
+ firstName?: string;
15
+ lastName?: string;
16
+ email?: string;
17
+ phoneNumber?: string;
18
+ errorMessages: InputErrorMessages;
19
+ firstErrorMessage?: string;
20
+ hasSubmissionError?: boolean;
21
+ };
22
+ export type LostPropertyEvent = {
23
+ type: 'ON_INPUT_CHANGE';
24
+ inputName: string;
25
+ value: unknown;
26
+ } | {
27
+ type: 'ON_TRANSPORTMODE_CHANGE';
28
+ value: TransportModeType;
29
+ } | {
30
+ type: 'ON_LINE_CHANGE';
31
+ value: Line | undefined;
32
+ } | {
33
+ type: 'SUBMIT';
34
+ orderedFormFieldNames: string[];
35
+ };
36
+ type MachinePaths = {
37
+ successPath: string;
38
+ errorPath: string;
39
+ };
40
+ type SubmitInput = {
41
+ transportMode?: string;
42
+ line?: string;
43
+ fromStop?: string;
44
+ toStop?: string;
45
+ date?: string;
46
+ plannedDepartureTime?: string;
47
+ tripId?: string;
48
+ feedback?: string;
49
+ firstName?: string;
50
+ lastName?: string;
51
+ email?: string;
52
+ phoneNumber?: string;
53
+ };
54
+ export declare function createLostPropertyMachine(onSubmit: (schemaName: FormSchemaName, state: Record<string, unknown>) => Promise<Response>, paths?: MachinePaths): import("xstate").StateMachine<LostPropertyContext, {
55
+ type: "ON_INPUT_CHANGE";
56
+ inputName: string;
57
+ value: unknown;
58
+ } | {
59
+ type: "ON_TRANSPORTMODE_CHANGE";
60
+ value: TransportModeType;
61
+ } | {
62
+ type: "ON_LINE_CHANGE";
63
+ value: Line | undefined;
64
+ } | {
65
+ type: "SUBMIT";
66
+ orderedFormFieldNames: string[];
67
+ }, {
68
+ [x: string]: import("xstate").ActorRefFromLogic<import("xstate").PromiseActorLogic<true, SubmitInput, import("xstate").EventObject>> | undefined;
69
+ }, {
70
+ src: "submit";
71
+ logic: import("xstate").PromiseActorLogic<true, SubmitInput, import("xstate").EventObject>;
72
+ id: string | undefined;
73
+ }, {
74
+ type: "onInputChange";
75
+ params: unknown;
76
+ } | {
77
+ type: "navigateToErrorPage";
78
+ params: unknown;
79
+ } | {
80
+ type: "navigateToSuccessPage";
81
+ params: unknown;
82
+ } | {
83
+ type: "clearValidationErrors";
84
+ params: unknown;
85
+ } | {
86
+ type: "setValidationErrors";
87
+ params: unknown;
88
+ } | {
89
+ type: "setSubmissionError";
90
+ params: unknown;
91
+ } | {
92
+ type: "onTransportModeChange";
93
+ params: unknown;
94
+ } | {
95
+ type: "onLineChange";
96
+ params: unknown;
97
+ } | {
98
+ type: "scrollToFirstError";
99
+ params: unknown;
100
+ }, {
101
+ type: "isFormValid";
102
+ params: unknown;
103
+ }, never, "success" | "editing" | "validating" | "submitting", string, import("xstate").NonReducibleUnknown, import("xstate").NonReducibleUnknown, import("xstate").EventObject, import("xstate").MetaObject, {
104
+ states: {
105
+ readonly editing: {};
106
+ readonly validating: {
107
+ id: "validating";
108
+ };
109
+ readonly submitting: {
110
+ id: "submitting";
111
+ };
112
+ readonly success: {};
113
+ };
114
+ }>;
115
+ export {};
116
+ //# sourceMappingURL=LostPropertyMachine.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LostPropertyMachine.d.ts","sourceRoot":"","sources":["../../src/lost-property/LostPropertyMachine.ts"],"names":[],"mappings":"AACA,OAAO,EAAwB,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAMzE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,sCAAsC,CAAC;AACjE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAE9D,MAAM,MAAM,mBAAmB,GAAG;IAChC,aAAa,CAAC,EAAE,iBAAiB,CAAC;IAClC,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,QAAQ,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5B,MAAM,CAAC,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,EAAE,kBAAkB,CAAC;IAClC,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B,CAAC;AAEF,MAAM,MAAM,iBAAiB,GACzB;IAAE,IAAI,EAAE,iBAAiB,CAAC;IAAC,SAAS,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAC9D;IAAE,IAAI,EAAE,yBAAyB,CAAC;IAAC,KAAK,EAAE,iBAAiB,CAAA;CAAE,GAC7D;IAAE,IAAI,EAAE,gBAAgB,CAAC;IAAC,KAAK,EAAE,IAAI,GAAG,SAAS,CAAA;CAAE,GACnD;IAAE,IAAI,EAAE,QAAQ,CAAC;IAAC,qBAAqB,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAExD,KAAK,YAAY,GAAG;IAAE,WAAW,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,CAAC;AAE/D,KAAK,WAAW,GAAG;IACjB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,wBAAgB,yBAAyB,CACvC,QAAQ,EAAE,CACR,UAAU,EAAE,cAAc,EAC1B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC3B,OAAO,CAAC,QAAQ,CAAC,EACtB,KAAK,CAAC,EAAE,YAAY;UA3BV,iBAAiB;eAAa,MAAM;WAAS,OAAO;;UACpD,yBAAyB;WAAS,iBAAiB;;UACnD,gBAAgB;WAAS,IAAI,GAAG,SAAS;;UACzC,QAAQ;2BAAyB,MAAM,EAAE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4NpD"}
@@ -0,0 +1,187 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createLostPropertyMachine = createLostPropertyMachine;
4
+ const xstate_1 = require("xstate");
5
+ const validation_1 = require("../validation");
6
+ const utils_1 = require("../utils");
7
+ function createLostPropertyMachine(onSubmit, paths) {
8
+ const successPath = paths?.successPath ?? '/contact/success';
9
+ const errorPath = paths?.errorPath ?? '/contact/error';
10
+ return (0, xstate_1.setup)({
11
+ types: {
12
+ context: {},
13
+ events: {},
14
+ },
15
+ guards: {
16
+ isFormValid: ({ context }) => {
17
+ const inputsToValidate = {
18
+ transportMode: context.transportMode,
19
+ line: context.line,
20
+ fromStop: context.fromStop,
21
+ toStop: context.toStop,
22
+ date: context.date,
23
+ plannedDepartureTime: context.plannedDepartureTime,
24
+ feedback: context.feedback,
25
+ firstName: context.firstName,
26
+ lastName: context.lastName,
27
+ email: context.email,
28
+ phoneNumber: context.phoneNumber,
29
+ };
30
+ const errors = (0, validation_1.commonInputValidator)(inputsToValidate);
31
+ return Object.keys(errors).length === 0;
32
+ },
33
+ },
34
+ actions: {
35
+ clearValidationErrors: (0, xstate_1.assign)({ errorMessages: {} }),
36
+ setValidationErrors: (0, xstate_1.assign)(({ context, event }) => {
37
+ if (event.type === 'SUBMIT') {
38
+ const inputsToValidate = {
39
+ transportMode: context.transportMode,
40
+ line: context.line,
41
+ fromStop: context.fromStop,
42
+ toStop: context.toStop,
43
+ date: context.date,
44
+ plannedDepartureTime: context.plannedDepartureTime,
45
+ feedback: context.feedback,
46
+ firstName: context.firstName,
47
+ lastName: context.lastName,
48
+ email: context.email,
49
+ phoneNumber: context.phoneNumber,
50
+ };
51
+ const errors = (0, validation_1.commonInputValidator)(inputsToValidate);
52
+ return {
53
+ firstErrorMessage: (0, utils_1.findFirstErrorMessage)(event.orderedFormFieldNames, errors),
54
+ errorMessages: { ...errors },
55
+ };
56
+ }
57
+ return context;
58
+ }),
59
+ scrollToFirstError: (0, xstate_1.assign)(({ context }) => {
60
+ (0, utils_1.scrollToFirstErrorMessage)(context.firstErrorMessage);
61
+ return context;
62
+ }),
63
+ setSubmissionError: (0, xstate_1.assign)({
64
+ hasSubmissionError: () => true,
65
+ }),
66
+ onInputChange: (0, xstate_1.assign)(({ context, event }) => {
67
+ if (event.type === 'ON_INPUT_CHANGE') {
68
+ const { inputName, value } = event;
69
+ context.errorMessages[inputName] = [];
70
+ const clearsDeparture = inputName === 'fromStop' || inputName === 'date';
71
+ return {
72
+ ...context,
73
+ [inputName]: value,
74
+ ...(clearsDeparture && {
75
+ plannedDepartureTime: undefined,
76
+ tripId: undefined,
77
+ }),
78
+ hasSubmissionError: undefined,
79
+ };
80
+ }
81
+ return context;
82
+ }),
83
+ onTransportModeChange: (0, xstate_1.assign)(({ context, event }) => {
84
+ if (event.type === 'ON_TRANSPORTMODE_CHANGE') {
85
+ return {
86
+ ...context,
87
+ transportMode: event.value,
88
+ line: undefined,
89
+ fromStop: undefined,
90
+ toStop: undefined,
91
+ plannedDepartureTime: undefined,
92
+ errorMessages: {
93
+ ...context.errorMessages,
94
+ transportMode: [],
95
+ line: [],
96
+ fromStop: [],
97
+ toStop: [],
98
+ plannedDepartureTime: [],
99
+ },
100
+ };
101
+ }
102
+ return context;
103
+ }),
104
+ onLineChange: (0, xstate_1.assign)(({ context, event }) => {
105
+ if (event.type === 'ON_LINE_CHANGE') {
106
+ return {
107
+ ...context,
108
+ line: event.value,
109
+ fromStop: undefined,
110
+ toStop: undefined,
111
+ plannedDepartureTime: undefined,
112
+ errorMessages: {
113
+ ...context.errorMessages,
114
+ line: [],
115
+ fromStop: [],
116
+ toStop: [],
117
+ plannedDepartureTime: [],
118
+ },
119
+ };
120
+ }
121
+ return context;
122
+ }),
123
+ navigateToSuccessPage: () => {
124
+ window.location.href = successPath;
125
+ },
126
+ navigateToErrorPage: () => {
127
+ window.location.href = errorPath;
128
+ },
129
+ },
130
+ actors: {
131
+ submit: (0, xstate_1.fromPromise)(async ({ input }) => {
132
+ const response = await onSubmit('lostProperty', input);
133
+ if (!response.ok)
134
+ throw new Error('Failed to submit');
135
+ return response.ok;
136
+ }),
137
+ },
138
+ }).createMachine({
139
+ initial: 'editing',
140
+ context: { errorMessages: {} },
141
+ on: {
142
+ ON_INPUT_CHANGE: { actions: 'onInputChange' },
143
+ ON_TRANSPORTMODE_CHANGE: { actions: 'onTransportModeChange' },
144
+ ON_LINE_CHANGE: { actions: 'onLineChange' },
145
+ SUBMIT: { target: '#validating' },
146
+ },
147
+ states: {
148
+ editing: {},
149
+ validating: {
150
+ id: 'validating',
151
+ always: [
152
+ { guard: 'isFormValid', target: '#submitting' },
153
+ {
154
+ actions: ['setValidationErrors', 'scrollToFirstError'],
155
+ target: 'editing',
156
+ },
157
+ ],
158
+ },
159
+ submitting: {
160
+ id: 'submitting',
161
+ invoke: {
162
+ src: 'submit',
163
+ input: ({ context }) => ({
164
+ transportMode: context.transportMode,
165
+ line: (0, utils_1.getLineName)(context.line),
166
+ fromStop: context.fromStop?.name,
167
+ toStop: context.toStop?.name,
168
+ date: context.date,
169
+ plannedDepartureTime: context.plannedDepartureTime,
170
+ tripId: context.tripId,
171
+ feedback: context.feedback,
172
+ firstName: context.firstName,
173
+ lastName: context.lastName,
174
+ email: context.email,
175
+ phoneNumber: context.phoneNumber,
176
+ }),
177
+ onDone: { target: 'success' },
178
+ onError: {
179
+ target: 'editing',
180
+ actions: 'setSubmissionError',
181
+ },
182
+ },
183
+ },
184
+ success: { entry: 'navigateToSuccessPage', type: 'final' },
185
+ },
186
+ });
187
+ }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lost-property/index.tsx"],"names":[],"mappings":"AAIA,MAAM,CAAC,OAAO,UAAU,mBAAmB,4CAkB1C"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/lost-property/index.tsx"],"names":[],"mappings":"AAaA,MAAM,CAAC,OAAO,UAAU,mBAAmB,4CA+C1C"}
@@ -1,11 +1,35 @@
1
+ 'use client';
1
2
  "use strict";
3
+ var __importDefault = (this && this.__importDefault) || function (mod) {
4
+ return (mod && mod.__esModule) ? mod : { "default": mod };
5
+ };
2
6
  Object.defineProperty(exports, "__esModule", { value: true });
3
7
  exports.default = LostPropertyContent;
4
8
  const jsx_runtime_1 = require("react/jsx-runtime");
5
- const components_1 = require("../components");
6
- const typography_1 = require("../components/typography");
9
+ const react_1 = require("@xstate/react");
10
+ const react_2 = require("react");
7
11
  const translations_1 = require("../translations");
12
+ const config_1 = require("../modules/config");
13
+ const button_1 = require("../components/button");
14
+ const error_message_1 = __importDefault(require("../components/error-message/error-message"));
15
+ const components_1 = require("../components");
16
+ const utils_1 = require("../utils");
17
+ const LostPropertyMachine_1 = require("./LostPropertyMachine");
18
+ const LostPropertyForm_1 = __importDefault(require("./LostPropertyForm"));
8
19
  function LostPropertyContent() {
20
+ const PageText = (0, translations_1.usePageText)();
9
21
  const { t } = (0, translations_1.useTranslation)();
10
- return ((0, jsx_runtime_1.jsx)(components_1.SectionCard, { title: t(translations_1.PageText.Contact.lostProperty.title), children: (0, jsx_runtime_1.jsx)(typography_1.Typo.p, { textType: "body__m", children: (0, jsx_runtime_1.jsxs)("span", { children: [t(translations_1.PageText.Contact.lostProperty.description.info), "\u00A0", (0, jsx_runtime_1.jsx)("a", { href: t(translations_1.PageText.Contact.lostProperty.description.url), target: "_blank", rel: "noreferrer", children: t(translations_1.PageText.Contact.lostProperty.description.externalLink) })] }) }) }));
22
+ const apiConfig = (0, config_1.useApiConfig)();
23
+ const { layout } = (0, config_1.useContactFormConfig)();
24
+ const successPath = layout?.successPath ??
25
+ (layout?.basePath ? `${layout.basePath}/success` : '/contact/success');
26
+ const errorPath = layout?.errorPath ??
27
+ (layout?.basePath ? `${layout.basePath}/error` : '/contact/error');
28
+ const machine = (0, react_2.useMemo)(() => (0, LostPropertyMachine_1.createLostPropertyMachine)(apiConfig.onSubmit, { successPath, errorPath }), [apiConfig.onSubmit, successPath, errorPath]);
29
+ const [state, send] = (0, react_1.useMachine)(machine);
30
+ const onSubmit = (e) => {
31
+ e.preventDefault();
32
+ send({ type: 'SUBMIT', orderedFormFieldNames: (0, utils_1.findOrderFormFields)(e) });
33
+ };
34
+ return ((0, jsx_runtime_1.jsx)(components_1.SectionCard, { title: t(PageText.Contact.lostAndFound.title), children: (0, jsx_runtime_1.jsxs)("form", { onSubmit: onSubmit, children: [(0, jsx_runtime_1.jsx)(LostPropertyForm_1.default, { state: state, send: send }), state.context.hasSubmissionError && ((0, jsx_runtime_1.jsx)(error_message_1.default, { message: t(PageText.Contact.error.info), id: "submission-error" })), (0, jsx_runtime_1.jsx)(button_1.Button, { title: t(PageText.Contact.submit), mode: "interactive_0--bordered", buttonProps: { type: 'submit' }, state: state.matches('submitting') ? 'loading' : undefined })] }) }));
11
35
  }
@@ -1 +1 @@
1
- {"version":3,"file":"delayForm.d.ts","sourceRoot":"","sources":["../../../src/means-of-transport/forms/delayForm.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AAiBvD,KAAK,cAAc,GAAG;IACpB,KAAK,EAAE;QAAE,OAAO,EAAE,4BAA4B,CAAA;KAAE,CAAC;IACjD,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,0BAA0B,KAAK,IAAI,CAAC;CAC1D,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,iBAAiB,cAAc,4CAyQxD,CAAC;AAEF,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"delayForm.d.ts","sourceRoot":"","sources":["../../../src/means-of-transport/forms/delayForm.tsx"],"names":[],"mappings":"AAGA,OAAO,EAAE,4BAA4B,EAAE,MAAM,oCAAoC,CAAC;AAClF,OAAO,EAAE,0BAA0B,EAAE,MAAM,WAAW,CAAC;AAiBvD,KAAK,cAAc,GAAG;IACpB,KAAK,EAAE;QAAE,OAAO,EAAE,4BAA4B,CAAA;KAAE,CAAC;IACjD,IAAI,EAAE,CAAC,KAAK,EAAE,OAAO,0BAA0B,KAAK,IAAI,CAAC;CAC1D,CAAC;AAEF,eAAO,MAAM,SAAS,GAAI,iBAAiB,cAAc,4CAkRxD,CAAC;AAEF,eAAe,SAAS,CAAC"}