@djangocfg/layouts 2.1.10 → 2.1.15

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 (107) 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/ProfileLayout.tsx +2 -2
  13. package/src/layouts/ProfileLayout/components/AvatarSection.tsx +2 -2
  14. package/src/layouts/ProfileLayout/components/ProfileForm.tsx +2 -2
  15. package/src/layouts/PublicLayout/components/PublicMobileDrawer.tsx +1 -1
  16. package/src/layouts/PublicLayout/components/PublicNavigation.tsx +1 -1
  17. package/src/layouts/_components/UserMenu.tsx +1 -1
  18. package/src/layouts/index.ts +0 -2
  19. package/src/snippets/Analytics/useAnalytics.ts +1 -1
  20. package/src/snippets/index.ts +0 -3
  21. package/src/auth/README.md +0 -962
  22. package/src/auth/context/AccountsContext.tsx +0 -240
  23. package/src/auth/context/AuthContext.tsx +0 -604
  24. package/src/auth/context/index.ts +0 -4
  25. package/src/auth/context/types.ts +0 -68
  26. package/src/auth/hooks/index.ts +0 -17
  27. package/src/auth/hooks/useAuthForm.ts +0 -332
  28. package/src/auth/hooks/useAuthGuard.ts +0 -25
  29. package/src/auth/hooks/useAuthRedirect.ts +0 -51
  30. package/src/auth/hooks/useAutoAuth.ts +0 -49
  31. package/src/auth/hooks/useGithubAuth.ts +0 -184
  32. package/src/auth/hooks/useLocalStorage.ts +0 -214
  33. package/src/auth/hooks/useProfileCache.ts +0 -146
  34. package/src/auth/hooks/useSessionStorage.ts +0 -189
  35. package/src/auth/index.ts +0 -10
  36. package/src/auth/middlewares/index.ts +0 -1
  37. package/src/auth/middlewares/proxy.ts +0 -32
  38. package/src/auth/server.ts +0 -6
  39. package/src/auth/utils/errors.ts +0 -34
  40. package/src/auth/utils/index.ts +0 -2
  41. package/src/auth/utils/validation.ts +0 -14
  42. package/src/contexts/LeadsContext.tsx +0 -156
  43. package/src/contexts/NewsletterContext.tsx +0 -263
  44. package/src/contexts/SupportContext.tsx +0 -256
  45. package/src/contexts/index.ts +0 -59
  46. package/src/contexts/knowbase/ChatContext.tsx +0 -174
  47. package/src/contexts/knowbase/DocumentsContext.tsx +0 -304
  48. package/src/contexts/knowbase/SessionsContext.tsx +0 -174
  49. package/src/contexts/knowbase/index.ts +0 -61
  50. package/src/contexts/payments/BalancesContext.tsx +0 -65
  51. package/src/contexts/payments/CurrenciesContext.tsx +0 -66
  52. package/src/contexts/payments/OverviewContext.tsx +0 -174
  53. package/src/contexts/payments/PaymentsContext.tsx +0 -132
  54. package/src/contexts/payments/README.md +0 -201
  55. package/src/contexts/payments/RootPaymentsContext.tsx +0 -68
  56. package/src/contexts/payments/index.ts +0 -50
  57. package/src/layouts/PaymentsLayout/PaymentsLayout.tsx +0 -92
  58. package/src/layouts/PaymentsLayout/components/CreatePaymentDialog.tsx +0 -291
  59. package/src/layouts/PaymentsLayout/components/PaymentDetailsDialog.tsx +0 -290
  60. package/src/layouts/PaymentsLayout/components/index.ts +0 -2
  61. package/src/layouts/PaymentsLayout/events.ts +0 -47
  62. package/src/layouts/PaymentsLayout/index.ts +0 -16
  63. package/src/layouts/PaymentsLayout/types.ts +0 -6
  64. package/src/layouts/PaymentsLayout/views/overview/components/BalanceCard.tsx +0 -128
  65. package/src/layouts/PaymentsLayout/views/overview/components/RecentPayments.tsx +0 -142
  66. package/src/layouts/PaymentsLayout/views/overview/components/index.ts +0 -2
  67. package/src/layouts/PaymentsLayout/views/overview/index.tsx +0 -20
  68. package/src/layouts/PaymentsLayout/views/payments/components/PaymentsList.tsx +0 -276
  69. package/src/layouts/PaymentsLayout/views/payments/components/index.ts +0 -1
  70. package/src/layouts/PaymentsLayout/views/payments/index.tsx +0 -17
  71. package/src/layouts/PaymentsLayout/views/transactions/components/TransactionsList.tsx +0 -273
  72. package/src/layouts/PaymentsLayout/views/transactions/components/index.ts +0 -1
  73. package/src/layouts/PaymentsLayout/views/transactions/index.tsx +0 -17
  74. package/src/layouts/SupportLayout/README.md +0 -91
  75. package/src/layouts/SupportLayout/SupportLayout.tsx +0 -179
  76. package/src/layouts/SupportLayout/components/CreateTicketDialog.tsx +0 -155
  77. package/src/layouts/SupportLayout/components/MessageInput.tsx +0 -92
  78. package/src/layouts/SupportLayout/components/MessageList.tsx +0 -314
  79. package/src/layouts/SupportLayout/components/TicketCard.tsx +0 -96
  80. package/src/layouts/SupportLayout/components/TicketList.tsx +0 -153
  81. package/src/layouts/SupportLayout/components/index.ts +0 -6
  82. package/src/layouts/SupportLayout/context/SupportLayoutContext.tsx +0 -263
  83. package/src/layouts/SupportLayout/context/index.ts +0 -2
  84. package/src/layouts/SupportLayout/events.ts +0 -33
  85. package/src/layouts/SupportLayout/hooks/index.ts +0 -2
  86. package/src/layouts/SupportLayout/hooks/useInfiniteMessages.ts +0 -119
  87. package/src/layouts/SupportLayout/hooks/useInfiniteTickets.ts +0 -92
  88. package/src/layouts/SupportLayout/index.ts +0 -8
  89. package/src/layouts/SupportLayout/types.ts +0 -21
  90. package/src/snippets/Chat/ChatUIContext.tsx +0 -110
  91. package/src/snippets/Chat/ChatWidget.tsx +0 -476
  92. package/src/snippets/Chat/README.md +0 -122
  93. package/src/snippets/Chat/components/MessageInput.tsx +0 -124
  94. package/src/snippets/Chat/components/MessageList.tsx +0 -169
  95. package/src/snippets/Chat/components/SessionList.tsx +0 -192
  96. package/src/snippets/Chat/components/index.ts +0 -9
  97. package/src/snippets/Chat/hooks/index.ts +0 -6
  98. package/src/snippets/Chat/hooks/useInfiniteSessions.ts +0 -82
  99. package/src/snippets/Chat/index.tsx +0 -45
  100. package/src/snippets/Chat/types.ts +0 -80
  101. package/src/snippets/ContactForm/ContactForm.tsx +0 -346
  102. package/src/snippets/ContactForm/ContactFormProvider.tsx +0 -153
  103. package/src/snippets/ContactForm/ContactInfo.tsx +0 -114
  104. package/src/snippets/ContactForm/ContactPage.tsx +0 -131
  105. package/src/snippets/ContactForm/dynamic.tsx +0 -55
  106. package/src/snippets/ContactForm/index.ts +0 -34
  107. package/src/snippets/ContactForm/types.ts +0 -110
