@autobusal/routes-order 1.2.0 → 1.3.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/Found/Found.tsx CHANGED
@@ -11,12 +11,13 @@ interface Props {
11
11
  loading: boolean
12
12
  data?: FoundData[]
13
13
  step1: RoutesSearchForm
14
+ preferredStop?: string
14
15
  t: TFunction<'common'>
15
16
  onSearch: (type: ('departure' | '_return'), day: string) => void
16
17
  onSave: (data: FoundData) => void
17
18
  }
18
19
 
19
- const Found = ({ type, loading, data, step1, t, onSearch, onSave }: Props): JSX.Element => (
20
+ const Found = ({ type, loading, data, step1, preferredStop, t, onSearch, onSave }: Props): JSX.Element => (
20
21
  <>
21
22
  <Dates type={ type } step1={ step1 } t={ t } onSearch={ onSearch } />
22
23
 
@@ -24,7 +25,14 @@ const Found = ({ type, loading, data, step1, t, onSearch, onSave }: Props): JSX.
24
25
 
25
26
  <Header t={ t } />
26
27
 
27
- <Orders loading={ loading } data={ data } t={ t } onSave={ onSave } />
28
+ <Orders
29
+ loading={ loading }
30
+ data={ data }
31
+ type={ type }
32
+ preferredStop={ Number(preferredStop) }
33
+ t={ t }
34
+ onSave={ onSave }
35
+ />
28
36
  </>
29
37
  );
30
38
 
@@ -1,17 +1,20 @@
1
1
  import { TFunction } from 'i18next';
2
2
  import { Inline } from '@autobusal/common';
3
3
  import Route from '../Route/Route';
4
+ import { getFavorites, getNormal } from './utilities';
4
5
  import { Container, ContainerNotFound } from './styles';
5
6
  import { FoundData } from '@autobusal/providers/types/routes';
6
7
 
7
8
  interface Props {
8
9
  loading: boolean
9
10
  data?: FoundData[]
11
+ type: 'departure' | '_return'
12
+ preferredStop?: number
10
13
  t: TFunction<'common'>
11
14
  onSave: (data: FoundData) => void
12
15
  }
13
16
 
14
- const Orders = ({ loading, data, t, onSave }: Props): JSX.Element => {
17
+ const Orders = ({ loading, data, type, preferredStop, t, onSave }: Props): JSX.Element => {
15
18
  if (loading) {
16
19
  return (
17
20
  <div className="box">
@@ -26,12 +29,29 @@ const Orders = ({ loading, data, t, onSave }: Props): JSX.Element => {
26
29
  );
27
30
  }
28
31
 
29
- const items = data?.map(item => (
30
- <Route key={ item.id } data={ item } t={ t } onSave={ onSave } />
32
+ const favorites = getFavorites(type, data, preferredStop).map(item => (
33
+ <Route
34
+ key={ item.id }
35
+ type="favorite"
36
+ data={ item }
37
+ t={ t }
38
+ onSave={ onSave }
39
+ />
40
+ ));
41
+
42
+ const items = getNormal(type, data, preferredStop).map(item => (
43
+ <Route
44
+ key={ item.id }
45
+ type="normal"
46
+ data={ item }
47
+ t={ t }
48
+ onSave={ onSave }
49
+ />
31
50
  ));
32
51
 
33
52
  return (
34
53
  <Container>
54
+ { favorites }
35
55
  { items }
36
56
  </Container>
37
57
  );
@@ -0,0 +1,25 @@
1
+ import { FoundData } from '@autobusal/providers/types/routes';
2
+
3
+ export const getFavorites = (type: string, data?: FoundData[], preferredStop?: number): FoundData[] => {
4
+ const favorites = data?.filter(item => {
5
+ if (type === 'departure') {
6
+ return item.locations.from.stop?.id === preferredStop;
7
+ } else {
8
+ return item.locations.to.stop?.id === preferredStop;
9
+ }
10
+ });
11
+
12
+ return favorites ?? [];
13
+ };
14
+
15
+ export const getNormal = (type: string, data?: FoundData[], preferredStop?: number): FoundData[] => {
16
+ const normal = data?.filter(item => {
17
+ if (type === 'departure') {
18
+ return item.locations.from.stop?.id !== preferredStop;
19
+ } else {
20
+ return item.locations.to.stop?.id !== preferredStop;
21
+ }
22
+ });
23
+
24
+ return normal ?? [];
25
+ };
@@ -3,16 +3,17 @@ import { TFunction } from 'i18next';
3
3
  import { HiOutlineArrowNarrowRight, HiOutlineDocumentText } from 'react-icons/hi';
4
4
  import { RiBus2Line } from 'react-icons/ri';
5
5
  import { Button, RouteFeature, Policy } from '@autobusal/common';
6
- import { Container, SpecialOffer, Trip, Company, Location, Time, Price, LinkCompany, Details, Detail, ButtonPolicy, TitleDetail, LinkRoute, Features, TitleFeatures, FeaturesItems } from './styles';
6
+ import { Container, SpecialOffer, FavoriteStop, Trip, Company, Location, Time, Price, LinkCompany, Details, Detail, ButtonPolicy, TitleDetail, LinkRoute, Features, TitleFeatures, FeaturesItems } from './styles';
7
7
  import { FoundData } from '@autobusal/providers/types/routes';
8
8
 
9
9
  interface Props {
10
10
  data: FoundData
11
+ type: 'favorite' | 'normal'
11
12
  t: TFunction<'common'>
12
13
  onSave: (data: FoundData) => void
13
14
  }
14
15
 
15
- const Route = ({ data, t, onSave }: Props): JSX.Element => {
16
+ const Route = ({ data, type, t, onSave }: Props): JSX.Element => {
16
17
  const [ policy, setPolicy ] = useState<boolean>(false);
17
18
 
18
19
  const customs = Object.values(data.customs).join(', ');
@@ -23,8 +24,9 @@ const Route = ({ data, t, onSave }: Props): JSX.Element => {
23
24
  ));
24
25
 
25
26
  return (
26
- <Container className="box">
27
+ <Container className="box" $type={ type }>
27
28
  { data.price.offer === true && <SpecialOffer>{ t('routes_order.step2.route.offer') }</SpecialOffer> }
29
+ { type === 'favorite' && <FavoriteStop>{ t('routes_order.step2.route.preferred_stop') }</FavoriteStop> }
28
30
 
29
31
  <Trip>
30
32
  <Company>
@@ -1,12 +1,16 @@
1
- import styled from 'styled-components';
1
+ import styled, { css } from 'styled-components';
2
2
  import { Link } from 'react-router-dom';
3
3
 
4
- export const Container = styled.div`
4
+ export const Container = styled.div<{ $type: 'favorite' | 'normal' }>`
5
5
  position: relative;
6
6
  display: flex;
7
7
  flex-direction: column;
8
8
  gap: 15px;
9
9
  padding: 15px;
10
+
11
+ ${ props => props.$type === 'favorite' && css`
12
+ border: 1px solid ${ props => props.theme.font.success };
13
+ ` }
10
14
  `;
11
15
 
12
16
  export const SpecialOffer = styled.div`
@@ -25,6 +29,21 @@ export const SpecialOffer = styled.div`
25
29
  background-image: url(${ import.meta.env.VITE_API_OBT }/storage/routes/offer.png);
26
30
  `;
27
31
 
32
+ export const FavoriteStop = styled.div`
33
+ position: absolute;
34
+ bottom: -1px;
35
+ right: -1px;
36
+ z-index: 2;
37
+ padding: 2px 10px;
38
+ color: #FFF;
39
+ font-size: ${ props => props.theme.size.xs };
40
+ text-transform: uppercase;
41
+ font-weight: 700;
42
+ background: ${ props => props.theme.font.success };
43
+ border-top-left-radius: ${ props => props.theme.borderRadius };
44
+ border-bottom-right-radius: ${ props => props.theme.borderRadius };
45
+ `;
46
+
28
47
  export const Trip = styled.div`
29
48
  display: flex;
30
49
  flex-direction: column;
package/Step1/Step1.tsx CHANGED
@@ -23,7 +23,7 @@ const Step1 = ({ value, redirected, t, onSave }: Props): JSX.Element => {
23
23
 
24
24
  const { data } = useGetSettings();
25
25
 
26
- const prepared = prepare(value, params, data.preferences.defaultLocations);
26
+ const prepared = prepare(value, params, searchParams, data.preferences.defaultLocations);
27
27
 
28
28
  const isSubmitted = searchParams.get('type') === 'submit';
29
29
 
@@ -45,8 +45,8 @@ const Step1 = ({ value, redirected, t, onSave }: Props): JSX.Element => {
45
45
  <div className="box">
46
46
  <RoutesSearch
47
47
  type={ prepared.type ?? 'departure' }
48
- from={ prepared.from }
49
- to={ prepared.to }
48
+ from={ `${ prepared.from }${ prepared.stop_from ? `:${ prepared.stop_from }` : '' }` }
49
+ to={ `${ prepared.to }${ prepared.stop_to ? `:${ prepared.stop_to }` : '' }` }
50
50
  departure={ prepared.departure }
51
51
  _return={ prepared._return ?? '' }
52
52
  adultsNo={ prepared.adults }
package/Step1/prepare.ts CHANGED
@@ -5,6 +5,7 @@ import { RoutesSearchForm } from '@autobusal/routes-search/types';
5
5
  const prepare = (
6
6
  value: (RoutesSearchForm | undefined),
7
7
  params: Readonly<Params<string>>,
8
+ searchParams: URLSearchParams,
8
9
  defaultLocations: { from: string, to: string }
9
10
  ): RoutesSearchForm => {
10
11
  if (value !== undefined) {
@@ -23,6 +24,9 @@ const prepare = (
23
24
  const children = params.children ?? 0;
24
25
  const babies = params.babies ?? 0;
25
26
 
27
+ const stop_from = searchParams.get('sfrom') ?? undefined;
28
+ const stop_to = searchParams.get('sto') ?? undefined;
29
+
26
30
  return {
27
31
  type,
28
32
  from,
@@ -31,7 +35,9 @@ const prepare = (
31
35
  _return,
32
36
  adults: Number(adults),
33
37
  children: Number(children),
34
- babies: Number(babies)
38
+ babies: Number(babies),
39
+ stop_from,
40
+ stop_to
35
41
  };
36
42
  };
37
43
 
package/Step2.tsx CHANGED
@@ -34,6 +34,7 @@ const Step2 = ({ step1, t, onSearch, onSave, onBack }: Props): JSX.Element => {
34
34
  loading={ isFetching }
35
35
  data={ data }
36
36
  step1={ step1 }
37
+ preferredStop={ step1.stop_from }
37
38
  t={ t }
38
39
  onSearch={ onSearch }
39
40
  onSave={ onSave }
package/Step3.tsx CHANGED
@@ -35,6 +35,7 @@ const Step3 = ({ step1, step2, t, onSearch, onSave, onBack }: Props): JSX.Elemen
35
35
  loading={ isFetching }
36
36
  data={ data }
37
37
  step1={ step1 }
38
+ preferredStop={ step1.stop_to }
38
39
  t={ t }
39
40
  onSearch={ onSearch }
40
41
  onSave={ onSave }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/routes-order",
3
- "version": "1.2.0",
3
+ "version": "1.3.0",
4
4
  "type": "module",
5
5
  "main": "index.ts"
6
6
  }