@djangocfg/layouts 2.1.241 → 2.1.243
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/README.md
CHANGED
|
@@ -69,7 +69,7 @@ export default function RootLayout({ children }) {
|
|
|
69
69
|
|
|
70
70
|
**Included automatically:**
|
|
71
71
|
- ThemeProvider, TooltipProvider, SWRConfig, DialogProvider
|
|
72
|
-
- AuthProvider + AuthDialog
|
|
72
|
+
- AuthProvider + AuthDialog (via zustand `dialogStore`, triggered by `window.dialog.auth()`)
|
|
73
73
|
- AnalyticsProvider, CentrifugoProvider
|
|
74
74
|
- PwaProvider (from `@djangocfg/ui-nextjs/pwa`)
|
|
75
75
|
- ErrorTrackingProvider, ErrorBoundary
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@djangocfg/layouts",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.243",
|
|
4
4
|
"description": "Simple, straightforward layout components for Next.js - import and use with props",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"layouts",
|
|
@@ -74,14 +74,14 @@
|
|
|
74
74
|
"check": "tsc --noEmit"
|
|
75
75
|
},
|
|
76
76
|
"peerDependencies": {
|
|
77
|
-
"@djangocfg/api": "^2.1.
|
|
78
|
-
"@djangocfg/centrifugo": "^2.1.
|
|
79
|
-
"@djangocfg/i18n": "^2.1.
|
|
80
|
-
"@djangocfg/monitor": "^2.1.
|
|
81
|
-
"@djangocfg/debuger": "^2.1.
|
|
82
|
-
"@djangocfg/ui-core": "^2.1.
|
|
83
|
-
"@djangocfg/ui-nextjs": "^2.1.
|
|
84
|
-
"@djangocfg/ui-tools": "^2.1.
|
|
77
|
+
"@djangocfg/api": "^2.1.243",
|
|
78
|
+
"@djangocfg/centrifugo": "^2.1.243",
|
|
79
|
+
"@djangocfg/i18n": "^2.1.243",
|
|
80
|
+
"@djangocfg/monitor": "^2.1.243",
|
|
81
|
+
"@djangocfg/debuger": "^2.1.243",
|
|
82
|
+
"@djangocfg/ui-core": "^2.1.243",
|
|
83
|
+
"@djangocfg/ui-nextjs": "^2.1.243",
|
|
84
|
+
"@djangocfg/ui-tools": "^2.1.243",
|
|
85
85
|
"@hookform/resolvers": "^5.2.2",
|
|
86
86
|
"consola": "^3.4.2",
|
|
87
87
|
"lucide-react": "^0.545.0",
|
|
@@ -109,15 +109,15 @@
|
|
|
109
109
|
"uuid": "^11.1.0"
|
|
110
110
|
},
|
|
111
111
|
"devDependencies": {
|
|
112
|
-
"@djangocfg/api": "^2.1.
|
|
113
|
-
"@djangocfg/i18n": "^2.1.
|
|
114
|
-
"@djangocfg/centrifugo": "^2.1.
|
|
115
|
-
"@djangocfg/monitor": "^2.1.
|
|
116
|
-
"@djangocfg/debuger": "^2.1.
|
|
117
|
-
"@djangocfg/typescript-config": "^2.1.
|
|
118
|
-
"@djangocfg/ui-core": "^2.1.
|
|
119
|
-
"@djangocfg/ui-nextjs": "^2.1.
|
|
120
|
-
"@djangocfg/ui-tools": "^2.1.
|
|
112
|
+
"@djangocfg/api": "^2.1.243",
|
|
113
|
+
"@djangocfg/i18n": "^2.1.243",
|
|
114
|
+
"@djangocfg/centrifugo": "^2.1.243",
|
|
115
|
+
"@djangocfg/monitor": "^2.1.243",
|
|
116
|
+
"@djangocfg/debuger": "^2.1.243",
|
|
117
|
+
"@djangocfg/typescript-config": "^2.1.243",
|
|
118
|
+
"@djangocfg/ui-core": "^2.1.243",
|
|
119
|
+
"@djangocfg/ui-nextjs": "^2.1.243",
|
|
120
|
+
"@djangocfg/ui-tools": "^2.1.243",
|
|
121
121
|
"@types/node": "^24.7.2",
|
|
122
122
|
"@types/react": "^19.1.0",
|
|
123
123
|
"@types/react-dom": "^19.1.0",
|
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
|
|
3
3
|
import { LogIn } from 'lucide-react';
|
|
4
|
-
import React, { useMemo
|
|
4
|
+
import React, { useMemo } from 'react';
|
|
5
5
|
|
|
6
6
|
import { useCfgRouter } from '@djangocfg/api/auth';
|
|
7
7
|
import { useAppT } from '@djangocfg/i18n';
|
|
8
8
|
import {
|
|
9
9
|
Button, Dialog, DialogContent, DialogHeader, DialogTitle
|
|
10
10
|
} from '@djangocfg/ui-core/components';
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
// Re-export events for backwards compatibility
|
|
14
|
-
export const DIALOG_EVENTS = {
|
|
15
|
-
OPEN_AUTH_DIALOG: 'OPEN_AUTH_DIALOG',
|
|
16
|
-
CLOSE_AUTH_DIALOG: 'CLOSE_AUTH_DIALOG',
|
|
17
|
-
AUTH_SUCCESS: 'AUTH_SUCCESS',
|
|
18
|
-
AUTH_FAILURE: 'AUTH_FAILURE',
|
|
19
|
-
} as const;
|
|
11
|
+
import { useDialogStore } from '@djangocfg/ui-core/lib/dialog-service';
|
|
20
12
|
|
|
21
13
|
interface AuthDialogProps {
|
|
22
14
|
onAuthRequired?: () => void;
|
|
@@ -27,7 +19,9 @@ export const AuthDialog: React.FC<AuthDialogProps> = ({
|
|
|
27
19
|
onAuthRequired,
|
|
28
20
|
authPath = '/auth'
|
|
29
21
|
}) => {
|
|
30
|
-
const
|
|
22
|
+
const open = useDialogStore((s) => s.authOpen);
|
|
23
|
+
const authOptions = useDialogStore((s) => s.authOptions);
|
|
24
|
+
const resolveAuth = useDialogStore((s) => s.resolveAuth);
|
|
31
25
|
const t = useAppT();
|
|
32
26
|
|
|
33
27
|
const labels = useMemo(() => ({
|
|
@@ -36,31 +30,17 @@ export const AuthDialog: React.FC<AuthDialogProps> = ({
|
|
|
36
30
|
goToSignIn: t('layouts.auth.goToSignIn'),
|
|
37
31
|
}), [t]);
|
|
38
32
|
|
|
39
|
-
const
|
|
33
|
+
const message = authOptions?.message || labels.pleaseSignIn;
|
|
40
34
|
const router = useCfgRouter();
|
|
41
35
|
|
|
42
|
-
// Listen for open auth dialog event
|
|
43
|
-
useEventListener(DIALOG_EVENTS.OPEN_AUTH_DIALOG, (payload: any) => {
|
|
44
|
-
if (payload?.message) {
|
|
45
|
-
setMessage(payload.message);
|
|
46
|
-
}
|
|
47
|
-
setOpen(true);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
// Listen for close auth dialog event
|
|
51
|
-
useEventListener(DIALOG_EVENTS.CLOSE_AUTH_DIALOG, () => {
|
|
52
|
-
setOpen(false);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
36
|
const handleClose = () => {
|
|
56
|
-
|
|
57
|
-
setOpen(false);
|
|
37
|
+
resolveAuth(false);
|
|
58
38
|
};
|
|
59
39
|
|
|
60
40
|
const handleGoToAuth = () => {
|
|
61
|
-
// Save current URL for redirect after successful auth
|
|
62
41
|
if (typeof window !== 'undefined') {
|
|
63
|
-
|
|
42
|
+
const redirect = authOptions?.redirectUrl || window.location.pathname;
|
|
43
|
+
sessionStorage.setItem('redirectAfterAuth', redirect);
|
|
64
44
|
}
|
|
65
45
|
|
|
66
46
|
if (onAuthRequired) {
|
|
@@ -69,11 +49,11 @@ export const AuthDialog: React.FC<AuthDialogProps> = ({
|
|
|
69
49
|
router.push(authPath);
|
|
70
50
|
}
|
|
71
51
|
|
|
72
|
-
|
|
52
|
+
resolveAuth(true);
|
|
73
53
|
};
|
|
74
54
|
|
|
75
55
|
return (
|
|
76
|
-
<Dialog open={open} onOpenChange={handleClose}>
|
|
56
|
+
<Dialog open={open} onOpenChange={(isOpen) => { if (!isOpen) handleClose(); }}>
|
|
77
57
|
<DialogContent className="max-w-sm">
|
|
78
58
|
<DialogHeader>
|
|
79
59
|
<DialogTitle>{labels.authRequired}</DialogTitle>
|
|
@@ -1,21 +1 @@
|
|
|
1
|
-
export
|
|
2
|
-
OPEN_AUTH_DIALOG: 'OPEN_AUTH_DIALOG',
|
|
3
|
-
CLOSE_AUTH_DIALOG: 'CLOSE_AUTH_DIALOG',
|
|
4
|
-
AUTH_SUCCESS: 'AUTH_SUCCESS',
|
|
5
|
-
AUTH_FAILURE: 'AUTH_FAILURE',
|
|
6
|
-
} as const;
|
|
7
|
-
|
|
8
|
-
export type AuthEventType = typeof AUTH_EVENTS[keyof typeof AUTH_EVENTS];
|
|
9
|
-
|
|
10
|
-
export interface OpenAuthDialogPayload {
|
|
11
|
-
message?: string;
|
|
12
|
-
redirectUrl?: string;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export interface AuthSuccessPayload {
|
|
16
|
-
user?: any;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export interface AuthFailurePayload {
|
|
20
|
-
error?: string;
|
|
21
|
-
}
|
|
1
|
+
export type { AuthDialogOptions } from '@djangocfg/ui-core/lib/dialog-service';
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export { AuthDialog
|
|
1
|
+
export { AuthDialog } from './AuthDialog';
|
|
2
2
|
export * from './events';
|
|
3
|
-
export { useAuthDialog } from './useAuthDialog';
|
|
3
|
+
export { useAuthDialog } from './useAuthDialog';
|
|
@@ -1,26 +1,30 @@
|
|
|
1
|
-
|
|
1
|
+
'use client';
|
|
2
2
|
|
|
3
3
|
import { useCallback } from 'react';
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import { AUTH_EVENTS, OpenAuthDialogPayload } from './events';
|
|
4
|
+
import { dialogStore } from '@djangocfg/ui-core/lib/dialog-service';
|
|
5
|
+
import type { AuthDialogOptions } from '@djangocfg/ui-core/lib/dialog-service';
|
|
8
6
|
|
|
9
7
|
/**
|
|
10
8
|
* Hook to control auth dialog from anywhere in the app
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const { openAuthDialog, closeAuthDialog } = useAuthDialog();
|
|
13
|
+
*
|
|
14
|
+
* // Opens auth dialog and waits for result
|
|
15
|
+
* const didAuth = await openAuthDialog({ message: 'Session expired' });
|
|
16
|
+
*
|
|
17
|
+
* // Or fire-and-forget
|
|
18
|
+
* openAuthDialog();
|
|
19
|
+
* ```
|
|
11
20
|
*/
|
|
12
21
|
export function useAuthDialog() {
|
|
13
|
-
const openAuthDialog = useCallback((options?:
|
|
14
|
-
|
|
15
|
-
type: AUTH_EVENTS.OPEN_AUTH_DIALOG,
|
|
16
|
-
payload: options,
|
|
17
|
-
});
|
|
22
|
+
const openAuthDialog = useCallback((options?: AuthDialogOptions) => {
|
|
23
|
+
return dialogStore.getState().openAuth(options);
|
|
18
24
|
}, []);
|
|
19
25
|
|
|
20
26
|
const closeAuthDialog = useCallback(() => {
|
|
21
|
-
|
|
22
|
-
type: AUTH_EVENTS.CLOSE_AUTH_DIALOG,
|
|
23
|
-
});
|
|
27
|
+
dialogStore.getState().resolveAuth(false);
|
|
24
28
|
}, []);
|
|
25
29
|
|
|
26
30
|
return {
|