@autobusal/common 1.15.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.
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { useLocation } from 'react-router-dom';
|
|
2
1
|
import { useGetSettings } from '@autobusal/providers/services';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -7,18 +6,28 @@ import { useGetSettings } from '@autobusal/providers/services';
|
|
|
7
6
|
* Edited: Ferjolt Ozuni - Date: 2026-08-01
|
|
8
7
|
*
|
|
9
8
|
* Without this the switch is one-way: the holding page replaces the whole
|
|
10
|
-
* router, so /admin
|
|
11
|
-
* back OFF
|
|
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
|
|
12
11
|
* trying to switch it off again.
|
|
13
12
|
*
|
|
14
13
|
* Staff routes are the exception, not the public site - somebody has to be
|
|
15
14
|
* able to log in and finish the work the site is closed for. Everything a
|
|
16
|
-
* visitor can reach still gets the holding page,
|
|
15
|
+
* visitor can reach still gets the holding page, deep links included.
|
|
17
16
|
*/
|
|
18
17
|
const ALWAYS_OPEN = [ '/admin', '/account', '/auth' ];
|
|
19
18
|
|
|
20
19
|
/**
|
|
21
|
-
* Whether the holding page should replace the app
|
|
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.
|
|
22
31
|
*
|
|
23
32
|
* obtapi sends `construction` only while the brand is actually under
|
|
24
33
|
* construction, so its presence is the switch.
|
|
@@ -26,14 +35,14 @@ const ALWAYS_OPEN = [ '/admin', '/account', '/auth' ];
|
|
|
26
35
|
const useUnderConstruction = (): boolean => {
|
|
27
36
|
const { data: settings } = useGetSettings();
|
|
28
37
|
|
|
29
|
-
const location = useLocation();
|
|
30
|
-
|
|
31
38
|
if (!settings?.construction) {
|
|
32
39
|
return false;
|
|
33
40
|
}
|
|
34
41
|
|
|
35
|
-
|
|
36
|
-
|
|
42
|
+
const path = typeof window === 'undefined' ? '/' : window.location.pathname;
|
|
43
|
+
|
|
44
|
+
return !ALWAYS_OPEN.some(open => (
|
|
45
|
+
path === open || path.startsWith(`${ open }/`)
|
|
37
46
|
));
|
|
38
47
|
};
|
|
39
48
|
|