@djangocfg/layouts 2.1.10 → 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.
- package/README.md +53 -161
- package/package.json +6 -6
- package/src/components/RedirectPage/RedirectPage.tsx +1 -1
- package/src/index.ts +0 -6
- package/src/layouts/AppLayout/AppLayout.tsx +1 -1
- package/src/layouts/AppLayout/BaseApp.tsx +1 -1
- package/src/layouts/AuthLayout/AuthContext.tsx +1 -1
- package/src/layouts/AuthLayout/OAuthCallback.tsx +1 -1
- package/src/layouts/AuthLayout/OAuthProviders.tsx +1 -1
- package/src/layouts/PrivateLayout/PrivateLayout.tsx +1 -1
- package/src/layouts/PrivateLayout/components/PrivateHeader.tsx +1 -1
- package/src/layouts/ProfileLayout/components/AvatarSection.tsx +2 -2
- package/src/layouts/PublicLayout/components/PublicMobileDrawer.tsx +1 -1
- package/src/layouts/PublicLayout/components/PublicNavigation.tsx +1 -1
- package/src/layouts/_components/UserMenu.tsx +1 -1
- package/src/layouts/index.ts +0 -2
- package/src/snippets/Analytics/useAnalytics.ts +1 -1
- package/src/snippets/index.ts +0 -3
- package/src/auth/README.md +0 -962
- package/src/auth/context/AccountsContext.tsx +0 -240
- package/src/auth/context/AuthContext.tsx +0 -604
- package/src/auth/context/index.ts +0 -4
- package/src/auth/context/types.ts +0 -68
- package/src/auth/hooks/index.ts +0 -17
- package/src/auth/hooks/useAuthForm.ts +0 -332
- package/src/auth/hooks/useAuthGuard.ts +0 -25
- package/src/auth/hooks/useAuthRedirect.ts +0 -51
- package/src/auth/hooks/useAutoAuth.ts +0 -49
- package/src/auth/hooks/useGithubAuth.ts +0 -184
- package/src/auth/hooks/useLocalStorage.ts +0 -214
- package/src/auth/hooks/useProfileCache.ts +0 -146
- package/src/auth/hooks/useSessionStorage.ts +0 -189
- package/src/auth/index.ts +0 -10
- package/src/auth/middlewares/index.ts +0 -1
- package/src/auth/middlewares/proxy.ts +0 -32
- package/src/auth/server.ts +0 -6
- package/src/auth/utils/errors.ts +0 -34
- package/src/auth/utils/index.ts +0 -2
- package/src/auth/utils/validation.ts +0 -14
- package/src/contexts/LeadsContext.tsx +0 -156
- package/src/contexts/NewsletterContext.tsx +0 -263
- package/src/contexts/SupportContext.tsx +0 -256
- package/src/contexts/index.ts +0 -59
- package/src/contexts/knowbase/ChatContext.tsx +0 -174
- package/src/contexts/knowbase/DocumentsContext.tsx +0 -304
- package/src/contexts/knowbase/SessionsContext.tsx +0 -174
- package/src/contexts/knowbase/index.ts +0 -61
- package/src/contexts/payments/BalancesContext.tsx +0 -65
- package/src/contexts/payments/CurrenciesContext.tsx +0 -66
- package/src/contexts/payments/OverviewContext.tsx +0 -174
- package/src/contexts/payments/PaymentsContext.tsx +0 -132
- package/src/contexts/payments/README.md +0 -201
- package/src/contexts/payments/RootPaymentsContext.tsx +0 -68
- package/src/contexts/payments/index.ts +0 -50
- package/src/layouts/PaymentsLayout/PaymentsLayout.tsx +0 -92
- package/src/layouts/PaymentsLayout/components/CreatePaymentDialog.tsx +0 -291
- package/src/layouts/PaymentsLayout/components/PaymentDetailsDialog.tsx +0 -290
- package/src/layouts/PaymentsLayout/components/index.ts +0 -2
- package/src/layouts/PaymentsLayout/events.ts +0 -47
- package/src/layouts/PaymentsLayout/index.ts +0 -16
- package/src/layouts/PaymentsLayout/types.ts +0 -6
- package/src/layouts/PaymentsLayout/views/overview/components/BalanceCard.tsx +0 -128
- package/src/layouts/PaymentsLayout/views/overview/components/RecentPayments.tsx +0 -142
- package/src/layouts/PaymentsLayout/views/overview/components/index.ts +0 -2
- package/src/layouts/PaymentsLayout/views/overview/index.tsx +0 -20
- package/src/layouts/PaymentsLayout/views/payments/components/PaymentsList.tsx +0 -276
- package/src/layouts/PaymentsLayout/views/payments/components/index.ts +0 -1
- package/src/layouts/PaymentsLayout/views/payments/index.tsx +0 -17
- package/src/layouts/PaymentsLayout/views/transactions/components/TransactionsList.tsx +0 -273
- package/src/layouts/PaymentsLayout/views/transactions/components/index.ts +0 -1
- package/src/layouts/PaymentsLayout/views/transactions/index.tsx +0 -17
- package/src/layouts/SupportLayout/README.md +0 -91
- package/src/layouts/SupportLayout/SupportLayout.tsx +0 -179
- package/src/layouts/SupportLayout/components/CreateTicketDialog.tsx +0 -155
- package/src/layouts/SupportLayout/components/MessageInput.tsx +0 -92
- package/src/layouts/SupportLayout/components/MessageList.tsx +0 -314
- package/src/layouts/SupportLayout/components/TicketCard.tsx +0 -96
- package/src/layouts/SupportLayout/components/TicketList.tsx +0 -153
- package/src/layouts/SupportLayout/components/index.ts +0 -6
- package/src/layouts/SupportLayout/context/SupportLayoutContext.tsx +0 -263
- package/src/layouts/SupportLayout/context/index.ts +0 -2
- package/src/layouts/SupportLayout/events.ts +0 -33
- package/src/layouts/SupportLayout/hooks/index.ts +0 -2
- package/src/layouts/SupportLayout/hooks/useInfiniteMessages.ts +0 -119
- package/src/layouts/SupportLayout/hooks/useInfiniteTickets.ts +0 -92
- package/src/layouts/SupportLayout/index.ts +0 -8
- package/src/layouts/SupportLayout/types.ts +0 -21
- package/src/snippets/Chat/ChatUIContext.tsx +0 -110
- package/src/snippets/Chat/ChatWidget.tsx +0 -476
- package/src/snippets/Chat/README.md +0 -122
- package/src/snippets/Chat/components/MessageInput.tsx +0 -124
- package/src/snippets/Chat/components/MessageList.tsx +0 -169
- package/src/snippets/Chat/components/SessionList.tsx +0 -192
- package/src/snippets/Chat/components/index.ts +0 -9
- package/src/snippets/Chat/hooks/index.ts +0 -6
- package/src/snippets/Chat/hooks/useInfiniteSessions.ts +0 -82
- package/src/snippets/Chat/index.tsx +0 -45
- package/src/snippets/Chat/types.ts +0 -80
- package/src/snippets/ContactForm/ContactForm.tsx +0 -346
- package/src/snippets/ContactForm/ContactFormProvider.tsx +0 -153
- package/src/snippets/ContactForm/ContactInfo.tsx +0 -114
- package/src/snippets/ContactForm/ContactPage.tsx +0 -131
- package/src/snippets/ContactForm/dynamic.tsx +0 -55
- package/src/snippets/ContactForm/index.ts +0 -34
- package/src/snippets/ContactForm/types.ts +0 -110
|
@@ -1,156 +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
|
-
useLeadsList,
|
|
8
|
-
useLeadsRetrieve,
|
|
9
|
-
useCreateLeadsCreate,
|
|
10
|
-
useUpdateLeadsUpdate,
|
|
11
|
-
usePartialUpdateLeadsPartialUpdate,
|
|
12
|
-
useDeleteLeadsDestroy,
|
|
13
|
-
} from '@djangocfg/api';
|
|
14
|
-
import type { API } from '@djangocfg/api';
|
|
15
|
-
import type {
|
|
16
|
-
LeadSubmission,
|
|
17
|
-
LeadSubmissionRequest,
|
|
18
|
-
PatchedLeadSubmissionRequest,
|
|
19
|
-
PaginatedLeadSubmissionList,
|
|
20
|
-
} from '@djangocfg/api';
|
|
21
|
-
|
|
22
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
23
|
-
// Context Type
|
|
24
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
25
|
-
|
|
26
|
-
export interface LeadsContextValue {
|
|
27
|
-
// List operations
|
|
28
|
-
leads: PaginatedLeadSubmissionList | undefined;
|
|
29
|
-
isLoadingLeads: boolean;
|
|
30
|
-
leadsError: Error | undefined;
|
|
31
|
-
refreshLeads: () => Promise<void>;
|
|
32
|
-
|
|
33
|
-
// CRUD operations
|
|
34
|
-
getLead: (id: number) => Promise<LeadSubmission | undefined>;
|
|
35
|
-
createLead: (data: LeadSubmissionRequest) => Promise<LeadSubmission>;
|
|
36
|
-
updateLead: (id: number, data: LeadSubmissionRequest) => Promise<LeadSubmission>;
|
|
37
|
-
partialUpdateLead: (id: number, data: PatchedLeadSubmissionRequest) => Promise<LeadSubmission>;
|
|
38
|
-
deleteLead: (id: number) => Promise<void>;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
42
|
-
// Context
|
|
43
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
44
|
-
|
|
45
|
-
const LeadsContext = createContext<LeadsContextValue | undefined>(undefined);
|
|
46
|
-
|
|
47
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
48
|
-
// Provider
|
|
49
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
50
|
-
|
|
51
|
-
export function LeadsProvider({ children }: { children: ReactNode }) {
|
|
52
|
-
const swrConfig = {
|
|
53
|
-
revalidateOnFocus: false,
|
|
54
|
-
revalidateOnReconnect: false,
|
|
55
|
-
revalidateIfStale: false,
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// List leads
|
|
59
|
-
const {
|
|
60
|
-
data: leads,
|
|
61
|
-
error: leadsError,
|
|
62
|
-
isLoading: isLoadingLeads,
|
|
63
|
-
mutate: mutateLeads,
|
|
64
|
-
} = useLeadsList({}, api as unknown as API);
|
|
65
|
-
|
|
66
|
-
const refreshLeads = async () => {
|
|
67
|
-
await mutateLeads();
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
// Mutations
|
|
71
|
-
const createMutation = useCreateLeadsCreate();
|
|
72
|
-
const updateMutation = useUpdateLeadsUpdate();
|
|
73
|
-
const partialUpdateMutation = usePartialUpdateLeadsPartialUpdate();
|
|
74
|
-
const deleteMutation = useDeleteLeadsDestroy();
|
|
75
|
-
|
|
76
|
-
// Get single lead
|
|
77
|
-
const getLead = async (id: number): Promise<LeadSubmission | undefined> => {
|
|
78
|
-
const { data } = useLeadsRetrieve(id, api as unknown as API);
|
|
79
|
-
return data;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
// Create lead
|
|
83
|
-
const createLead = async (data: LeadSubmissionRequest): Promise<LeadSubmission> => {
|
|
84
|
-
const result = await createMutation(data, api as unknown as API);
|
|
85
|
-
await refreshLeads();
|
|
86
|
-
return result as LeadSubmission;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
// Update lead
|
|
90
|
-
const updateLead = async (id: number, data: LeadSubmissionRequest): Promise<LeadSubmission> => {
|
|
91
|
-
const result = await updateMutation(id, data, api as unknown as API);
|
|
92
|
-
await refreshLeads();
|
|
93
|
-
return result as LeadSubmission;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
// Partial update lead (currently not supported by generated API)
|
|
97
|
-
const partialUpdateLead = async (
|
|
98
|
-
id: number,
|
|
99
|
-
data: PatchedLeadSubmissionRequest
|
|
100
|
-
): Promise<LeadSubmission> => {
|
|
101
|
-
// TODO: Fix generator to include data parameter for PATCH requests
|
|
102
|
-
// const result = await partialUpdateMutation(id, data, api as unknown as API);
|
|
103
|
-
// For now, fallback to full update
|
|
104
|
-
const result = await updateMutation(id, data as unknown as LeadSubmissionRequest, api as unknown as API);
|
|
105
|
-
await refreshLeads();
|
|
106
|
-
return result as LeadSubmission;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
// Delete lead
|
|
110
|
-
const deleteLead = async (id: number): Promise<void> => {
|
|
111
|
-
await deleteMutation(id, api as unknown as API);
|
|
112
|
-
await refreshLeads();
|
|
113
|
-
};
|
|
114
|
-
|
|
115
|
-
const value: LeadsContextValue = {
|
|
116
|
-
leads,
|
|
117
|
-
isLoadingLeads,
|
|
118
|
-
leadsError,
|
|
119
|
-
refreshLeads,
|
|
120
|
-
getLead,
|
|
121
|
-
createLead,
|
|
122
|
-
updateLead,
|
|
123
|
-
partialUpdateLead,
|
|
124
|
-
deleteLead,
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
return (
|
|
128
|
-
<SWRConfig value={swrConfig}>
|
|
129
|
-
<LeadsContext.Provider value={value}>{children}</LeadsContext.Provider>
|
|
130
|
-
</SWRConfig>
|
|
131
|
-
);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
135
|
-
// Hook
|
|
136
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
137
|
-
|
|
138
|
-
export function useLeadsContext(): LeadsContextValue {
|
|
139
|
-
const context = useContext(LeadsContext);
|
|
140
|
-
if (!context) {
|
|
141
|
-
throw new Error('useLeadsContext must be used within LeadsProvider');
|
|
142
|
-
}
|
|
143
|
-
return context;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
147
|
-
// Re-export types for external use
|
|
148
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
149
|
-
|
|
150
|
-
export type {
|
|
151
|
-
LeadSubmission,
|
|
152
|
-
LeadSubmissionRequest,
|
|
153
|
-
PatchedLeadSubmissionRequest,
|
|
154
|
-
PaginatedLeadSubmissionList,
|
|
155
|
-
};
|
|
156
|
-
|
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Newsletter Context
|
|
3
|
-
*
|
|
4
|
-
* Manages newsletter campaigns and subscriptions using generated SWR hooks
|
|
5
|
-
*
|
|
6
|
-
* Features:
|
|
7
|
-
* - Campaign management (create, update, delete, send)
|
|
8
|
-
* - Subscription management (subscribe, unsubscribe)
|
|
9
|
-
* - Campaign lists with pagination
|
|
10
|
-
* - Subscription lists with pagination
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
"use client";
|
|
14
|
-
|
|
15
|
-
import { createContext, useContext, ReactNode } from 'react';
|
|
16
|
-
import { SWRConfig, useSWRConfig } from 'swr';
|
|
17
|
-
import { api } from '@djangocfg/api';
|
|
18
|
-
import {
|
|
19
|
-
useNewsletterCampaignsList,
|
|
20
|
-
useNewsletterCampaignsRetrieve,
|
|
21
|
-
useCreateNewsletterCampaignsCreate,
|
|
22
|
-
useUpdateNewsletterCampaignsUpdate,
|
|
23
|
-
usePartialUpdateNewsletterCampaignsPartialUpdate,
|
|
24
|
-
useDeleteNewsletterCampaignsDestroy,
|
|
25
|
-
useCreateNewsletterCampaignsSendCreate,
|
|
26
|
-
useNewsletterSubscriptionsList,
|
|
27
|
-
useCreateNewsletterSubscribeCreate,
|
|
28
|
-
useCreateNewsletterUnsubscribeCreate,
|
|
29
|
-
} from '@djangocfg/api';
|
|
30
|
-
import type { API } from '@djangocfg/api';
|
|
31
|
-
import type {
|
|
32
|
-
NewsletterCampaign,
|
|
33
|
-
NewsletterCampaignRequest,
|
|
34
|
-
PatchedNewsletterCampaignRequest,
|
|
35
|
-
NewsletterSubscription,
|
|
36
|
-
PaginatedNewsletterCampaignList,
|
|
37
|
-
PaginatedNewsletterSubscriptionList,
|
|
38
|
-
SubscribeRequest,
|
|
39
|
-
SubscribeResponse,
|
|
40
|
-
UnsubscribeRequest,
|
|
41
|
-
SuccessResponse,
|
|
42
|
-
SendCampaignRequest,
|
|
43
|
-
SendCampaignResponse,
|
|
44
|
-
} from '@djangocfg/api';
|
|
45
|
-
|
|
46
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
47
|
-
// Context Type
|
|
48
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
49
|
-
|
|
50
|
-
export interface NewsletterContextValue {
|
|
51
|
-
// Campaigns list state
|
|
52
|
-
campaigns: NewsletterCampaign[];
|
|
53
|
-
isLoadingCampaigns: boolean;
|
|
54
|
-
campaignsError: Error | null;
|
|
55
|
-
pagination?: {
|
|
56
|
-
count: number;
|
|
57
|
-
next: number | null;
|
|
58
|
-
previous: number | null;
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
// Campaign operations
|
|
62
|
-
getCampaign: (id: number) => { data?: NewsletterCampaign; error?: Error; isLoading: boolean };
|
|
63
|
-
createCampaign: (data: NewsletterCampaignRequest) => Promise<NewsletterCampaign>;
|
|
64
|
-
updateCampaign: (id: number, data: NewsletterCampaignRequest) => Promise<NewsletterCampaign>;
|
|
65
|
-
partialUpdateCampaign: (id: number, data: PatchedNewsletterCampaignRequest) => Promise<NewsletterCampaign>;
|
|
66
|
-
deleteCampaign: (id: number) => Promise<void>;
|
|
67
|
-
sendCampaign: (campaignId: number) => Promise<SendCampaignResponse>;
|
|
68
|
-
|
|
69
|
-
// Subscriptions list state
|
|
70
|
-
subscriptions: NewsletterSubscription[];
|
|
71
|
-
isLoadingSubscriptions: boolean;
|
|
72
|
-
subscriptionsError: Error | null;
|
|
73
|
-
|
|
74
|
-
// Subscription operations
|
|
75
|
-
subscribe: (data: SubscribeRequest) => Promise<SubscribeResponse>;
|
|
76
|
-
unsubscribe: (data: UnsubscribeRequest) => Promise<SuccessResponse>;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
80
|
-
// Context
|
|
81
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
82
|
-
|
|
83
|
-
const NewsletterContext = createContext<NewsletterContextValue | undefined>(undefined);
|
|
84
|
-
|
|
85
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
86
|
-
// Provider Props
|
|
87
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
88
|
-
|
|
89
|
-
interface NewsletterProviderProps {
|
|
90
|
-
children: ReactNode;
|
|
91
|
-
page?: number;
|
|
92
|
-
pageSize?: number;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
96
|
-
// Provider Component
|
|
97
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
98
|
-
|
|
99
|
-
export function NewsletterProvider({
|
|
100
|
-
children,
|
|
101
|
-
page = 1,
|
|
102
|
-
pageSize = 100
|
|
103
|
-
}: NewsletterProviderProps) {
|
|
104
|
-
const { mutate } = useSWRConfig();
|
|
105
|
-
|
|
106
|
-
const swrConfig = {
|
|
107
|
-
revalidateOnFocus: false,
|
|
108
|
-
revalidateOnReconnect: false,
|
|
109
|
-
revalidateIfStale: false,
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
// List params for proper revalidation
|
|
113
|
-
const listParams = { page, page_size: pageSize };
|
|
114
|
-
|
|
115
|
-
// Campaigns list
|
|
116
|
-
const {
|
|
117
|
-
data: campaignsData,
|
|
118
|
-
error: campaignsError,
|
|
119
|
-
isLoading: isLoadingCampaigns,
|
|
120
|
-
} = useNewsletterCampaignsList(listParams, api as unknown as API);
|
|
121
|
-
|
|
122
|
-
// Subscriptions list
|
|
123
|
-
const {
|
|
124
|
-
data: subscriptionsData,
|
|
125
|
-
error: subscriptionsError,
|
|
126
|
-
isLoading: isLoadingSubscriptions,
|
|
127
|
-
} = useNewsletterSubscriptionsList(listParams, api as unknown as API);
|
|
128
|
-
|
|
129
|
-
// Mutation hooks
|
|
130
|
-
const createCampaignMutation = useCreateNewsletterCampaignsCreate();
|
|
131
|
-
const updateCampaignMutation = useUpdateNewsletterCampaignsUpdate();
|
|
132
|
-
const partialUpdateCampaignMutation = usePartialUpdateNewsletterCampaignsPartialUpdate();
|
|
133
|
-
const deleteCampaignMutation = useDeleteNewsletterCampaignsDestroy();
|
|
134
|
-
const sendCampaignMutation = useCreateNewsletterCampaignsSendCreate();
|
|
135
|
-
const subscribeMutation = useCreateNewsletterSubscribeCreate();
|
|
136
|
-
const unsubscribeMutation = useCreateNewsletterUnsubscribeCreate();
|
|
137
|
-
|
|
138
|
-
// Extract data from paginated responses
|
|
139
|
-
const campaigns = campaignsData?.results || [];
|
|
140
|
-
const subscriptions = subscriptionsData?.results || [];
|
|
141
|
-
|
|
142
|
-
// Get single campaign
|
|
143
|
-
const getCampaign = (id: number) => {
|
|
144
|
-
const { data, error, isLoading } = useNewsletterCampaignsRetrieve(id, api as unknown as API);
|
|
145
|
-
return { data, error, isLoading };
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// Create campaign
|
|
149
|
-
const createCampaign = async (data: NewsletterCampaignRequest): Promise<NewsletterCampaign> => {
|
|
150
|
-
const result = await createCampaignMutation(data, api as unknown as API);
|
|
151
|
-
await mutate(['cfg-newsletter-campaigns-list', listParams]);
|
|
152
|
-
return result as NewsletterCampaign;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
// Update campaign (full)
|
|
156
|
-
const updateCampaign = async (id: number, data: NewsletterCampaignRequest): Promise<NewsletterCampaign> => {
|
|
157
|
-
const result = await updateCampaignMutation(id, data, api as unknown as API);
|
|
158
|
-
await mutate(['cfg-newsletter-campaigns-list', listParams]);
|
|
159
|
-
await mutate(['cfg-newsletter-campaigns-retrieve', id]);
|
|
160
|
-
return result as NewsletterCampaign;
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
// Partial update campaign (currently not supported by generated API)
|
|
164
|
-
const partialUpdateCampaign = async (id: number, data: PatchedNewsletterCampaignRequest): Promise<NewsletterCampaign> => {
|
|
165
|
-
// TODO: Fix generator to include data parameter for PATCH requests
|
|
166
|
-
// const result = await partialUpdateCampaignMutation(id, data, api as unknown as API);
|
|
167
|
-
// For now, fallback to full update
|
|
168
|
-
const result = await updateCampaignMutation(id, data as NewsletterCampaignRequest, api as unknown as API);
|
|
169
|
-
await mutate(['cfg-newsletter-campaigns-list', listParams]);
|
|
170
|
-
await mutate(['cfg-newsletter-campaigns-retrieve', id]);
|
|
171
|
-
return result as NewsletterCampaign;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
// Delete campaign
|
|
175
|
-
const deleteCampaign = async (id: number): Promise<void> => {
|
|
176
|
-
await deleteCampaignMutation(id, api as unknown as API);
|
|
177
|
-
await mutate(['cfg-newsletter-campaigns-list', listParams]);
|
|
178
|
-
};
|
|
179
|
-
|
|
180
|
-
// Send campaign
|
|
181
|
-
const sendCampaign = async (campaignId: number): Promise<SendCampaignResponse> => {
|
|
182
|
-
const result = await sendCampaignMutation({ campaign_id: campaignId }, api as unknown as API);
|
|
183
|
-
await mutate(['cfg-newsletter-campaigns-list', listParams]);
|
|
184
|
-
await mutate(['cfg-newsletter-campaigns-retrieve', campaignId]);
|
|
185
|
-
return result as SendCampaignResponse;
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
// Subscribe
|
|
189
|
-
const subscribe = async (data: SubscribeRequest): Promise<SubscribeResponse> => {
|
|
190
|
-
const result = await subscribeMutation(data, api as unknown as API);
|
|
191
|
-
await mutate(['cfg-newsletter-subscriptions-list', listParams]);
|
|
192
|
-
return result as SubscribeResponse;
|
|
193
|
-
};
|
|
194
|
-
|
|
195
|
-
// Unsubscribe
|
|
196
|
-
const unsubscribe = async (data: UnsubscribeRequest): Promise<SuccessResponse> => {
|
|
197
|
-
const result = await unsubscribeMutation(data, api as unknown as API);
|
|
198
|
-
await mutate(['cfg-newsletter-subscriptions-list', listParams]);
|
|
199
|
-
return result as SuccessResponse;
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
const value: NewsletterContextValue = {
|
|
203
|
-
campaigns,
|
|
204
|
-
isLoadingCampaigns,
|
|
205
|
-
campaignsError,
|
|
206
|
-
pagination: campaignsData ? {
|
|
207
|
-
count: campaignsData.count,
|
|
208
|
-
next: campaignsData.next_page ?? null,
|
|
209
|
-
previous: campaignsData.previous_page ?? null,
|
|
210
|
-
} : undefined,
|
|
211
|
-
getCampaign,
|
|
212
|
-
createCampaign,
|
|
213
|
-
updateCampaign,
|
|
214
|
-
partialUpdateCampaign,
|
|
215
|
-
deleteCampaign,
|
|
216
|
-
sendCampaign,
|
|
217
|
-
subscriptions,
|
|
218
|
-
isLoadingSubscriptions,
|
|
219
|
-
subscriptionsError,
|
|
220
|
-
subscribe,
|
|
221
|
-
unsubscribe,
|
|
222
|
-
};
|
|
223
|
-
|
|
224
|
-
return (
|
|
225
|
-
<SWRConfig value={swrConfig}>
|
|
226
|
-
<NewsletterContext.Provider value={value}>
|
|
227
|
-
{children}
|
|
228
|
-
</NewsletterContext.Provider>
|
|
229
|
-
</SWRConfig>
|
|
230
|
-
);
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
234
|
-
// Hook
|
|
235
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
236
|
-
|
|
237
|
-
export function useNewsletterContext(): NewsletterContextValue {
|
|
238
|
-
const context = useContext(NewsletterContext);
|
|
239
|
-
if (!context) {
|
|
240
|
-
throw new Error('useNewsletterContext must be used within NewsletterProvider');
|
|
241
|
-
}
|
|
242
|
-
return context;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
246
|
-
// Re-export types for external use
|
|
247
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
248
|
-
|
|
249
|
-
export type {
|
|
250
|
-
NewsletterCampaign,
|
|
251
|
-
NewsletterCampaignRequest,
|
|
252
|
-
PatchedNewsletterCampaignRequest,
|
|
253
|
-
NewsletterSubscription,
|
|
254
|
-
PaginatedNewsletterCampaignList,
|
|
255
|
-
PaginatedNewsletterSubscriptionList,
|
|
256
|
-
SubscribeRequest,
|
|
257
|
-
SubscribeResponse,
|
|
258
|
-
UnsubscribeRequest,
|
|
259
|
-
SuccessResponse,
|
|
260
|
-
SendCampaignRequest,
|
|
261
|
-
SendCampaignResponse,
|
|
262
|
-
};
|
|
263
|
-
|
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
'use client';
|
|
2
|
-
|
|
3
|
-
import React, { createContext, useContext, type ReactNode } from 'react';
|
|
4
|
-
import { api } from '@djangocfg/api';
|
|
5
|
-
import {
|
|
6
|
-
useSupportTicketsList,
|
|
7
|
-
useSupportTicketsRetrieve,
|
|
8
|
-
useCreateSupportTicketsCreate,
|
|
9
|
-
useUpdateSupportTicketsUpdate,
|
|
10
|
-
usePartialUpdateSupportTicketsPartialUpdate,
|
|
11
|
-
useDeleteSupportTicketsDestroy,
|
|
12
|
-
useSupportTicketsMessagesList,
|
|
13
|
-
useSupportTicketsMessagesRetrieve,
|
|
14
|
-
useCreateSupportTicketsMessagesCreate,
|
|
15
|
-
useUpdateSupportTicketsMessagesUpdate,
|
|
16
|
-
usePartialUpdateSupportTicketsMessagesPartialUpdate,
|
|
17
|
-
useDeleteSupportTicketsMessagesDestroy,
|
|
18
|
-
} from '@djangocfg/api';
|
|
19
|
-
import type { API } from '@djangocfg/api';
|
|
20
|
-
import type {
|
|
21
|
-
Ticket,
|
|
22
|
-
TicketRequest,
|
|
23
|
-
PatchedTicketRequest,
|
|
24
|
-
Message,
|
|
25
|
-
MessageRequest,
|
|
26
|
-
MessageCreateRequest,
|
|
27
|
-
PatchedMessageRequest,
|
|
28
|
-
} from '@djangocfg/api';
|
|
29
|
-
|
|
30
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
31
|
-
// Context Type
|
|
32
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
33
|
-
|
|
34
|
-
export interface SupportContextValue {
|
|
35
|
-
// Tickets
|
|
36
|
-
tickets: Ticket[] | undefined;
|
|
37
|
-
isLoadingTickets: boolean;
|
|
38
|
-
ticketsError: Error | undefined;
|
|
39
|
-
refreshTickets: () => Promise<void>;
|
|
40
|
-
|
|
41
|
-
// Ticket operations
|
|
42
|
-
getTicket: (uuid: string) => Promise<Ticket | undefined>;
|
|
43
|
-
createTicket: (data: TicketRequest) => Promise<Ticket>;
|
|
44
|
-
updateTicket: (uuid: string, data: TicketRequest) => Promise<Ticket>;
|
|
45
|
-
partialUpdateTicket: (uuid: string, data: PatchedTicketRequest) => Promise<Ticket>;
|
|
46
|
-
deleteTicket: (uuid: string) => Promise<void>;
|
|
47
|
-
|
|
48
|
-
// Messages
|
|
49
|
-
getMessages: (ticketUuid: string) => Promise<Message[] | undefined>;
|
|
50
|
-
getMessage: (ticketUuid: string, messageUuid: string) => Promise<Message | undefined>;
|
|
51
|
-
createMessage: (ticketUuid: string, data: MessageCreateRequest) => Promise<Message>;
|
|
52
|
-
updateMessage: (ticketUuid: string, messageUuid: string, data: MessageRequest) => Promise<Message>;
|
|
53
|
-
partialUpdateMessage: (
|
|
54
|
-
ticketUuid: string,
|
|
55
|
-
messageUuid: string,
|
|
56
|
-
data: PatchedMessageRequest
|
|
57
|
-
) => Promise<Message>;
|
|
58
|
-
deleteMessage: (ticketUuid: string, messageUuid: string) => Promise<void>;
|
|
59
|
-
refreshMessages: (ticketUuid: string) => Promise<void>;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
63
|
-
// Context
|
|
64
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
65
|
-
|
|
66
|
-
const SupportContext = createContext<SupportContextValue | undefined>(undefined);
|
|
67
|
-
|
|
68
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
69
|
-
// Provider
|
|
70
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
71
|
-
|
|
72
|
-
export function SupportProvider({ children }: { children: ReactNode }) {
|
|
73
|
-
// List tickets (first page only for count)
|
|
74
|
-
const {
|
|
75
|
-
data: ticketsData,
|
|
76
|
-
error: ticketsError,
|
|
77
|
-
isLoading: isLoadingTickets,
|
|
78
|
-
mutate: mutateTickets,
|
|
79
|
-
} = useSupportTicketsList({ page: 1, page_size: 1 }, api as unknown as API);
|
|
80
|
-
|
|
81
|
-
const refreshTickets = async () => {
|
|
82
|
-
await mutateTickets();
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
// Ticket mutations
|
|
86
|
-
const createTicketMutation = useCreateSupportTicketsCreate();
|
|
87
|
-
const updateTicketMutation = useUpdateSupportTicketsUpdate();
|
|
88
|
-
const partialUpdateTicketMutation = usePartialUpdateSupportTicketsPartialUpdate();
|
|
89
|
-
const deleteTicketMutation = useDeleteSupportTicketsDestroy();
|
|
90
|
-
|
|
91
|
-
// Message mutations
|
|
92
|
-
const createMessageMutation = useCreateSupportTicketsMessagesCreate();
|
|
93
|
-
const updateMessageMutation = useUpdateSupportTicketsMessagesUpdate();
|
|
94
|
-
const partialUpdateMessageMutation = usePartialUpdateSupportTicketsMessagesPartialUpdate();
|
|
95
|
-
const deleteMessageMutation = useDeleteSupportTicketsMessagesDestroy();
|
|
96
|
-
|
|
97
|
-
// Get single ticket
|
|
98
|
-
const getTicket = async (uuid: string): Promise<Ticket | undefined> => {
|
|
99
|
-
const { data } = useSupportTicketsRetrieve(uuid, api as unknown as API);
|
|
100
|
-
return data;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
// Create ticket
|
|
104
|
-
const createTicket = async (data: TicketRequest): Promise<Ticket> => {
|
|
105
|
-
const result = await createTicketMutation(data, api as unknown as API);
|
|
106
|
-
await refreshTickets();
|
|
107
|
-
return result as Ticket;
|
|
108
|
-
};
|
|
109
|
-
|
|
110
|
-
// Update ticket
|
|
111
|
-
const updateTicket = async (uuid: string, data: TicketRequest): Promise<Ticket> => {
|
|
112
|
-
const result = await updateTicketMutation(uuid, data, api as unknown as API);
|
|
113
|
-
await refreshTickets();
|
|
114
|
-
return result as Ticket;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
// Partial update ticket (currently not supported by generated API)
|
|
118
|
-
const partialUpdateTicket = async (
|
|
119
|
-
uuid: string,
|
|
120
|
-
data: PatchedTicketRequest
|
|
121
|
-
): Promise<Ticket> => {
|
|
122
|
-
// TODO: Fix generator to include data parameter for PATCH requests
|
|
123
|
-
// const result = await partialUpdateTicketMutation(uuid, data, api as unknown as API);
|
|
124
|
-
// For now, fallback to full update
|
|
125
|
-
const result = await updateTicketMutation(uuid, data as unknown as TicketRequest, api as unknown as API);
|
|
126
|
-
await refreshTickets();
|
|
127
|
-
return result as Ticket;
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
// Delete ticket
|
|
131
|
-
const deleteTicket = async (uuid: string): Promise<void> => {
|
|
132
|
-
await deleteTicketMutation(uuid, api as unknown as API);
|
|
133
|
-
await refreshTickets();
|
|
134
|
-
};
|
|
135
|
-
|
|
136
|
-
// Get messages for ticket
|
|
137
|
-
const getMessages = async (ticketUuid: string): Promise<Message[] | undefined> => {
|
|
138
|
-
const { data } = useSupportTicketsMessagesList(ticketUuid, { page: 1, page_size: 100 }, api as unknown as API);
|
|
139
|
-
return data?.results;
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
// Get single message
|
|
143
|
-
const getMessage = async (
|
|
144
|
-
ticketUuid: string,
|
|
145
|
-
messageUuid: string
|
|
146
|
-
): Promise<Message | undefined> => {
|
|
147
|
-
const { data } = useSupportTicketsMessagesRetrieve(
|
|
148
|
-
ticketUuid,
|
|
149
|
-
messageUuid,
|
|
150
|
-
api as unknown as API
|
|
151
|
-
);
|
|
152
|
-
return data;
|
|
153
|
-
};
|
|
154
|
-
|
|
155
|
-
// Create message
|
|
156
|
-
const createMessage = async (
|
|
157
|
-
ticketUuid: string,
|
|
158
|
-
data: MessageCreateRequest
|
|
159
|
-
): Promise<Message> => {
|
|
160
|
-
const result = await createMessageMutation(ticketUuid, data, api as unknown as API);
|
|
161
|
-
return result as Message;
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
// Update message
|
|
165
|
-
const updateMessage = async (
|
|
166
|
-
ticketUuid: string,
|
|
167
|
-
messageUuid: string,
|
|
168
|
-
data: MessageRequest
|
|
169
|
-
): Promise<Message> => {
|
|
170
|
-
const result = await updateMessageMutation(
|
|
171
|
-
ticketUuid,
|
|
172
|
-
messageUuid,
|
|
173
|
-
data,
|
|
174
|
-
api as unknown as API
|
|
175
|
-
);
|
|
176
|
-
return result as Message;
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
// Partial update message (currently not supported by generated API)
|
|
180
|
-
const partialUpdateMessage = async (
|
|
181
|
-
ticketUuid: string,
|
|
182
|
-
messageUuid: string,
|
|
183
|
-
data: PatchedMessageRequest
|
|
184
|
-
): Promise<Message> => {
|
|
185
|
-
// TODO: Fix generator to include data parameter for PATCH requests
|
|
186
|
-
// const result = await partialUpdateMessageMutation(ticketUuid, messageUuid, data, api as unknown as API);
|
|
187
|
-
// For now, fallback to full update
|
|
188
|
-
const result = await updateMessageMutation(
|
|
189
|
-
ticketUuid,
|
|
190
|
-
messageUuid,
|
|
191
|
-
data as MessageRequest,
|
|
192
|
-
api as unknown as API
|
|
193
|
-
);
|
|
194
|
-
return result as Message;
|
|
195
|
-
};
|
|
196
|
-
|
|
197
|
-
// Delete message
|
|
198
|
-
const deleteMessage = async (ticketUuid: string, messageUuid: string): Promise<void> => {
|
|
199
|
-
await deleteMessageMutation(ticketUuid, messageUuid, api as unknown as API);
|
|
200
|
-
};
|
|
201
|
-
|
|
202
|
-
// Refresh messages for specific ticket
|
|
203
|
-
const refreshMessages = async (ticketUuid: string): Promise<void> => {
|
|
204
|
-
// We'll use mutate from the hook, but we need to get it dynamically
|
|
205
|
-
// For now, we can just refresh tickets which will update everything
|
|
206
|
-
await refreshTickets();
|
|
207
|
-
};
|
|
208
|
-
|
|
209
|
-
const value: SupportContextValue = {
|
|
210
|
-
tickets: ticketsData?.results,
|
|
211
|
-
isLoadingTickets,
|
|
212
|
-
ticketsError,
|
|
213
|
-
refreshTickets,
|
|
214
|
-
getTicket,
|
|
215
|
-
createTicket,
|
|
216
|
-
updateTicket,
|
|
217
|
-
partialUpdateTicket,
|
|
218
|
-
deleteTicket,
|
|
219
|
-
getMessages,
|
|
220
|
-
getMessage,
|
|
221
|
-
createMessage,
|
|
222
|
-
updateMessage,
|
|
223
|
-
partialUpdateMessage,
|
|
224
|
-
deleteMessage,
|
|
225
|
-
refreshMessages,
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
return <SupportContext.Provider value={value}>{children}</SupportContext.Provider>;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
232
|
-
// Hook
|
|
233
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
234
|
-
|
|
235
|
-
export function useSupportContext(): SupportContextValue {
|
|
236
|
-
const context = useContext(SupportContext);
|
|
237
|
-
if (!context) {
|
|
238
|
-
throw new Error('useSupportContext must be used within SupportProvider');
|
|
239
|
-
}
|
|
240
|
-
return context;
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
244
|
-
// Re-export types for external use
|
|
245
|
-
// ─────────────────────────────────────────────────────────────────────────
|
|
246
|
-
|
|
247
|
-
export type {
|
|
248
|
-
Ticket,
|
|
249
|
-
TicketRequest,
|
|
250
|
-
PatchedTicketRequest,
|
|
251
|
-
Message,
|
|
252
|
-
MessageRequest,
|
|
253
|
-
MessageCreateRequest,
|
|
254
|
-
PatchedMessageRequest,
|
|
255
|
-
};
|
|
256
|
-
|