@djangocfg/layouts 2.1.9 → 2.1.14

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.
Files changed (106) hide show
  1. package/README.md +53 -161
  2. package/package.json +6 -6
  3. package/src/components/RedirectPage/RedirectPage.tsx +1 -1
  4. package/src/index.ts +0 -6
  5. package/src/layouts/AppLayout/AppLayout.tsx +1 -1
  6. package/src/layouts/AppLayout/BaseApp.tsx +1 -1
  7. package/src/layouts/AuthLayout/AuthContext.tsx +1 -1
  8. package/src/layouts/AuthLayout/OAuthCallback.tsx +1 -1
  9. package/src/layouts/AuthLayout/OAuthProviders.tsx +1 -1
  10. package/src/layouts/PrivateLayout/PrivateLayout.tsx +1 -1
  11. package/src/layouts/PrivateLayout/components/PrivateHeader.tsx +1 -1
  12. package/src/layouts/ProfileLayout/components/AvatarSection.tsx +2 -2
  13. package/src/layouts/PublicLayout/components/PublicMobileDrawer.tsx +1 -1
  14. package/src/layouts/PublicLayout/components/PublicNavigation.tsx +1 -1
  15. package/src/layouts/_components/UserMenu.tsx +1 -1
  16. package/src/layouts/index.ts +0 -2
  17. package/src/snippets/Analytics/useAnalytics.ts +1 -1
  18. package/src/snippets/McpChat/hooks/useAIChat.ts +16 -3
  19. package/src/snippets/index.ts +0 -3
  20. package/src/auth/README.md +0 -962
  21. package/src/auth/context/AccountsContext.tsx +0 -240
  22. package/src/auth/context/AuthContext.tsx +0 -604
  23. package/src/auth/context/index.ts +0 -4
  24. package/src/auth/context/types.ts +0 -68
  25. package/src/auth/hooks/index.ts +0 -17
  26. package/src/auth/hooks/useAuthForm.ts +0 -332
  27. package/src/auth/hooks/useAuthGuard.ts +0 -25
  28. package/src/auth/hooks/useAuthRedirect.ts +0 -51
  29. package/src/auth/hooks/useAutoAuth.ts +0 -49
  30. package/src/auth/hooks/useGithubAuth.ts +0 -184
  31. package/src/auth/hooks/useLocalStorage.ts +0 -214
  32. package/src/auth/hooks/useProfileCache.ts +0 -146
  33. package/src/auth/hooks/useSessionStorage.ts +0 -189
  34. package/src/auth/index.ts +0 -10
  35. package/src/auth/middlewares/index.ts +0 -1
  36. package/src/auth/middlewares/proxy.ts +0 -32
  37. package/src/auth/server.ts +0 -6
  38. package/src/auth/utils/errors.ts +0 -34
  39. package/src/auth/utils/index.ts +0 -2
  40. package/src/auth/utils/validation.ts +0 -14
  41. package/src/contexts/LeadsContext.tsx +0 -156
  42. package/src/contexts/NewsletterContext.tsx +0 -263
  43. package/src/contexts/SupportContext.tsx +0 -256
  44. package/src/contexts/index.ts +0 -59
  45. package/src/contexts/knowbase/ChatContext.tsx +0 -174
  46. package/src/contexts/knowbase/DocumentsContext.tsx +0 -304
  47. package/src/contexts/knowbase/SessionsContext.tsx +0 -174
  48. package/src/contexts/knowbase/index.ts +0 -61
  49. package/src/contexts/payments/BalancesContext.tsx +0 -65
  50. package/src/contexts/payments/CurrenciesContext.tsx +0 -66
  51. package/src/contexts/payments/OverviewContext.tsx +0 -174
  52. package/src/contexts/payments/PaymentsContext.tsx +0 -132
  53. package/src/contexts/payments/README.md +0 -201
  54. package/src/contexts/payments/RootPaymentsContext.tsx +0 -68
  55. package/src/contexts/payments/index.ts +0 -50
  56. package/src/layouts/PaymentsLayout/PaymentsLayout.tsx +0 -92
  57. package/src/layouts/PaymentsLayout/components/CreatePaymentDialog.tsx +0 -291
  58. package/src/layouts/PaymentsLayout/components/PaymentDetailsDialog.tsx +0 -290
  59. package/src/layouts/PaymentsLayout/components/index.ts +0 -2
  60. package/src/layouts/PaymentsLayout/events.ts +0 -47
  61. package/src/layouts/PaymentsLayout/index.ts +0 -16
  62. package/src/layouts/PaymentsLayout/types.ts +0 -6
  63. package/src/layouts/PaymentsLayout/views/overview/components/BalanceCard.tsx +0 -128
  64. package/src/layouts/PaymentsLayout/views/overview/components/RecentPayments.tsx +0 -142
  65. package/src/layouts/PaymentsLayout/views/overview/components/index.ts +0 -2
  66. package/src/layouts/PaymentsLayout/views/overview/index.tsx +0 -20
  67. package/src/layouts/PaymentsLayout/views/payments/components/PaymentsList.tsx +0 -276
  68. package/src/layouts/PaymentsLayout/views/payments/components/index.ts +0 -1
  69. package/src/layouts/PaymentsLayout/views/payments/index.tsx +0 -17
  70. package/src/layouts/PaymentsLayout/views/transactions/components/TransactionsList.tsx +0 -273
  71. package/src/layouts/PaymentsLayout/views/transactions/components/index.ts +0 -1
  72. package/src/layouts/PaymentsLayout/views/transactions/index.tsx +0 -17
  73. package/src/layouts/SupportLayout/README.md +0 -91
  74. package/src/layouts/SupportLayout/SupportLayout.tsx +0 -179
  75. package/src/layouts/SupportLayout/components/CreateTicketDialog.tsx +0 -155
  76. package/src/layouts/SupportLayout/components/MessageInput.tsx +0 -92
  77. package/src/layouts/SupportLayout/components/MessageList.tsx +0 -314
  78. package/src/layouts/SupportLayout/components/TicketCard.tsx +0 -96
  79. package/src/layouts/SupportLayout/components/TicketList.tsx +0 -153
  80. package/src/layouts/SupportLayout/components/index.ts +0 -6
  81. package/src/layouts/SupportLayout/context/SupportLayoutContext.tsx +0 -263
  82. package/src/layouts/SupportLayout/context/index.ts +0 -2
  83. package/src/layouts/SupportLayout/events.ts +0 -33
  84. package/src/layouts/SupportLayout/hooks/index.ts +0 -2
  85. package/src/layouts/SupportLayout/hooks/useInfiniteMessages.ts +0 -119
  86. package/src/layouts/SupportLayout/hooks/useInfiniteTickets.ts +0 -92
  87. package/src/layouts/SupportLayout/index.ts +0 -8
  88. package/src/layouts/SupportLayout/types.ts +0 -21
  89. package/src/snippets/Chat/ChatUIContext.tsx +0 -110
  90. package/src/snippets/Chat/ChatWidget.tsx +0 -476
  91. package/src/snippets/Chat/README.md +0 -122
  92. package/src/snippets/Chat/components/MessageInput.tsx +0 -124
  93. package/src/snippets/Chat/components/MessageList.tsx +0 -169
  94. package/src/snippets/Chat/components/SessionList.tsx +0 -192
  95. package/src/snippets/Chat/components/index.ts +0 -9
  96. package/src/snippets/Chat/hooks/index.ts +0 -6
  97. package/src/snippets/Chat/hooks/useInfiniteSessions.ts +0 -82
  98. package/src/snippets/Chat/index.tsx +0 -45
  99. package/src/snippets/Chat/types.ts +0 -80
  100. package/src/snippets/ContactForm/ContactForm.tsx +0 -346
  101. package/src/snippets/ContactForm/ContactFormProvider.tsx +0 -153
  102. package/src/snippets/ContactForm/ContactInfo.tsx +0 -114
  103. package/src/snippets/ContactForm/ContactPage.tsx +0 -131
  104. package/src/snippets/ContactForm/dynamic.tsx +0 -55
  105. package/src/snippets/ContactForm/index.ts +0 -34
  106. package/src/snippets/ContactForm/types.ts +0 -110
