@autobusal/common 1.14.0 → 1.15.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.
@@ -0,0 +1,49 @@
1
+ import { useGetSettings } from '@autobusal/providers/services';
2
+
3
+ /**
4
+ * Paths that stay reachable while the site is closed.
5
+ *
6
+ * Edited: Ferjolt Ozuni - Date: 2026-08-01
7
+ *
8
+ * Without this the switch is one-way: the holding page replaces the whole
9
+ * router, so /admin went behind it too and the only way to turn maintenance
10
+ * back OFF was a database edit. Found by actually switching it on and then
11
+ * trying to switch it off again.
12
+ *
13
+ * Staff routes are the exception, not the public site - somebody has to be
14
+ * able to log in and finish the work the site is closed for. Everything a
15
+ * visitor can reach still gets the holding page, deep links included.
16
+ */
17
+ const ALWAYS_OPEN = [ '/admin', '/account', '/auth' ];
18
+
19
+ /**
20
+ * Whether the holding page should replace the app right now.
21
+ *
22
+ * Reads the path from `window.location` rather than react-router's
23
+ * useLocation: this runs ABOVE <RouterProvider> (it decides whether to
24
+ * render the router at all), so there is no router context to read from -
25
+ * calling useLocation here throws and blanks the entire page, which is
26
+ * exactly what happened the first time.
27
+ *
28
+ * The consequence is that it does not re-evaluate on client-side
29
+ * navigation, which is fine: the holding page renders no links, so the only
30
+ * way to leave it is a real page load, and that re-runs this.
31
+ *
32
+ * obtapi sends `construction` only while the brand is actually under
33
+ * construction, so its presence is the switch.
34
+ */
35
+ const useUnderConstruction = (): boolean => {
36
+ const { data: settings } = useGetSettings();
37
+
38
+ if (!settings?.construction) {
39
+ return false;
40
+ }
41
+
42
+ const path = typeof window === 'undefined' ? '/' : window.location.pathname;
43
+
44
+ return !ALWAYS_OPEN.some(open => (
45
+ path === open || path.startsWith(`${ open }/`)
46
+ ));
47
+ };
48
+
49
+ export default useUnderConstruction;
package/index.ts CHANGED
@@ -32,6 +32,7 @@ import RouteItem from './RouteItem/RouteItem';
32
32
  import Row from './Table/Row';
33
33
  import Table from './Table/Table';
34
34
  import UnderConstruction from './UnderConstruction/UnderConstruction';
35
+ import useUnderConstruction from './UnderConstruction/useUnderConstruction';
35
36
  import Viewer from './Viewer/Viewer';
36
37
 
37
38
  export {
@@ -73,5 +74,6 @@ export {
73
74
  Row,
74
75
  Table,
75
76
  UnderConstruction,
77
+ useUnderConstruction,
76
78
  Viewer
77
79
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/common",
3
- "version": "1.14.0",
3
+ "version": "1.15.1",
4
4
  "author": "Ferjolt Ozuni",
5
5
  "type": "module",
6
6
  "main": "index.ts"