@autobusal/routes-search 0.0.6 → 1.0.1
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 +16 -17
- package/package.json +1 -1
- package/services.ts +1 -1
package/RoutesSearch.tsx
CHANGED
|
@@ -3,13 +3,12 @@ import { TFunction } from 'i18next';
|
|
|
3
3
|
import { useForm } from 'react-hook-form';
|
|
4
4
|
import { FaArrowUp, FaHistory } from 'react-icons/fa';
|
|
5
5
|
import { AiOutlineSearch } from 'react-icons/ai';
|
|
6
|
-
import { Button } from '@autobusal/common';
|
|
7
|
-
import {
|
|
8
|
-
import { Autocomplete, Calendar, Passengers } from '@autobusal/common';
|
|
6
|
+
import { Button, Autocomplete, Calendar, Passengers } from '@autobusal/common';
|
|
7
|
+
import { Display, createDate } from '@autobusal/utilities';
|
|
9
8
|
import { Options, Columns, Column, Item, Title, Action } from './styles';
|
|
10
|
-
import { RoutesSearchForm } from './types';
|
|
11
9
|
import { AutocompleteData } from '@autobusal/common/Autocomplete/types';
|
|
12
|
-
import {
|
|
10
|
+
import { RoutesSearchForm } from './types';
|
|
11
|
+
import { useGetSuggestions } from './services';
|
|
13
12
|
|
|
14
13
|
interface Props {
|
|
15
14
|
type: 'departure' | 'return'
|
|
@@ -17,19 +16,19 @@ interface Props {
|
|
|
17
16
|
to: string
|
|
18
17
|
departure: string
|
|
19
18
|
_return: string
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
adultsNo: number
|
|
20
|
+
childrenNo: number
|
|
21
|
+
babiesNo: number
|
|
23
22
|
t: TFunction<'common'>
|
|
24
23
|
onSearch: (data: RoutesSearchForm) => void
|
|
25
24
|
}
|
|
26
25
|
|
|
27
|
-
const RoutesSearch = ({ type, from, to, departure, _return,
|
|
26
|
+
const RoutesSearch = ({ type, from, to, departure, _return, adultsNo, childrenNo, babiesNo, t, onSearch }: Props): JSX.Element => {
|
|
28
27
|
const [ selected, setSelected ] = useState<'departure' | 'return'>(type);
|
|
29
28
|
|
|
30
29
|
const { register, handleSubmit, formState: { errors }, setValue } = useForm<RoutesSearchForm>();
|
|
31
30
|
|
|
32
|
-
const { data } =
|
|
31
|
+
const { data } = useGetSuggestions();
|
|
33
32
|
|
|
34
33
|
const onClick = (type: ('departure' | 'return')): void => {
|
|
35
34
|
setSelected(type);
|
|
@@ -101,7 +100,7 @@ const RoutesSearch = ({ type, from, to, departure, _return, adults, children, ba
|
|
|
101
100
|
onUpdate={ setValue }
|
|
102
101
|
/>
|
|
103
102
|
|
|
104
|
-
{
|
|
103
|
+
{ Display(errors.from) }
|
|
105
104
|
</Item>
|
|
106
105
|
|
|
107
106
|
<Item>
|
|
@@ -117,7 +116,7 @@ const RoutesSearch = ({ type, from, to, departure, _return, adults, children, ba
|
|
|
117
116
|
onUpdate={ setValue }
|
|
118
117
|
/>
|
|
119
118
|
|
|
120
|
-
{
|
|
119
|
+
{ Display(errors.to) }
|
|
121
120
|
</Item>
|
|
122
121
|
</Column>
|
|
123
122
|
|
|
@@ -135,7 +134,7 @@ const RoutesSearch = ({ type, from, to, departure, _return, adults, children, ba
|
|
|
135
134
|
onUpdate={ setValue }
|
|
136
135
|
/>
|
|
137
136
|
|
|
138
|
-
{
|
|
137
|
+
{ Display(errors.departure) }
|
|
139
138
|
</Item>
|
|
140
139
|
|
|
141
140
|
{ selected === 'return' && (
|
|
@@ -152,7 +151,7 @@ const RoutesSearch = ({ type, from, to, departure, _return, adults, children, ba
|
|
|
152
151
|
onUpdate={ setValue }
|
|
153
152
|
/>
|
|
154
153
|
|
|
155
|
-
{
|
|
154
|
+
{ Display(errors._return) }
|
|
156
155
|
</Item>
|
|
157
156
|
) }
|
|
158
157
|
</Column>
|
|
@@ -162,9 +161,9 @@ const RoutesSearch = ({ type, from, to, departure, _return, adults, children, ba
|
|
|
162
161
|
<Title>{ t('routes_search.passengers', { ns: 'common' }) }</Title>
|
|
163
162
|
|
|
164
163
|
<Passengers
|
|
165
|
-
defaultAdults={
|
|
166
|
-
defaultChildren={
|
|
167
|
-
defaultBabies={
|
|
164
|
+
defaultAdults={ adultsNo }
|
|
165
|
+
defaultChildren={ childrenNo }
|
|
166
|
+
defaultBabies={ babiesNo }
|
|
168
167
|
t={ t }
|
|
169
168
|
refs={ register }
|
|
170
169
|
onUpdate={ setValue }
|
package/package.json
CHANGED
package/services.ts
CHANGED
|
@@ -2,7 +2,7 @@ import { useSuspenseQuery, UseSuspenseQueryResult } from '@tanstack/react-query'
|
|
|
2
2
|
import { apiClient } from '@autobusal/providers';
|
|
3
3
|
import { CityData } from '@autobusal/providers/types/locations';
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const useGetSuggestions = (): UseSuspenseQueryResult<CityData[]> => (
|
|
6
6
|
useSuspenseQuery({
|
|
7
7
|
queryKey: ['search-suggestions'],
|
|
8
8
|
queryFn: async () => (
|