analytica-frontend-lib 1.2.47 → 1.2.49
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/ActivityCardQuestionBanks/index.css +28 -2
- package/dist/ActivityCardQuestionBanks/index.css.map +1 -1
- package/dist/ActivityCardQuestionPreview/index.css +28 -2
- package/dist/ActivityCardQuestionPreview/index.css.map +1 -1
- package/dist/ActivityDetails/index.css +28 -2
- package/dist/ActivityDetails/index.css.map +1 -1
- package/dist/ActivityFilters/index.css +28 -2
- package/dist/ActivityFilters/index.css.map +1 -1
- package/dist/ActivityPreview/index.css +28 -2
- package/dist/ActivityPreview/index.css.map +1 -1
- package/dist/AlertManager/index.css +28 -2
- package/dist/AlertManager/index.css.map +1 -1
- package/dist/ProgressCircle/index.d.ts.map +1 -1
- package/dist/ProgressCircle/index.js +8 -8
- package/dist/ProgressCircle/index.js.map +1 -1
- package/dist/ProgressCircle/index.mjs +8 -8
- package/dist/ProgressCircle/index.mjs.map +1 -1
- package/dist/RecommendedLessonDetails/index.d.ts +4 -0
- package/dist/RecommendedLessonDetails/index.d.ts.map +1 -0
- package/dist/RecommendedLessonDetails/index.js +2250 -0
- package/dist/RecommendedLessonDetails/index.js.map +1 -0
- package/dist/RecommendedLessonDetails/index.mjs +2242 -0
- package/dist/RecommendedLessonDetails/index.mjs.map +1 -0
- package/dist/RecommendedLessonsHistory/index.css +28 -2
- package/dist/RecommendedLessonsHistory/index.css.map +1 -1
- package/dist/RecommendedLessonsHistory/index.js +3 -5
- package/dist/RecommendedLessonsHistory/index.js.map +1 -1
- package/dist/RecommendedLessonsHistory/index.mjs +3 -5
- package/dist/RecommendedLessonsHistory/index.mjs.map +1 -1
- package/dist/SendActivityModal/SendActivityModal.css +19353 -0
- package/dist/SendActivityModal/SendActivityModal.css.map +1 -0
- package/dist/SendActivityModal/SendActivityModal.d.ts +12 -0
- package/dist/SendActivityModal/SendActivityModal.d.ts.map +1 -0
- package/dist/SendActivityModal/SendActivityModal.js +6446 -0
- package/dist/SendActivityModal/SendActivityModal.js.map +1 -0
- package/dist/SendActivityModal/SendActivityModal.mjs +6486 -0
- package/dist/SendActivityModal/SendActivityModal.mjs.map +1 -0
- package/dist/SendActivityModal/hooks/useSendActivityModal.d.ts +43 -0
- package/dist/SendActivityModal/hooks/useSendActivityModal.d.ts.map +1 -0
- package/dist/SendActivityModal/hooks/useSendActivityModal.js +269 -0
- package/dist/SendActivityModal/hooks/useSendActivityModal.js.map +1 -0
- package/dist/SendActivityModal/hooks/useSendActivityModal.mjs +243 -0
- package/dist/SendActivityModal/hooks/useSendActivityModal.mjs.map +1 -0
- package/dist/SendActivityModal/index.css +28 -2
- package/dist/SendActivityModal/index.css.map +1 -1
- package/dist/SendActivityModal/types.d.ts +95 -0
- package/dist/SendActivityModal/types.d.ts.map +1 -0
- package/dist/SendActivityModal/types.js +35 -0
- package/dist/SendActivityModal/types.js.map +1 -0
- package/dist/SendActivityModal/types.mjs +10 -0
- package/dist/SendActivityModal/types.mjs.map +1 -0
- package/dist/SendActivityModal/validation.d.ts +133 -0
- package/dist/SendActivityModal/validation.d.ts.map +1 -0
- package/dist/SendActivityModal/validation.js +178 -0
- package/dist/SendActivityModal/validation.js.map +1 -0
- package/dist/SendActivityModal/validation.mjs +144 -0
- package/dist/SendActivityModal/validation.mjs.map +1 -0
- package/dist/TableProvider/index.css +28 -2
- package/dist/TableProvider/index.css.map +1 -1
- package/dist/hooks/useRecommendedLessonDetails/index.d.ts +780 -0
- package/dist/hooks/useRecommendedLessonDetails/index.d.ts.map +1 -0
- package/dist/hooks/useRecommendedLessonDetails/index.js +204 -0
- package/dist/hooks/useRecommendedLessonDetails/index.js.map +1 -0
- package/dist/hooks/useRecommendedLessonDetails/index.mjs +174 -0
- package/dist/hooks/useRecommendedLessonDetails/index.mjs.map +1 -0
- package/dist/hooks/useRecommendedLessonDetails.d.ts +780 -0
- package/dist/hooks/useRecommendedLessonDetails.d.ts.map +1 -0
- package/dist/index.css +28 -2
- package/dist/index.css.map +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +657 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +645 -10
- package/dist/index.mjs.map +1 -1
- package/dist/styles.css +28 -2
- package/dist/styles.css.map +1 -1
- package/dist/types/recommendedLessons/index.d.ts +156 -0
- package/dist/types/recommendedLessons/index.d.ts.map +1 -1
- package/dist/types/recommendedLessons/index.js +47 -2
- package/dist/types/recommendedLessons/index.js.map +1 -1
- package/dist/types/recommendedLessons/index.mjs +41 -1
- package/dist/types/recommendedLessons/index.mjs.map +1 -1
- package/dist/types/recommendedLessons.d.ts +156 -0
- package/dist/types/recommendedLessons.d.ts.map +1 -1
- package/package.json +3 -1
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { SendActivityFormData, StepErrors, CategoryConfig } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Store interface for SendActivityModal
|
|
4
|
+
*/
|
|
5
|
+
export interface SendActivityModalStore {
|
|
6
|
+
/** Form data */
|
|
7
|
+
formData: Partial<SendActivityFormData>;
|
|
8
|
+
/** Set form data */
|
|
9
|
+
setFormData: (data: Partial<SendActivityFormData>) => void;
|
|
10
|
+
/** Current step (1, 2, or 3) */
|
|
11
|
+
currentStep: number;
|
|
12
|
+
/** Completed steps */
|
|
13
|
+
completedSteps: number[];
|
|
14
|
+
/** Go to a specific step */
|
|
15
|
+
goToStep: (step: number) => void;
|
|
16
|
+
/** Go to next step (validates current step first) */
|
|
17
|
+
nextStep: () => boolean;
|
|
18
|
+
/** Go to previous step */
|
|
19
|
+
previousStep: () => void;
|
|
20
|
+
/** Validation errors */
|
|
21
|
+
errors: StepErrors;
|
|
22
|
+
/** Set errors */
|
|
23
|
+
setErrors: (errors: StepErrors) => void;
|
|
24
|
+
/** Validate current step */
|
|
25
|
+
validateCurrentStep: () => boolean;
|
|
26
|
+
/** Validate all steps */
|
|
27
|
+
validateAllSteps: () => boolean;
|
|
28
|
+
/** Categories state managed by CheckboxGroup */
|
|
29
|
+
categories: CategoryConfig[];
|
|
30
|
+
/** Update categories (called by CheckboxGroup) */
|
|
31
|
+
setCategories: (categories: CategoryConfig[]) => void;
|
|
32
|
+
/** Reset store to initial state */
|
|
33
|
+
reset: () => void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Creates the SendActivityModal store
|
|
37
|
+
*/
|
|
38
|
+
export declare const useSendActivityModalStore: import("zustand").UseBoundStore<import("zustand").StoreApi<SendActivityModalStore>>;
|
|
39
|
+
/**
|
|
40
|
+
* Hook to use the SendActivityModal store
|
|
41
|
+
*/
|
|
42
|
+
export declare function useSendActivityModal(): SendActivityModalStore;
|
|
43
|
+
//# sourceMappingURL=useSendActivityModal.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useSendActivityModal.d.ts","sourceRoot":"","sources":["../../../../src/components/SendActivityModal/hooks/useSendActivityModal.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAG5E;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,gBAAgB;IAChB,QAAQ,EAAE,OAAO,CAAC,oBAAoB,CAAC,CAAC;IACxC,oBAAoB;IACpB,WAAW,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,oBAAoB,CAAC,KAAK,IAAI,CAAC;IAE3D,gCAAgC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,sBAAsB;IACtB,cAAc,EAAE,MAAM,EAAE,CAAC;IACzB,4BAA4B;IAC5B,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACjC,qDAAqD;IACrD,QAAQ,EAAE,MAAM,OAAO,CAAC;IACxB,0BAA0B;IAC1B,YAAY,EAAE,MAAM,IAAI,CAAC;IAEzB,wBAAwB;IACxB,MAAM,EAAE,UAAU,CAAC;IACnB,iBAAiB;IACjB,SAAS,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IACxC,4BAA4B;IAC5B,mBAAmB,EAAE,MAAM,OAAO,CAAC;IACnC,yBAAyB;IACzB,gBAAgB,EAAE,MAAM,OAAO,CAAC;IAEhC,gDAAgD;IAChD,UAAU,EAAE,cAAc,EAAE,CAAC;IAC7B,kDAAkD;IAClD,aAAa,EAAE,CAAC,UAAU,EAAE,cAAc,EAAE,KAAK,IAAI,CAAC;IAEtD,mCAAmC;IACnC,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB;AAsED;;GAEG;AACH,eAAO,MAAM,yBAAyB,qFA8ErC,CAAC;AAEF;;GAEG;AACH,wBAAgB,oBAAoB,2BAEnC"}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/components/SendActivityModal/hooks/useSendActivityModal.ts
|
|
21
|
+
var useSendActivityModal_exports = {};
|
|
22
|
+
__export(useSendActivityModal_exports, {
|
|
23
|
+
useSendActivityModal: () => useSendActivityModal,
|
|
24
|
+
useSendActivityModalStore: () => useSendActivityModalStore
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(useSendActivityModal_exports);
|
|
27
|
+
var import_zustand = require("zustand");
|
|
28
|
+
|
|
29
|
+
// src/components/SendActivityModal/validation.ts
|
|
30
|
+
var import_zod = require("zod");
|
|
31
|
+
var ERROR_MESSAGES = {
|
|
32
|
+
SUBTYPE_REQUIRED: "Campo obrigat\xF3rio! Por favor, selecione uma op\xE7\xE3o para continuar.",
|
|
33
|
+
TITLE_REQUIRED: "Campo obrigat\xF3rio! Por favor, preencha este campo para continuar.",
|
|
34
|
+
STUDENTS_REQUIRED: "Campo obrigat\xF3rio! Por favor, selecione pelo menos um aluno para continuar.",
|
|
35
|
+
START_DATE_REQUIRED: "Campo obrigat\xF3rio! Por favor, preencha este campo para continuar.",
|
|
36
|
+
FINAL_DATE_REQUIRED: "Campo obrigat\xF3rio! Por favor, preencha este campo para continuar.",
|
|
37
|
+
FINAL_DATE_INVALID: "A data final deve ser maior ou igual \xE0 data inicial."
|
|
38
|
+
};
|
|
39
|
+
var activityStepSchema = import_zod.z.object({
|
|
40
|
+
subtype: import_zod.z.enum(["TAREFA", "TRABALHO", "PROVA"], {
|
|
41
|
+
errorMap: () => ({ message: ERROR_MESSAGES.SUBTYPE_REQUIRED })
|
|
42
|
+
}),
|
|
43
|
+
title: import_zod.z.string({ required_error: ERROR_MESSAGES.TITLE_REQUIRED }).transform((val) => val.trim()).refine((val) => val.length > 0, {
|
|
44
|
+
message: ERROR_MESSAGES.TITLE_REQUIRED
|
|
45
|
+
}),
|
|
46
|
+
notification: import_zod.z.string().optional()
|
|
47
|
+
});
|
|
48
|
+
var recipientStepSchema = import_zod.z.object({
|
|
49
|
+
students: import_zod.z.array(
|
|
50
|
+
import_zod.z.object({
|
|
51
|
+
studentId: import_zod.z.string(),
|
|
52
|
+
userInstitutionId: import_zod.z.string()
|
|
53
|
+
}),
|
|
54
|
+
{
|
|
55
|
+
required_error: ERROR_MESSAGES.STUDENTS_REQUIRED,
|
|
56
|
+
invalid_type_error: ERROR_MESSAGES.STUDENTS_REQUIRED
|
|
57
|
+
}
|
|
58
|
+
).min(1, ERROR_MESSAGES.STUDENTS_REQUIRED)
|
|
59
|
+
});
|
|
60
|
+
var DATE_REGEX = /^\d{4}-\d{2}-\d{2}$/;
|
|
61
|
+
var TIME_REGEX = /^\d{2}:\d{2}$/;
|
|
62
|
+
var deadlineStepBaseSchema = import_zod.z.object({
|
|
63
|
+
startDate: import_zod.z.string({
|
|
64
|
+
required_error: ERROR_MESSAGES.START_DATE_REQUIRED,
|
|
65
|
+
invalid_type_error: ERROR_MESSAGES.START_DATE_REQUIRED
|
|
66
|
+
}).min(1, ERROR_MESSAGES.START_DATE_REQUIRED).regex(DATE_REGEX, ERROR_MESSAGES.START_DATE_REQUIRED),
|
|
67
|
+
startTime: import_zod.z.string().regex(TIME_REGEX).default("00:00"),
|
|
68
|
+
finalDate: import_zod.z.string({
|
|
69
|
+
required_error: ERROR_MESSAGES.FINAL_DATE_REQUIRED,
|
|
70
|
+
invalid_type_error: ERROR_MESSAGES.FINAL_DATE_REQUIRED
|
|
71
|
+
}).min(1, ERROR_MESSAGES.FINAL_DATE_REQUIRED).regex(DATE_REGEX, ERROR_MESSAGES.FINAL_DATE_REQUIRED),
|
|
72
|
+
finalTime: import_zod.z.string().regex(TIME_REGEX).default("23:59"),
|
|
73
|
+
canRetry: import_zod.z.boolean().default(false)
|
|
74
|
+
});
|
|
75
|
+
var deadlineStepSchema = deadlineStepBaseSchema.refine(
|
|
76
|
+
(data) => {
|
|
77
|
+
const start = /* @__PURE__ */ new Date(`${data.startDate}T${data.startTime}`);
|
|
78
|
+
const end = /* @__PURE__ */ new Date(`${data.finalDate}T${data.finalTime}`);
|
|
79
|
+
return end >= start;
|
|
80
|
+
},
|
|
81
|
+
{ message: ERROR_MESSAGES.FINAL_DATE_INVALID, path: ["finalDate"] }
|
|
82
|
+
);
|
|
83
|
+
function validateActivityStep(data) {
|
|
84
|
+
const errors = {};
|
|
85
|
+
const result = activityStepSchema.safeParse({
|
|
86
|
+
subtype: data.subtype,
|
|
87
|
+
title: data.title,
|
|
88
|
+
notification: data.notification
|
|
89
|
+
});
|
|
90
|
+
if (!result.success) {
|
|
91
|
+
result.error.issues.forEach((issue) => {
|
|
92
|
+
const field = issue.path[0];
|
|
93
|
+
if (field === "subtype" || field === "title") {
|
|
94
|
+
errors[field] = issue.message;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return errors;
|
|
99
|
+
}
|
|
100
|
+
function validateRecipientStep(data) {
|
|
101
|
+
const errors = {};
|
|
102
|
+
const result = recipientStepSchema.safeParse({
|
|
103
|
+
students: data.students
|
|
104
|
+
});
|
|
105
|
+
if (!result.success) {
|
|
106
|
+
result.error.issues.forEach((issue) => {
|
|
107
|
+
if (issue.path[0] === "students") {
|
|
108
|
+
errors.students = issue.message;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
return errors;
|
|
113
|
+
}
|
|
114
|
+
function validateDeadlineStep(data) {
|
|
115
|
+
const errors = {};
|
|
116
|
+
if (!data.startDate) {
|
|
117
|
+
errors.startDate = ERROR_MESSAGES.START_DATE_REQUIRED;
|
|
118
|
+
}
|
|
119
|
+
if (!data.finalDate) {
|
|
120
|
+
errors.finalDate = ERROR_MESSAGES.FINAL_DATE_REQUIRED;
|
|
121
|
+
}
|
|
122
|
+
if (data.startDate && data.finalDate) {
|
|
123
|
+
const result = deadlineStepSchema.safeParse({
|
|
124
|
+
startDate: data.startDate,
|
|
125
|
+
startTime: data.startTime ?? "00:00",
|
|
126
|
+
finalDate: data.finalDate,
|
|
127
|
+
finalTime: data.finalTime ?? "23:59",
|
|
128
|
+
canRetry: data.canRetry ?? false
|
|
129
|
+
});
|
|
130
|
+
if (!result.success) {
|
|
131
|
+
result.error.issues.forEach((issue) => {
|
|
132
|
+
const field = issue.path[0];
|
|
133
|
+
if (field === "startDate" || field === "finalDate") {
|
|
134
|
+
errors[field] = issue.message;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return errors;
|
|
140
|
+
}
|
|
141
|
+
function validateStep(step, data) {
|
|
142
|
+
switch (step) {
|
|
143
|
+
case 1:
|
|
144
|
+
return validateActivityStep(data);
|
|
145
|
+
case 2:
|
|
146
|
+
return validateRecipientStep(data);
|
|
147
|
+
case 3:
|
|
148
|
+
return validateDeadlineStep(data);
|
|
149
|
+
default:
|
|
150
|
+
return {};
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// src/components/SendActivityModal/hooks/useSendActivityModal.ts
|
|
155
|
+
var initialState = {
|
|
156
|
+
formData: {
|
|
157
|
+
canRetry: false,
|
|
158
|
+
startTime: "00:00",
|
|
159
|
+
finalTime: "23:59"
|
|
160
|
+
},
|
|
161
|
+
currentStep: 1,
|
|
162
|
+
completedSteps: [],
|
|
163
|
+
errors: {},
|
|
164
|
+
categories: []
|
|
165
|
+
};
|
|
166
|
+
function extractStudentsFromCategories(categories) {
|
|
167
|
+
const studentsCategory = categories.find(
|
|
168
|
+
(cat) => cat.key === "students" || cat.key === "alunos" || cat.key === "student"
|
|
169
|
+
);
|
|
170
|
+
if (!studentsCategory?.selectedIds || !studentsCategory.itens) {
|
|
171
|
+
return [];
|
|
172
|
+
}
|
|
173
|
+
return studentsCategory.selectedIds.map((id) => {
|
|
174
|
+
const student = studentsCategory.itens?.find((item) => item.id === id);
|
|
175
|
+
if (student) {
|
|
176
|
+
const rawStudentId = student.studentId;
|
|
177
|
+
const rawUserInstId = student.userInstitutionId;
|
|
178
|
+
const rawInstId = student.institutionId;
|
|
179
|
+
const studentId = typeof rawStudentId === "string" || typeof rawStudentId === "number" ? String(rawStudentId) : student.id;
|
|
180
|
+
let userInstitutionId = "";
|
|
181
|
+
if (typeof rawUserInstId === "string" || typeof rawUserInstId === "number") {
|
|
182
|
+
userInstitutionId = String(rawUserInstId);
|
|
183
|
+
} else if (typeof rawInstId === "string" || typeof rawInstId === "number") {
|
|
184
|
+
userInstitutionId = String(rawInstId);
|
|
185
|
+
}
|
|
186
|
+
if (!userInstitutionId) {
|
|
187
|
+
return null;
|
|
188
|
+
}
|
|
189
|
+
return { studentId, userInstitutionId };
|
|
190
|
+
}
|
|
191
|
+
return null;
|
|
192
|
+
}).filter(
|
|
193
|
+
(s) => s !== null
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
var useSendActivityModalStore = (0, import_zustand.create)(
|
|
197
|
+
(set, get) => ({
|
|
198
|
+
...initialState,
|
|
199
|
+
setFormData: (data) => {
|
|
200
|
+
set((state) => ({
|
|
201
|
+
formData: { ...state.formData, ...data }
|
|
202
|
+
}));
|
|
203
|
+
},
|
|
204
|
+
goToStep: (step) => {
|
|
205
|
+
if (step >= 1 && step <= 3) {
|
|
206
|
+
set({ currentStep: step, errors: {} });
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
nextStep: () => {
|
|
210
|
+
const state = get();
|
|
211
|
+
const isValid = state.validateCurrentStep();
|
|
212
|
+
if (isValid && state.currentStep < 3) {
|
|
213
|
+
set((prev) => ({
|
|
214
|
+
currentStep: prev.currentStep + 1,
|
|
215
|
+
completedSteps: prev.completedSteps.includes(prev.currentStep) ? prev.completedSteps : [...prev.completedSteps, prev.currentStep],
|
|
216
|
+
errors: {}
|
|
217
|
+
}));
|
|
218
|
+
return true;
|
|
219
|
+
}
|
|
220
|
+
return isValid;
|
|
221
|
+
},
|
|
222
|
+
previousStep: () => {
|
|
223
|
+
const state = get();
|
|
224
|
+
if (state.currentStep > 1) {
|
|
225
|
+
set({ currentStep: state.currentStep - 1, errors: {} });
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
setErrors: (errors) => {
|
|
229
|
+
set({ errors });
|
|
230
|
+
},
|
|
231
|
+
validateCurrentStep: () => {
|
|
232
|
+
const state = get();
|
|
233
|
+
const errors = validateStep(state.currentStep, state.formData);
|
|
234
|
+
set({ errors });
|
|
235
|
+
return Object.keys(errors).length === 0;
|
|
236
|
+
},
|
|
237
|
+
validateAllSteps: () => {
|
|
238
|
+
const state = get();
|
|
239
|
+
const errors1 = validateStep(1, state.formData);
|
|
240
|
+
const errors2 = validateStep(2, state.formData);
|
|
241
|
+
const errors3 = validateStep(3, state.formData);
|
|
242
|
+
const allErrors = { ...errors1, ...errors2, ...errors3 };
|
|
243
|
+
set({ errors: allErrors });
|
|
244
|
+
return Object.keys(allErrors).length === 0;
|
|
245
|
+
},
|
|
246
|
+
setCategories: (categories) => {
|
|
247
|
+
const students = extractStudentsFromCategories(categories);
|
|
248
|
+
set((state) => ({
|
|
249
|
+
categories,
|
|
250
|
+
formData: { ...state.formData, students }
|
|
251
|
+
}));
|
|
252
|
+
},
|
|
253
|
+
reset: () => {
|
|
254
|
+
set({
|
|
255
|
+
...initialState,
|
|
256
|
+
categories: []
|
|
257
|
+
});
|
|
258
|
+
}
|
|
259
|
+
})
|
|
260
|
+
);
|
|
261
|
+
function useSendActivityModal() {
|
|
262
|
+
return useSendActivityModalStore();
|
|
263
|
+
}
|
|
264
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
265
|
+
0 && (module.exports = {
|
|
266
|
+
useSendActivityModal,
|
|
267
|
+
useSendActivityModalStore
|
|
268
|
+
});
|
|
269
|
+
//# sourceMappingURL=useSendActivityModal.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/SendActivityModal/hooks/useSendActivityModal.ts","../../../src/components/SendActivityModal/validation.ts"],"sourcesContent":["import { create } from 'zustand';\nimport { SendActivityFormData, StepErrors, CategoryConfig } from '../types';\nimport { validateStep } from '../validation';\n\n/**\n * Store interface for SendActivityModal\n */\nexport interface SendActivityModalStore {\n /** Form data */\n formData: Partial<SendActivityFormData>;\n /** Set form data */\n setFormData: (data: Partial<SendActivityFormData>) => void;\n\n /** Current step (1, 2, or 3) */\n currentStep: number;\n /** Completed steps */\n completedSteps: number[];\n /** Go to a specific step */\n goToStep: (step: number) => void;\n /** Go to next step (validates current step first) */\n nextStep: () => boolean;\n /** Go to previous step */\n previousStep: () => void;\n\n /** Validation errors */\n errors: StepErrors;\n /** Set errors */\n setErrors: (errors: StepErrors) => void;\n /** Validate current step */\n validateCurrentStep: () => boolean;\n /** Validate all steps */\n validateAllSteps: () => boolean;\n\n /** Categories state managed by CheckboxGroup */\n categories: CategoryConfig[];\n /** Update categories (called by CheckboxGroup) */\n setCategories: (categories: CategoryConfig[]) => void;\n\n /** Reset store to initial state */\n reset: () => void;\n}\n\nconst initialState = {\n formData: {\n canRetry: false,\n startTime: '00:00',\n finalTime: '23:59',\n } as Partial<SendActivityFormData>,\n currentStep: 1,\n completedSteps: [] as number[],\n errors: {} as StepErrors,\n categories: [] as CategoryConfig[],\n};\n\n/**\n * Helper to extract selected students from the students category\n */\nfunction extractStudentsFromCategories(\n categories: CategoryConfig[]\n): Array<{ studentId: string; userInstitutionId: string }> {\n // Find the students category (first matching by key 'students', 'alunos', or 'student')\n const studentsCategory = categories.find(\n (cat) =>\n cat.key === 'students' || cat.key === 'alunos' || cat.key === 'student'\n );\n\n if (!studentsCategory?.selectedIds || !studentsCategory.itens) {\n return [];\n }\n\n return studentsCategory.selectedIds\n .map((id) => {\n const student = studentsCategory.itens?.find((item) => item.id === id);\n if (student) {\n const rawStudentId = student.studentId;\n const rawUserInstId = student.userInstitutionId;\n const rawInstId = student.institutionId;\n\n // Extract studentId with type guard\n const studentId =\n typeof rawStudentId === 'string' || typeof rawStudentId === 'number'\n ? String(rawStudentId)\n : student.id;\n let userInstitutionId = '';\n if (\n typeof rawUserInstId === 'string' ||\n typeof rawUserInstId === 'number'\n ) {\n userInstitutionId = String(rawUserInstId);\n } else if (\n typeof rawInstId === 'string' ||\n typeof rawInstId === 'number'\n ) {\n userInstitutionId = String(rawInstId);\n }\n\n // Filter out entries without valid userInstitutionId\n if (!userInstitutionId) {\n return null;\n }\n\n return { studentId, userInstitutionId };\n }\n return null;\n })\n .filter(\n (s): s is { studentId: string; userInstitutionId: string } => s !== null\n );\n}\n\n/**\n * Creates the SendActivityModal store\n */\nexport const useSendActivityModalStore = create<SendActivityModalStore>(\n (set, get) => ({\n ...initialState,\n\n setFormData: (data) => {\n set((state) => ({\n formData: { ...state.formData, ...data },\n }));\n },\n\n goToStep: (step) => {\n if (step >= 1 && step <= 3) {\n set({ currentStep: step, errors: {} });\n }\n },\n\n nextStep: () => {\n const state = get();\n const isValid = state.validateCurrentStep();\n\n if (isValid && state.currentStep < 3) {\n set((prev) => ({\n currentStep: prev.currentStep + 1,\n completedSteps: prev.completedSteps.includes(prev.currentStep)\n ? prev.completedSteps\n : [...prev.completedSteps, prev.currentStep],\n errors: {},\n }));\n return true;\n }\n\n return isValid;\n },\n\n previousStep: () => {\n const state = get();\n if (state.currentStep > 1) {\n set({ currentStep: state.currentStep - 1, errors: {} });\n }\n },\n\n setErrors: (errors) => {\n set({ errors });\n },\n\n validateCurrentStep: () => {\n const state = get();\n const errors = validateStep(state.currentStep, state.formData);\n set({ errors });\n return Object.keys(errors).length === 0;\n },\n\n validateAllSteps: () => {\n const state = get();\n const errors1 = validateStep(1, state.formData);\n const errors2 = validateStep(2, state.formData);\n const errors3 = validateStep(3, state.formData);\n const allErrors = { ...errors1, ...errors2, ...errors3 };\n set({ errors: allErrors });\n return Object.keys(allErrors).length === 0;\n },\n\n setCategories: (categories) => {\n // Extract students from categories and update formData\n const students = extractStudentsFromCategories(categories);\n set((state) => ({\n categories,\n formData: { ...state.formData, students },\n }));\n },\n\n reset: () => {\n set({\n ...initialState,\n categories: [],\n });\n },\n })\n);\n\n/**\n * Hook to use the SendActivityModal store\n */\nexport function useSendActivityModal() {\n return useSendActivityModalStore();\n}\n","import { z } from 'zod';\nimport { SendActivityFormData, StepErrors } from './types';\n\n/**\n * Error messages for validation\n */\nexport const ERROR_MESSAGES = {\n SUBTYPE_REQUIRED:\n 'Campo obrigatório! Por favor, selecione uma opção para continuar.',\n TITLE_REQUIRED:\n 'Campo obrigatório! Por favor, preencha este campo para continuar.',\n STUDENTS_REQUIRED:\n 'Campo obrigatório! Por favor, selecione pelo menos um aluno para continuar.',\n START_DATE_REQUIRED:\n 'Campo obrigatório! Por favor, preencha este campo para continuar.',\n FINAL_DATE_REQUIRED:\n 'Campo obrigatório! Por favor, preencha este campo para continuar.',\n FINAL_DATE_INVALID: 'A data final deve ser maior ou igual à data inicial.',\n} as const;\n\n/**\n * Zod schema for activity step (Step 1)\n */\nexport const activityStepSchema = z.object({\n subtype: z.enum(['TAREFA', 'TRABALHO', 'PROVA'], {\n errorMap: () => ({ message: ERROR_MESSAGES.SUBTYPE_REQUIRED }),\n }),\n title: z\n .string({ required_error: ERROR_MESSAGES.TITLE_REQUIRED })\n .transform((val) => val.trim())\n .refine((val) => val.length > 0, {\n message: ERROR_MESSAGES.TITLE_REQUIRED,\n }),\n notification: z.string().optional(),\n});\n\n/**\n * Zod schema for recipient step (Step 2)\n */\nexport const recipientStepSchema = z.object({\n students: z\n .array(\n z.object({\n studentId: z.string(),\n userInstitutionId: z.string(),\n }),\n {\n required_error: ERROR_MESSAGES.STUDENTS_REQUIRED,\n invalid_type_error: ERROR_MESSAGES.STUDENTS_REQUIRED,\n }\n )\n .min(1, ERROR_MESSAGES.STUDENTS_REQUIRED),\n});\n\n/**\n * Regex patterns for date and time validation\n */\nconst DATE_REGEX = /^\\d{4}-\\d{2}-\\d{2}$/;\nconst TIME_REGEX = /^\\d{2}:\\d{2}$/;\n\n/**\n * Zod schema for deadline step (Step 3) - base validation\n */\nconst deadlineStepBaseSchema = z.object({\n startDate: z\n .string({\n required_error: ERROR_MESSAGES.START_DATE_REQUIRED,\n invalid_type_error: ERROR_MESSAGES.START_DATE_REQUIRED,\n })\n .min(1, ERROR_MESSAGES.START_DATE_REQUIRED)\n .regex(DATE_REGEX, ERROR_MESSAGES.START_DATE_REQUIRED),\n startTime: z.string().regex(TIME_REGEX).default('00:00'),\n finalDate: z\n .string({\n required_error: ERROR_MESSAGES.FINAL_DATE_REQUIRED,\n invalid_type_error: ERROR_MESSAGES.FINAL_DATE_REQUIRED,\n })\n .min(1, ERROR_MESSAGES.FINAL_DATE_REQUIRED)\n .regex(DATE_REGEX, ERROR_MESSAGES.FINAL_DATE_REQUIRED),\n finalTime: z.string().regex(TIME_REGEX).default('23:59'),\n canRetry: z.boolean().default(false),\n});\n\n/**\n * Zod schema for deadline step with date comparison refinement\n */\nexport const deadlineStepSchema = deadlineStepBaseSchema.refine(\n (data) => {\n const start = new Date(`${data.startDate}T${data.startTime}`);\n const end = new Date(`${data.finalDate}T${data.finalTime}`);\n return end >= start;\n },\n { message: ERROR_MESSAGES.FINAL_DATE_INVALID, path: ['finalDate'] }\n);\n\n/**\n * Type inference from Zod schemas\n */\nexport type ActivityStepData = z.infer<typeof activityStepSchema>;\nexport type RecipientStepData = z.infer<typeof recipientStepSchema>;\nexport type DeadlineStepData = z.infer<typeof deadlineStepSchema>;\n\n/**\n * Validates the activity step (Step 1) using Zod\n * @param data - Partial form data\n * @returns StepErrors object with any validation errors\n */\nexport function validateActivityStep(\n data: Partial<SendActivityFormData>\n): StepErrors {\n const errors: StepErrors = {};\n\n const result = activityStepSchema.safeParse({\n subtype: data.subtype,\n title: data.title,\n notification: data.notification,\n });\n\n if (!result.success) {\n result.error.issues.forEach((issue) => {\n const field = issue.path[0] as keyof StepErrors;\n if (field === 'subtype' || field === 'title') {\n errors[field] = issue.message;\n }\n });\n }\n\n return errors;\n}\n\n/**\n * Validates the recipient step (Step 2) using Zod\n * @param data - Partial form data\n * @returns StepErrors object with any validation errors\n */\nexport function validateRecipientStep(\n data: Partial<SendActivityFormData>\n): StepErrors {\n const errors: StepErrors = {};\n\n const result = recipientStepSchema.safeParse({\n students: data.students,\n });\n\n if (!result.success) {\n result.error.issues.forEach((issue) => {\n if (issue.path[0] === 'students') {\n errors.students = issue.message;\n }\n });\n }\n\n return errors;\n}\n\n/**\n * Validates the deadline step (Step 3) using Zod\n * @param data - Partial form data\n * @returns StepErrors object with any validation errors\n */\nexport function validateDeadlineStep(\n data: Partial<SendActivityFormData>\n): StepErrors {\n const errors: StepErrors = {};\n\n // First validate individual fields\n if (!data.startDate) {\n errors.startDate = ERROR_MESSAGES.START_DATE_REQUIRED;\n }\n\n if (!data.finalDate) {\n errors.finalDate = ERROR_MESSAGES.FINAL_DATE_REQUIRED;\n }\n\n // If both dates exist, validate with the full schema (including refinement)\n if (data.startDate && data.finalDate) {\n const result = deadlineStepSchema.safeParse({\n startDate: data.startDate,\n startTime: data.startTime ?? '00:00',\n finalDate: data.finalDate,\n finalTime: data.finalTime ?? '23:59',\n canRetry: data.canRetry ?? false,\n });\n\n if (!result.success) {\n result.error.issues.forEach((issue) => {\n const field = issue.path[0] as keyof StepErrors;\n if (field === 'startDate' || field === 'finalDate') {\n errors[field] = issue.message;\n }\n });\n }\n }\n\n return errors;\n}\n\n/**\n * Validates a specific step\n * @param step - Step number (1, 2, or 3)\n * @param data - Partial form data\n * @returns StepErrors object with any validation errors\n */\nexport function validateStep(\n step: number,\n data: Partial<SendActivityFormData>\n): StepErrors {\n switch (step) {\n case 1:\n return validateActivityStep(data);\n case 2:\n return validateRecipientStep(data);\n case 3:\n return validateDeadlineStep(data);\n default:\n return {};\n }\n}\n\n/**\n * Checks if a specific step is valid\n * @param step - Step number (1, 2, or 3)\n * @param data - Partial form data\n * @returns true if the step is valid\n */\nexport function isStepValid(\n step: number,\n data: Partial<SendActivityFormData>\n): boolean {\n const errors = validateStep(step, data);\n return Object.keys(errors).length === 0;\n}\n\n/**\n * Checks if all steps are valid (form can be submitted)\n * @param data - Partial form data\n * @returns true if all steps are valid\n */\nexport function isFormValid(data: Partial<SendActivityFormData>): boolean {\n return isStepValid(1, data) && isStepValid(2, data) && isStepValid(3, data);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;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,QACF,GAAG;AAAA,QACH,YAAY,CAAC;AAAA,MACf,CAAC;AAAA,IACH;AAAA,EACF;AACF;AAKO,SAAS,uBAAuB;AACrC,SAAO,0BAA0B;AACnC;","names":[]}
|
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// src/components/SendActivityModal/hooks/useSendActivityModal.ts
|
|
2
|
+
import { create } from "zustand";
|
|
3
|
+
|
|
4
|
+
// src/components/SendActivityModal/validation.ts
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
var ERROR_MESSAGES = {
|
|
7
|
+
SUBTYPE_REQUIRED: "Campo obrigat\xF3rio! Por favor, selecione uma op\xE7\xE3o para continuar.",
|
|
8
|
+
TITLE_REQUIRED: "Campo obrigat\xF3rio! Por favor, preencha este campo para continuar.",
|
|
9
|
+
STUDENTS_REQUIRED: "Campo obrigat\xF3rio! Por favor, selecione pelo menos um aluno para continuar.",
|
|
10
|
+
START_DATE_REQUIRED: "Campo obrigat\xF3rio! Por favor, preencha este campo para continuar.",
|
|
11
|
+
FINAL_DATE_REQUIRED: "Campo obrigat\xF3rio! Por favor, preencha este campo para continuar.",
|
|
12
|
+
FINAL_DATE_INVALID: "A data final deve ser maior ou igual \xE0 data inicial."
|
|
13
|
+
};
|
|
14
|
+
var activityStepSchema = z.object({
|
|
15
|
+
subtype: z.enum(["TAREFA", "TRABALHO", "PROVA"], {
|
|
16
|
+
errorMap: () => ({ message: ERROR_MESSAGES.SUBTYPE_REQUIRED })
|
|
17
|
+
}),
|
|
18
|
+
title: z.string({ required_error: ERROR_MESSAGES.TITLE_REQUIRED }).transform((val) => val.trim()).refine((val) => val.length > 0, {
|
|
19
|
+
message: ERROR_MESSAGES.TITLE_REQUIRED
|
|
20
|
+
}),
|
|
21
|
+
notification: z.string().optional()
|
|
22
|
+
});
|
|
23
|
+
var recipientStepSchema = z.object({
|
|
24
|
+
students: z.array(
|
|
25
|
+
z.object({
|
|
26
|
+
studentId: z.string(),
|
|
27
|
+
userInstitutionId: z.string()
|
|
28
|
+
}),
|
|
29
|
+
{
|
|
30
|
+
required_error: ERROR_MESSAGES.STUDENTS_REQUIRED,
|
|
31
|
+
invalid_type_error: ERROR_MESSAGES.STUDENTS_REQUIRED
|
|
32
|
+
}
|
|
33
|
+
).min(1, ERROR_MESSAGES.STUDENTS_REQUIRED)
|
|
34
|
+
});
|
|
35
|
+
var DATE_REGEX = /^\d{4}-\d{2}-\d{2}$/;
|
|
36
|
+
var TIME_REGEX = /^\d{2}:\d{2}$/;
|
|
37
|
+
var deadlineStepBaseSchema = z.object({
|
|
38
|
+
startDate: z.string({
|
|
39
|
+
required_error: ERROR_MESSAGES.START_DATE_REQUIRED,
|
|
40
|
+
invalid_type_error: ERROR_MESSAGES.START_DATE_REQUIRED
|
|
41
|
+
}).min(1, ERROR_MESSAGES.START_DATE_REQUIRED).regex(DATE_REGEX, ERROR_MESSAGES.START_DATE_REQUIRED),
|
|
42
|
+
startTime: z.string().regex(TIME_REGEX).default("00:00"),
|
|
43
|
+
finalDate: z.string({
|
|
44
|
+
required_error: ERROR_MESSAGES.FINAL_DATE_REQUIRED,
|
|
45
|
+
invalid_type_error: ERROR_MESSAGES.FINAL_DATE_REQUIRED
|
|
46
|
+
}).min(1, ERROR_MESSAGES.FINAL_DATE_REQUIRED).regex(DATE_REGEX, ERROR_MESSAGES.FINAL_DATE_REQUIRED),
|
|
47
|
+
finalTime: z.string().regex(TIME_REGEX).default("23:59"),
|
|
48
|
+
canRetry: z.boolean().default(false)
|
|
49
|
+
});
|
|
50
|
+
var deadlineStepSchema = deadlineStepBaseSchema.refine(
|
|
51
|
+
(data) => {
|
|
52
|
+
const start = /* @__PURE__ */ new Date(`${data.startDate}T${data.startTime}`);
|
|
53
|
+
const end = /* @__PURE__ */ new Date(`${data.finalDate}T${data.finalTime}`);
|
|
54
|
+
return end >= start;
|
|
55
|
+
},
|
|
56
|
+
{ message: ERROR_MESSAGES.FINAL_DATE_INVALID, path: ["finalDate"] }
|
|
57
|
+
);
|
|
58
|
+
function validateActivityStep(data) {
|
|
59
|
+
const errors = {};
|
|
60
|
+
const result = activityStepSchema.safeParse({
|
|
61
|
+
subtype: data.subtype,
|
|
62
|
+
title: data.title,
|
|
63
|
+
notification: data.notification
|
|
64
|
+
});
|
|
65
|
+
if (!result.success) {
|
|
66
|
+
result.error.issues.forEach((issue) => {
|
|
67
|
+
const field = issue.path[0];
|
|
68
|
+
if (field === "subtype" || field === "title") {
|
|
69
|
+
errors[field] = issue.message;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
return errors;
|
|
74
|
+
}
|
|
75
|
+
function validateRecipientStep(data) {
|
|
76
|
+
const errors = {};
|
|
77
|
+
const result = recipientStepSchema.safeParse({
|
|
78
|
+
students: data.students
|
|
79
|
+
});
|
|
80
|
+
if (!result.success) {
|
|
81
|
+
result.error.issues.forEach((issue) => {
|
|
82
|
+
if (issue.path[0] === "students") {
|
|
83
|
+
errors.students = issue.message;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
return errors;
|
|
88
|
+
}
|
|
89
|
+
function validateDeadlineStep(data) {
|
|
90
|
+
const errors = {};
|
|
91
|
+
if (!data.startDate) {
|
|
92
|
+
errors.startDate = ERROR_MESSAGES.START_DATE_REQUIRED;
|
|
93
|
+
}
|
|
94
|
+
if (!data.finalDate) {
|
|
95
|
+
errors.finalDate = ERROR_MESSAGES.FINAL_DATE_REQUIRED;
|
|
96
|
+
}
|
|
97
|
+
if (data.startDate && data.finalDate) {
|
|
98
|
+
const result = deadlineStepSchema.safeParse({
|
|
99
|
+
startDate: data.startDate,
|
|
100
|
+
startTime: data.startTime ?? "00:00",
|
|
101
|
+
finalDate: data.finalDate,
|
|
102
|
+
finalTime: data.finalTime ?? "23:59",
|
|
103
|
+
canRetry: data.canRetry ?? false
|
|
104
|
+
});
|
|
105
|
+
if (!result.success) {
|
|
106
|
+
result.error.issues.forEach((issue) => {
|
|
107
|
+
const field = issue.path[0];
|
|
108
|
+
if (field === "startDate" || field === "finalDate") {
|
|
109
|
+
errors[field] = issue.message;
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return errors;
|
|
115
|
+
}
|
|
116
|
+
function validateStep(step, data) {
|
|
117
|
+
switch (step) {
|
|
118
|
+
case 1:
|
|
119
|
+
return validateActivityStep(data);
|
|
120
|
+
case 2:
|
|
121
|
+
return validateRecipientStep(data);
|
|
122
|
+
case 3:
|
|
123
|
+
return validateDeadlineStep(data);
|
|
124
|
+
default:
|
|
125
|
+
return {};
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// src/components/SendActivityModal/hooks/useSendActivityModal.ts
|
|
130
|
+
var initialState = {
|
|
131
|
+
formData: {
|
|
132
|
+
canRetry: false,
|
|
133
|
+
startTime: "00:00",
|
|
134
|
+
finalTime: "23:59"
|
|
135
|
+
},
|
|
136
|
+
currentStep: 1,
|
|
137
|
+
completedSteps: [],
|
|
138
|
+
errors: {},
|
|
139
|
+
categories: []
|
|
140
|
+
};
|
|
141
|
+
function extractStudentsFromCategories(categories) {
|
|
142
|
+
const studentsCategory = categories.find(
|
|
143
|
+
(cat) => cat.key === "students" || cat.key === "alunos" || cat.key === "student"
|
|
144
|
+
);
|
|
145
|
+
if (!studentsCategory?.selectedIds || !studentsCategory.itens) {
|
|
146
|
+
return [];
|
|
147
|
+
}
|
|
148
|
+
return studentsCategory.selectedIds.map((id) => {
|
|
149
|
+
const student = studentsCategory.itens?.find((item) => item.id === id);
|
|
150
|
+
if (student) {
|
|
151
|
+
const rawStudentId = student.studentId;
|
|
152
|
+
const rawUserInstId = student.userInstitutionId;
|
|
153
|
+
const rawInstId = student.institutionId;
|
|
154
|
+
const studentId = typeof rawStudentId === "string" || typeof rawStudentId === "number" ? String(rawStudentId) : student.id;
|
|
155
|
+
let userInstitutionId = "";
|
|
156
|
+
if (typeof rawUserInstId === "string" || typeof rawUserInstId === "number") {
|
|
157
|
+
userInstitutionId = String(rawUserInstId);
|
|
158
|
+
} else if (typeof rawInstId === "string" || typeof rawInstId === "number") {
|
|
159
|
+
userInstitutionId = String(rawInstId);
|
|
160
|
+
}
|
|
161
|
+
if (!userInstitutionId) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
return { studentId, userInstitutionId };
|
|
165
|
+
}
|
|
166
|
+
return null;
|
|
167
|
+
}).filter(
|
|
168
|
+
(s) => s !== null
|
|
169
|
+
);
|
|
170
|
+
}
|
|
171
|
+
var useSendActivityModalStore = create(
|
|
172
|
+
(set, get) => ({
|
|
173
|
+
...initialState,
|
|
174
|
+
setFormData: (data) => {
|
|
175
|
+
set((state) => ({
|
|
176
|
+
formData: { ...state.formData, ...data }
|
|
177
|
+
}));
|
|
178
|
+
},
|
|
179
|
+
goToStep: (step) => {
|
|
180
|
+
if (step >= 1 && step <= 3) {
|
|
181
|
+
set({ currentStep: step, errors: {} });
|
|
182
|
+
}
|
|
183
|
+
},
|
|
184
|
+
nextStep: () => {
|
|
185
|
+
const state = get();
|
|
186
|
+
const isValid = state.validateCurrentStep();
|
|
187
|
+
if (isValid && state.currentStep < 3) {
|
|
188
|
+
set((prev) => ({
|
|
189
|
+
currentStep: prev.currentStep + 1,
|
|
190
|
+
completedSteps: prev.completedSteps.includes(prev.currentStep) ? prev.completedSteps : [...prev.completedSteps, prev.currentStep],
|
|
191
|
+
errors: {}
|
|
192
|
+
}));
|
|
193
|
+
return true;
|
|
194
|
+
}
|
|
195
|
+
return isValid;
|
|
196
|
+
},
|
|
197
|
+
previousStep: () => {
|
|
198
|
+
const state = get();
|
|
199
|
+
if (state.currentStep > 1) {
|
|
200
|
+
set({ currentStep: state.currentStep - 1, errors: {} });
|
|
201
|
+
}
|
|
202
|
+
},
|
|
203
|
+
setErrors: (errors) => {
|
|
204
|
+
set({ errors });
|
|
205
|
+
},
|
|
206
|
+
validateCurrentStep: () => {
|
|
207
|
+
const state = get();
|
|
208
|
+
const errors = validateStep(state.currentStep, state.formData);
|
|
209
|
+
set({ errors });
|
|
210
|
+
return Object.keys(errors).length === 0;
|
|
211
|
+
},
|
|
212
|
+
validateAllSteps: () => {
|
|
213
|
+
const state = get();
|
|
214
|
+
const errors1 = validateStep(1, state.formData);
|
|
215
|
+
const errors2 = validateStep(2, state.formData);
|
|
216
|
+
const errors3 = validateStep(3, state.formData);
|
|
217
|
+
const allErrors = { ...errors1, ...errors2, ...errors3 };
|
|
218
|
+
set({ errors: allErrors });
|
|
219
|
+
return Object.keys(allErrors).length === 0;
|
|
220
|
+
},
|
|
221
|
+
setCategories: (categories) => {
|
|
222
|
+
const students = extractStudentsFromCategories(categories);
|
|
223
|
+
set((state) => ({
|
|
224
|
+
categories,
|
|
225
|
+
formData: { ...state.formData, students }
|
|
226
|
+
}));
|
|
227
|
+
},
|
|
228
|
+
reset: () => {
|
|
229
|
+
set({
|
|
230
|
+
...initialState,
|
|
231
|
+
categories: []
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
})
|
|
235
|
+
);
|
|
236
|
+
function useSendActivityModal() {
|
|
237
|
+
return useSendActivityModalStore();
|
|
238
|
+
}
|
|
239
|
+
export {
|
|
240
|
+
useSendActivityModal,
|
|
241
|
+
useSendActivityModalStore
|
|
242
|
+
};
|
|
243
|
+
//# sourceMappingURL=useSendActivityModal.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/components/SendActivityModal/hooks/useSendActivityModal.ts","../../../src/components/SendActivityModal/validation.ts"],"sourcesContent":["import { create } from 'zustand';\nimport { SendActivityFormData, StepErrors, CategoryConfig } from '../types';\nimport { validateStep } from '../validation';\n\n/**\n * Store interface for SendActivityModal\n */\nexport interface SendActivityModalStore {\n /** Form data */\n formData: Partial<SendActivityFormData>;\n /** Set form data */\n setFormData: (data: Partial<SendActivityFormData>) => void;\n\n /** Current step (1, 2, or 3) */\n currentStep: number;\n /** Completed steps */\n completedSteps: number[];\n /** Go to a specific step */\n goToStep: (step: number) => void;\n /** Go to next step (validates current step first) */\n nextStep: () => boolean;\n /** Go to previous step */\n previousStep: () => void;\n\n /** Validation errors */\n errors: StepErrors;\n /** Set errors */\n setErrors: (errors: StepErrors) => void;\n /** Validate current step */\n validateCurrentStep: () => boolean;\n /** Validate all steps */\n validateAllSteps: () => boolean;\n\n /** Categories state managed by CheckboxGroup */\n categories: CategoryConfig[];\n /** Update categories (called by CheckboxGroup) */\n setCategories: (categories: CategoryConfig[]) => void;\n\n /** Reset store to initial state */\n reset: () => void;\n}\n\nconst initialState = {\n formData: {\n canRetry: false,\n startTime: '00:00',\n finalTime: '23:59',\n } as Partial<SendActivityFormData>,\n currentStep: 1,\n completedSteps: [] as number[],\n errors: {} as StepErrors,\n categories: [] as CategoryConfig[],\n};\n\n/**\n * Helper to extract selected students from the students category\n */\nfunction extractStudentsFromCategories(\n categories: CategoryConfig[]\n): Array<{ studentId: string; userInstitutionId: string }> {\n // Find the students category (first matching by key 'students', 'alunos', or 'student')\n const studentsCategory = categories.find(\n (cat) =>\n cat.key === 'students' || cat.key === 'alunos' || cat.key === 'student'\n );\n\n if (!studentsCategory?.selectedIds || !studentsCategory.itens) {\n return [];\n }\n\n return studentsCategory.selectedIds\n .map((id) => {\n const student = studentsCategory.itens?.find((item) => item.id === id);\n if (student) {\n const rawStudentId = student.studentId;\n const rawUserInstId = student.userInstitutionId;\n const rawInstId = student.institutionId;\n\n // Extract studentId with type guard\n const studentId =\n typeof rawStudentId === 'string' || typeof rawStudentId === 'number'\n ? String(rawStudentId)\n : student.id;\n let userInstitutionId = '';\n if (\n typeof rawUserInstId === 'string' ||\n typeof rawUserInstId === 'number'\n ) {\n userInstitutionId = String(rawUserInstId);\n } else if (\n typeof rawInstId === 'string' ||\n typeof rawInstId === 'number'\n ) {\n userInstitutionId = String(rawInstId);\n }\n\n // Filter out entries without valid userInstitutionId\n if (!userInstitutionId) {\n return null;\n }\n\n return { studentId, userInstitutionId };\n }\n return null;\n })\n .filter(\n (s): s is { studentId: string; userInstitutionId: string } => s !== null\n );\n}\n\n/**\n * Creates the SendActivityModal store\n */\nexport const useSendActivityModalStore = create<SendActivityModalStore>(\n (set, get) => ({\n ...initialState,\n\n setFormData: (data) => {\n set((state) => ({\n formData: { ...state.formData, ...data },\n }));\n },\n\n goToStep: (step) => {\n if (step >= 1 && step <= 3) {\n set({ currentStep: step, errors: {} });\n }\n },\n\n nextStep: () => {\n const state = get();\n const isValid = state.validateCurrentStep();\n\n if (isValid && state.currentStep < 3) {\n set((prev) => ({\n currentStep: prev.currentStep + 1,\n completedSteps: prev.completedSteps.includes(prev.currentStep)\n ? prev.completedSteps\n : [...prev.completedSteps, prev.currentStep],\n errors: {},\n }));\n return true;\n }\n\n return isValid;\n },\n\n previousStep: () => {\n const state = get();\n if (state.currentStep > 1) {\n set({ currentStep: state.currentStep - 1, errors: {} });\n }\n },\n\n setErrors: (errors) => {\n set({ errors });\n },\n\n validateCurrentStep: () => {\n const state = get();\n const errors = validateStep(state.currentStep, state.formData);\n set({ errors });\n return Object.keys(errors).length === 0;\n },\n\n validateAllSteps: () => {\n const state = get();\n const errors1 = validateStep(1, state.formData);\n const errors2 = validateStep(2, state.formData);\n const errors3 = validateStep(3, state.formData);\n const allErrors = { ...errors1, ...errors2, ...errors3 };\n set({ errors: allErrors });\n return Object.keys(allErrors).length === 0;\n },\n\n setCategories: (categories) => {\n // Extract students from categories and update formData\n const students = extractStudentsFromCategories(categories);\n set((state) => ({\n categories,\n formData: { ...state.formData, students },\n }));\n },\n\n reset: () => {\n set({\n ...initialState,\n categories: [],\n });\n },\n })\n);\n\n/**\n * Hook to use the SendActivityModal store\n */\nexport function useSendActivityModal() {\n return useSendActivityModalStore();\n}\n","import { z } from 'zod';\nimport { SendActivityFormData, StepErrors } from './types';\n\n/**\n * Error messages for validation\n */\nexport const ERROR_MESSAGES = {\n SUBTYPE_REQUIRED:\n 'Campo obrigatório! Por favor, selecione uma opção para continuar.',\n TITLE_REQUIRED:\n 'Campo obrigatório! Por favor, preencha este campo para continuar.',\n STUDENTS_REQUIRED:\n 'Campo obrigatório! Por favor, selecione pelo menos um aluno para continuar.',\n START_DATE_REQUIRED:\n 'Campo obrigatório! Por favor, preencha este campo para continuar.',\n FINAL_DATE_REQUIRED:\n 'Campo obrigatório! Por favor, preencha este campo para continuar.',\n FINAL_DATE_INVALID: 'A data final deve ser maior ou igual à data inicial.',\n} as const;\n\n/**\n * Zod schema for activity step (Step 1)\n */\nexport const activityStepSchema = z.object({\n subtype: z.enum(['TAREFA', 'TRABALHO', 'PROVA'], {\n errorMap: () => ({ message: ERROR_MESSAGES.SUBTYPE_REQUIRED }),\n }),\n title: z\n .string({ required_error: ERROR_MESSAGES.TITLE_REQUIRED })\n .transform((val) => val.trim())\n .refine((val) => val.length > 0, {\n message: ERROR_MESSAGES.TITLE_REQUIRED,\n }),\n notification: z.string().optional(),\n});\n\n/**\n * Zod schema for recipient step (Step 2)\n */\nexport const recipientStepSchema = z.object({\n students: z\n .array(\n z.object({\n studentId: z.string(),\n userInstitutionId: z.string(),\n }),\n {\n required_error: ERROR_MESSAGES.STUDENTS_REQUIRED,\n invalid_type_error: ERROR_MESSAGES.STUDENTS_REQUIRED,\n }\n )\n .min(1, ERROR_MESSAGES.STUDENTS_REQUIRED),\n});\n\n/**\n * Regex patterns for date and time validation\n */\nconst DATE_REGEX = /^\\d{4}-\\d{2}-\\d{2}$/;\nconst TIME_REGEX = /^\\d{2}:\\d{2}$/;\n\n/**\n * Zod schema for deadline step (Step 3) - base validation\n */\nconst deadlineStepBaseSchema = z.object({\n startDate: z\n .string({\n required_error: ERROR_MESSAGES.START_DATE_REQUIRED,\n invalid_type_error: ERROR_MESSAGES.START_DATE_REQUIRED,\n })\n .min(1, ERROR_MESSAGES.START_DATE_REQUIRED)\n .regex(DATE_REGEX, ERROR_MESSAGES.START_DATE_REQUIRED),\n startTime: z.string().regex(TIME_REGEX).default('00:00'),\n finalDate: z\n .string({\n required_error: ERROR_MESSAGES.FINAL_DATE_REQUIRED,\n invalid_type_error: ERROR_MESSAGES.FINAL_DATE_REQUIRED,\n })\n .min(1, ERROR_MESSAGES.FINAL_DATE_REQUIRED)\n .regex(DATE_REGEX, ERROR_MESSAGES.FINAL_DATE_REQUIRED),\n finalTime: z.string().regex(TIME_REGEX).default('23:59'),\n canRetry: z.boolean().default(false),\n});\n\n/**\n * Zod schema for deadline step with date comparison refinement\n */\nexport const deadlineStepSchema = deadlineStepBaseSchema.refine(\n (data) => {\n const start = new Date(`${data.startDate}T${data.startTime}`);\n const end = new Date(`${data.finalDate}T${data.finalTime}`);\n return end >= start;\n },\n { message: ERROR_MESSAGES.FINAL_DATE_INVALID, path: ['finalDate'] }\n);\n\n/**\n * Type inference from Zod schemas\n */\nexport type ActivityStepData = z.infer<typeof activityStepSchema>;\nexport type RecipientStepData = z.infer<typeof recipientStepSchema>;\nexport type DeadlineStepData = z.infer<typeof deadlineStepSchema>;\n\n/**\n * Validates the activity step (Step 1) using Zod\n * @param data - Partial form data\n * @returns StepErrors object with any validation errors\n */\nexport function validateActivityStep(\n data: Partial<SendActivityFormData>\n): StepErrors {\n const errors: StepErrors = {};\n\n const result = activityStepSchema.safeParse({\n subtype: data.subtype,\n title: data.title,\n notification: data.notification,\n });\n\n if (!result.success) {\n result.error.issues.forEach((issue) => {\n const field = issue.path[0] as keyof StepErrors;\n if (field === 'subtype' || field === 'title') {\n errors[field] = issue.message;\n }\n });\n }\n\n return errors;\n}\n\n/**\n * Validates the recipient step (Step 2) using Zod\n * @param data - Partial form data\n * @returns StepErrors object with any validation errors\n */\nexport function validateRecipientStep(\n data: Partial<SendActivityFormData>\n): StepErrors {\n const errors: StepErrors = {};\n\n const result = recipientStepSchema.safeParse({\n students: data.students,\n });\n\n if (!result.success) {\n result.error.issues.forEach((issue) => {\n if (issue.path[0] === 'students') {\n errors.students = issue.message;\n }\n });\n }\n\n return errors;\n}\n\n/**\n * Validates the deadline step (Step 3) using Zod\n * @param data - Partial form data\n * @returns StepErrors object with any validation errors\n */\nexport function validateDeadlineStep(\n data: Partial<SendActivityFormData>\n): StepErrors {\n const errors: StepErrors = {};\n\n // First validate individual fields\n if (!data.startDate) {\n errors.startDate = ERROR_MESSAGES.START_DATE_REQUIRED;\n }\n\n if (!data.finalDate) {\n errors.finalDate = ERROR_MESSAGES.FINAL_DATE_REQUIRED;\n }\n\n // If both dates exist, validate with the full schema (including refinement)\n if (data.startDate && data.finalDate) {\n const result = deadlineStepSchema.safeParse({\n startDate: data.startDate,\n startTime: data.startTime ?? '00:00',\n finalDate: data.finalDate,\n finalTime: data.finalTime ?? '23:59',\n canRetry: data.canRetry ?? false,\n });\n\n if (!result.success) {\n result.error.issues.forEach((issue) => {\n const field = issue.path[0] as keyof StepErrors;\n if (field === 'startDate' || field === 'finalDate') {\n errors[field] = issue.message;\n }\n });\n }\n }\n\n return errors;\n}\n\n/**\n * Validates a specific step\n * @param step - Step number (1, 2, or 3)\n * @param data - Partial form data\n * @returns StepErrors object with any validation errors\n */\nexport function validateStep(\n step: number,\n data: Partial<SendActivityFormData>\n): StepErrors {\n switch (step) {\n case 1:\n return validateActivityStep(data);\n case 2:\n return validateRecipientStep(data);\n case 3:\n return validateDeadlineStep(data);\n default:\n return {};\n }\n}\n\n/**\n * Checks if a specific step is valid\n * @param step - Step number (1, 2, or 3)\n * @param data - Partial form data\n * @returns true if the step is valid\n */\nexport function isStepValid(\n step: number,\n data: Partial<SendActivityFormData>\n): boolean {\n const errors = validateStep(step, data);\n return Object.keys(errors).length === 0;\n}\n\n/**\n * Checks if all steps are valid (form can be submitted)\n * @param data - Partial form data\n * @returns true if all steps are valid\n */\nexport function isFormValid(data: Partial<SendActivityFormData>): boolean {\n return isStepValid(1, data) && isStepValid(2, data) && isStepValid(3, data);\n}\n"],"mappings":";AAAA,SAAS,cAAc;;;ACAvB,SAAS,SAAS;AAMX,IAAM,iBAAiB;AAAA,EAC5B,kBACE;AAAA,EACF,gBACE;AAAA,EACF,mBACE;AAAA,EACF,qBACE;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