Skip to content

Commit 044af1e

Browse files
committed
cleanup some hooks
1 parent e3a5421 commit 044af1e

File tree

9 files changed

+94
-141
lines changed

9 files changed

+94
-141
lines changed

apps/dashboard/app/(main)/websites/[id]/profiles/_components/profile-utils.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
import { GlobeIcon } from 'lucide-react';
2-
import Image from 'next/image';
32
import {
43
getBrowserIcon,
54
getDeviceTypeIcon,
65
getOSIcon,
76
} from '../../_components/utils/technology-helpers';
87

9-
// Default date range for testing
108
export const getDefaultDateRange = () => {
119
const today = new Date();
1210
const thirtyDaysAgo = new Date(today);
@@ -18,7 +16,6 @@ export const getDefaultDateRange = () => {
1816
};
1917
};
2018

21-
// Helper function to get device icon
2219
export const getDeviceIcon = (device: string) => {
2320
return getDeviceTypeIcon(device, 'md');
2421
};
@@ -67,7 +64,6 @@ export const getCountryFlag = (country: string) => {
6764
);
6865
};
6966

70-
// Helper function to format duration
7167
export const formatDuration = (seconds: number): string => {
7268
if (!seconds || seconds < 60) {
7369
return `${Math.round(seconds || 0)}s`;

apps/dashboard/hooks/use-dynamic-query.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import {
2626
useQuery,
2727
} from '@tanstack/react-query';
2828
import { useCallback, useMemo } from 'react';
29-
import { formatDuration } from '../app/(main)/websites/[id]/profiles/_components/profile-utils';
29+
import { formatDuration } from '@/app/(main)/websites/[id]/profiles/_components/profile-utils';
3030
import { usePreferences } from './use-preferences';
3131

3232
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:3001';
@@ -1193,7 +1193,6 @@ export function useSessionsData(
11931193
* Transform profiles data from API2 format to frontend format
11941194
*/
11951195
function transformProfilesData(profiles: any[]): ProfileData[] {
1196-
// Group profiles by visitor_id to combine sessions
11971196
const profilesByVisitor = new Map();
11981197

11991198
for (const profile of profiles) {

apps/dashboard/hooks/use-funnels.ts

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
11
import type { DateRange } from '@databuddy/shared';
2-
import {
3-
useMutation,
4-
useQueries,
5-
useQuery,
6-
useQueryClient,
7-
} from '@tanstack/react-query';
8-
import { useCallback, useMemo } from 'react';
2+
import { useQueries, useQueryClient } from '@tanstack/react-query';
3+
import { useMemo } from 'react';
94
import { trpc } from '@/lib/trpc';
105

11-
// Types
126
export interface FunnelStep {
137
type: 'PAGE_VIEW' | 'EVENT' | 'CUSTOM';
148
target: string;
159
name: string;
16-
conditions?: Record<string, any>;
10+
conditions?: Record<string, unknown>;
1711
}
1812

1913
export interface FunnelFilter {
@@ -64,7 +58,6 @@ export interface CreateFunnelData {
6458
filters?: FunnelFilter[];
6559
}
6660

67-
// Simple autocomplete data types
6861
export interface AutocompleteData {
6962
customEvents: string[];
7063
pagePaths: string[];
@@ -88,7 +81,6 @@ export interface FunnelAnalyticsByReferrerResult {
8881
conversion_rate: number;
8982
}
9083

91-
// Hook for managing funnels (CRUD operations)
9284
export function useFunnels(websiteId: string, enabled = true) {
9385
const queryClient = useQueryClient();
9486

@@ -107,14 +99,12 @@ export function useFunnels(websiteId: string, enabled = true) {
10799
[query.data]
108100
);
109101

110-
// Create funnel mutation
111102
const createMutation = trpc.funnels.create.useMutation({
112103
onSuccess: () => {
113104
queryClient.invalidateQueries({ queryKey: [['funnels', 'list']] });
114105
},
115106
});
116107

117-
// Update funnel mutation
118108
const updateMutation = trpc.funnels.update.useMutation({
119109
onSuccess: () => {
120110
queryClient.invalidateQueries({ queryKey: [['funnels', 'list']] });
@@ -124,7 +114,6 @@ export function useFunnels(websiteId: string, enabled = true) {
124114
},
125115
});
126116

127-
// Delete funnel mutation
128117
const deleteMutation = trpc.funnels.delete.useMutation({
129118
onSuccess: () => {
130119
queryClient.invalidateQueries({ queryKey: [['funnels', 'list']] });
@@ -140,14 +129,13 @@ export function useFunnels(websiteId: string, enabled = true) {
140129
error: query.error,
141130
refetch: query.refetch,
142131

143-
// Mutations
144-
createFunnel: async (funnelData: CreateFunnelData) => {
132+
createFunnel: (funnelData: CreateFunnelData) => {
145133
return createMutation.mutateAsync({
146134
websiteId,
147135
...funnelData,
148136
});
149137
},
150-
updateFunnel: async ({
138+
updateFunnel: ({
151139
funnelId,
152140
updates,
153141
}: {
@@ -159,11 +147,10 @@ export function useFunnels(websiteId: string, enabled = true) {
159147
...updates,
160148
});
161149
},
162-
deleteFunnel: async (funnelId: string) => {
150+
deleteFunnel: (funnelId: string) => {
163151
return deleteMutation.mutateAsync({ id: funnelId });
164152
},
165153

166-
// Mutation states
167154
isCreating: createMutation.isPending,
168155
isUpdating: updateMutation.isPending,
169156
isDeleting: deleteMutation.isPending,
@@ -174,15 +161,13 @@ export function useFunnels(websiteId: string, enabled = true) {
174161
};
175162
}
176163

177-
// Hook for single funnel details
178164
export function useFunnel(websiteId: string, funnelId: string, enabled = true) {
179165
return trpc.funnels.getById.useQuery(
180166
{ id: funnelId, websiteId },
181167
{ enabled: enabled && !!websiteId && !!funnelId }
182168
);
183169
}
184170

185-
// Hook for funnel analytics data
186171
export function useFunnelAnalytics(
187172
websiteId: string,
188173
funnelId: string,
@@ -200,7 +185,6 @@ export function useFunnelAnalytics(
200185
);
201186
}
202187

203-
// Hook for funnel analytics grouped by referrer
204188
export function useFunnelAnalyticsByReferrer(
205189
websiteId: string,
206190
funnelId: string,
@@ -218,22 +202,18 @@ export function useFunnelAnalyticsByReferrer(
218202
);
219203
}
220204

221-
// Hook for comprehensive funnel analytics using direct endpoints
222205
export function useEnhancedFunnelAnalytics(
223206
websiteId: string,
224207
funnelId: string,
225208
dateRange: DateRange,
226209
enabled = true
227210
) {
228-
// Get funnel definition
229211
const funnelQuery = useFunnel(websiteId, funnelId, enabled);
230212

231-
// Get analytics data using direct endpoint
232213
const analyticsQuery = useFunnelAnalytics(websiteId, funnelId, dateRange, {
233214
enabled,
234215
});
235216

236-
// Process and structure the enhanced data
237217
const enhancedData = useMemo(() => {
238218
const analytics = analyticsQuery.data;
239219

@@ -260,7 +240,6 @@ export function useEnhancedFunnelAnalytics(
260240
};
261241
}, [analyticsQuery.data]);
262242

263-
// Calculate loading and error states
264243
const isLoading = funnelQuery.isLoading || analyticsQuery.isLoading;
265244
const error = funnelQuery.error || analyticsQuery.error;
266245

@@ -275,7 +254,7 @@ export function useEnhancedFunnelAnalytics(
275254
},
276255
};
277256
}
278-
// Hook for funnel comparison
257+
279258
export function useFunnelComparison(
280259
websiteId: string,
281260
funnelIds: string[],
@@ -314,7 +293,6 @@ export function useFunnelComparison(
314293
};
315294
}
316295

317-
// Hook to get funnel performance metrics (for overview cards)
318296
export function useFunnelPerformance(
319297
websiteId: string,
320298
dateRange: DateRange,
@@ -346,7 +324,9 @@ export function useFunnelPerformance(
346324
const performanceData = useMemo(() => {
347325
return results
348326
.map((result, index) => {
349-
if (!result.data) return null;
327+
if (!result.data) {
328+
return null;
329+
}
350330
return {
351331
funnelId: funnels[index].id,
352332
funnelName: funnels[index].name,

apps/dashboard/hooks/use-goals.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import type { GoalFilter } from '@databuddy/shared';
2-
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
2+
import { useQueryClient } from '@tanstack/react-query';
33
import { useMemo } from 'react';
44
import { trpc } from '@/lib/trpc';
55

@@ -66,10 +66,10 @@ export function useGoals(websiteId: string, enabled = true) {
6666
isLoading: query.isLoading,
6767
error: query.error,
6868
refetch: query.refetch,
69-
createGoal: async (goalData: CreateGoalData) => {
69+
createGoal: (goalData: CreateGoalData) => {
7070
return createMutation.mutateAsync(goalData);
7171
},
72-
updateGoal: async ({
72+
updateGoal: ({
7373
goalId,
7474
updates,
7575
}: {
@@ -78,7 +78,7 @@ export function useGoals(websiteId: string, enabled = true) {
7878
}) => {
7979
return updateMutation.mutateAsync({ id: goalId, ...updates });
8080
},
81-
deleteGoal: async (goalId: string) => {
81+
deleteGoal: (goalId: string) => {
8282
return deleteMutation.mutateAsync({ id: goalId });
8383
},
8484
isCreating: createMutation.isPending,

apps/dashboard/hooks/use-mobile.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
import * as React from 'react';
1+
import { useEffect, useState } from 'react';
22

33
const MOBILE_BREAKPOINT = 768;
44

55
export function useIsMobile() {
6-
const [isMobile, setIsMobile] = React.useState<boolean | undefined>(
7-
undefined
8-
);
6+
const [isMobile, setIsMobile] = useState<boolean | undefined>(undefined);
97

10-
React.useEffect(() => {
8+
useEffect(() => {
119
const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
1210
const onChange = () => {
1311
setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);

0 commit comments

Comments
 (0)