analytica-frontend-lib
Version:
Repositório público dos componentes utilizados nas plataformas da Analytica Ensino
210 lines • 7.32 kB
TypeScript
import { z } from 'zod';
import { ActivityApiStatus } from '../types/activitiesHistory';
import type { ActivityHistoryResponse, ActivityTableItem, ActivitiesHistoryApiResponse, ActivityHistoryFilters, ActivityPagination } from '../types/activitiesHistory';
export declare const activitiesHistoryApiResponseSchema: z.ZodObject<{
message: z.ZodString;
data: z.ZodObject<{
activities: z.ZodArray<z.ZodObject<{
id: z.ZodString;
title: z.ZodString;
startDate: z.ZodNullable<z.ZodString>;
finalDate: z.ZodNullable<z.ZodString>;
status: z.ZodNativeEnum<typeof ActivityApiStatus>;
completionPercentage: z.ZodNumber;
subjectId: z.ZodNullable<z.ZodOptional<z.ZodString>>;
schoolId: z.ZodOptional<z.ZodString>;
schoolName: z.ZodOptional<z.ZodString>;
year: z.ZodOptional<z.ZodString>;
className: z.ZodOptional<z.ZodString>;
subjectName: z.ZodOptional<z.ZodString>;
}, "strip", z.ZodTypeAny, {
id: string;
title: string;
status: ActivityApiStatus;
startDate: string | null;
finalDate: string | null;
completionPercentage: number;
className?: string | undefined;
schoolName?: string | undefined;
year?: string | undefined;
subjectName?: string | undefined;
schoolId?: string | undefined;
subjectId?: string | null | undefined;
}, {
id: string;
title: string;
status: ActivityApiStatus;
startDate: string | null;
finalDate: string | null;
completionPercentage: number;
className?: string | undefined;
schoolName?: string | undefined;
year?: string | undefined;
subjectName?: string | undefined;
schoolId?: string | undefined;
subjectId?: string | null | undefined;
}>, "many">;
pagination: z.ZodObject<{
total: z.ZodNumber;
page: z.ZodNumber;
limit: z.ZodNumber;
totalPages: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
page: number;
limit: number;
totalPages: number;
total: number;
}, {
page: number;
limit: number;
totalPages: number;
total: number;
}>;
}, "strip", z.ZodTypeAny, {
activities: {
id: string;
title: string;
status: ActivityApiStatus;
startDate: string | null;
finalDate: string | null;
completionPercentage: number;
className?: string | undefined;
schoolName?: string | undefined;
year?: string | undefined;
subjectName?: string | undefined;
schoolId?: string | undefined;
subjectId?: string | null | undefined;
}[];
pagination: {
page: number;
limit: number;
totalPages: number;
total: number;
};
}, {
activities: {
id: string;
title: string;
status: ActivityApiStatus;
startDate: string | null;
finalDate: string | null;
completionPercentage: number;
className?: string | undefined;
schoolName?: string | undefined;
year?: string | undefined;
subjectName?: string | undefined;
schoolId?: string | undefined;
subjectId?: string | null | undefined;
}[];
pagination: {
page: number;
limit: number;
totalPages: number;
total: number;
};
}>;
}, "strip", z.ZodTypeAny, {
data: {
activities: {
id: string;
title: string;
status: ActivityApiStatus;
startDate: string | null;
finalDate: string | null;
completionPercentage: number;
className?: string | undefined;
schoolName?: string | undefined;
year?: string | undefined;
subjectName?: string | undefined;
schoolId?: string | undefined;
subjectId?: string | null | undefined;
}[];
pagination: {
page: number;
limit: number;
totalPages: number;
total: number;
};
};
message: string;
}, {
data: {
activities: {
id: string;
title: string;
status: ActivityApiStatus;
startDate: string | null;
finalDate: string | null;
completionPercentage: number;
className?: string | undefined;
schoolName?: string | undefined;
year?: string | undefined;
subjectName?: string | undefined;
schoolId?: string | undefined;
subjectId?: string | null | undefined;
}[];
pagination: {
page: number;
limit: number;
totalPages: number;
total: number;
};
};
message: string;
}>;
/**
* Hook state interface
*/
export interface UseActivitiesHistoryState {
activities: ActivityTableItem[];
loading: boolean;
error: string | null;
pagination: ActivityPagination;
}
/**
* Hook return type
*/
export interface UseActivitiesHistoryReturn extends UseActivitiesHistoryState {
fetchActivities: (filters?: ActivityHistoryFilters) => Promise<void>;
}
/**
* Default pagination values
*/
export declare const DEFAULT_ACTIVITIES_PAGINATION: ActivityPagination;
/**
* Transform API response to table item format
* @param activity - Activity from API response
* @returns Formatted activity for table display
*/
export declare const transformActivityToTableItem: (activity: ActivityHistoryResponse) => ActivityTableItem;
/**
* Handle errors during activity fetch
* Uses the generic error handler factory to reduce code duplication
*/
export declare const handleActivityFetchError: (error: unknown) => string;
/**
* Factory function to create useActivitiesHistory hook
*
* @param fetchActivitiesHistory - Function to fetch activities from API
* @returns Hook for managing activities history
*
* @example
* ```tsx
* // In your app setup
* const fetchActivitiesHistory = async (filters) => {
* const response = await api.get('/activities/history', { params: filters });
* return response.data;
* };
*
* const useActivitiesHistory = createUseActivitiesHistory(fetchActivitiesHistory);
*
* // In your component
* const { activities, loading, error, pagination, fetchActivities } = useActivitiesHistory();
* ```
*/
export declare const createUseActivitiesHistory: (fetchActivitiesHistory: (filters?: ActivityHistoryFilters) => Promise<ActivitiesHistoryApiResponse>) => () => UseActivitiesHistoryReturn;
/**
* Alias for createUseActivitiesHistory
*/
export declare const createActivitiesHistoryHook: (fetchActivitiesHistory: (filters?: ActivityHistoryFilters) => Promise<ActivitiesHistoryApiResponse>) => () => UseActivitiesHistoryReturn;
//# sourceMappingURL=useActivitiesHistory.d.ts.map