@autobusal/operator-routes 1.3.1 → 1.3.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,32 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.3.3
4
+
5
+ ### Fixed
6
+
7
+ - **The ticket-language dropdown offered a country code and three options.**
8
+ It listed the two content languages plus Greek as `gr` - the code for the
9
+ country; the language is `el` - so an operator choosing it got English
10
+ tickets and no error to say so. Now all fifteen languages the API can
11
+ print, under their own names and their real codes.
12
+
13
+ ## 1.3.2
14
+
15
+ ### Added
16
+
17
+ - **A stop added in a multi-zone country says so.** Times are stored local
18
+ to their stop, and a country with no zone recorded falls back to the
19
+ application's clock - a duration that reads plausibly and is wrong by
20
+ hours. The API now answers `warning: 'timezone'` and the operator is told,
21
+ because the operator is who sees the wrong number and would otherwise
22
+ "fix" it by editing times that are correct as stored.
23
+
24
+ ### Fixed
25
+
26
+ - **`useAddLocation` returns its response.** It was awaited and discarded,
27
+ so `onSuccess` received undefined - harmless while the endpoint answered
28
+ with an empty object, and it would have swallowed the warning above.
29
+
3
30
  ## [1.3.1] - 2026-08-07
4
31
 
5
32
  ### Fixed
@@ -2,7 +2,7 @@ import { TFunction } from 'i18next';
2
2
  import { useForm } from 'react-hook-form';
3
3
  import { FiPlus } from 'react-icons/fi';
4
4
  import { Button } from '@autobusal/common';
5
- import { Validate, Display, success } from '@autobusal/utilities';
5
+ import { Validate, Display, success, notify } from '@autobusal/utilities';
6
6
  import Loading from './Loading';
7
7
  import { getStops } from '../utilities';
8
8
  import { Container, Title, ContainerAdd, Choose, Notice } from './styles';
