feat: add recharts, analytics types, and API client
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
36
frontend/src/api/analytics.ts
Normal file
36
frontend/src/api/analytics.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import apiClient from './client'
|
||||
import type {
|
||||
TeamAnalyticsResponse,
|
||||
PersonalAnalyticsResponse,
|
||||
FlowAnalyticsResponse,
|
||||
AnalyticsPeriod,
|
||||
} from '@/types'
|
||||
|
||||
const analyticsApi = {
|
||||
async getTeamAnalytics(period: AnalyticsPeriod = '30d', engineerId?: string): Promise<TeamAnalyticsResponse> {
|
||||
const params: Record<string, string> = { period }
|
||||
if (engineerId) params.engineer_id = engineerId
|
||||
const response = await apiClient.get<TeamAnalyticsResponse>('/analytics/team', { params })
|
||||
return response.data
|
||||
},
|
||||
|
||||
async getPersonalAnalytics(period: AnalyticsPeriod = '30d'): Promise<PersonalAnalyticsResponse> {
|
||||
const response = await apiClient.get<PersonalAnalyticsResponse>('/analytics/me', { params: { period } })
|
||||
return response.data
|
||||
},
|
||||
|
||||
async getFlowAnalytics(treeId: string, period: AnalyticsPeriod = '30d'): Promise<FlowAnalyticsResponse> {
|
||||
const response = await apiClient.get<FlowAnalyticsResponse>(`/analytics/flows/${treeId}`, { params: { period } })
|
||||
return response.data
|
||||
},
|
||||
|
||||
async rateSession(sessionId: string, rating: number, comment?: string): Promise<void> {
|
||||
await apiClient.post(`/sessions/${sessionId}/rate`, { rating, comment })
|
||||
},
|
||||
|
||||
async submitStepFeedback(stepId: string, sessionId: string, wasHelpful: boolean): Promise<void> {
|
||||
await apiClient.post(`/steps/${stepId}/feedback`, { session_id: sessionId, was_helpful: wasHelpful })
|
||||
},
|
||||
}
|
||||
|
||||
export default analyticsApi
|
||||
@@ -12,3 +12,4 @@ export { default as accountsApi } from './accounts'
|
||||
export { default as adminApi } from './admin'
|
||||
export { treeMarkdownApi } from './treeMarkdown'
|
||||
export { default as pinnedFlowsApi } from './pinnedFlows'
|
||||
export { default as analyticsApi } from './analytics'
|
||||
|
||||
82
frontend/src/types/analytics.ts
Normal file
82
frontend/src/types/analytics.ts
Normal file
@@ -0,0 +1,82 @@
|
||||
export interface OutcomeBreakdown {
|
||||
resolved: number
|
||||
escalated: number
|
||||
workaround: number
|
||||
unresolved: number
|
||||
}
|
||||
|
||||
export interface AnalyticsSummary {
|
||||
total_sessions: number
|
||||
completed_sessions: number
|
||||
completion_rate: number
|
||||
median_duration_minutes: number
|
||||
active_engineers: number
|
||||
outcome_breakdown: OutcomeBreakdown
|
||||
}
|
||||
|
||||
export interface TimeSeriesPoint {
|
||||
date: string
|
||||
sessions: number
|
||||
resolved: number
|
||||
escalated: number
|
||||
workaround: number
|
||||
unresolved: number
|
||||
}
|
||||
|
||||
export interface TopFlow {
|
||||
tree_id: string
|
||||
name: string
|
||||
sessions: number
|
||||
completion_rate: number
|
||||
median_duration_minutes: number
|
||||
avg_csat?: number
|
||||
}
|
||||
|
||||
export interface TopEngineer {
|
||||
user_id: string
|
||||
name: string
|
||||
sessions: number
|
||||
completion_rate: number
|
||||
median_duration_minutes: number
|
||||
}
|
||||
|
||||
export interface TeamAnalyticsResponse {
|
||||
summary: AnalyticsSummary
|
||||
time_series: TimeSeriesPoint[]
|
||||
top_flows: TopFlow[]
|
||||
top_engineers: TopEngineer[]
|
||||
}
|
||||
|
||||
export interface PersonalAnalyticsResponse {
|
||||
summary: AnalyticsSummary
|
||||
time_series: TimeSeriesPoint[]
|
||||
top_flows: TopFlow[]
|
||||
}
|
||||
|
||||
export interface StepFeedbackSummary {
|
||||
node_id: string
|
||||
node_title: string
|
||||
helpful_yes: number
|
||||
helpful_no: number
|
||||
helpful_rate: number
|
||||
visit_count: number
|
||||
dropoff_count: number
|
||||
dropoff_rate: number
|
||||
}
|
||||
|
||||
export interface FlowRatingItem {
|
||||
rating: number
|
||||
comment?: string
|
||||
created_at: string
|
||||
}
|
||||
|
||||
export interface FlowAnalyticsResponse {
|
||||
summary: AnalyticsSummary
|
||||
avg_csat?: number
|
||||
total_ratings: number
|
||||
time_series: TimeSeriesPoint[]
|
||||
step_feedback: StepFeedbackSummary[]
|
||||
recent_comments: FlowRatingItem[]
|
||||
}
|
||||
|
||||
export type AnalyticsPeriod = '7d' | '30d' | '90d'
|
||||
@@ -9,6 +9,7 @@ export * from './folder'
|
||||
export * from './step'
|
||||
export type { Account, Subscription, PlanLimits, SubscriptionDetails, AccountInvite, AccountMember } from './account'
|
||||
export * from './admin'
|
||||
export * from './analytics'
|
||||
|
||||
// API response wrapper types
|
||||
export interface PaginatedResponse<T> {
|
||||
|
||||
Reference in New Issue
Block a user