@@ -1,240 +0,0 @@
1
- /**
2
- * Accounts Context
3
- *
4
- * Manages user authentication and profile operations using generated SWR hooks
5
- *
6
- * Features:
7
- * - OTP-based authentication
8
- * - User profile management
9
- * - Avatar upload
10
- * - Profile updates
11
- * - localStorage cache with TTL (1 hour)
12
- */
13
-
14
- "use client";
15
-
16
- import { createContext, useContext, ReactNode, useState, useCallback, useRef, useEffect } from 'react';
17
- import { getCachedProfile, setCachedProfile, clearProfileCache } from '../hooks/useProfileCache';
18
- import { authLogger } from '../../utils/logger';
19
- import {
20
- api,
21
- usePartialUpdateAccountsProfilePartialUpdate,
22
- useUpdateAccountsProfileUpdateUpdate,
23
- useCreateAccountsProfileAvatarCreate,
24
- useCreateAccountsOtpRequestCreate,
25
- useCreateAccountsOtpVerifyCreate,
26
- useCreateAccountsTokenRefreshCreate,
27
- getAccountsProfileRetrieve,
28
- PatchedUserProfileUpdateRequestSchema,
29
- type User,
30
- type UserProfileUpdateRequest,
31
- type PatchedUserProfileUpdateRequest,
32
- type OTPRequestRequest,
33
- type OTPVerifyRequest,
34
- type OTPRequestResponse,
35
- type OTPVerifyResponse,
36
- type TokenRefresh,
37
- type API,
38
- } from '@djangocfg/api';
39
-
40
- // Re-export schemas for external use
41
- export { PatchedUserProfileUpdateRequestSchema };
42
- export type { PatchedUserProfileUpdateRequest };
43
-
44
- // ─────────────────────────────────────────────────────────────────────────
45
- // Context Type
46
- // ─────────────────────────────────────────────────────────────────────────
47
-
48
- export interface AccountsContextValue {
49
- // Current user profile
50
- profile?: User;
51
- isLoadingProfile: boolean;
52
- profileError: Error | null;
53
-
54
- // Profile operations
55
- updateProfile: (data: UserProfileUpdateRequest) => Promise<User>;
56
- partialUpdateProfile: (data: PatchedUserProfileUpdateRequest) => Promise<User>;
57
- uploadAvatar: (formData: FormData) => Promise<User>;
58
- refreshProfile: (callerId?: string) => Promise<User | undefined>;
59
-
60
- // Authentication
61
- requestOTP: (data: OTPRequestRequest) => Promise<OTPRequestResponse>;
62
- verifyOTP: (data: OTPVerifyRequest) => Promise<OTPVerifyResponse>;
63
- refreshToken: (refresh: string) => Promise<TokenRefresh>;
64
- logout: () => void;
65
- }
66
-
67
- // ─────────────────────────────────────────────────────────────────────────
68
- // Context
69
- // ─────────────────────────────────────────────────────────────────────────
70
-
71
- const AccountsContext = createContext<AccountsContextValue | undefined>(undefined);
72
-
73
- // ─────────────────────────────────────────────────────────────────────────
74
- // Provider Component
75
- // ─────────────────────────────────────────────────────────────────────────
76
-
77
- interface AccountsProviderProps {
78
- children: ReactNode;
79
- }
80
-
81
- export function AccountsProvider({ children }: AccountsProviderProps) {
82
- // State management with localStorage cache
83
- const [profile, setProfile] = useState<User | undefined>(() => {
84
- // Initialize from cache on mount
85
- const cached = getCachedProfile();
86
- return cached || undefined;
87
- });
88
- const [isLoadingProfile, setIsLoadingProfile] = useState(false);
89
- const [profileError, setProfileError] = useState<Error | null>(null);
90
-
91
- // Use refs to access current state without adding to dependencies
92
- const profileRef = useRef<User | undefined>(profile);
93
- const isLoadingRef = useRef(false);
94
-
95
- // Keep refs in sync with state
96
- useEffect(() => {
97
- profileRef.current = profile;
98
- }, [profile]);
99
-
100
- useEffect(() => {
101
- isLoadingRef.current = isLoadingProfile;
102
- }, [isLoadingProfile]);
103
-
104
- // Mutation hooks
105
- const updateMutation = useUpdateAccountsProfileUpdateUpdate();
106
- const partialUpdateMutation = usePartialUpdateAccountsProfilePartialUpdate();
107
- const avatarMutation = useCreateAccountsProfileAvatarCreate();
108
- const otpRequestMutation = useCreateAccountsOtpRequestCreate();
109
- const otpVerifyMutation = useCreateAccountsOtpVerifyCreate();
110
- const tokenRefreshMutation = useCreateAccountsTokenRefreshCreate();
111
-
112
- // Refresh profile - fetch and cache with stable callback
113
- const refreshProfile = useCallback(async (callerId?: string): Promise<User | undefined> => {
114
- // Use refs to check current state without creating dependency
115
- const currentProfile = profileRef.current;
116
- const currentLoading = isLoadingRef.current;
117
-
118
- // Prevent duplicate calls if profile is already loaded and not loading
119
- if (currentProfile && !currentLoading) {
120
- authLogger.debug(`Profile already loaded, returning cached (caller: ${callerId})`);
121
- return currentProfile;
122
- }
123
-
124
- setIsLoadingProfile(true);
125
- isLoadingRef.current = true;
126
- setProfileError(null);
127
- try {
128
- // Log caller for debugging excessive API calls using consola logger
129
- if (callerId) {
130
- authLogger.debug(`Profile refresh called by: ${callerId}`);
131
- }
132
- const result = await getAccountsProfileRetrieve(api as unknown as API);
133
- setProfile(result);
134
- profileRef.current = result;
135
- // Save to cache with 1 hour TTL
136
- setCachedProfile(result);
137
- return result;
138
- } catch (error) {
139
- const err = error instanceof Error ? error : new Error('Failed to fetch profile');
140
- setProfileError(err);
141
- throw err;
142
- } finally {
143
- setIsLoadingProfile(false);
144
- isLoadingRef.current = false;
145
- }
146
- }, []); // Empty dependencies - callback is stable
147
-
148
- // Update profile (full)
149
- const updateProfile = async (data: UserProfileUpdateRequest): Promise<User> => {
150
- const result = await updateMutation(data, api as unknown as API);
151
- await refreshProfile('AccountsContext.updateProfile');
152
- return result as User;
153
- };
154
-
155
- // Partial update profile
156
- const partialUpdateProfile = async (data: PatchedUserProfileUpdateRequest): Promise<User> => {
157
- const result = await partialUpdateMutation(data, api as unknown as API);
158
- await refreshProfile('AccountsContext.partialUpdateProfile');
159
- return result as User;
160
- };
161
-
162
- // Upload avatar
163
- const uploadAvatar = async (formData: FormData): Promise<User> => {
164
- const result = await avatarMutation(formData, api as unknown as API);
165
- await refreshProfile('AccountsContext.uploadAvatar');
166
- return result as User;
167
- };
168
-
169
- // Request OTP
170
- const requestOTP = async (data: OTPRequestRequest): Promise<OTPRequestResponse> => {
171
- const result = await otpRequestMutation(data, api as unknown as API);
172
- return result as OTPRequestResponse;
173
- };
174
-
175
- // Verify OTP
176
- const verifyOTP = async (data: OTPVerifyRequest): Promise<OTPVerifyResponse> => {
177
- const result = await otpVerifyMutation(data, api as unknown as API);
178
-
179
- // Automatically save tokens after successful verification
180
- if (result.access && result.refresh) {
181
- api.setToken(result.access, result.refresh);
182
- // Refresh profile to load user data with new token
183
- await refreshProfile('AccountsContext.verifyOTP');
184
- }
185
-
186
- return result as OTPVerifyResponse;
187
- };
188
-
189
- // Refresh token
190
- const refreshToken = async (refresh: string): Promise<TokenRefresh> => {
191
- const result = await tokenRefreshMutation({ refresh }, api as unknown as API);
192
-
193
- // Automatically save new access token
194
- if (result.access) {
195
- api.setToken(result.access, refresh);
196
- }
197
-
198
- return result as TokenRefresh;
199
- };
200
-
201
- // Logout - clear tokens, profile state, and cache
202
- const logout = useCallback(() => {
203
- api.clearTokens();
204
- setProfile(undefined);
205
- setProfileError(null);
206
- clearProfileCache();
207
- }, []);
208
-
209
- const value: AccountsContextValue = {
210
- profile,
211
- isLoadingProfile,
212
- profileError,
213
- updateProfile,
214
- partialUpdateProfile,
215
- uploadAvatar,
216
- refreshProfile,
217
- requestOTP,
218
- verifyOTP,
219
- refreshToken,
220
- logout,
221
- };
222
-
223
- return (
224
- <AccountsContext.Provider value={value}>
225
- {children}
226
- </AccountsContext.Provider>
227
- );
228
- }
229
-
230
- // ─────────────────────────────────────────────────────────────────────────
231
- // Hook
232
- // ─────────────────────────────────────────────────────────────────────────
233
-
234
- export function useAccountsContext(): AccountsContextValue {
235
- const context = useContext(AccountsContext);
236
- if (!context) {
237
- throw new Error('useAccountsContext must be used within AccountsProvider');
238
- }
239
- return context;
240
- }