@@ -28,9 +28,26 @@ const Add = ({ routeId, t, onReload }: Props): JSX.Element => {
28
28
 
29
29
  const onSubmit = (data: AddForm): void => {
30
30
  Save(data, {
31
- onSuccess: () => {
31
+ onSuccess: (response) => {
32
32
  success(t('locations_manage.messages.added', { ns: 'common' }));
33
33
 
34
+ /*
35
+ * Edited: Ferjolt Ozuni - Date: 2026-08-07
36
+ *
37
+ * The stop was added - this is a caveat, not a failure, so it comes
38
+ * after the success and does not stop the reload.
39
+ *
40
+ * It is worth saying out loud because the consequence is a wrong
41
+ * NUMBER rather than an error: times at this stop fall back to our
42
+ * clock, so a duration can read short or long by hours. An operator
43
+ * who sees that without being told why is likely to correct it by
44
+ * editing the stored times, and that turns something we can fix
45
+ * centrally into data nobody can untangle later.
46
+ */
47
+ if (response?.warning === 'timezone') {
48
+ notify(t('locations_manage.messages.timezone', { ns: 'common' }));
49
+ }
50
+
34
51
  onReload();
35
52
  }
36
53
  });
@@ -2,7 +2,7 @@ import { UseMutationResult, UseQueryResult, UseSuspenseQueryResult, useMutation,
2
2
  import { apiClient } from '@autobusal/providers';
3
3
  import { RouteData } from '@autobusal/providers/types/routes';
4
4
  import { CountryData } from '@autobusal/providers/types/locations';
5
- import { AddForm, LocationForm } from './types';
5
+ import { AddForm, AddResponse, LocationForm } from './types';
6
6
 
7
7
  export const useGetLocations = (id: number): UseSuspenseQueryResult<RouteData> => (
8
8
  useSuspenseQuery({
@@ -36,19 +36,27 @@ export const useGetStops = (routeId: number): UseQueryResult<CountryData[]> => (
36
36
  })
37
37
  );
38
38
 
39
- export const useAddLocation = (id: number): UseMutationResult<void, Error, AddForm, unknown> => (
39
+ /*
40
+ * Edited: Ferjolt Ozuni - Date: 2026-08-07
41
+ *
42
+ * Returns the response instead of discarding it. It was awaited and thrown
43
+ * away, so `onSuccess` was handed undefined - which was invisible while the
44
+ * endpoint answered with an empty object, and would have quietly swallowed
45
+ * the `warning` it can now carry.
46
+ */
47
+ export const useAddLocation = (id: number): UseMutationResult<AddResponse, Error, AddForm, unknown> => (
40
48
  useMutation({
41
49
  mutationKey: ['operator-locations-add', { id }],
42
- mutationFn: async (data: AddForm) => {
43
- await apiClient
50
+ mutationFn: async (data: AddForm) => (
51
+ apiClient
44
52
  .post('/api/locations/operator/add', {
45
53
  ...data,
46
54
  id
47
55
  })
48
56
  .then(response => (
49
- response.data
57
+ response.data as AddResponse
50
58
  ))
51
- }
59
+ )
52
60
  })
53
61
  );
54
62
 
@@ -2,6 +2,19 @@ export interface AddForm {
2
2
  group_id: string
3
3
  }
4
4
 
5
+ /**
6
+ * What adding a stop answers with.
7
+ *
8
+ * Empty on the ordinary path. `warning` is a CODE rather than a sentence -
9
+ * the API has no business writing operator-facing prose in fifteen
10
+ * languages - and 'timezone' means the stop's country spans several zones,
11
+ * so the times shown for it fall back to the application's clock rather
12
+ * than its own.
13
+ */
14
+ export interface AddResponse {
15
+ warning?: 'timezone'
16
+ }
17
+
5
18
  export interface LocationForm {
6
19
  tomorrow: number
7
20
  departure: string
package/Manage.tsx CHANGED
@@ -155,7 +155,7 @@ const Manage = ({ url, t }: Props): JSX.Element => {
155
155
  label: t('operator_routes.manage.language', { ns: 'common' }),
156
156
  name: 'language',
157
157
  type: 'select',
158
- values: getLanguagesExtended(),
158
+ values: getLanguagesExtended(t),
159
159
  value: data?.language ?? 'en',
160
160
  rules: 'required'
161
161
  }, {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/operator-routes",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
4
4
  "author": "Ferjolt Ozuni",
5
5
  "type": "module",
6
6
  "main": "index.ts"
package/utilities.tsx CHANGED
@@ -1,6 +1,5 @@
1
1
  import { TFunction } from 'i18next';
2
2
  import { IoGlobeOutline } from 'react-icons/io5';
3
- import { getLanguages } from '@autobusal/utilities';
4
3
  import { DropdownData } from '@autobusal/providers/types/other';
5
4
  import { ViewData } from '@autobusal/common/Viewer/types';
6
5
 
@@ -34,16 +33,39 @@ const getOptionsTypes = (t: TFunction<'common'>): DropdownData[] => ([
34
33
  }
35
34
  ]);
36
35
 
37
- export const getLanguagesExtended = (): DropdownData[] => {
38
- const languages = getLanguages();
36
+ /**
37
+ * The languages a TICKET can be printed in.
38
+ *
39
+ * Edited: Ferjolt Ozuni - Date: 2026-08-07
40
+ *
41
+ * This used to be the two CONTENT languages plus Greek bolted on as 'gr'.
42
+ * Two things were wrong with that.
43
+ *
44
+ * 'gr' is the country code for Greece; the language code is 'el'. The API
45
+ * resolves this value to a directory under lang/, there is no lang/gr, so an
46
+ * operator who picked "Gr" got English tickets and no error anywhere to say
47
+ * so. One route in the database had the same fault spelled 'al' for Albanian
48
+ * (which is 'sq') - see the 2026_08_07_150000 migration.
49
+ *
50
+ * And the list was three long while the API ships ticket translations in
51
+ * fifteen. An operator running a Tirana-Milan coach could not choose Italian
52
+ * for a document their passengers have to read at a border.
53
+ *
54
+ * Named from `languages.*`, which already holds all fifteen under their
55
+ * correct codes and in their own language - so the codes cannot drift from
56
+ * the ones the API accepts, and an operator picks "Italiano" rather than
57
+ * decoding "It".
58
+ */
59
+ const TICKET_LANGUAGES = [
60
+ 'sq', 'en', 'bg', 'bs', 'de', 'el', 'es', 'fr', 'hr', 'it', 'me', 'mk', 'ro', 'sl', 'sr'
61
+ ];
39
62
 
40
- languages.push({
41
- name: 'Gr',
42
- id: 'gr'
43
- });
44
-
45
- return languages;
46
- };
63
+ export const getLanguagesExtended = (t: TFunction<'normal'>): DropdownData[] => (
64
+ TICKET_LANGUAGES.map(id => ({
65
+ id,
66
+ name: t(`languages.${ id }`, { ns: 'common' })
67
+ }))
68
+ );
47
69
 
48
70
  export const getTemplates = (t: TFunction<'normal'>): DropdownData[] => ([
49
71
  {