analytica-frontend-lib 1.2.83 → 1.2.85
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/dist/ActivitiesHistory/index.js +156 -147
- package/dist/ActivitiesHistory/index.js.map +1 -1
- package/dist/ActivitiesHistory/index.mjs +155 -146
- package/dist/ActivitiesHistory/index.mjs.map +1 -1
- package/dist/ActivityCardQuestionBanks/index.d.ts +6 -4
- package/dist/ActivityCardQuestionBanks/index.d.ts.map +1 -1
- package/dist/ActivityCardQuestionBanks/index.js.map +1 -1
- package/dist/ActivityCardQuestionBanks/index.mjs.map +1 -1
- package/dist/RecommendedLessonsHistory/index.js +460 -286
- package/dist/RecommendedLessonsHistory/index.js.map +1 -1
- package/dist/RecommendedLessonsHistory/index.mjs +409 -235
- package/dist/RecommendedLessonsHistory/index.mjs.map +1 -1
- package/dist/hooks/useActivitiesHistory/index.js.map +1 -1
- package/dist/hooks/useActivitiesHistory/index.mjs.map +1 -1
- package/dist/hooks/useActivityModels/index.d.ts +1 -1
- package/dist/hooks/useActivityModels/index.d.ts.map +1 -1
- package/dist/hooks/useActivityModels/index.js +13 -2
- package/dist/hooks/useActivityModels/index.js.map +1 -1
- package/dist/hooks/useActivityModels/index.mjs +13 -2
- package/dist/hooks/useActivityModels/index.mjs.map +1 -1
- package/dist/hooks/useActivityModels.d.ts +1 -1
- package/dist/hooks/useActivityModels.d.ts.map +1 -1
- package/dist/hooks/useGoalDrafts/index.d.ts +57 -0
- package/dist/hooks/useGoalDrafts/index.d.ts.map +1 -0
- package/dist/hooks/useGoalDrafts/index.js +189 -0
- package/dist/hooks/useGoalDrafts/index.js.map +1 -0
- package/dist/hooks/useGoalDrafts/index.mjs +151 -0
- package/dist/hooks/useGoalDrafts/index.mjs.map +1 -0
- package/dist/hooks/useGoalDrafts.d.ts +57 -0
- package/dist/hooks/useGoalDrafts.d.ts.map +1 -0
- package/dist/hooks/useRecommendedLessonsPage/index.d.ts +4 -0
- package/dist/hooks/useRecommendedLessonsPage/index.d.ts.map +1 -1
- package/dist/hooks/useRecommendedLessonsPage/index.js +24 -0
- package/dist/hooks/useRecommendedLessonsPage/index.js.map +1 -1
- package/dist/hooks/useRecommendedLessonsPage/index.mjs +24 -0
- package/dist/hooks/useRecommendedLessonsPage/index.mjs.map +1 -1
- package/dist/hooks/useRecommendedLessonsPage.d.ts +4 -0
- package/dist/hooks/useRecommendedLessonsPage.d.ts.map +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2251 -1058
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2264 -1078
- package/dist/index.mjs.map +1 -1
- package/dist/types/activitiesHistory/index.d.ts +11 -1
- package/dist/types/activitiesHistory/index.d.ts.map +1 -1
- package/dist/types/activitiesHistory/index.js.map +1 -1
- package/dist/types/activitiesHistory/index.mjs.map +1 -1
- package/dist/types/activitiesHistory.d.ts +11 -1
- package/dist/types/activitiesHistory.d.ts.map +1 -1
- package/dist/types/questions.d.ts +1 -0
- package/dist/types/questions.d.ts.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/hooks/useGoalDrafts.ts
|
|
31
|
+
var useGoalDrafts_exports = {};
|
|
32
|
+
__export(useGoalDrafts_exports, {
|
|
33
|
+
DEFAULT_GOAL_DRAFTS_PAGINATION: () => DEFAULT_GOAL_DRAFTS_PAGINATION,
|
|
34
|
+
createGoalDraftsHook: () => createGoalDraftsHook,
|
|
35
|
+
createUseGoalDrafts: () => createUseGoalDrafts,
|
|
36
|
+
handleGoalDraftFetchError: () => handleGoalDraftFetchError
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(useGoalDrafts_exports);
|
|
39
|
+
var import_react2 = require("react");
|
|
40
|
+
|
|
41
|
+
// src/hooks/useGoalModels.ts
|
|
42
|
+
var import_react = require("react");
|
|
43
|
+
var import_zod2 = require("zod");
|
|
44
|
+
var import_dayjs = __toESM(require("dayjs"));
|
|
45
|
+
|
|
46
|
+
// src/types/recommendedLessons.ts
|
|
47
|
+
var GOAL_FILTER_STATUS_OPTIONS = [
|
|
48
|
+
{ id: "VENCIDA" /* VENCIDA */, name: "Vencida" },
|
|
49
|
+
{ id: "A_VENCER" /* A_VENCER */, name: "Ativa" }
|
|
50
|
+
];
|
|
51
|
+
var GOAL_STATUS_OPTIONS = [
|
|
52
|
+
{ id: "A_VENCER" /* A_VENCER */, name: "A Vencer" },
|
|
53
|
+
{ id: "VENCIDA" /* VENCIDA */, name: "Vencida" },
|
|
54
|
+
{ id: "CONCLUIDA" /* CONCLUIDA */, name: "Conclu\xEDda" }
|
|
55
|
+
];
|
|
56
|
+
var GoalDraftType = /* @__PURE__ */ ((GoalDraftType2) => {
|
|
57
|
+
GoalDraftType2["MODELO"] = "MODELO";
|
|
58
|
+
GoalDraftType2["RASCUNHO"] = "RASCUNHO";
|
|
59
|
+
return GoalDraftType2;
|
|
60
|
+
})(GoalDraftType || {});
|
|
61
|
+
|
|
62
|
+
// src/utils/hookErrorHandler.ts
|
|
63
|
+
var import_zod = require("zod");
|
|
64
|
+
var createFetchErrorHandler = (validationErrorMessage, genericErrorMessage) => (error) => {
|
|
65
|
+
if (error instanceof import_zod.z.ZodError) {
|
|
66
|
+
console.error(validationErrorMessage, error);
|
|
67
|
+
return validationErrorMessage;
|
|
68
|
+
}
|
|
69
|
+
console.error(genericErrorMessage, error);
|
|
70
|
+
return genericErrorMessage;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
// src/hooks/useGoalModels.ts
|
|
74
|
+
var goalModelResponseSchema = import_zod2.z.object({
|
|
75
|
+
id: import_zod2.z.string().uuid(),
|
|
76
|
+
type: import_zod2.z.nativeEnum(GoalDraftType),
|
|
77
|
+
title: import_zod2.z.string(),
|
|
78
|
+
description: import_zod2.z.string().nullable(),
|
|
79
|
+
creatorUserInstitutionId: import_zod2.z.string().uuid(),
|
|
80
|
+
subjectId: import_zod2.z.string().uuid().nullable(),
|
|
81
|
+
startDate: import_zod2.z.string().nullable(),
|
|
82
|
+
finalDate: import_zod2.z.string().nullable(),
|
|
83
|
+
createdAt: import_zod2.z.string(),
|
|
84
|
+
updatedAt: import_zod2.z.string()
|
|
85
|
+
});
|
|
86
|
+
var goalModelsApiResponseSchema = import_zod2.z.object({
|
|
87
|
+
message: import_zod2.z.string(),
|
|
88
|
+
data: import_zod2.z.object({
|
|
89
|
+
drafts: import_zod2.z.array(goalModelResponseSchema),
|
|
90
|
+
total: import_zod2.z.number()
|
|
91
|
+
})
|
|
92
|
+
});
|
|
93
|
+
var transformGoalModelToTableItem = (model, subjectsMap) => {
|
|
94
|
+
const subjectName = model.subjectId ? subjectsMap?.get(model.subjectId) || "" : "";
|
|
95
|
+
return {
|
|
96
|
+
id: model.id,
|
|
97
|
+
title: model.title || "Sem t\xEDtulo",
|
|
98
|
+
savedAt: (0, import_dayjs.default)(model.createdAt).format("DD/MM/YYYY"),
|
|
99
|
+
subject: subjectName,
|
|
100
|
+
subjectId: model.subjectId
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
var handleGoalModelFetchError = createFetchErrorHandler(
|
|
104
|
+
"Erro ao validar dados de modelos de aulas",
|
|
105
|
+
"Erro ao carregar modelos de aulas"
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
// src/hooks/useGoalDrafts.ts
|
|
109
|
+
var DEFAULT_GOAL_DRAFTS_PAGINATION = {
|
|
110
|
+
total: 0,
|
|
111
|
+
page: 1,
|
|
112
|
+
limit: 10,
|
|
113
|
+
totalPages: 0
|
|
114
|
+
};
|
|
115
|
+
var handleGoalDraftFetchError = createFetchErrorHandler(
|
|
116
|
+
"Erro ao validar dados de rascunhos de aulas",
|
|
117
|
+
"Erro ao carregar rascunhos de aulas"
|
|
118
|
+
);
|
|
119
|
+
var createUseGoalDrafts = (fetchGoalDrafts, deleteGoalDraft) => {
|
|
120
|
+
return () => {
|
|
121
|
+
const [state, setState] = (0, import_react2.useState)({
|
|
122
|
+
models: [],
|
|
123
|
+
loading: false,
|
|
124
|
+
error: null,
|
|
125
|
+
pagination: DEFAULT_GOAL_DRAFTS_PAGINATION
|
|
126
|
+
});
|
|
127
|
+
const fetchModels = (0, import_react2.useCallback)(
|
|
128
|
+
async (filters, subjectsMap) => {
|
|
129
|
+
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
130
|
+
try {
|
|
131
|
+
const responseData = await fetchGoalDrafts(filters);
|
|
132
|
+
const validatedData = goalModelsApiResponseSchema.parse(responseData);
|
|
133
|
+
const tableItems = validatedData.data.drafts.map(
|
|
134
|
+
(draft) => transformGoalModelToTableItem(draft, subjectsMap)
|
|
135
|
+
);
|
|
136
|
+
const limit = filters?.limit || 10;
|
|
137
|
+
const page = filters?.page || 1;
|
|
138
|
+
const total = validatedData.data.total;
|
|
139
|
+
const totalPages = Math.ceil(total / limit);
|
|
140
|
+
setState({
|
|
141
|
+
models: tableItems,
|
|
142
|
+
loading: false,
|
|
143
|
+
error: null,
|
|
144
|
+
pagination: {
|
|
145
|
+
total,
|
|
146
|
+
page,
|
|
147
|
+
limit,
|
|
148
|
+
totalPages
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
} catch (error) {
|
|
152
|
+
const errorMessage = handleGoalDraftFetchError(error);
|
|
153
|
+
setState((prev) => ({
|
|
154
|
+
...prev,
|
|
155
|
+
loading: false,
|
|
156
|
+
error: errorMessage
|
|
157
|
+
}));
|
|
158
|
+
}
|
|
159
|
+
},
|
|
160
|
+
[fetchGoalDrafts]
|
|
161
|
+
);
|
|
162
|
+
const deleteModel = (0, import_react2.useCallback)(
|
|
163
|
+
async (id) => {
|
|
164
|
+
try {
|
|
165
|
+
await deleteGoalDraft(id);
|
|
166
|
+
return true;
|
|
167
|
+
} catch (error) {
|
|
168
|
+
console.error("Erro ao deletar rascunho:", error);
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
},
|
|
172
|
+
[deleteGoalDraft]
|
|
173
|
+
);
|
|
174
|
+
return {
|
|
175
|
+
...state,
|
|
176
|
+
fetchModels,
|
|
177
|
+
deleteModel
|
|
178
|
+
};
|
|
179
|
+
};
|
|
180
|
+
};
|
|
181
|
+
var createGoalDraftsHook = createUseGoalDrafts;
|
|
182
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
183
|
+
0 && (module.exports = {
|
|
184
|
+
DEFAULT_GOAL_DRAFTS_PAGINATION,
|
|
185
|
+
createGoalDraftsHook,
|
|
186
|
+
createUseGoalDrafts,
|
|
187
|
+
handleGoalDraftFetchError
|
|
188
|
+
});
|
|
189
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/useGoalDrafts.ts","../../../src/hooks/useGoalModels.ts","../../../src/types/recommendedLessons.ts","../../../src/utils/hookErrorHandler.ts"],"sourcesContent":["import { useState, useCallback } from 'react';\nimport {\n goalModelsApiResponseSchema,\n transformGoalModelToTableItem,\n} from './useGoalModels';\nimport { createFetchErrorHandler } from '../utils/hookErrorHandler';\nimport type {\n GoalModelTableItem,\n GoalModelsApiResponse,\n GoalModelFilters,\n GoalModelPagination,\n} from '../types/recommendedLessons';\n\n/**\n * Hook state interface for goal drafts\n */\nexport interface UseGoalDraftsState {\n models: GoalModelTableItem[];\n loading: boolean;\n error: string | null;\n pagination: GoalModelPagination;\n}\n\n/**\n * Hook return type for goal drafts\n */\nexport interface UseGoalDraftsReturn extends UseGoalDraftsState {\n fetchModels: (\n filters?: GoalModelFilters,\n subjectsMap?: Map<string, string>\n ) => Promise<void>;\n deleteModel: (id: string) => Promise<boolean>;\n}\n\n/**\n * Default pagination values for drafts\n */\nexport const DEFAULT_GOAL_DRAFTS_PAGINATION: GoalModelPagination = {\n total: 0,\n page: 1,\n limit: 10,\n totalPages: 0,\n};\n\n/**\n * Handle errors during draft fetch\n * Uses the generic error handler factory to reduce code duplication\n */\nexport const handleGoalDraftFetchError = createFetchErrorHandler(\n 'Erro ao validar dados de rascunhos de aulas',\n 'Erro ao carregar rascunhos de aulas'\n);\n\n/**\n * Factory function to create useGoalDrafts hook\n *\n * @param fetchGoalDrafts - Function to fetch drafts from API\n * @param deleteGoalDraft - Function to delete a draft\n * @returns Hook for managing goal drafts\n *\n * @example\n * ```tsx\n * // In your app setup\n * const fetchGoalDrafts = async (filters) => {\n * const response = await api.get('/recommended-class/drafts', { params: { ...filters, type: 'RASCUNHO' } });\n * return response.data;\n * };\n *\n * const deleteGoalDraft = async (id) => {\n * await api.delete(`/recommended-class/drafts/${id}`);\n * };\n *\n * const useGoalDrafts = createUseGoalDrafts(fetchGoalDrafts, deleteGoalDraft);\n *\n * // In your component\n * const { models, loading, error, pagination, fetchModels, deleteModel } = useGoalDrafts();\n * ```\n */\nexport const createUseGoalDrafts = (\n fetchGoalDrafts: (\n filters?: GoalModelFilters\n ) => Promise<GoalModelsApiResponse>,\n deleteGoalDraft: (id: string) => Promise<void>\n) => {\n return (): UseGoalDraftsReturn => {\n const [state, setState] = useState<UseGoalDraftsState>({\n models: [],\n loading: false,\n error: null,\n pagination: DEFAULT_GOAL_DRAFTS_PAGINATION,\n });\n\n /**\n * Fetch goal drafts from API\n * @param filters - Optional filters for pagination, search, etc.\n * @param subjectsMap - Map of subject IDs to subject names for display\n */\n const fetchModels = useCallback(\n async (filters?: GoalModelFilters, subjectsMap?: Map<string, string>) => {\n setState((prev) => ({ ...prev, loading: true, error: null }));\n\n try {\n // Fetch data from API\n const responseData = await fetchGoalDrafts(filters);\n\n // Validate response with Zod\n const validatedData = goalModelsApiResponseSchema.parse(responseData);\n\n // Transform drafts to table format\n const tableItems = validatedData.data.drafts.map((draft) =>\n transformGoalModelToTableItem(draft, subjectsMap)\n );\n\n // Calculate pagination\n const limit = filters?.limit || 10;\n const page = filters?.page || 1;\n const total = validatedData.data.total;\n const totalPages = Math.ceil(total / limit);\n\n // Update state with validated and transformed data\n setState({\n models: tableItems,\n loading: false,\n error: null,\n pagination: {\n total,\n page,\n limit,\n totalPages,\n },\n });\n } catch (error) {\n const errorMessage = handleGoalDraftFetchError(error);\n setState((prev) => ({\n ...prev,\n loading: false,\n error: errorMessage,\n }));\n }\n },\n [fetchGoalDrafts]\n );\n\n /**\n * Delete a goal draft\n * @param id - Draft ID to delete\n * @returns True if deletion was successful\n */\n const deleteModel = useCallback(\n async (id: string): Promise<boolean> => {\n try {\n await deleteGoalDraft(id);\n return true;\n } catch (error) {\n console.error('Erro ao deletar rascunho:', error);\n return false;\n }\n },\n [deleteGoalDraft]\n );\n\n return {\n ...state,\n fetchModels,\n deleteModel,\n };\n };\n};\n\n/**\n * Alias for createUseGoalDrafts\n */\nexport const createGoalDraftsHook = createUseGoalDrafts;\n","import { useState, useCallback } from 'react';\nimport { z } from 'zod';\nimport dayjs from 'dayjs';\nimport { GoalDraftType } from '../types/recommendedLessons';\nimport type {\n GoalModelResponse,\n GoalModelTableItem,\n GoalModelsApiResponse,\n GoalModelFilters,\n GoalModelPagination,\n} from '../types/recommendedLessons';\nimport { createFetchErrorHandler } from '../utils/hookErrorHandler';\n\n/**\n * Zod schema for goal model response validation\n */\nconst goalModelResponseSchema = z.object({\n id: z.string().uuid(),\n type: z.nativeEnum(GoalDraftType),\n title: z.string(),\n description: z.string().nullable(),\n creatorUserInstitutionId: z.string().uuid(),\n subjectId: z.string().uuid().nullable(),\n startDate: z.string().nullable(),\n finalDate: z.string().nullable(),\n createdAt: z.string(),\n updatedAt: z.string(),\n});\n\n/**\n * Zod schema for goal models API response validation\n */\nexport const goalModelsApiResponseSchema = z.object({\n message: z.string(),\n data: z.object({\n drafts: z.array(goalModelResponseSchema),\n total: z.number(),\n }),\n});\n\n/**\n * Hook state interface\n */\nexport interface UseGoalModelsState {\n models: GoalModelTableItem[];\n loading: boolean;\n error: string | null;\n pagination: GoalModelPagination;\n}\n\n/**\n * Hook return type\n */\nexport interface UseGoalModelsReturn extends UseGoalModelsState {\n fetchModels: (\n filters?: GoalModelFilters,\n subjectsMap?: Map<string, string>\n ) => Promise<void>;\n deleteModel: (id: string) => Promise<boolean>;\n}\n\n/**\n * Default pagination values\n */\nexport const DEFAULT_GOAL_MODELS_PAGINATION: GoalModelPagination = {\n total: 0,\n page: 1,\n limit: 10,\n totalPages: 0,\n};\n\n/**\n * Transform API response to table item format\n * @param model - Goal model from API response\n * @param subjectsMap - Map of subject IDs to subject names\n * @returns Formatted model for table display\n */\nexport const transformGoalModelToTableItem = (\n model: GoalModelResponse,\n subjectsMap?: Map<string, string>\n): GoalModelTableItem => {\n const subjectName = model.subjectId\n ? subjectsMap?.get(model.subjectId) || ''\n : '';\n\n return {\n id: model.id,\n title: model.title || 'Sem título',\n savedAt: dayjs(model.createdAt).format('DD/MM/YYYY'),\n subject: subjectName,\n subjectId: model.subjectId,\n };\n};\n\n/**\n * Handle errors during model fetch\n * Uses the generic error handler factory to reduce code duplication\n */\nexport const handleGoalModelFetchError = createFetchErrorHandler(\n 'Erro ao validar dados de modelos de aulas',\n 'Erro ao carregar modelos de aulas'\n);\n\n/**\n * Factory function to create useGoalModels hook\n *\n * @param fetchGoalModels - Function to fetch models from API\n * @param deleteGoalModel - Function to delete a model\n * @returns Hook for managing goal models\n *\n * @example\n * ```tsx\n * // In your app setup\n * const fetchGoalModels = async (filters) => {\n * const response = await api.get('/recommended-class/drafts', { params: { ...filters, type: 'MODELO' } });\n * return response.data;\n * };\n *\n * const deleteGoalModel = async (id) => {\n * await api.delete(`/recommended-class/drafts/${id}`);\n * };\n *\n * const useGoalModels = createUseGoalModels(fetchGoalModels, deleteGoalModel);\n *\n * // In your component\n * const { models, loading, error, pagination, fetchModels, deleteModel } = useGoalModels();\n * ```\n */\nexport const createUseGoalModels = (\n fetchGoalModels: (\n filters?: GoalModelFilters\n ) => Promise<GoalModelsApiResponse>,\n deleteGoalModel: (id: string) => Promise<void>\n) => {\n return (): UseGoalModelsReturn => {\n const [state, setState] = useState<UseGoalModelsState>({\n models: [],\n loading: false,\n error: null,\n pagination: DEFAULT_GOAL_MODELS_PAGINATION,\n });\n\n /**\n * Fetch goal models from API\n * @param filters - Optional filters for pagination, search, etc.\n * @param subjectsMap - Map of subject IDs to subject names for display\n */\n const fetchModels = useCallback(\n async (filters?: GoalModelFilters, subjectsMap?: Map<string, string>) => {\n setState((prev) => ({ ...prev, loading: true, error: null }));\n\n try {\n // Fetch data from API\n const responseData = await fetchGoalModels(filters);\n\n // Validate response with Zod\n const validatedData = goalModelsApiResponseSchema.parse(responseData);\n\n // Transform models to table format\n const tableItems = validatedData.data.drafts.map((model) =>\n transformGoalModelToTableItem(model, subjectsMap)\n );\n\n // Calculate pagination\n const limit = filters?.limit || 10;\n const page = filters?.page || 1;\n const total = validatedData.data.total;\n const totalPages = Math.ceil(total / limit);\n\n // Update state with validated and transformed data\n setState({\n models: tableItems,\n loading: false,\n error: null,\n pagination: {\n total,\n page,\n limit,\n totalPages,\n },\n });\n } catch (error) {\n const errorMessage = handleGoalModelFetchError(error);\n setState((prev) => ({\n ...prev,\n loading: false,\n error: errorMessage,\n }));\n }\n },\n [fetchGoalModels]\n );\n\n /**\n * Delete a goal model\n * @param id - Model ID to delete\n * @returns True if deletion was successful\n */\n const deleteModel = useCallback(\n async (id: string): Promise<boolean> => {\n try {\n await deleteGoalModel(id);\n return true;\n } catch (error) {\n console.error('Erro ao deletar modelo:', error);\n return false;\n }\n },\n [deleteGoalModel]\n );\n\n return {\n ...state,\n fetchModels,\n deleteModel,\n };\n };\n};\n\n/**\n * Alias for createUseGoalModels\n */\nexport const createGoalModelsHook = createUseGoalModels;\n","/**\n * Recommended Lessons / Goals (Aulas Recomendadas) Type Definitions\n * Based on /recommended-class/history endpoint\n */\n\nimport {\n GenericApiStatus,\n GenericDisplayStatus,\n BadgeActionType,\n getStatusBadgeAction,\n} from './common';\n\n/**\n * Goal status from backend API\n * Re-exported from common for backward compatibility\n */\nexport { GenericApiStatus as GoalApiStatus } from './common';\n\n/**\n * Goal status for display in UI (Badge component)\n * Re-exported from common for backward compatibility\n */\nexport { GenericDisplayStatus as GoalDisplayStatus } from './common';\n\n/**\n * Badge action types for goal status visualization\n * Re-exported from common for backward compatibility\n */\nexport { BadgeActionType as GoalBadgeActionType } from './common';\n\n/**\n * Subject info from API response\n */\nexport interface GoalSubject {\n id: string;\n name: string;\n}\n\n/**\n * Creator info from API response\n */\nexport interface GoalCreator {\n id: string;\n name: string;\n}\n\n/**\n * Goal stats from API response\n */\nexport interface GoalStats {\n totalStudents: number;\n completedCount: number;\n completionPercentage: number;\n}\n\n/**\n * Class breakdown info from API response\n */\nexport interface GoalBreakdown {\n classId: string;\n className: string;\n schoolId: string;\n schoolName: string;\n studentCount: number;\n completedCount: number;\n}\n\n/**\n * Goal data from API response\n */\nexport interface GoalData {\n id: string;\n title: string;\n startDate: string | null;\n finalDate: string | null;\n createdAt: string;\n progress: number;\n totalLessons: number;\n}\n\n/**\n * Goal history item from /recommended-class/history endpoint\n */\nexport interface GoalHistoryItem {\n goal: GoalData;\n subject: GoalSubject | null;\n creator: GoalCreator | null;\n stats: GoalStats;\n breakdown: GoalBreakdown[];\n}\n\n/**\n * Goal table item interface for goals list table\n */\nexport interface GoalTableItem extends Record<string, unknown> {\n id: string;\n startDate: string | null;\n deadline: string | null;\n title: string;\n school: string;\n year: string;\n subject: string;\n class: string;\n status: GenericDisplayStatus;\n completionPercentage: number;\n}\n\n/**\n * Goals history API complete response from /recommended-class/history\n */\nexport interface GoalsHistoryApiResponse {\n message: string;\n data: {\n goals: GoalHistoryItem[];\n total: number;\n };\n}\n\n/**\n * Goal history filters for API query parameters\n */\nexport interface GoalHistoryFilters {\n page?: number;\n limit?: number;\n status?: GenericApiStatus;\n search?: string;\n startDate?: string;\n finalDate?: string;\n subjectId?: string;\n schoolId?: string;\n schoolIds?: string[];\n classId?: string;\n classIds?: string[];\n studentIds?: string[];\n sortBy?: 'createdAt' | 'finalDate' | 'title' | 'completionPercentage';\n sortOrder?: 'asc' | 'desc';\n}\n\n/**\n * Pagination info for goals history\n */\nexport interface GoalHistoryPagination {\n total: number;\n page: number;\n limit: number;\n totalPages: number;\n}\n\n/**\n * Filter option for dropdowns\n * Extends with index signature to be compatible with CheckBoxGroup Item type\n */\nexport interface GoalFilterOption {\n id: string;\n name: string;\n [key: string]: unknown;\n}\n\n/**\n * User data for filter options (schools, classes, subjects)\n */\nexport interface GoalUserFilterData {\n schools?: Array<{ id: string; name: string }>;\n classes?: Array<{ id: string; name: string; schoolId?: string }>;\n subjects?: Array<{ id: string; name: string }>;\n schoolYears?: Array<{ id: string; name: string }>;\n}\n\n/**\n * Get status badge action based on goal display status\n * @param status - Goal display status\n * @returns Badge action type for styling\n */\nexport const getGoalStatusBadgeAction = (\n status: GenericDisplayStatus\n): BadgeActionType => getStatusBadgeAction(status);\n\n/**\n * Goal status options for filter (Vencida and Ativa)\n */\nexport const GOAL_FILTER_STATUS_OPTIONS: GoalFilterOption[] = [\n { id: GenericApiStatus.VENCIDA, name: 'Vencida' },\n { id: GenericApiStatus.A_VENCER, name: 'Ativa' },\n];\n\n/**\n * All goal status options\n */\nexport const GOAL_STATUS_OPTIONS: GoalFilterOption[] = [\n { id: GenericApiStatus.A_VENCER, name: 'A Vencer' },\n { id: GenericApiStatus.VENCIDA, name: 'Vencida' },\n { id: GenericApiStatus.CONCLUIDA, name: 'Concluída' },\n];\n\n// ============================================\n// Recommended Lesson Details Types\n// Based on /goals/{id} and /goals/{id}/details endpoints\n// ============================================\n\n/**\n * Student status for display in UI\n */\nexport enum StudentLessonStatus {\n A_INICIAR = 'A INICIAR',\n EM_ANDAMENTO = 'EM ANDAMENTO',\n NAO_FINALIZADO = 'NÃO FINALIZADO',\n CONCLUIDO = 'CONCLUÍDO',\n}\n\n/**\n * Badge action type for student status\n */\nexport const getStudentStatusBadgeAction = (\n status: StudentLessonStatus\n): 'success' | 'warning' | 'error' | 'info' => {\n const actionMap: Record<\n StudentLessonStatus,\n 'success' | 'warning' | 'error' | 'info'\n > = {\n [StudentLessonStatus.CONCLUIDO]: 'success',\n [StudentLessonStatus.EM_ANDAMENTO]: 'info',\n [StudentLessonStatus.A_INICIAR]: 'warning',\n [StudentLessonStatus.NAO_FINALIZADO]: 'error',\n };\n return actionMap[status] ?? 'warning';\n};\n\n/**\n * Checks if a deadline has passed\n * @param deadline - ISO date string of the deadline\n * @returns true if deadline has passed, false otherwise\n */\nexport const isDeadlinePassed = (deadline: string | null): boolean => {\n if (!deadline) return false;\n return new Date(deadline) < new Date();\n};\n\n/**\n * Derives student display status from progress, completedAt, and deadline\n * @param progress - Student progress percentage (0-100)\n * @param completedAt - ISO date string when student completed, or null\n * @param deadline - ISO date string of the goal deadline, or null\n * @returns The appropriate StudentLessonStatus\n */\nexport const deriveStudentStatus = (\n progress: number,\n completedAt: string | null,\n deadline?: string | null\n): StudentLessonStatus => {\n // If completed (either by completedAt or 100% progress), it's CONCLUIDO\n if (completedAt) return StudentLessonStatus.CONCLUIDO;\n if (progress === 100) return StudentLessonStatus.CONCLUIDO;\n\n // If deadline passed and not completed, it's NAO_FINALIZADO\n if (isDeadlinePassed(deadline ?? null) && progress < 100) {\n return StudentLessonStatus.NAO_FINALIZADO;\n }\n\n // Otherwise, derive from progress\n if (progress === 0) return StudentLessonStatus.A_INICIAR;\n if (progress > 0) return StudentLessonStatus.EM_ANDAMENTO;\n return StudentLessonStatus.A_INICIAR;\n};\n\n/**\n * Formats days to complete as a readable string\n */\nexport const formatDaysToComplete = (\n daysToComplete: number | null\n): string | null => {\n if (daysToComplete === null) return null;\n if (daysToComplete === 1) return '1 dia';\n return `${daysToComplete} dias`;\n};\n\n// ============================================\n// API Response Types - /goals/{id}/details\n// ============================================\n\n/**\n * Student data from /goals/{id}/details endpoint\n */\nexport interface GoalDetailStudent {\n userInstitutionId: string;\n userId: string;\n name: string;\n progress: number;\n completedAt: string | null;\n avgScore: number | null;\n daysToComplete: number | null;\n}\n\n/**\n * Aggregated stats from /goals/{id}/details endpoint\n */\nexport interface GoalDetailAggregated {\n completionPercentage: number;\n avgScore: number | null;\n}\n\n/**\n * Content performance item from /goals/{id}/details endpoint\n */\nexport interface GoalDetailContentPerformanceItem {\n contentId: string;\n contentName: string;\n rate: number;\n}\n\n/**\n * Content performance from /goals/{id}/details endpoint\n */\nexport interface GoalDetailContentPerformance {\n best: GoalDetailContentPerformanceItem | null;\n worst: GoalDetailContentPerformanceItem | null;\n}\n\n/**\n * Response data from /goals/{id}/details endpoint\n */\nexport interface GoalDetailsData {\n students: GoalDetailStudent[];\n aggregated: GoalDetailAggregated;\n contentPerformance: GoalDetailContentPerformance;\n}\n\n/**\n * Full API response from /goals/{id}/details endpoint\n */\nexport interface GoalDetailsApiResponse {\n message: string;\n data: GoalDetailsData;\n}\n\n// ============================================\n// Goal Activity Types - /goals/{id} activities\n// ============================================\n\n/**\n * Activity status for goal activities\n * Used in activitiesGoals array from /goals/{id} endpoint\n */\nexport const GOAL_ACTIVITY_STATUS = {\n PENDENTE: 'PENDENTE',\n CONCLUIDA: 'CONCLUIDA',\n EXPIRADA: 'EXPIRADA',\n} as const;\n\nexport type GoalActivityStatus =\n (typeof GOAL_ACTIVITY_STATUS)[keyof typeof GOAL_ACTIVITY_STATUS];\n\n/**\n * Activity details within a goal\n */\nexport interface GoalActivity {\n id: string;\n title: string;\n status: GoalActivityStatus;\n}\n\n/**\n * User activities within a goal\n */\nexport interface GoalSupUsersActivities {\n id: string;\n activity: GoalActivity;\n userInstitutionId: string;\n answeredAt: string | null;\n timeSpent: number;\n score: number | null;\n lastInteraction: string;\n}\n\n/**\n * Activities associated with a goal\n */\nexport interface GoalActivitiesGoals {\n goalId: string;\n supUsersActivitiesId: string;\n supUsersActivities: GoalSupUsersActivities;\n}\n\n// ============================================\n// API Response Types - /goals/{id}\n// ============================================\n\n/**\n * Subject info from lesson in /goals/{id} response\n */\nexport interface GoalLessonSubject {\n id: string;\n name: string;\n color: string;\n icon: string;\n}\n\n/**\n * Lesson info from /goals/{id} response\n */\nexport interface GoalLesson {\n id: string;\n content: { id: string; name: string };\n subtopic: { id: string; name: string };\n topic: { id: string; name: string };\n subject: GoalLessonSubject;\n}\n\n/**\n * Lesson progress from /goals/{id} response\n */\nexport interface GoalLessonProgress {\n id: string;\n userId: string;\n lessonId: string;\n progress: number;\n lesson: GoalLesson;\n}\n\n/**\n * Lesson goal item from /goals/{id} response\n */\nexport interface GoalLessonGoalItem {\n goalId: string;\n supLessonsProgressId: string;\n supLessonsProgress: GoalLessonProgress;\n}\n\n/**\n * Goal metadata from /goals/{id} endpoint\n */\nexport interface GoalMetadata {\n id: string;\n title: string;\n startDate: string;\n finalDate: string;\n progress: number;\n lessonsGoals: GoalLessonGoalItem[];\n activitiesGoals?: GoalActivitiesGoals[];\n}\n\n/**\n * Full API response from /goals/{id} endpoint\n */\nexport interface GoalApiResponse {\n message: string;\n data: GoalMetadata;\n}\n\n// ============================================\n// Combined Data for Component\n// ============================================\n\n/**\n * Combined data structure for RecommendedLessonDetails component\n * Combines data from /goals/{id}, /goals/{id}/details, and breakdown info\n */\nexport interface LessonDetailsData {\n /** Goal metadata from /goals/{id} */\n goal: GoalMetadata;\n /** Details from /goals/{id}/details */\n details: GoalDetailsData;\n /** Optional breakdown info from /recommended-class/history */\n breakdown?: GoalBreakdown;\n}\n\n// ============================================\n// Goal Draft/Model Types\n// Based on /recommended-class/drafts endpoint\n// ============================================\n\n/**\n * Goal draft type enum - matches backend GOAL_DRAFT_TYPE\n */\nexport enum GoalDraftType {\n MODELO = 'MODELO',\n RASCUNHO = 'RASCUNHO',\n}\n\n/**\n * Goal model response from backend API /recommended-class/drafts\n */\nexport interface GoalModelResponse {\n id: string;\n type: GoalDraftType;\n title: string;\n description: string | null;\n creatorUserInstitutionId: string;\n subjectId: string | null;\n startDate: string | null;\n finalDate: string | null;\n createdAt: string;\n updatedAt: string;\n}\n\n/**\n * Goal model table item for display in models table\n */\nexport interface GoalModelTableItem extends Record<string, unknown> {\n id: string;\n title: string;\n savedAt: string;\n subject: string;\n subjectId: string | null;\n}\n\n/**\n * Goal models API complete response from /recommended-class/drafts\n */\nexport interface GoalModelsApiResponse {\n message: string;\n data: {\n drafts: GoalModelResponse[];\n total: number;\n };\n}\n\n/**\n * Goal model filters for API query parameters\n */\nexport interface GoalModelFilters {\n page?: number;\n limit?: number;\n search?: string;\n subjectId?: string;\n type?: GoalDraftType;\n}\n\n/**\n * Pagination info for goal models\n */\nexport interface GoalModelPagination {\n total: number;\n page: number;\n limit: number;\n totalPages: number;\n}\n","import { z } from 'zod';\n\n/**\n * Factory function to create a fetch error handler\n * This reduces code duplication across data fetching hooks\n *\n * @param validationErrorMessage - Message to display for Zod validation errors\n * @param genericErrorMessage - Message to display for other errors\n * @returns Error handler function that returns appropriate error message\n *\n * @example\n * ```typescript\n * const handleFetchError = createFetchErrorHandler(\n * 'Erro ao validar dados',\n * 'Erro ao carregar dados'\n * );\n *\n * try {\n * // fetch data\n * } catch (error) {\n * const errorMessage = handleFetchError(error);\n * }\n * ```\n */\nexport const createFetchErrorHandler =\n (validationErrorMessage: string, genericErrorMessage: string) =>\n (error: unknown): string => {\n if (error instanceof z.ZodError) {\n console.error(validationErrorMessage, error);\n return validationErrorMessage;\n }\n\n console.error(genericErrorMessage, error);\n return genericErrorMessage;\n };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,IAAAA,gBAAsC;;;ACAtC,mBAAsC;AACtC,IAAAC,cAAkB;AAClB,mBAAkB;;;ACkLX,IAAM,6BAAiD;AAAA,EAC5D,EAAE,6BAA8B,MAAM,UAAU;AAAA,EAChD,EAAE,+BAA+B,MAAM,QAAQ;AACjD;AAKO,IAAM,sBAA0C;AAAA,EACrD,EAAE,+BAA+B,MAAM,WAAW;AAAA,EAClD,EAAE,6BAA8B,MAAM,UAAU;AAAA,EAChD,EAAE,iCAAgC,MAAM,eAAY;AACtD;AAyRO,IAAK,gBAAL,kBAAKC,mBAAL;AACL,EAAAA,eAAA,YAAS;AACT,EAAAA,eAAA,cAAW;AAFD,SAAAA;AAAA,GAAA;;;ACzdZ,iBAAkB;AAwBX,IAAM,0BACX,CAAC,wBAAgC,wBACjC,CAAC,UAA2B;AAC1B,MAAI,iBAAiB,aAAE,UAAU;AAC/B,YAAQ,MAAM,wBAAwB,KAAK;AAC3C,WAAO;AAAA,EACT;AAEA,UA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;AAAA,EACF;AACF;AAKO,IAAM,uBAAuB;","names":["import_react","import_zod","GoalDraftType","dayjs"]}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
// src/hooks/useGoalDrafts.ts
|
|
2
|
+
import { useState as useState2, useCallback as useCallback2 } from "react";
|
|
3
|
+
|
|
4
|
+
// src/hooks/useGoalModels.ts
|
|
5
|
+
import { useState, useCallback } from "react";
|
|
6
|
+
import { z as z2 } from "zod";
|
|
7
|
+
import dayjs from "dayjs";
|
|
8
|
+
|
|
9
|
+
// src/types/recommendedLessons.ts
|
|
10
|
+
var GOAL_FILTER_STATUS_OPTIONS = [
|
|
11
|
+
{ id: "VENCIDA" /* VENCIDA */, name: "Vencida" },
|
|
12
|
+
{ id: "A_VENCER" /* A_VENCER */, name: "Ativa" }
|
|
13
|
+
];
|
|
14
|
+
var GOAL_STATUS_OPTIONS = [
|
|
15
|
+
{ id: "A_VENCER" /* A_VENCER */, name: "A Vencer" },
|
|
16
|
+
{ id: "VENCIDA" /* VENCIDA */, name: "Vencida" },
|
|
17
|
+
{ id: "CONCLUIDA" /* CONCLUIDA */, name: "Conclu\xEDda" }
|
|
18
|
+
];
|
|
19
|
+
var GoalDraftType = /* @__PURE__ */ ((GoalDraftType2) => {
|
|
20
|
+
GoalDraftType2["MODELO"] = "MODELO";
|
|
21
|
+
GoalDraftType2["RASCUNHO"] = "RASCUNHO";
|
|
22
|
+
return GoalDraftType2;
|
|
23
|
+
})(GoalDraftType || {});
|
|
24
|
+
|
|
25
|
+
// src/utils/hookErrorHandler.ts
|
|
26
|
+
import { z } from "zod";
|
|
27
|
+
var createFetchErrorHandler = (validationErrorMessage, genericErrorMessage) => (error) => {
|
|
28
|
+
if (error instanceof z.ZodError) {
|
|
29
|
+
console.error(validationErrorMessage, error);
|
|
30
|
+
return validationErrorMessage;
|
|
31
|
+
}
|
|
32
|
+
console.error(genericErrorMessage, error);
|
|
33
|
+
return genericErrorMessage;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
// src/hooks/useGoalModels.ts
|
|
37
|
+
var goalModelResponseSchema = z2.object({
|
|
38
|
+
id: z2.string().uuid(),
|
|
39
|
+
type: z2.nativeEnum(GoalDraftType),
|
|
40
|
+
title: z2.string(),
|
|
41
|
+
description: z2.string().nullable(),
|
|
42
|
+
creatorUserInstitutionId: z2.string().uuid(),
|
|
43
|
+
subjectId: z2.string().uuid().nullable(),
|
|
44
|
+
startDate: z2.string().nullable(),
|
|
45
|
+
finalDate: z2.string().nullable(),
|
|
46
|
+
createdAt: z2.string(),
|
|
47
|
+
updatedAt: z2.string()
|
|
48
|
+
});
|
|
49
|
+
var goalModelsApiResponseSchema = z2.object({
|
|
50
|
+
message: z2.string(),
|
|
51
|
+
data: z2.object({
|
|
52
|
+
drafts: z2.array(goalModelResponseSchema),
|
|
53
|
+
total: z2.number()
|
|
54
|
+
})
|
|
55
|
+
});
|
|
56
|
+
var transformGoalModelToTableItem = (model, subjectsMap) => {
|
|
57
|
+
const subjectName = model.subjectId ? subjectsMap?.get(model.subjectId) || "" : "";
|
|
58
|
+
return {
|
|
59
|
+
id: model.id,
|
|
60
|
+
title: model.title || "Sem t\xEDtulo",
|
|
61
|
+
savedAt: dayjs(model.createdAt).format("DD/MM/YYYY"),
|
|
62
|
+
subject: subjectName,
|
|
63
|
+
subjectId: model.subjectId
|
|
64
|
+
};
|
|
65
|
+
};
|
|
66
|
+
var handleGoalModelFetchError = createFetchErrorHandler(
|
|
67
|
+
"Erro ao validar dados de modelos de aulas",
|
|
68
|
+
"Erro ao carregar modelos de aulas"
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
// src/hooks/useGoalDrafts.ts
|
|
72
|
+
var DEFAULT_GOAL_DRAFTS_PAGINATION = {
|
|
73
|
+
total: 0,
|
|
74
|
+
page: 1,
|
|
75
|
+
limit: 10,
|
|
76
|
+
totalPages: 0
|
|
77
|
+
};
|
|
78
|
+
var handleGoalDraftFetchError = createFetchErrorHandler(
|
|
79
|
+
"Erro ao validar dados de rascunhos de aulas",
|
|
80
|
+
"Erro ao carregar rascunhos de aulas"
|
|
81
|
+
);
|
|
82
|
+
var createUseGoalDrafts = (fetchGoalDrafts, deleteGoalDraft) => {
|
|
83
|
+
return () => {
|
|
84
|
+
const [state, setState] = useState2({
|
|
85
|
+
models: [],
|
|
86
|
+
loading: false,
|
|
87
|
+
error: null,
|
|
88
|
+
pagination: DEFAULT_GOAL_DRAFTS_PAGINATION
|
|
89
|
+
});
|
|
90
|
+
const fetchModels = useCallback2(
|
|
91
|
+
async (filters, subjectsMap) => {
|
|
92
|
+
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
93
|
+
try {
|
|
94
|
+
const responseData = await fetchGoalDrafts(filters);
|
|
95
|
+
const validatedData = goalModelsApiResponseSchema.parse(responseData);
|
|
96
|
+
const tableItems = validatedData.data.drafts.map(
|
|
97
|
+
(draft) => transformGoalModelToTableItem(draft, subjectsMap)
|
|
98
|
+
);
|
|
99
|
+
const limit = filters?.limit || 10;
|
|
100
|
+
const page = filters?.page || 1;
|
|
101
|
+
const total = validatedData.data.total;
|
|
102
|
+
const totalPages = Math.ceil(total / limit);
|
|
103
|
+
setState({
|
|
104
|
+
models: tableItems,
|
|
105
|
+
loading: false,
|
|
106
|
+
error: null,
|
|
107
|
+
pagination: {
|
|
108
|
+
total,
|
|
109
|
+
page,
|
|
110
|
+
limit,
|
|
111
|
+
totalPages
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
} catch (error) {
|
|
115
|
+
const errorMessage = handleGoalDraftFetchError(error);
|
|
116
|
+
setState((prev) => ({
|
|
117
|
+
...prev,
|
|
118
|
+
loading: false,
|
|
119
|
+
error: errorMessage
|
|
120
|
+
}));
|
|
121
|
+
}
|
|
122
|
+
},
|
|
123
|
+
[fetchGoalDrafts]
|
|
124
|
+
);
|
|
125
|
+
const deleteModel = useCallback2(
|
|
126
|
+
async (id) => {
|
|
127
|
+
try {
|
|
128
|
+
await deleteGoalDraft(id);
|
|
129
|
+
return true;
|
|
130
|
+
} catch (error) {
|
|
131
|
+
console.error("Erro ao deletar rascunho:", error);
|
|
132
|
+
return false;
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
[deleteGoalDraft]
|
|
136
|
+
);
|
|
137
|
+
return {
|
|
138
|
+
...state,
|
|
139
|
+
fetchModels,
|
|
140
|
+
deleteModel
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
var createGoalDraftsHook = createUseGoalDrafts;
|
|
145
|
+
export {
|
|
146
|
+
DEFAULT_GOAL_DRAFTS_PAGINATION,
|
|
147
|
+
createGoalDraftsHook,
|
|
148
|
+
createUseGoalDrafts,
|
|
149
|
+
handleGoalDraftFetchError
|
|
150
|
+
};
|
|
151
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/useGoalDrafts.ts","../../../src/hooks/useGoalModels.ts","../../../src/types/recommendedLessons.ts","../../../src/utils/hookErrorHandler.ts"],"sourcesContent":["import { useState, useCallback } from 'react';\nimport {\n goalModelsApiResponseSchema,\n transformGoalModelToTableItem,\n} from './useGoalModels';\nimport { createFetchErrorHandler } from '../utils/hookErrorHandler';\nimport type {\n GoalModelTableItem,\n GoalModelsApiResponse,\n GoalModelFilters,\n GoalModelPagination,\n} from '../types/recommendedLessons';\n\n/**\n * Hook state interface for goal drafts\n */\nexport interface UseGoalDraftsState {\n models: GoalModelTableItem[];\n loading: boolean;\n error: string | null;\n pagination: GoalModelPagination;\n}\n\n/**\n * Hook return type for goal drafts\n */\nexport interface UseGoalDraftsReturn extends UseGoalDraftsState {\n fetchModels: (\n filters?: GoalModelFilters,\n subjectsMap?: Map<string, string>\n ) => Promise<void>;\n deleteModel: (id: string) => Promise<boolean>;\n}\n\n/**\n * Default pagination values for drafts\n */\nexport const DEFAULT_GOAL_DRAFTS_PAGINATION: GoalModelPagination = {\n total: 0,\n page: 1,\n limit: 10,\n totalPages: 0,\n};\n\n/**\n * Handle errors during draft fetch\n * Uses the generic error handler factory to reduce code duplication\n */\nexport const handleGoalDraftFetchError = createFetchErrorHandler(\n 'Erro ao validar dados de rascunhos de aulas',\n 'Erro ao carregar rascunhos de aulas'\n);\n\n/**\n * Factory function to create useGoalDrafts hook\n *\n * @param fetchGoalDrafts - Function to fetch drafts from API\n * @param deleteGoalDraft - Function to delete a draft\n * @returns Hook for managing goal drafts\n *\n * @example\n * ```tsx\n * // In your app setup\n * const fetchGoalDrafts = async (filters) => {\n * const response = await api.get('/recommended-class/drafts', { params: { ...filters, type: 'RASCUNHO' } });\n * return response.data;\n * };\n *\n * const deleteGoalDraft = async (id) => {\n * await api.delete(`/recommended-class/drafts/${id}`);\n * };\n *\n * const useGoalDrafts = createUseGoalDrafts(fetchGoalDrafts, deleteGoalDraft);\n *\n * // In your component\n * const { models, loading, error, pagination, fetchModels, deleteModel } = useGoalDrafts();\n * ```\n */\nexport const createUseGoalDrafts = (\n fetchGoalDrafts: (\n filters?: GoalModelFilters\n ) => Promise<GoalModelsApiResponse>,\n deleteGoalDraft: (id: string) => Promise<void>\n) => {\n return (): UseGoalDraftsReturn => {\n const [state, setState] = useState<UseGoalDraftsState>({\n models: [],\n loading: false,\n error: null,\n pagination: DEFAULT_GOAL_DRAFTS_PAGINATION,\n });\n\n /**\n * Fetch goal drafts from API\n * @param filters - Optional filters for pagination, search, etc.\n * @param subjectsMap - Map of subject IDs to subject names for display\n */\n const fetchModels = useCallback(\n async (filters?: GoalModelFilters, subjectsMap?: Map<string, string>) => {\n setState((prev) => ({ ...prev, loading: true, error: null }));\n\n try {\n // Fetch data from API\n const responseData = await fetchGoalDrafts(filters);\n\n // Validate response with Zod\n const validatedData = goalModelsApiResponseSchema.parse(responseData);\n\n // Transform drafts to table format\n const tableItems = validatedData.data.drafts.map((draft) =>\n transformGoalModelToTableItem(draft, subjectsMap)\n );\n\n // Calculate pagination\n const limit = filters?.limit || 10;\n const page = filters?.page || 1;\n const total = validatedData.data.total;\n const totalPages = Math.ceil(total / limit);\n\n // Update state with validated and transformed data\n setState({\n models: tableItems,\n loading: false,\n error: null,\n pagination: {\n total,\n page,\n limit,\n totalPages,\n },\n });\n } catch (error) {\n const errorMessage = handleGoalDraftFetchError(error);\n setState((prev) => ({\n ...prev,\n loading: false,\n error: errorMessage,\n }));\n }\n },\n [fetchGoalDrafts]\n );\n\n /**\n * Delete a goal draft\n * @param id - Draft ID to delete\n * @returns True if deletion was successful\n */\n const deleteModel = useCallback(\n async (id: string): Promise<boolean> => {\n try {\n await deleteGoalDraft(id);\n return true;\n } catch (error) {\n console.error('Erro ao deletar rascunho:', error);\n return false;\n }\n },\n [deleteGoalDraft]\n );\n\n return {\n ...state,\n fetchModels,\n deleteModel,\n };\n };\n};\n\n/**\n * Alias for createUseGoalDrafts\n */\nexport const createGoalDraftsHook = createUseGoalDrafts;\n","import { useState, useCallback } from 'react';\nimport { z } from 'zod';\nimport dayjs from 'dayjs';\nimport { GoalDraftType } from '../types/recommendedLessons';\nimport type {\n GoalModelResponse,\n GoalModelTableItem,\n GoalModelsApiResponse,\n GoalModelFilters,\n GoalModelPagination,\n} from '../types/recommendedLessons';\nimport { createFetchErrorHandler } from '../utils/hookErrorHandler';\n\n/**\n * Zod schema for goal model response validation\n */\nconst goalModelResponseSchema = z.object({\n id: z.string().uuid(),\n type: z.nativeEnum(GoalDraftType),\n title: z.string(),\n description: z.string().nullable(),\n creatorUserInstitutionId: z.string().uuid(),\n subjectId: z.string().uuid().nullable(),\n startDate: z.string().nullable(),\n finalDate: z.string().nullable(),\n createdAt: z.string(),\n updatedAt: z.string(),\n});\n\n/**\n * Zod schema for goal models API response validation\n */\nexport const goalModelsApiResponseSchema = z.object({\n message: z.string(),\n data: z.object({\n drafts: z.array(goalModelResponseSchema),\n total: z.number(),\n }),\n});\n\n/**\n * Hook state interface\n */\nexport interface UseGoalModelsState {\n models: GoalModelTableItem[];\n loading: boolean;\n error: string | null;\n pagination: GoalModelPagination;\n}\n\n/**\n * Hook return type\n */\nexport interface UseGoalModelsReturn extends UseGoalModelsState {\n fetchModels: (\n filters?: GoalModelFilters,\n subjectsMap?: Map<string, string>\n ) => Promise<void>;\n deleteModel: (id: string) => Promise<boolean>;\n}\n\n/**\n * Default pagination values\n */\nexport const DEFAULT_GOAL_MODELS_PAGINATION: GoalModelPagination = {\n total: 0,\n page: 1,\n limit: 10,\n totalPages: 0,\n};\n\n/**\n * Transform API response to table item format\n * @param model - Goal model from API response\n * @param subjectsMap - Map of subject IDs to subject names\n * @returns Formatted model for table display\n */\nexport const transformGoalModelToTableItem = (\n model: GoalModelResponse,\n subjectsMap?: Map<string, string>\n): GoalModelTableItem => {\n const subjectName = model.subjectId\n ? subjectsMap?.get(model.subjectId) || ''\n : '';\n\n return {\n id: model.id,\n title: model.title || 'Sem título',\n savedAt: dayjs(model.createdAt).format('DD/MM/YYYY'),\n subject: subjectName,\n subjectId: model.subjectId,\n };\n};\n\n/**\n * Handle errors during model fetch\n * Uses the generic error handler factory to reduce code duplication\n */\nexport const handleGoalModelFetchError = createFetchErrorHandler(\n 'Erro ao validar dados de modelos de aulas',\n 'Erro ao carregar modelos de aulas'\n);\n\n/**\n * Factory function to create useGoalModels hook\n *\n * @param fetchGoalModels - Function to fetch models from API\n * @param deleteGoalModel - Function to delete a model\n * @returns Hook for managing goal models\n *\n * @example\n * ```tsx\n * // In your app setup\n * const fetchGoalModels = async (filters) => {\n * const response = await api.get('/recommended-class/drafts', { params: { ...filters, type: 'MODELO' } });\n * return response.data;\n * };\n *\n * const deleteGoalModel = async (id) => {\n * await api.delete(`/recommended-class/drafts/${id}`);\n * };\n *\n * const useGoalModels = createUseGoalModels(fetchGoalModels, deleteGoalModel);\n *\n * // In your component\n * const { models, loading, error, pagination, fetchModels, deleteModel } = useGoalModels();\n * ```\n */\nexport const createUseGoalModels = (\n fetchGoalModels: (\n filters?: GoalModelFilters\n ) => Promise<GoalModelsApiResponse>,\n deleteGoalModel: (id: string) => Promise<void>\n) => {\n return (): UseGoalModelsReturn => {\n const [state, setState] = useState<UseGoalModelsState>({\n models: [],\n loading: false,\n error: null,\n pagination: DEFAULT_GOAL_MODELS_PAGINATION,\n });\n\n /**\n * Fetch goal models from API\n * @param filters - Optional filters for pagination, search, etc.\n * @param subjectsMap - Map of subject IDs to subject names for display\n */\n const fetchModels = useCallback(\n async (filters?: GoalModelFilters, subjectsMap?: Map<string, string>) => {\n setState((prev) => ({ ...prev, loading: true, error: null }));\n\n try {\n // Fetch data from API\n const responseData = await fetchGoalModels(filters);\n\n // Validate response with Zod\n const validatedData = goalModelsApiResponseSchema.parse(responseData);\n\n // Transform models to table format\n const tableItems = validatedData.data.drafts.map((model) =>\n transformGoalModelToTableItem(model, subjectsMap)\n );\n\n // Calculate pagination\n const limit = filters?.limit || 10;\n const page = filters?.page || 1;\n const total = validatedData.data.total;\n const totalPages = Math.ceil(total / limit);\n\n // Update state with validated and transformed data\n setState({\n models: tableItems,\n loading: false,\n error: null,\n pagination: {\n total,\n page,\n limit,\n totalPages,\n },\n });\n } catch (error) {\n const errorMessage = handleGoalModelFetchError(error);\n setState((prev) => ({\n ...prev,\n loading: false,\n error: errorMessage,\n }));\n }\n },\n [fetchGoalModels]\n );\n\n /**\n * Delete a goal model\n * @param id - Model ID to delete\n * @returns True if deletion was successful\n */\n const deleteModel = useCallback(\n async (id: string): Promise<boolean> => {\n try {\n await deleteGoalModel(id);\n return true;\n } catch (error) {\n console.error('Erro ao deletar modelo:', error);\n return false;\n }\n },\n [deleteGoalModel]\n );\n\n return {\n ...state,\n fetchModels,\n deleteModel,\n };\n };\n};\n\n/**\n * Alias for createUseGoalModels\n */\nexport const createGoalModelsHook = createUseGoalModels;\n","/**\n * Recommended Lessons / Goals (Aulas Recomendadas) Type Definitions\n * Based on /recommended-class/history endpoint\n */\n\nimport {\n GenericApiStatus,\n GenericDisplayStatus,\n BadgeActionType,\n getStatusBadgeAction,\n} from './common';\n\n/**\n * Goal status from backend API\n * Re-exported from common for backward compatibility\n */\nexport { GenericApiStatus as GoalApiStatus } from './common';\n\n/**\n * Goal status for display in UI (Badge component)\n * Re-exported from common for backward compatibility\n */\nexport { GenericDisplayStatus as GoalDisplayStatus } from './common';\n\n/**\n * Badge action types for goal status visualization\n * Re-exported from common for backward compatibility\n */\nexport { BadgeActionType as GoalBadgeActionType } from './common';\n\n/**\n * Subject info from API response\n */\nexport interface GoalSubject {\n id: string;\n name: string;\n}\n\n/**\n * Creator info from API response\n */\nexport interface GoalCreator {\n id: string;\n name: string;\n}\n\n/**\n * Goal stats from API response\n */\nexport interface GoalStats {\n totalStudents: number;\n completedCount: number;\n completionPercentage: number;\n}\n\n/**\n * Class breakdown info from API response\n */\nexport interface GoalBreakdown {\n classId: string;\n className: string;\n schoolId: string;\n schoolName: string;\n studentCount: number;\n completedCount: number;\n}\n\n/**\n * Goal data from API response\n */\nexport interface GoalData {\n id: string;\n title: string;\n startDate: string | null;\n finalDate: string | null;\n createdAt: string;\n progress: number;\n totalLessons: number;\n}\n\n/**\n * Goal history item from /recommended-class/history endpoint\n */\nexport interface GoalHistoryItem {\n goal: GoalData;\n subject: GoalSubject | null;\n creator: GoalCreator | null;\n stats: GoalStats;\n breakdown: GoalBreakdown[];\n}\n\n/**\n * Goal table item interface for goals list table\n */\nexport interface GoalTableItem extends Record<string, unknown> {\n id: string;\n startDate: string | null;\n deadline: string | null;\n title: string;\n school: string;\n year: string;\n subject: string;\n class: string;\n status: GenericDisplayStatus;\n completionPercentage: number;\n}\n\n/**\n * Goals history API complete response from /recommended-class/history\n */\nexport interface GoalsHistoryApiResponse {\n message: string;\n data: {\n goals: GoalHistoryItem[];\n total: number;\n };\n}\n\n/**\n * Goal history filters for API query parameters\n */\nexport interface GoalHistoryFilters {\n page?: number;\n limit?: number;\n status?: GenericApiStatus;\n search?: string;\n startDate?: string;\n finalDate?: string;\n subjectId?: string;\n schoolId?: string;\n schoolIds?: string[];\n classId?: string;\n classIds?: string[];\n studentIds?: string[];\n sortBy?: 'createdAt' | 'finalDate' | 'title' | 'completionPercentage';\n sortOrder?: 'asc' | 'desc';\n}\n\n/**\n * Pagination info for goals history\n */\nexport interface GoalHistoryPagination {\n total: number;\n page: number;\n limit: number;\n totalPages: number;\n}\n\n/**\n * Filter option for dropdowns\n * Extends with index signature to be compatible with CheckBoxGroup Item type\n */\nexport interface GoalFilterOption {\n id: string;\n name: string;\n [key: string]: unknown;\n}\n\n/**\n * User data for filter options (schools, classes, subjects)\n */\nexport interface GoalUserFilterData {\n schools?: Array<{ id: string; name: string }>;\n classes?: Array<{ id: string; name: string; schoolId?: string }>;\n subjects?: Array<{ id: string; name: string }>;\n schoolYears?: Array<{ id: string; name: string }>;\n}\n\n/**\n * Get status badge action based on goal display status\n * @param status - Goal display status\n * @returns Badge action type for styling\n */\nexport const getGoalStatusBadgeAction = (\n status: GenericDisplayStatus\n): BadgeActionType => getStatusBadgeAction(status);\n\n/**\n * Goal status options for filter (Vencida and Ativa)\n */\nexport const GOAL_FILTER_STATUS_OPTIONS: GoalFilterOption[] = [\n { id: GenericApiStatus.VENCIDA, name: 'Vencida' },\n { id: GenericApiStatus.A_VENCER, name: 'Ativa' },\n];\n\n/**\n * All goal status options\n */\nexport const GOAL_STATUS_OPTIONS: GoalFilterOption[] = [\n { id: GenericApiStatus.A_VENCER, name: 'A Vencer' },\n { id: GenericApiStatus.VENCIDA, name: 'Vencida' },\n { id: GenericApiStatus.CONCLUIDA, name: 'Concluída' },\n];\n\n// ============================================\n// Recommended Lesson Details Types\n// Based on /goals/{id} and /goals/{id}/details endpoints\n// ============================================\n\n/**\n * Student status for display in UI\n */\nexport enum StudentLessonStatus {\n A_INICIAR = 'A INICIAR',\n EM_ANDAMENTO = 'EM ANDAMENTO',\n NAO_FINALIZADO = 'NÃO FINALIZADO',\n CONCLUIDO = 'CONCLUÍDO',\n}\n\n/**\n * Badge action type for student status\n */\nexport const getStudentStatusBadgeAction = (\n status: StudentLessonStatus\n): 'success' | 'warning' | 'error' | 'info' => {\n const actionMap: Record<\n StudentLessonStatus,\n 'success' | 'warning' | 'error' | 'info'\n > = {\n [StudentLessonStatus.CONCLUIDO]: 'success',\n [StudentLessonStatus.EM_ANDAMENTO]: 'info',\n [StudentLessonStatus.A_INICIAR]: 'warning',\n [StudentLessonStatus.NAO_FINALIZADO]: 'error',\n };\n return actionMap[status] ?? 'warning';\n};\n\n/**\n * Checks if a deadline has passed\n * @param deadline - ISO date string of the deadline\n * @returns true if deadline has passed, false otherwise\n */\nexport const isDeadlinePassed = (deadline: string | null): boolean => {\n if (!deadline) return false;\n return new Date(deadline) < new Date();\n};\n\n/**\n * Derives student display status from progress, completedAt, and deadline\n * @param progress - Student progress percentage (0-100)\n * @param completedAt - ISO date string when student completed, or null\n * @param deadline - ISO date string of the goal deadline, or null\n * @returns The appropriate StudentLessonStatus\n */\nexport const deriveStudentStatus = (\n progress: number,\n completedAt: string | null,\n deadline?: string | null\n): StudentLessonStatus => {\n // If completed (either by completedAt or 100% progress), it's CONCLUIDO\n if (completedAt) return StudentLessonStatus.CONCLUIDO;\n if (progress === 100) return StudentLessonStatus.CONCLUIDO;\n\n // If deadline passed and not completed, it's NAO_FINALIZADO\n if (isDeadlinePassed(deadline ?? null) && progress < 100) {\n return StudentLessonStatus.NAO_FINALIZADO;\n }\n\n // Otherwise, derive from progress\n if (progress === 0) return StudentLessonStatus.A_INICIAR;\n if (progress > 0) return StudentLessonStatus.EM_ANDAMENTO;\n return StudentLessonStatus.A_INICIAR;\n};\n\n/**\n * Formats days to complete as a readable string\n */\nexport const formatDaysToComplete = (\n daysToComplete: number | null\n): string | null => {\n if (daysToComplete === null) return null;\n if (daysToComplete === 1) return '1 dia';\n return `${daysToComplete} dias`;\n};\n\n// ============================================\n// API Response Types - /goals/{id}/details\n// ============================================\n\n/**\n * Student data from /goals/{id}/details endpoint\n */\nexport interface GoalDetailStudent {\n userInstitutionId: string;\n userId: string;\n name: string;\n progress: number;\n completedAt: string | null;\n avgScore: number | null;\n daysToComplete: number | null;\n}\n\n/**\n * Aggregated stats from /goals/{id}/details endpoint\n */\nexport interface GoalDetailAggregated {\n completionPercentage: number;\n avgScore: number | null;\n}\n\n/**\n * Content performance item from /goals/{id}/details endpoint\n */\nexport interface GoalDetailContentPerformanceItem {\n contentId: string;\n contentName: string;\n rate: number;\n}\n\n/**\n * Content performance from /goals/{id}/details endpoint\n */\nexport interface GoalDetailContentPerformance {\n best: GoalDetailContentPerformanceItem | null;\n worst: GoalDetailContentPerformanceItem | null;\n}\n\n/**\n * Response data from /goals/{id}/details endpoint\n */\nexport interface GoalDetailsData {\n students: GoalDetailStudent[];\n aggregated: GoalDetailAggregated;\n contentPerformance: GoalDetailContentPerformance;\n}\n\n/**\n * Full API response from /goals/{id}/details endpoint\n */\nexport interface GoalDetailsApiResponse {\n message: string;\n data: GoalDetailsData;\n}\n\n// ============================================\n// Goal Activity Types - /goals/{id} activities\n// ============================================\n\n/**\n * Activity status for goal activities\n * Used in activitiesGoals array from /goals/{id} endpoint\n */\nexport const GOAL_ACTIVITY_STATUS = {\n PENDENTE: 'PENDENTE',\n CONCLUIDA: 'CONCLUIDA',\n EXPIRADA: 'EXPIRADA',\n} as const;\n\nexport type GoalActivityStatus =\n (typeof GOAL_ACTIVITY_STATUS)[keyof typeof GOAL_ACTIVITY_STATUS];\n\n/**\n * Activity details within a goal\n */\nexport interface GoalActivity {\n id: string;\n title: string;\n status: GoalActivityStatus;\n}\n\n/**\n * User activities within a goal\n */\nexport interface GoalSupUsersActivities {\n id: string;\n activity: GoalActivity;\n userInstitutionId: string;\n answeredAt: string | null;\n timeSpent: number;\n score: number | null;\n lastInteraction: string;\n}\n\n/**\n * Activities associated with a goal\n */\nexport interface GoalActivitiesGoals {\n goalId: string;\n supUsersActivitiesId: string;\n supUsersActivities: GoalSupUsersActivities;\n}\n\n// ============================================\n// API Response Types - /goals/{id}\n// ============================================\n\n/**\n * Subject info from lesson in /goals/{id} response\n */\nexport interface GoalLessonSubject {\n id: string;\n name: string;\n color: string;\n icon: string;\n}\n\n/**\n * Lesson info from /goals/{id} response\n */\nexport interface GoalLesson {\n id: string;\n content: { id: string; name: string };\n subtopic: { id: string; name: string };\n topic: { id: string; name: string };\n subject: GoalLessonSubject;\n}\n\n/**\n * Lesson progress from /goals/{id} response\n */\nexport interface GoalLessonProgress {\n id: string;\n userId: string;\n lessonId: string;\n progress: number;\n lesson: GoalLesson;\n}\n\n/**\n * Lesson goal item from /goals/{id} response\n */\nexport interface GoalLessonGoalItem {\n goalId: string;\n supLessonsProgressId: string;\n supLessonsProgress: GoalLessonProgress;\n}\n\n/**\n * Goal metadata from /goals/{id} endpoint\n */\nexport interface GoalMetadata {\n id: string;\n title: string;\n startDate: string;\n finalDate: string;\n progress: number;\n lessonsGoals: GoalLessonGoalItem[];\n activitiesGoals?: GoalActivitiesGoals[];\n}\n\n/**\n * Full API response from /goals/{id} endpoint\n */\nexport interface GoalApiResponse {\n message: string;\n data: GoalMetadata;\n}\n\n// ============================================\n// Combined Data for Component\n// ============================================\n\n/**\n * Combined data structure for RecommendedLessonDetails component\n * Combines data from /goals/{id}, /goals/{id}/details, and breakdown info\n */\nexport interface LessonDetailsData {\n /** Goal metadata from /goals/{id} */\n goal: GoalMetadata;\n /** Details from /goals/{id}/details */\n details: GoalDetailsData;\n /** Optional breakdown info from /recommended-class/history */\n breakdown?: GoalBreakdown;\n}\n\n// ============================================\n// Goal Draft/Model Types\n// Based on /recommended-class/drafts endpoint\n// ============================================\n\n/**\n * Goal draft type enum - matches backend GOAL_DRAFT_TYPE\n */\nexport enum GoalDraftType {\n MODELO = 'MODELO',\n RASCUNHO = 'RASCUNHO',\n}\n\n/**\n * Goal model response from backend API /recommended-class/drafts\n */\nexport interface GoalModelResponse {\n id: string;\n type: GoalDraftType;\n title: string;\n description: string | null;\n creatorUserInstitutionId: string;\n subjectId: string | null;\n startDate: string | null;\n finalDate: string | null;\n createdAt: string;\n updatedAt: string;\n}\n\n/**\n * Goal model table item for display in models table\n */\nexport interface GoalModelTableItem extends Record<string, unknown> {\n id: string;\n title: string;\n savedAt: string;\n subject: string;\n subjectId: string | null;\n}\n\n/**\n * Goal models API complete response from /recommended-class/drafts\n */\nexport interface GoalModelsApiResponse {\n message: string;\n data: {\n drafts: GoalModelResponse[];\n total: number;\n };\n}\n\n/**\n * Goal model filters for API query parameters\n */\nexport interface GoalModelFilters {\n page?: number;\n limit?: number;\n search?: string;\n subjectId?: string;\n type?: GoalDraftType;\n}\n\n/**\n * Pagination info for goal models\n */\nexport interface GoalModelPagination {\n total: number;\n page: number;\n limit: number;\n totalPages: number;\n}\n","import { z } from 'zod';\n\n/**\n * Factory function to create a fetch error handler\n * This reduces code duplication across data fetching hooks\n *\n * @param validationErrorMessage - Message to display for Zod validation errors\n * @param genericErrorMessage - Message to display for other errors\n * @returns Error handler function that returns appropriate error message\n *\n * @example\n * ```typescript\n * const handleFetchError = createFetchErrorHandler(\n * 'Erro ao validar dados',\n * 'Erro ao carregar dados'\n * );\n *\n * try {\n * // fetch data\n * } catch (error) {\n * const errorMessage = handleFetchError(error);\n * }\n * ```\n */\nexport const createFetchErrorHandler =\n (validationErrorMessage: string, genericErrorMessage: string) =>\n (error: unknown): string => {\n if (error instanceof z.ZodError) {\n console.error(validationErrorMessage, error);\n return validationErrorMessage;\n }\n\n console.error(genericErrorMessage, error);\n return genericErrorMessage;\n };\n"],"mappings":";AAAA,SAAS,YAAAA,WAAU,eAAAC,oBAAmB;;;ACAtC,SAAS,UAAU,mBAAmB;AACtC,SAAS,KAAAC,UAAS;AAClB,OAAO,WAAW;;;ACkLX,IAAM,6BAAiD;AAAA,EAC5D,EAAE,6BAA8B,MAAM,UAAU;AAAA,EAChD,EAAE,+BAA+B,MAAM,QAAQ;AACjD;AAKO,IAAM,sBAA0C;AAAA,EACrD,EAAE,+BAA+B,MAAM,WAAW;AAAA,EAClD,EAAE,6BAA8B,MAAM,UAAU;AAAA,EAChD,EAAE,iCAAgC,MAAM,eAAY;AACtD;AAyRO,IAAK,gBAAL,kBAAKC,m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cA;AAAA,MAClB,OAAO,OAAiC;AACtC,YAAI;AACF,gBAAM,gBAAgB,EAAE;AACxB,iBAAO;AAAA,QACT,SAAS,OAAO;AACd,kBAAQ,MAAM,6BAA6B,KAAK;AAChD,iBAAO;AAAA,QACT;AAAA,MACF;AAAA,MACA,CAAC,eAAe;AAAA,IAClB;AAEA,WAAO;AAAA,MACL,GAAG;AAAA,MACH;AAAA,MACA;AAAA,IACF;AAAA,EACF;AACF;AAKO,IAAM,uBAAuB;","names":["useState","useCallback","z","GoalDraftType","z","useState","useCallback"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { GoalModelTableItem, GoalModelsApiResponse, GoalModelFilters, GoalModelPagination } from '../types/recommendedLessons';
|
|
2
|
+
/**
|
|
3
|
+
* Hook state interface for goal drafts
|
|
4
|
+
*/
|
|
5
|
+
export interface UseGoalDraftsState {
|
|
6
|
+
models: GoalModelTableItem[];
|
|
7
|
+
loading: boolean;
|
|
8
|
+
error: string | null;
|
|
9
|
+
pagination: GoalModelPagination;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Hook return type for goal drafts
|
|
13
|
+
*/
|
|
14
|
+
export interface UseGoalDraftsReturn extends UseGoalDraftsState {
|
|
15
|
+
fetchModels: (filters?: GoalModelFilters, subjectsMap?: Map<string, string>) => Promise<void>;
|
|
16
|
+
deleteModel: (id: string) => Promise<boolean>;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Default pagination values for drafts
|
|
20
|
+
*/
|
|
21
|
+
export declare const DEFAULT_GOAL_DRAFTS_PAGINATION: GoalModelPagination;
|
|
22
|
+
/**
|
|
23
|
+
* Handle errors during draft fetch
|
|
24
|
+
* Uses the generic error handler factory to reduce code duplication
|
|
25
|
+
*/
|
|
26
|
+
export declare const handleGoalDraftFetchError: (error: unknown) => string;
|
|
27
|
+
/**
|
|
28
|
+
* Factory function to create useGoalDrafts hook
|
|
29
|
+
*
|
|
30
|
+
* @param fetchGoalDrafts - Function to fetch drafts from API
|
|
31
|
+
* @param deleteGoalDraft - Function to delete a draft
|
|
32
|
+
* @returns Hook for managing goal drafts
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```tsx
|
|
36
|
+
* // In your app setup
|
|
37
|
+
* const fetchGoalDrafts = async (filters) => {
|
|
38
|
+
* const response = await api.get('/recommended-class/drafts', { params: { ...filters, type: 'RASCUNHO' } });
|
|
39
|
+
* return response.data;
|
|
40
|
+
* };
|
|
41
|
+
*
|
|
42
|
+
* const deleteGoalDraft = async (id) => {
|
|
43
|
+
* await api.delete(`/recommended-class/drafts/${id}`);
|
|
44
|
+
* };
|
|
45
|
+
*
|
|
46
|
+
* const useGoalDrafts = createUseGoalDrafts(fetchGoalDrafts, deleteGoalDraft);
|
|
47
|
+
*
|
|
48
|
+
* // In your component
|
|
49
|
+
* const { models, loading, error, pagination, fetchModels, deleteModel } = useGoalDrafts();
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
export declare const createUseGoalDrafts: (fetchGoalDrafts: (filters?: GoalModelFilters) => Promise<GoalModelsApiResponse>, deleteGoalDraft: (id: string) => Promise<void>) => () => UseGoalDraftsReturn;
|
|
53
|
+
/**
|
|
54
|
+
* Alias for createUseGoalDrafts
|
|
55
|
+
*/
|
|
56
|
+
export declare const createGoalDraftsHook: (fetchGoalDrafts: (filters?: GoalModelFilters) => Promise<GoalModelsApiResponse>, deleteGoalDraft: (id: string) => Promise<void>) => () => UseGoalDraftsReturn;
|
|
57
|
+
//# sourceMappingURL=useGoalDrafts.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGoalDrafts.d.ts","sourceRoot":"","sources":["../../src/hooks/useGoalDrafts.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,kBAAkB,EAClB,qBAAqB,EACrB,gBAAgB,EAChB,mBAAmB,EACpB,MAAM,6BAA6B,CAAC;AAErC;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAC7B,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,UAAU,EAAE,mBAAmB,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,kBAAkB;IAC7D,WAAW,EAAE,CACX,OAAO,CAAC,EAAE,gBAAgB,EAC1B,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,KAC9B,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,WAAW,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC/C;AAED;;GAEG;AACH,eAAO,MAAM,8BAA8B,EAAE,mBAK5C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,yBAAyB,4BAGrC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,mBAAmB,GAC9B,iBAAiB,CACf,OAAO,CAAC,EAAE,gBAAgB,KACvB,OAAO,CAAC,qBAAqB,CAAC,EACnC,iBAAiB,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,WAEnC,mBAmFZ,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,oBAAoB,oBA7Fd,CACf,OAAO,CAAC,EAAE,gBAAgB,KACvB,OAAO,CAAC,qBAAqB,CAAC,mBAClB,CAAC,EAAE,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,WAEnC,mBAwF0C,CAAC"}
|
|
@@ -134,6 +134,10 @@ export interface UseRecommendedLessonsPageReturn {
|
|
|
134
134
|
onEditGoal: (id: string) => void;
|
|
135
135
|
onEditModel: (model: GoalModelTableItem) => void;
|
|
136
136
|
onSendLesson: (model: GoalModelTableItem) => void;
|
|
137
|
+
fetchGoalDrafts: (filters?: GoalModelFilters) => Promise<GoalModelsApiResponse>;
|
|
138
|
+
deleteGoalDraft: (id: string) => Promise<void>;
|
|
139
|
+
onSendDraft: (draft: GoalModelTableItem) => void;
|
|
140
|
+
onEditDraft: (draft: GoalModelTableItem) => void;
|
|
137
141
|
emptyStateImage: string;
|
|
138
142
|
noSearchImage: string;
|
|
139
143
|
mapSubjectNameToEnum: (subjectName: string) => SubjectEnum | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useRecommendedLessonsPage.d.ts","sourceRoot":"","sources":["../../src/hooks/useRecommendedLessonsPage.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,uBAAuB,EAC5B,KAAK,aAAa,EAElB,KAAK,gBAAgB,EACrB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACxB,MAAM,6BAA6B,CAAC;AACrC,OAAO,KAAK,EACV,kBAAkB,EAClB,cAAc,EACf,MAAM,qCAAqC,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAEnD;;GAEG;AACH,MAAM,WAAW,2BAA2B;IAC1C,GAAG,EAAE,CAAC,CAAC,EACL,GAAG,EAAE,MAAM,EACX,MAAM,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,KAC1C,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,CAAC;IAC1B,IAAI,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,CAAC;IAC/D,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,CAAA;KAAE,CAAC,CAAC;CAClD;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE;QAAE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E,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI,CAAC;CACjE;AAgFD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,eAAO,MAAM,+BAA+B,GAC1C,QAAQ,+BAA+B,KACtC,CAAC,MAAM,+BAA+B,CAgRxC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gCAAgC,WAtRnC,+BAA+B,KACtC,CAAC,MAAM,+BAA+B,CAqRsC,CAAC"}
|
|
@@ -135,6 +135,26 @@ var createUseRecommendedLessonsPage = (config) => {
|
|
|
135
135
|
},
|
|
136
136
|
[api, endpoints.goalDrafts]
|
|
137
137
|
);
|
|
138
|
+
const fetchGoalDrafts = (0, import_react.useCallback)(
|
|
139
|
+
async (filters) => {
|
|
140
|
+
const params = buildQueryParams({
|
|
141
|
+
...filters,
|
|
142
|
+
type: "RASCUNHO" /* RASCUNHO */
|
|
143
|
+
});
|
|
144
|
+
const response = await api.get(
|
|
145
|
+
endpoints.goalDrafts,
|
|
146
|
+
{ params }
|
|
147
|
+
);
|
|
148
|
+
return response.data;
|
|
149
|
+
},
|
|
150
|
+
[api, endpoints.goalDrafts]
|
|
151
|
+
);
|
|
152
|
+
const deleteGoalDraft = (0, import_react.useCallback)(
|
|
153
|
+
async (id) => {
|
|
154
|
+
await api.delete(`${endpoints.goalDrafts}/${id}`);
|
|
155
|
+
},
|
|
156
|
+
[api, endpoints.goalDrafts]
|
|
157
|
+
);
|
|
138
158
|
const handleCreateLesson = (0, import_react.useCallback)(() => {
|
|
139
159
|
navigate(paths.createLesson);
|
|
140
160
|
}, []);
|
|
@@ -216,6 +236,10 @@ var createUseRecommendedLessonsPage = (config) => {
|
|
|
216
236
|
onEditGoal: handleEditGoal,
|
|
217
237
|
onEditModel: handleEditModel,
|
|
218
238
|
onSendLesson: handleSendLesson,
|
|
239
|
+
fetchGoalDrafts,
|
|
240
|
+
deleteGoalDraft,
|
|
241
|
+
onSendDraft: handleSendLesson,
|
|
242
|
+
onEditDraft: handleEditModel,
|
|
219
243
|
emptyStateImage,
|
|
220
244
|
noSearchImage,
|
|
221
245
|
mapSubjectNameToEnum,
|