@@ -1,174 +0,0 @@
1
- /**
2
- * Knowbase Sessions Context
3
- * Context for managing chat sessions
4
- */
5
-
6
- 'use client';
7
-
8
- import React, { createContext, useContext, type ReactNode } from 'react';
9
- import { api } from '@djangocfg/api';
10
- import {
11
- useKnowbaseAdminSessionsList,
12
- useKnowbaseAdminSessionsRetrieve,
13
- useCreateKnowbaseAdminSessionsCreate,
14
- useUpdateKnowbaseAdminSessionsUpdate,
15
- usePartialUpdateKnowbaseAdminSessionsPartialUpdate,
16
- useDeleteKnowbaseAdminSessionsDestroy,
17
- useCreateKnowbaseAdminSessionsActivateCreate,
18
- useCreateKnowbaseAdminSessionsArchiveCreate,
19
- } from '@djangocfg/api';
20
- import type { API } from '@djangocfg/api';
21
- import type {
22
- PaginatedChatSessionList,
23
- ChatSession,
24
- ChatSessionCreateRequest,
25
- ChatSessionRequest,
26
- PatchedChatSessionRequest,
27
- } from '@djangocfg/api';
28
-
29
- // ─────────────────────────────────────────────────────────────────────────
30
- // Context Type
31
- // ─────────────────────────────────────────────────────────────────────────
32
-
33
- export interface KnowbaseSessionsContextValue {
34
- // Sessions list
35
- sessions: PaginatedChatSessionList | undefined;
36
- isLoadingSessions: boolean;
37
- sessionsError: Error | undefined;
38
- refreshSessions: () => Promise<void>;
39
-
40
- // Session operations
41
- getSession: (id: string) => Promise<ChatSession | undefined>;
42
- createSession: (data: ChatSessionCreateRequest) => Promise<ChatSession>;
43
- updateSession: (id: string, data: ChatSessionRequest) => Promise<ChatSession>;
44
- partialUpdateSession: (id: string, data: PatchedChatSessionRequest) => Promise<ChatSession>;
45
- deleteSession: (id: string) => Promise<void>;
46
-
47
- // Session actions
48
- activateSession: (id: string, data: ChatSessionRequest) => Promise<ChatSession>;
49
- archiveSession: (id: string, data: ChatSessionRequest) => Promise<ChatSession>;
50
- }
51
-
52
- // ─────────────────────────────────────────────────────────────────────────
53
- // Context
54
- // ─────────────────────────────────────────────────────────────────────────
55
-
56
- const KnowbaseSessionsContext = createContext<KnowbaseSessionsContextValue | undefined>(undefined);
57
-
58
- // ─────────────────────────────────────────────────────────────────────────
59
- // Provider
60
- // ─────────────────────────────────────────────────────────────────────────
61
-
62
- export function KnowbaseSessionsProvider({ children }: { children: ReactNode }) {
63
- // List sessions (first page only for count)
64
- const {
65
- data: sessions,
66
- error: sessionsError,
67
- isLoading: isLoadingSessions,
68
- mutate: mutateSessions,
69
- } = useKnowbaseAdminSessionsList({ page: 1, page_size: 1 }, api as unknown as API);
70
-
71
- const refreshSessions = async () => {
72
- await mutateSessions();
73
- };
74
-
75
- // Mutations
76
- const createSessionMutation = useCreateKnowbaseAdminSessionsCreate();
77
- const updateSessionMutation = useUpdateKnowbaseAdminSessionsUpdate();
78
- const partialUpdateSessionMutation = usePartialUpdateKnowbaseAdminSessionsPartialUpdate();
79
- const deleteSessionMutation = useDeleteKnowbaseAdminSessionsDestroy();
80
- const activateSessionMutation = useCreateKnowbaseAdminSessionsActivateCreate();
81
- const archiveSessionMutation = useCreateKnowbaseAdminSessionsArchiveCreate();
82
-
83
- // Get single session
84
- const getSession = async (id: string): Promise<ChatSession | undefined> => {
85
- const { data } = useKnowbaseAdminSessionsRetrieve(id, api as unknown as API);
86
- return data;
87
- };
88
-
89
- // Create session
90
- const createSession = async (data: ChatSessionCreateRequest): Promise<ChatSession> => {
91
- const result = await createSessionMutation(data, api as unknown as API);
92
- await refreshSessions();
93
- return result as ChatSession;
94
- };
95
-
96
- // Update session
97
- const updateSession = async (id: string, data: ChatSessionRequest): Promise<ChatSession> => {
98
- const result = await updateSessionMutation(id, data, api as unknown as API);
99
- await refreshSessions();
100
- return result as ChatSession;
101
- };
102
-
103
- // Partial update session
104
- const partialUpdateSession = async (
105
- id: string,
106
- data: PatchedChatSessionRequest
107
- ): Promise<ChatSession> => {
108
- const result = await partialUpdateSessionMutation(id, data, api as unknown as API);
109
- await refreshSessions();
110
- return result as ChatSession;
111
- };
112
-
113
- // Delete session
114
- const deleteSession = async (id: string): Promise<void> => {
115
- await deleteSessionMutation(id, api as unknown as API);
116
- await refreshSessions();
117
- };
118
-
119
- // Activate session
120
- const activateSession = async (id: string, data: ChatSessionRequest): Promise<ChatSession> => {
121
- const result = await activateSessionMutation(id, data, api as unknown as API);
122
- await refreshSessions();
123
- return result as ChatSession;
124
- };
125
-
126
- // Archive session
127
- const archiveSession = async (id: string, data: ChatSessionRequest): Promise<ChatSession> => {
128
- const result = await archiveSessionMutation(id, data, api as unknown as API);
129
- await refreshSessions();
130
- return result as ChatSession;
131
- };
132
-
133
- const value: KnowbaseSessionsContextValue = {
134
- sessions,
135
- isLoadingSessions,
136
- sessionsError,
137
- refreshSessions,
138
- getSession,
139
- createSession,
140
- updateSession,
141
- partialUpdateSession,
142
- deleteSession,
143
- activateSession,
144
- archiveSession,
145
- };
146
-
147
- return (
148
- <KnowbaseSessionsContext.Provider value={value}>{children}</KnowbaseSessionsContext.Provider>
149
- );
150
- }
151
-
152
- // ─────────────────────────────────────────────────────────────────────────
153
- // Hook
154
- // ─────────────────────────────────────────────────────────────────────────
155
-
156
- export function useKnowbaseSessionsContext(): KnowbaseSessionsContextValue {
157
- const context = useContext(KnowbaseSessionsContext);
158
- if (!context) {
159
- throw new Error('useKnowbaseSessionsContext must be used within KnowbaseSessionsProvider');
160
- }
161
- return context;
162
- }
163
-
164
- // ─────────────────────────────────────────────────────────────────────────
165
- // Re-export types for external use
166
- // ─────────────────────────────────────────────────────────────────────────
167
-
168
- export type {
169
- ChatSession,
170
- ChatSessionCreateRequest,
171
- ChatSessionRequest,
172
- PatchedChatSessionRequest,
173
- } from '@djangocfg/api';
174
-
@@ -1,61 +0,0 @@
1
- /**
2
- * Knowbase Contexts
3
- *
4
- * Contexts for knowledge base functionality:
5
- * - ChatContext: RAG-powered chat
6
- * - DocumentsContext: Documents and archives management
7
- * - SessionsContext: Chat sessions management
8
- */
9
-
10
- 'use client';
11
-
12
- // Chat Context
13
- export {
14
- KnowbaseChatProvider,
15
- useKnowbaseChatContext,
16
- } from './ChatContext';
17
- export type {
18
- KnowbaseChatContextValue,
19
- ChatResponse,
20
- ChatResponseRequest,
21
- PatchedChatResponseRequest,
22
- ChatHistory,
23
- ChatQueryRequest,
24
- ChatMessage,
25
- ChatSource,
26
- } from './ChatContext';
27
-
28
- // Documents Context
29
- export {
30
- KnowbaseDocumentsProvider,
31
- useKnowbaseDocumentsContext,
32
- } from './DocumentsContext';
33
- export type {
34
- KnowbaseDocumentsContextValue,
35
- Document,
36
- DocumentCreateRequest,
37
- DocumentRequest,
38
- PatchedDocumentRequest,
39
- DocumentProcessingStatus,
40
- DocumentStats,
41
- DocumentArchive,
42
- DocumentArchiveDetail,
43
- PatchedDocumentArchiveRequest,
44
- ArchiveProcessingResult,
45
- ArchiveStatistics,
46
- } from './DocumentsContext';
47
-
48
- // Sessions Context
49
- export {
50
- KnowbaseSessionsProvider,
51
- useKnowbaseSessionsContext,
52
- } from './SessionsContext';
53
- export type {
54
- KnowbaseSessionsContextValue,
55
- ChatSession,
56
- ChatSessionCreateRequest,
57
- ChatSessionRequest,
58
- PatchedChatSessionRequest,
59
- } from './SessionsContext';
60
-
61
-
@@ -1,65 +0,0 @@
1
- 'use client';
2
-
3
- import React, { createContext, useContext, type ReactNode } from 'react';
4
- import { api } from '@djangocfg/api';
5
- import {
6
- usePaymentsBalanceRetrieve,
7
- } from '@djangocfg/api';
8
- import type { API } from '@djangocfg/api';
9
-
10
- // ─────────────────────────────────────────────────────────────────────────
11
- // Context Type
12
- // ─────────────────────────────────────────────────────────────────────────
13
-
14
- export interface BalancesContextValue {
15
- // Balance data - single endpoint returns balance info
16
- balance: any | undefined;
17
- isLoadingBalance: boolean;
18
- balanceError: Error | undefined;
19
- refreshBalance: () => Promise<void>;
20
- }
21
-
22
- // ─────────────────────────────────────────────────────────────────────────
23
- // Context
24
- // ─────────────────────────────────────────────────────────────────────────
25
-
26
- const BalancesContext = createContext<BalancesContextValue | undefined>(undefined);
27
-
28
- // ─────────────────────────────────────────────────────────────────────────
29
- // Provider
30
- // ─────────────────────────────────────────────────────────────────────────
31
-
32
- export function BalancesProvider({ children }: { children: ReactNode }) {
33
- // Get balance from /cfg/payments/balance/
34
- const {
35
- data: balance,
36
- error: balanceError,
37
- isLoading: isLoadingBalance,
38
- mutate: mutateBalance,
39
- } = usePaymentsBalanceRetrieve(api as unknown as API);
40
-
41
- const refreshBalance = async () => {
42
- await mutateBalance();
43
- };
44
-
45
- const value: BalancesContextValue = {
46
- balance,
47
- isLoadingBalance,
48
- balanceError,
49
- refreshBalance,
50
- };
51
-
52
- return <BalancesContext.Provider value={value}>{children}</BalancesContext.Provider>;
53
- }
54
-
55
- // ─────────────────────────────────────────────────────────────────────────
56
- // Hook
57
- // ─────────────────────────────────────────────────────────────────────────
58
-
59
- export function useBalancesContext(): BalancesContextValue {
60
- const context = useContext(BalancesContext);
61
- if (!context) {
62
- throw new Error('useBalancesContext must be used within BalancesProvider');
63
- }
64
- return context;
65
- }
@@ -1,66 +0,0 @@
1
- 'use client';
2
-
3
- import React, { createContext, useContext, type ReactNode } from 'react';
4
- import { api } from '@djangocfg/api';
5
- import {
6
- usePaymentsCurrenciesList,
7
- } from '@djangocfg/api';
8
- import type { API } from '@djangocfg/api';
9
-
10
- // ─────────────────────────────────────────────────────────────────────────
11
- // Context Type
12
- // ─────────────────────────────────────────────────────────────────────────
13
-
14
- export interface CurrenciesContextValue {
15
- // Currencies data - returns raw response with currencies array
16
- currencies: any | undefined;
17
- isLoadingCurrencies: boolean;
18
- currenciesError: Error | undefined;
19
- refreshCurrencies: () => Promise<void>;
20
- }
21
-
22
- // ─────────────────────────────────────────────────────────────────────────
23
- // Context
24
- // ─────────────────────────────────────────────────────────────────────────
25
-
26
- const CurrenciesContext = createContext<CurrenciesContextValue | undefined>(undefined);
27
-
28
- // ─────────────────────────────────────────────────────────────────────────
29
- // Provider
30
- // ─────────────────────────────────────────────────────────────────────────
31
-
32
- export function CurrenciesProvider({ children }: { children: ReactNode }) {
33
- // Get currencies list from /cfg/payments/currencies/
34
- const {
35
- data: currencies,
36
- error: currenciesError,
37
- isLoading: isLoadingCurrencies,
38
- mutate: mutateCurrencies,
39
- } = usePaymentsCurrenciesList(api as unknown as API);
40
-
41
- const refreshCurrencies = async () => {
42
- await mutateCurrencies();
43
- };
44
-
45
- const value: CurrenciesContextValue = {
46
- currencies,
47
- isLoadingCurrencies,
48
- currenciesError,
49
- refreshCurrencies,
50
- };
51
-
52
- return <CurrenciesContext.Provider value={value}>{children}</CurrenciesContext.Provider>;
53
- }
54
-
55
- // ─────────────────────────────────────────────────────────────────────────
56
- // Hook
57
- // ─────────────────────────────────────────────────────────────────────────
58
-
59
- export function useCurrenciesContext(): CurrenciesContextValue {
60
- const context = useContext(CurrenciesContext);
61
- if (!context) {
62
- throw new Error('useCurrenciesContext must be used within CurrenciesProvider');
63
- }
64
- return context;
65
- }
66
-
@@ -1,174 +0,0 @@
1
- 'use client';
2
-
3
- import React, { createContext, useContext, type ReactNode } from 'react';
4
- import { SWRConfig } from 'swr';
5
- import { api } from '@djangocfg/api';
6
- import {
7
- usePaymentsBalanceRetrieve,
8
- usePaymentsPaymentsList,
9
- usePaymentsTransactionsList,
10
- useCreatePaymentsPaymentsCreateCreate,
11
- } from '@djangocfg/api';
12
- import type { API } from '@djangocfg/api';
13
- import type {
14
- PaginatedPaymentListList,
15
- PaymentList,
16
- } from '@djangocfg/api';
17
-
18
- // ─────────────────────────────────────────────────────────────────────────
19
- // Context Type
20
- // ─────────────────────────────────────────────────────────────────────────
21
-
22
- export interface OverviewContextValue {
23
- // Balance data
24
- balance: any | undefined;
25
- isLoadingBalance: boolean;
26
- balanceError: Error | undefined;
27
- refreshBalance: () => Promise<void>;
28
-
29
- // Payments data
30
- payments: PaginatedPaymentListList | undefined;
31
- isLoadingPayments: boolean;
32
- paymentsError: Error | undefined;
33
- refreshPayments: () => Promise<void>;
34
-
35
- // Transactions data
36
- transactions: any | undefined;
37
- isLoadingTransactions: boolean;
38
- transactionsError: Error | undefined;
39
- refreshTransactions: () => Promise<void>;
40
-
41
- // Payment operations
42
- createPayment: () => Promise<PaymentList>;
43
-
44
- // Loading states
45
- isLoadingOverview: boolean;
46
- overviewError: Error | undefined;
47
-
48
- // Operations
49
- refreshOverview: () => Promise<void>;
50
- }
51
-
52
- // ─────────────────────────────────────────────────────────────────────────
53
- // Context
54
- // ─────────────────────────────────────────────────────────────────────────
55
-
56
- const OverviewContext = createContext<OverviewContextValue | undefined>(undefined);
57
-
58
- // ─────────────────────────────────────────────────────────────────────────
59
- // Provider
60
- // ─────────────────────────────────────────────────────────────────────────
61
-
62
- export function OverviewProvider({ children }: { children: ReactNode }) {
63
- // SWR config for overview data - disable auto-revalidation
64
- const swrConfig = {
65
- revalidateOnFocus: false,
66
- revalidateOnReconnect: false,
67
- revalidateIfStale: false,
68
- };
69
-
70
- // Balance
71
- const {
72
- data: balance,
73
- error: balanceError,
74
- isLoading: isLoadingBalance,
75
- mutate: mutateBalance,
76
- } = usePaymentsBalanceRetrieve(api as unknown as API);
77
-
78
- // Payments list
79
- const {
80
- data: payments,
81
- error: paymentsError,
82
- isLoading: isLoadingPayments,
83
- mutate: mutatePayments,
84
- } = usePaymentsPaymentsList({}, api as unknown as API);
85
-
86
- // Transactions
87
- const {
88
- data: transactions,
89
- error: transactionsError,
90
- isLoading: isLoadingTransactions,
91
- mutate: mutateTransactions,
92
- } = usePaymentsTransactionsList({}, api as unknown as API);
93
-
94
- // Payment mutations
95
- const createPaymentMutation = useCreatePaymentsPaymentsCreateCreate();
96
-
97
- const isLoadingOverview = isLoadingBalance || isLoadingPayments || isLoadingTransactions;
98
- const overviewError = balanceError || paymentsError || transactionsError;
99
-
100
- const refreshBalance = async () => {
101
- await mutateBalance();
102
- };
103
-
104
- const refreshPayments = async () => {
105
- await mutatePayments();
106
- };
107
-
108
- const refreshTransactions = async () => {
109
- await mutateTransactions();
110
- };
111
-
112
- const refreshOverview = async () => {
113
- await Promise.all([
114
- mutateBalance(),
115
- mutatePayments(),
116
- mutateTransactions(),
117
- ]);
118
- };
119
-
120
- // Create payment
121
- const createPayment = async (): Promise<PaymentList> => {
122
- const result = await createPaymentMutation(api as unknown as API);
123
- // Refresh overview data to show new payment
124
- await refreshOverview();
125
- return result as PaymentList;
126
- };
127
-
128
- const value: OverviewContextValue = {
129
- balance,
130
- isLoadingBalance,
131
- balanceError,
132
- refreshBalance,
133
- payments,
134
- isLoadingPayments,
135
- paymentsError,
136
- refreshPayments,
137
- transactions,
138
- isLoadingTransactions,
139
- transactionsError,
140
- refreshTransactions,
141
- createPayment,
142
- isLoadingOverview,
143
- overviewError,
144
- refreshOverview,
145
- };
146
-
147
- return (
148
- <SWRConfig value={swrConfig}>
149
- <OverviewContext.Provider value={value}>{children}</OverviewContext.Provider>
150
- </SWRConfig>
151
- );
152
- }
153
-
154
- // ─────────────────────────────────────────────────────────────────────────
155
- // Hook
156
- // ─────────────────────────────────────────────────────────────────────────
157
-
158
- export function useOverviewContext(): OverviewContextValue {
159
- const context = useContext(OverviewContext);
160
- if (!context) {
161
- throw new Error('useOverviewContext must be used within OverviewProvider');
162
- }
163
- return context;
164
- }
165
-
166
- // ─────────────────────────────────────────────────────────────────────────
167
- // Re-export types
168
- // ─────────────────────────────────────────────────────────────────────────
169
-
170
- export type {
171
- PaginatedPaymentListList,
172
- PaymentList,
173
- };
174
-
@@ -1,132 +0,0 @@
1
- 'use client';
2
-
3
- import React, { createContext, useContext, type ReactNode } from 'react';
4
- import { api } from '@djangocfg/api';
5
- import {
6
- usePaymentsPaymentsList,
7
- usePaymentsPaymentsRetrieve,
8
- useCreatePaymentsPaymentsCreateCreate,
9
- useCreatePaymentsPaymentsConfirmCreate,
10
- usePaymentsPaymentsStatusRetrieve,
11
- } from '@djangocfg/api';
12
- import { getPaymentsPaymentsRetrieve } from '@djangocfg/api/cfg/generated/fetchers';
13
- import { APILogger } from '@djangocfg/api';
14
- import type { API } from '@djangocfg/api';
15
- import type {
16
- PaginatedPaymentListList,
17
- PaymentDetail,
18
- PaymentList,
19
- } from '@djangocfg/api';
20
-
21
- // ─────────────────────────────────────────────────────────────────────────
22
- // Context Type
23
- // ─────────────────────────────────────────────────────────────────────────
24
-
25
- export interface PaymentsContextValue {
26
- // List
27
- payments: PaginatedPaymentListList | undefined;
28
- isLoadingPayments: boolean;
29
- paymentsError: Error | undefined;
30
- refreshPayments: () => Promise<void>;
31
-
32
- // Operations
33
- getPayment: (id: string) => Promise<PaymentDetail | undefined>;
34
- createPayment: () => Promise<PaymentList>;
35
- confirmPayment: (id: string) => Promise<PaymentList>;
36
- checkPaymentStatus: (id: string) => Promise<PaymentList | undefined>;
37
- }
38
-
39
- // ─────────────────────────────────────────────────────────────────────────
40
- // Context
41
- // ─────────────────────────────────────────────────────────────────────────
42
-
43
- const PaymentsContext = createContext<PaymentsContextValue | undefined>(undefined);
44
-
45
- // ─────────────────────────────────────────────────────────────────────────
46
- // Provider
47
- // ─────────────────────────────────────────────────────────────────────────
48
-
49
- export function PaymentsProvider({ children }: { children: ReactNode }) {
50
- // List payments (first page only for count)
51
- const {
52
- data: payments,
53
- error: paymentsError,
54
- isLoading: isLoadingPayments,
55
- mutate: mutatePayments,
56
- } = usePaymentsPaymentsList({ page: 1, page_size: 1 }, api as unknown as API);
57
-
58
- const refreshPayments = async () => {
59
- await mutatePayments();
60
- };
61
-
62
- // Mutations
63
- const createPaymentMutation = useCreatePaymentsPaymentsCreateCreate();
64
- const confirmPaymentMutation = useCreatePaymentsPaymentsConfirmCreate();
65
-
66
- // Get single payment
67
- const getPayment = async (id: string): Promise<PaymentDetail | undefined> => {
68
- try {
69
- const result = await getPaymentsPaymentsRetrieve(id, api as unknown as API);
70
- return result;
71
- } catch (error) {
72
- new APILogger().error('Failed to retrieve payment:', error);
73
- return undefined;
74
- }
75
- };
76
-
77
- // Create payment
78
- const createPayment = async (): Promise<PaymentList> => {
79
- const result = await createPaymentMutation(api as unknown as API);
80
- await refreshPayments();
81
- return result as PaymentList;
82
- };
83
-
84
- // Confirm payment (user clicked "I paid")
85
- const confirmPayment = async (id: string): Promise<PaymentList> => {
86
- const result = await confirmPaymentMutation(id, api as unknown as API);
87
- await refreshPayments();
88
- return result as PaymentList;
89
- };
90
-
91
- // Check payment status
92
- const checkPaymentStatus = async (id: string): Promise<PaymentList | undefined> => {
93
- const { data } = usePaymentsPaymentsStatusRetrieve(id, api as unknown as API);
94
- return data;
95
- };
96
-
97
- const value: PaymentsContextValue = {
98
- payments,
99
- isLoadingPayments,
100
- paymentsError,
101
- refreshPayments,
102
- getPayment,
103
- createPayment,
104
- confirmPayment,
105
- checkPaymentStatus,
106
- };
107
-
108
- return <PaymentsContext.Provider value={value}>{children}</PaymentsContext.Provider>;
109
- }
110
-
111
- // ─────────────────────────────────────────────────────────────────────────
112
- // Hook
113
- // ─────────────────────────────────────────────────────────────────────────
114
-
115
- export function usePaymentsContext(): PaymentsContextValue {
116
- const context = useContext(PaymentsContext);
117
- if (!context) {
118
- throw new Error('usePaymentsContext must be used within PaymentsProvider');
119
- }
120
- return context;
121
- }
122
-
123
- // ─────────────────────────────────────────────────────────────────────────
124
- // Re-export types
125
- // ─────────────────────────────────────────────────────────────────────────
126
-
127
- export type {
128
- PaginatedPaymentListList,
129
- PaymentDetail,
130
- PaymentList,
131
- };
132
-