@autobusal/routes-search 1.0.1 → 1.1.0

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.
package/RoutesSearch.tsx CHANGED
@@ -5,8 +5,8 @@ import { FaArrowUp, FaHistory } from 'react-icons/fa';
5
5
  import { AiOutlineSearch } from 'react-icons/ai';
6
6
  import { Button, Autocomplete, Calendar, Passengers } from '@autobusal/common';
7
7
  import { Display, createDate } from '@autobusal/utilities';
8
+ import { getCities } from './utilities';
8
9
  import { Options, Columns, Column, Item, Title, Action } from './styles';
9
- import { AutocompleteData } from '@autobusal/common/Autocomplete/types';
10
10
  import { RoutesSearchForm } from './types';
11
11
  import { useGetSuggestions } from './services';
12
12
 
@@ -28,7 +28,7 @@ const RoutesSearch = ({ type, from, to, departure, _return, adultsNo, childrenNo
28
28
 
29
29
  const { register, handleSubmit, formState: { errors }, setValue } = useForm<RoutesSearchForm>();
30
30
 
31
- const { data } = useGetSuggestions();
31
+ const { data: CitiesData } = useGetSuggestions();
32
32
 
33
33
  const onClick = (type: ('departure' | 'return')): void => {
34
34
  setSelected(type);
@@ -45,6 +45,16 @@ const RoutesSearch = ({ type, from, to, departure, _return, adultsNo, childrenNo
45
45
  data.babies = Number(data.babies);
46
46
  data.children = Number(data.children);
47
47
 
48
+ // add the locations
49
+ const from = data.from.split(':');
50
+ data.from = from[0];
51
+ data.stop_from = from[1];
52
+
53
+ // add the to locations
54
+ const to = data.to.split(':');
55
+ data.to = to[0];
56
+ data.stop_to = to[1];
57
+
48
58
  if (data.adults == 0) {
49
59
  alert(t('routes_search.errors.adults'));
50
60
  } else if (data.adults + data.children > 5) {
@@ -58,10 +68,7 @@ const RoutesSearch = ({ type, from, to, departure, _return, adultsNo, childrenNo
58
68
  }
59
69
  };
60
70
 
61
- const cities: AutocompleteData[] = data.map(city => ({
62
- name: `${ city.name }, ${ city.country?.name ?? '' }`,
63
- value: city.slug
64
- }));
71
+ const cities = getCities(CitiesData, t);
65
72
 
66
73
  return (
67
74
  <form onSubmit={ handleSubmit(onSubmit) }>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/routes-search",
3
- "version": "1.0.1",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "main": "index.ts"
6
6
  }
package/types.ts CHANGED
@@ -7,4 +7,6 @@ export interface RoutesSearchForm {
7
7
  adults: number
8
8
  children: number
9
9
  babies: number
10
+ stop_from?: string
11
+ stop_to?: string
10
12
  }
package/utilities.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { TFunction } from 'i18next';
2
+ import { AutocompleteData } from '@autobusal/common/Autocomplete/types';
3
+ import { CityData } from '@autobusal/providers/types/locations';
4
+
5
+ export const getCities = (cities: CityData[], t: TFunction<'common'>): AutocompleteData[] => {
6
+ const data: AutocompleteData[] = [];
7
+
8
+ cities.forEach(city => {
9
+ data.push({
10
+ name: `${ city.name }, ${ city.country?.name ?? '' } (${ t('all_stations', { ns: 'common' }) })`,
11
+ value: `${ city.slug }`
12
+ });
13
+
14
+ city.stops?.forEach(stop => {
15
+ data.push({
16
+ name: `${ city.name }, ${ city.country?.name ?? '' } (${ stop.name })`,
17
+ value: `${ city.slug }:${ stop.id }`
18
+ });
19
+ });
20
+ });
21
+
22
+ return data;
23
+ };