@autobusal/operator-routes 1.0.10 → 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.
@@ -2,7 +2,7 @@ import { TFunction } from 'i18next';
2
2
  import { useParams, Navigate, useNavigate } from 'react-router-dom';
3
3
  import { BsPlusCircleFill } from 'react-icons/bs';
4
4
  import { Meta, BackWithTitle, Button, Table, Row } from '@autobusal/common';
5
- import { usePage } from '@autobusal/hooks';
5
+ import { usePage, useBreadcrumbs } from '@autobusal/hooks';
6
6
  import { success } from '@autobusal/utilities';
7
7
  import { useGetAlternates, usePostAdd, useDeleteAlternate } from './services';
8
8
 
@@ -17,6 +17,7 @@ const Browse = ({ url, backUrl, t }: Props): JSX.Element => {
17
17
 
18
18
  const id = Number(params.id);
19
19
 
20
+ const baseUrl = backUrl;
20
21
  url = url.replace('[id]', String(id));
21
22
  backUrl = backUrl.replace('[id]', String(id));
22
23
 
@@ -26,6 +27,16 @@ const Browse = ({ url, backUrl, t }: Props): JSX.Element => {
26
27
 
27
28
  const { data, isLoading, isFetching, refetch } = useGetAlternates(id);
28
29
 
30
+ const title = t('alternates.browse.title', { name: data?.name, ns: 'common' });
31
+
32
+ useBreadcrumbs(title, [{
33
+ name: t('operator_routes.browse.title.manage', { ns: 'common' }),
34
+ url: baseUrl.replace('/manage/[id]', '')
35
+ }, {
36
+ name: t('operator_routes.manage.title.update', { name: data?.name, ns: 'common' }),
37
+ url: backUrl
38
+ }]);
39
+
29
40
  const { mutate: Add, isPending } = usePostAdd(id);
30
41
 
31
42
  const { mutate: Delete } = useDeleteAlternate(id);
@@ -68,8 +79,6 @@ const Browse = ({ url, backUrl, t }: Props): JSX.Element => {
68
79
  />
69
80
  ));
70
81
 
71
- const title = t('alternates.browse.title', { name: data?.name, ns: 'common' });
72
-
73
82
  return (
74
83
  <Meta title={ title }>
75
84
  <BackWithTitle title={ title } to={ backUrl } t={ t } />
package/Browse.tsx CHANGED
@@ -1,7 +1,7 @@
1
1
  import { TFunction } from 'i18next';
2
2
  import { useSearchParams } from 'react-router-dom';
3
3
  import { Meta, Table, Row } from '@autobusal/common';
4
- import { usePage } from '@autobusal/hooks';
4
+ import { usePage, useBreadcrumbs } from '@autobusal/hooks';
5
5
  import { getParams } from '@autobusal/utilities';
6
6
  import { Bags, Dates } from './Information';
7
7
  import { useGetRoutes } from './services';
@@ -16,6 +16,8 @@ const Browse = ({ url, t }: Props): JSX.Element => {
16
16
 
17
17
  usePage('routes');
18
18
 
19
+ useBreadcrumbs(t('operator_routes.browse.title.manage', { ns: 'common' }));
20
+
19
21
  const { data, isLoading, isFetching } = useGetRoutes(getParams(searchParams, ['page', 'sort', 'order', 'q']));
20
22
 
21
23
  const rows = data?.data.map(item => (
@@ -1,7 +1,7 @@
1
1
  import { TFunction } from 'i18next';
2
2
  import { useParams } from 'react-router-dom';
3
3
  import { Meta, BackWithTitle, Report } from '@autobusal/common';
4
- import { usePage } from '@autobusal/hooks';
4
+ import { usePage, useBreadcrumbs } from '@autobusal/hooks';
5
5
  import Add from './Add/Add';
6
6
  import Browse from './Browse/Browse';
7
7
  import { useGetLocations } from './services';
@@ -16,18 +16,27 @@ const Manage = ({ url, t }: Props): JSX.Element => {
16
16
 
17
17
  const id = Number(params.id);
18
18
 
19
+ const baseUrl = url;
19
20
  url = url.replace('[id]', String(id));
20
21
 
21
22
  usePage('routes');
22
23
 
23
24
  const { data, refetch } = useGetLocations(id);
24
25
 
26
+ const title = t('locations_manage.title', { name: data?.name, ns: 'common' });
27
+
28
+ useBreadcrumbs(title, [{
29
+ name: t('operator_routes.browse.title.manage', { ns: 'common' }),
30
+ url: baseUrl.replace('/manage/[id]', '')
31
+ }, {
32
+ name: t('operator_routes.manage.title.update', { name: data?.name, ns: 'common' }),
33
+ url
34
+ }]);
35
+
25
36
  const onReload = (): void => {
26
37
  refetch();
27
38
  };
28
39
 
29
- const title = t('locations_manage.title', { name: data?.name, ns: 'common' });
30
-
31
40
  return (
32
41
  <Meta title={ title }>
33
42
  <BackWithTitle title={ title } to={ url } t={ t } />
package/Manage.tsx CHANGED
@@ -1,11 +1,11 @@
1
- import { useState, useEffect } from 'react';
1
+ import { useState } from 'react';
2
2
  import { TFunction } from 'i18next';
3
3
  import { useParams, useNavigate } from 'react-router-dom';
4
4
  import { RiMoneyEuroCircleLine } from 'react-icons/ri';
5
5
  import { FaMapMarkerAlt } from 'react-icons/fa';
6
6
  import { IoCalendarClearOutline } from 'react-icons/io5';
7
7
  import { Meta, BackWithTitle, Viewer } from '@autobusal/common';
8
- import { usePage, useRouteFeatures, useOperatorDrivers } from '@autobusal/hooks';
8
+ import { usePage, useBreadcrumbs, useRouteFeatures, useOperatorDrivers } from '@autobusal/hooks';
9
9
  import { success } from '@autobusal/utilities';
10
10
  import Template from './Template';
11
11
  import Options from './Options';
@@ -33,6 +33,10 @@ const Manage = ({ url, t }: Props): JSX.Element => {
33
33
 
34
34
  const { data, isFetching } = useGetRoute(id);
35
35
 
36
+ const title = id > 0 ? t('operator_routes.manage.title.update', { name: data?.name, ns: 'common' }) : t('operator_routes.manage.title.new', { ns: 'common' });
37
+
38
+ useBreadcrumbs(title, [{ name: t('operator_routes.browse.title.manage', { ns: 'common' }), url }]);
39
+
36
40
  const { mutate: Update, isPending: isPendingSave } = usePostRoute(id, seating);
37
41
 
38
42
  const { mutate: Delete, isPending: isPendingDelete } = useDeleteRoute();
@@ -65,8 +69,6 @@ const Manage = ({ url, t }: Props): JSX.Element => {
65
69
  setSeating(options);
66
70
  };
67
71
 
68
- const title = id > 0 ? t('operator_routes.manage.title.update', { name: data?.name, ns: 'common' }) : t('operator_routes.manage.title.new', { ns: 'common' });
69
-
70
72
  return (
71
73
  <Meta title={ title }>
72
74
  <BackWithTitle title={ title } to={ url } t={ t } />
package/Prices/Manage.tsx CHANGED
@@ -1,10 +1,11 @@
1
1
  import { TFunction } from 'i18next';
2
2
  import { useParams } from 'react-router-dom';
3
3
  import { Meta, BackWithTitle } from '@autobusal/common';
4
- import { usePage } from '@autobusal/hooks';
4
+ import { usePage, useBreadcrumbs } from '@autobusal/hooks';
5
5
  import Options from './Options/Options';
6
6
  import Schedule from './Schedule/Schedule';
7
7
  import Browse from './Browse/Browse';
8
+ import { getBreadcrumbs } from './utilities';
8
9
  import { useGetPrices } from './services';
9
10
 
10
11
  interface Props {
@@ -19,18 +20,21 @@ const Manage = ({ type, url, t }: Props): JSX.Element => {
19
20
  const id = Number(params.id);
20
21
  const name = String(params.name ?? '');
21
22
 
23
+ const baseUrl = url;
22
24
  url = url.replace('[id]', String(id));
23
25
 
24
26
  usePage('routes');
25
27
 
26
28
  const { data, refetch } = useGetPrices(id, type, name);
27
29
 
30
+ const title = t(`prices_manage.title.${ type }`, { name: data?.name, ns: 'common' });
31
+
32
+ useBreadcrumbs(title, getBreadcrumbs(type, baseUrl, url, t, data?.name));
33
+
28
34
  const onReload = () => {
29
35
  refetch();
30
36
  };
31
37
 
32
- const title = t(`prices_manage.title.${ type }`, { name: data?.name, ns: 'common' });
33
-
34
38
  // get the correct column
35
39
  const prices = type === 'alternate' ? data?.alternates : data?.prices;
36
40
 
@@ -71,7 +71,7 @@ const Schedule = ({ id, data, name, t }: Props): JSX.Element => {
71
71
  <div className="row">
72
72
  <label>
73
73
  <input type="checkbox" value="1" defaultChecked={ details?.offer } { ...register('offer') } />&nbsp;
74
- { t('alternates_manage.offer', { ns: 'common' }) }
74
+ { t('alternates.manage.offer', { ns: 'common' }) }
75
75
  </label>
76
76
  </div>
77
77
 
@@ -0,0 +1,33 @@
1
+ import { TFunction } from 'i18next';
2
+ import { BreadcrumbData } from '@autobusal/providers/types/pages';
3
+
4
+ export const getBreadcrumbs = (type: string, baseUrl: string, backUrl: string, t: TFunction<'common'>, name?: string): BreadcrumbData[] => {
5
+ const final: BreadcrumbData[] = [];
6
+
7
+ let rootUrl = baseUrl.replace('/manage/[id]', '');
8
+ let backUrlFinal = backUrl;
9
+
10
+ if (type === 'alternate') {
11
+ rootUrl = baseUrl.replace('/alternates/[id]', '');
12
+ backUrlFinal = backUrlFinal.replace('/alternates/', '/manage/');
13
+ }
14
+
15
+ final.push({
16
+ name: t('operator_routes.browse.title.manage', { ns: 'common' }),
17
+ url: rootUrl
18
+ });
19
+
20
+ final.push({
21
+ name: t('operator_routes.manage.title.update', { name, ns: 'common' }),
22
+ url: backUrlFinal
23
+ });
24
+
25
+ if (type === 'alternate') {
26
+ final.push({
27
+ name: t('alternates.browse.title', { name: name, ns: 'common' }),
28
+ url: backUrl
29
+ });
30
+ }
31
+
32
+ return final;
33
+ };
@@ -1,7 +1,7 @@
1
1
  import { TFunction } from 'i18next';
2
2
  import { useParams, Navigate, useNavigate } from 'react-router-dom';
3
3
  import { Meta, BackWithTitle, Viewer } from '@autobusal/common';
4
- import { usePage } from '@autobusal/hooks';
4
+ import { usePage, useBreadcrumbs } from '@autobusal/hooks';
5
5
  import { success } from '@autobusal/utilities';
6
6
  import { getSchedules } from './utilities';
7
7
  import { AvailableData } from '@autobusal/providers/types/routes';
@@ -17,6 +17,7 @@ const Manage = ({ url, t }: Props): JSX.Element => {
17
17
 
18
18
  const id = Number(params.id);
19
19
 
20
+ const baseUrl = url;
20
21
  url = url.replace('[id]', String(id));
21
22
 
22
23
  usePage('routes');
@@ -25,6 +26,16 @@ const Manage = ({ url, t }: Props): JSX.Element => {
25
26
 
26
27
  const { data, isFetching } = useGetSchedule(id);
27
28
 
29
+ const title = t('schedules_manage.title', { name: data?.name, ns: 'common' });
30
+
31
+ useBreadcrumbs(title, [{
32
+ name: t('operator_routes.browse.title.manage', { ns: 'common' }),
33
+ url: baseUrl.replace('/manage/[id]', '')
34
+ }, {
35
+ name: t('operator_routes.manage.title.update', { name: data?.name, ns: 'common' }),
36
+ url
37
+ }]);
38
+
28
39
  const { mutate: Update, isPending } = usePostSchedule(id);
29
40
 
30
41
  if (id === 0) {
@@ -41,8 +52,6 @@ const Manage = ({ url, t }: Props): JSX.Element => {
41
52
  });
42
53
  };
43
54
 
44
- const title = t('schedules_manage.title', { name: data?.name, ns: 'common' });
45
-
46
55
  return (
47
56
  <Meta title={ title }>
48
57
  <BackWithTitle title={ title } to={ url } t={ t } />
package/Seating.tsx CHANGED
@@ -25,7 +25,7 @@ const Seating = ({ trip, t, onUpdated }: Props): JSX.Element => {
25
25
 
26
26
  useEffect(() => {
27
27
  onUpdated(data);
28
- }, [data]);
28
+ }, [data, onUpdated]);
29
29
 
30
30
  const onSeatingChange = (type: string): void => {
31
31
  const newData = { ...data };
@@ -1,7 +1,7 @@
1
1
  import { TFunction } from 'i18next';
2
2
  import { useParams, Navigate } from 'react-router-dom';
3
3
  import { Meta, BackWithTitle, Viewer, Box } from '@autobusal/common';
4
- import { usePage, useCountries } from '@autobusal/hooks';
4
+ import { usePage, useBreadcrumbs, useCountries } from '@autobusal/hooks';
5
5
  import { success } from '@autobusal/utilities';
6
6
  import Countries from './Countries';
7
7
  import { filterCountries } from './utilities';
@@ -18,6 +18,7 @@ const Manage = ({ url, t }: Props): JSX.Element => {
18
18
 
19
19
  const id = Number(params.id);
20
20
 
21
+ const baseUrl = url;
21
22
  url = url.replace('[id]', String(id));
22
23
 
23
24
  usePage('routes');
@@ -26,6 +27,16 @@ const Manage = ({ url, t }: Props): JSX.Element => {
26
27
 
27
28
  const { data, isFetching, refetch } = useGetTransiting(id);
28
29
 
30
+ const title = t('transiting_manage.title', { name: data?.name, ns: 'common' });
31
+
32
+ useBreadcrumbs(title, [{
33
+ name: t('operator_routes.browse.title.manage', { ns: 'common' }),
34
+ url: baseUrl.replace('/manage/[id]', '')
35
+ }, {
36
+ name: t('operator_routes.manage.title.update', { name: data?.name, ns: 'common' }),
37
+ url
38
+ }]);
39
+
29
40
  const { mutate: Update, isPending: isPendingSave } = usePostTransiting(id);
30
41
 
31
42
  const { mutate: Delete, isPending: isPendingDelete } = useDeleteTransiting(id);
@@ -58,8 +69,6 @@ const Manage = ({ url, t }: Props): JSX.Element => {
58
69
  });
59
70
  };
60
71
 
61
- const title = t('transiting_manage.title', { name: data?.name, ns: 'common' });
62
-
63
72
  return (
64
73
  <Meta title={ title }>
65
74
  <BackWithTitle title={ title } to={ url } t={ t } />
@@ -1,7 +1,7 @@
1
1
  import { TFunction } from 'i18next';
2
2
  import { useParams, Navigate } from 'react-router-dom';
3
3
  import { Meta, BackWithTitle, Table, Row } from '@autobusal/common';
4
- import { usePage } from '@autobusal/hooks';
4
+ import { usePage, useBreadcrumbs } from '@autobusal/hooks';
5
5
  import { useGetUnavailableDates, useDeleteUnavailable } from './services';
6
6
 
7
7
  interface Props {
@@ -14,12 +14,23 @@ const Browse = ({ url, t }: Props): JSX.Element => {
14
14
 
15
15
  const id = Number(params.id);
16
16
 
17
+ const baseUrl = url;
17
18
  url = url.replace('[id]', String(id));
18
19
 
19
20
  usePage('routes');
20
21
 
21
22
  const { data, isLoading, isFetching, refetch } = useGetUnavailableDates(id);
22
23
 
24
+ const title = t('unavailable.browse.title', { name: data?.name, ns: 'common' });
25
+
26
+ useBreadcrumbs(title, [{
27
+ name: t('operator_routes.browse.title.manage', { ns: 'common' }),
28
+ url: baseUrl.replace('/manage/[id]', '')
29
+ }, {
30
+ name: t('operator_routes.manage.title.update', { name: data?.name, ns: 'common' }),
31
+ url
32
+ }]);
33
+
23
34
  const { mutate: Delete } = useDeleteUnavailable(id);
24
35
 
25
36
  if (id === 0) {
@@ -42,8 +53,6 @@ const Browse = ({ url, t }: Props): JSX.Element => {
42
53
  />
43
54
  ));
44
55
 
45
- const title = t('unavailable.browse.title', { name: data?.name, ns: 'common' });
46
-
47
56
  return (
48
57
  <Meta title={ title }>
49
58
  <BackWithTitle title={ title } to={ url } t={ t } />
@@ -1,7 +1,7 @@
1
1
  import { TFunction } from 'i18next';
2
2
  import { useParams, Navigate, useNavigate } from 'react-router-dom';
3
3
  import { Meta, BackWithTitle, Viewer } from '@autobusal/common';
4
- import { usePage } from '@autobusal/hooks';
4
+ import { usePage, useBreadcrumbs } from '@autobusal/hooks';
5
5
  import { success } from '@autobusal/utilities';
6
6
  import { UnavailableData } from '@autobusal/providers/types/routes';
7
7
  import { useGetUnavailable, usePostUnavailable, useDeleteUnavailable } from './services';
@@ -17,6 +17,7 @@ const Manage = ({ url, t }: Props): JSX.Element => {
17
17
  const id = Number(params.id);
18
18
  const routeId = Number(params.route_id);
19
19
 
20
+ const baseUrl = url;
20
21
  url = url.replace('[routeId]', String(routeId));
21
22
 
22
23
  usePage('routes');
@@ -25,6 +26,19 @@ const Manage = ({ url, t }: Props): JSX.Element => {
25
26
 
26
27
  const { data, isFetching } = useGetUnavailable(routeId, id);
27
28
 
29
+ const title = id > 0 ? t('unavailable.manage.title.update', { name: data?.name, ns: 'common' }) : t('unavailable.manage.title.new', { name: data?.name, ns: 'common' });
30
+
31
+ useBreadcrumbs(title, [{
32
+ name: t('operator_routes.browse.title.manage', { ns: 'common' }),
33
+ url: baseUrl.replace('/unavailable/[routeId]', '')
34
+ }, {
35
+ name: t('operator_routes.manage.title.update', { name: data?.name, ns: 'common' }),
36
+ url: baseUrl.replace('/unavailable/[routeId]', `/manage/${ routeId }`)
37
+ }, {
38
+ name: t('unavailable.browse.title', { name: data?.name, ns: 'common' }),
39
+ url
40
+ }]);
41
+
28
42
  const { mutate: Update, isPending: isPendingSave } = usePostUnavailable(routeId, id);
29
43
 
30
44
  const { mutate: Delete, isPending: isPendingDelete } = useDeleteUnavailable(routeId);
@@ -53,8 +67,6 @@ const Manage = ({ url, t }: Props): JSX.Element => {
53
67
  });
54
68
  };
55
69
 
56
- const title = id > 0 ? t('unavailable.manage.title.update', { name: data?.name, ns: 'common' }) : t('unavailable.manage.title.new', { name: data?.name, ns: 'common' });
57
-
58
70
  const unavailable = data?.unavailable !== undefined && data.unavailable.length > 0 ? data.unavailable[0] : undefined;
59
71
 
60
72
  return (
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/operator-routes",
3
- "version": "1.0.10",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "main": "index.ts"
6
6
  }