feat: setup dashboard analytics api (#604)
* feat: setup dashboard analytics api * chore: requested pr fixes * fix: dash analytics server side type * refactor: update Avatar component usage across the dashboard - Replaced custom Avatar component with the new @cio/ui/base/avatar implementation for consistency. - Enhanced avatar rendering with fallback options and improved accessibility. - Cleaned up unused Avatar component files and related functions. - Updated various components to utilize the new Avatar structure, ensuring a uniform appearance and behavior across the application. * chore: remove console.log statements from analytics routes and API calls - Eliminated console.log statements for orgId and siteName in the dash analytics router and DashStatApi class to clean up the code and improve performance. --------- Co-authored-by: Rotimi Best <best@classroomio.com>
This commit is contained in:
co-authored by
Rotimi Best
parent
c7854efae3
commit
9a5aee1ee0
@@ -0,0 +1,34 @@
|
||||
import { BaseApi, classroomio } from '$lib/utils/services/api';
|
||||
|
||||
import type { DashStatsSuccess } from '$lib/features/org/utils/types';
|
||||
|
||||
/**
|
||||
* API class for organization dashboard analytics
|
||||
*/
|
||||
class DashStatApi extends BaseApi {
|
||||
stats = $state<DashStatsSuccess['data']>({
|
||||
enrollments: [],
|
||||
numberOfCourses: 0,
|
||||
revenue: 0,
|
||||
totalStudents: 0,
|
||||
topCourses: []
|
||||
});
|
||||
|
||||
/**
|
||||
* Fetches dashboard statistics for an organization
|
||||
* @param orgId Optional organization ID
|
||||
* @param siteName Optional site name
|
||||
* @returns Organization analytics data (enrollments, courses, revenue, students, top courses)
|
||||
*/
|
||||
async fetchOrgStats({ orgId, siteName }: { orgId?: string; siteName?: string }) {
|
||||
await this.execute<typeof classroomio.dash.stats.$post>({
|
||||
requestFn: () => classroomio.dash.stats.$post({ json: { orgId, siteName } }),
|
||||
logContext: 'fetching organization stats',
|
||||
onSuccess: (response) => {
|
||||
this.stats = response.data;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const dashStatApi = new DashStatApi();
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from './org.svelte';
|
||||
export * from './org-plan.svelte';
|
||||
export * from './dash-stats.svelte';
|
||||
|
||||
@@ -33,6 +33,11 @@ export type CoursesByOrganizationSiteNameSuccess = Extract<
|
||||
|
||||
export type CoursesByOrganizationSiteName = CoursesByOrganizationSiteNameSuccess['data'];
|
||||
|
||||
// dashboard analytics types
|
||||
export type GetDashStatsResponse = typeof classroomio.dash.stats.$post;
|
||||
export type DashStatsResponse = InferResponseType<GetDashStatsResponse> | null;
|
||||
export type DashStatsSuccess = Extract<InferResponseType<GetDashStatsResponse>, { success: true }>;
|
||||
|
||||
export type InviteTeamResponse = (typeof classroomio.organization)[':orgId']['team']['invite']['$post'];
|
||||
export type InviteTeamSuccess = Extract<InferResponseType<InviteTeamResponse>, { success: true }>;
|
||||
export type InviteTeamData = InviteTeamSuccess['data'];
|
||||
|
||||
Reference in New Issue
Block a user