@appcorp/fusion-storybook 0.2.31 → 0.2.33

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.
@@ -6,7 +6,6 @@ import { getCachedWorkspaceSync } from "../workspace/cache";
6
6
  import converter from "json-2-csv";
7
7
  import { Timeline } from "../../components/timeline";
8
8
  import { useTranslations } from "next-intl";
9
- import { CSVS } from "../../constants";
10
9
  import { CLASS_API_ROUTES, pageLimit } from "./constants";
11
10
  import { invalidateClassesCache } from "./cache";
12
11
  import { CLASS_ACTION_TYPES, useClassContext } from "./context";
@@ -14,8 +13,8 @@ import { useRef, useEffect, useCallback } from "react";
14
13
  const workspace = getCachedWorkspaceSync();
15
14
  const POLL_INTERVAL_MS = 2000;
16
15
  const POLL_TIMEOUT_MS = 300000;
17
- const handleGetAllRecords = async (schoolId) => {
18
- const response = await fetch(`${CLASS_API_ROUTES.UNIT}?pageLimit=1000&currentPage=1&schoolId=${schoolId}`);
16
+ const handleGetAllRecords = async (schoolId, pageLimit) => {
17
+ const response = await fetch(`${CLASS_API_ROUTES.UNIT}?pageLimit=${pageLimit}&currentPage=1&schoolId=${schoolId}`);
19
18
  const result = await response.json();
20
19
  const csv = await converter.json2csv(result.items || [], {});
21
20
  const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
@@ -123,8 +122,8 @@ export const ClassMoreActions = () => {
123
122
  msgs.push("name is required");
124
123
  }
125
124
  else {
126
- if (!((_d = row.code) === null || _d === void 0 ? void 0 : _d.trim()))
127
- msgs.push("code is required for update");
125
+ if (!((_d = row.id) === null || _d === void 0 ? void 0 : _d.trim()))
126
+ msgs.push("id is required for update");
128
127
  }
129
128
  if (msgs.length > 0) {
130
129
  validationErrors.push({ row: i + 1, messages: msgs });
@@ -210,7 +209,8 @@ export const ClassMoreActions = () => {
210
209
  id: "1",
211
210
  title: t("downloadEmptyCsvTemplate"),
212
211
  handleOnClick: async () => {
213
- await downloadFromUrl(CSVS.Class, "class-template.csv");
212
+ var _a;
213
+ await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1);
214
214
  },
215
215
  },
216
216
  { id: "2", title: t("addYourDataToTheCsv") },
@@ -225,7 +225,7 @@ export const ClassMoreActions = () => {
225
225
  title: t("downloadPopulatedCsvTemplate"),
226
226
  handleOnClick: async () => {
227
227
  var _a;
228
- await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "");
228
+ await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1000);
229
229
  },
230
230
  },
231
231
  { id: "2", title: t("updateYourDataInTheCsv") },
@@ -6,7 +6,6 @@ import { getCachedWorkspaceSync } from "../workspace/cache";
6
6
  import converter from "json-2-csv";
7
7
  import { Timeline } from "../../components/timeline";
8
8
  import { useTranslations } from "next-intl";
9
- import { CSVS } from "../../constants";
10
9
  import { teacherFormValidation } from "./validate";
11
10
  import { TEACHER_API_ROUTES, pageLimit } from "./constants";
12
11
  import { invalidateTeachersCache } from "./cache";
@@ -15,12 +14,8 @@ import { useRef, useEffect, useCallback } from "react";
15
14
  const workspace = getCachedWorkspaceSync();
16
15
  const POLL_INTERVAL_MS = 2000;
17
16
  const POLL_TIMEOUT_MS = 300000;
18
- const handleGetAllRecords = async (schoolId) => {
19
- const response = await fetch(`${TEACHER_API_ROUTES.UNIT}?pageLimit=1000&currentPage=1&schoolId=${schoolId}`, {
20
- // headers: {
21
- // "x-api-token": process.env.NEXT_PUBLIC_API_KEY!,
22
- // },
23
- });
17
+ const handleGetAllRecords = async (schoolId, pageLimit) => {
18
+ const response = await fetch(`${TEACHER_API_ROUTES.UNIT}?pageLimit=${pageLimit}&currentPage=1&schoolId=${schoolId}`);
24
19
  const result = await response.json();
25
20
  const csv = await converter.json2csv(result.items || [], {});
26
21
  const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
@@ -103,7 +98,7 @@ export const TeacherMoreActions = () => {
103
98
  };
104
99
  }, []);
105
100
  const handleBulkFlow = useCallback(async (files, method) => {
106
- var _a, _b, _c, _d;
101
+ var _a, _b, _c, _d, _e;
107
102
  const closeDrawer = () => {
108
103
  dispatch({
109
104
  type: TEACHER_ACTION_TYPES.SET_DRAWER,
@@ -127,12 +122,20 @@ export const TeacherMoreActions = () => {
127
122
  // Client-side validation — fast feedback, saves worker round-trip
128
123
  const validationErrors = [];
129
124
  for (let i = 0; i < records.length; i++) {
130
- const result = teacherFormValidation.safeParse(records[i]);
131
- if (!result.success) {
132
- validationErrors.push({
133
- row: i + 1,
134
- messages: result.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`),
135
- });
125
+ const row = records[i];
126
+ const msgs = [];
127
+ if (method === "POST") {
128
+ const result = teacherFormValidation.safeParse(records[i]);
129
+ if (!result.success) {
130
+ msgs.push(...result.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`));
131
+ }
132
+ }
133
+ else {
134
+ if (!((_b = row.id) === null || _b === void 0 ? void 0 : _b.trim()))
135
+ msgs.push("id is required for update");
136
+ }
137
+ if (msgs.length > 0) {
138
+ validationErrors.push({ row: i + 1, messages: msgs });
136
139
  }
137
140
  }
138
141
  if (validationErrors.length > 0) {
@@ -161,7 +164,7 @@ export const TeacherMoreActions = () => {
161
164
  return;
162
165
  if (status.status === "completed") {
163
166
  const r = status.results;
164
- if (r && ((_b = r.errors) === null || _b === void 0 ? void 0 : _b.length) > 0) {
167
+ if (r && ((_c = r.errors) === null || _c === void 0 ? void 0 : _c.length) > 0) {
165
168
  const summary = formatErrorSummary(r.errors);
166
169
  showSuccessToast(`Created ${r.created} | Updated ${r.updated} | Skipped ${r.skipped}\n${summary}`);
167
170
  }
@@ -172,7 +175,7 @@ export const TeacherMoreActions = () => {
172
175
  showSuccessToast("Bulk operation completed successfully");
173
176
  }
174
177
  invalidateTeachersCache();
175
- const schoolId = ((_c = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _c === void 0 ? void 0 : _c.id) || "";
178
+ const schoolId = ((_d = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _d === void 0 ? void 0 : _d.id) || "";
176
179
  fetch(`${TEACHER_API_ROUTES.LIST}?currentPage=1&pageLimit=${pageLimit}&schoolId=${schoolId}`, {
177
180
  headers: {
178
181
  "Content-Type": "application/json",
@@ -197,7 +200,7 @@ export const TeacherMoreActions = () => {
197
200
  }
198
201
  else {
199
202
  const r = status.results;
200
- const detail = ((_d = r === null || r === void 0 ? void 0 : r.errors) === null || _d === void 0 ? void 0 : _d.length)
203
+ const detail = ((_e = r === null || r === void 0 ? void 0 : r.errors) === null || _e === void 0 ? void 0 : _e.length)
201
204
  ? formatErrorSummary(r.errors)
202
205
  : "Unknown error";
203
206
  showErrorToast(`Bulk ${label} failed.\n${detail}`);
@@ -216,7 +219,8 @@ export const TeacherMoreActions = () => {
216
219
  id: "1",
217
220
  title: t("moreActionsDownloadEmptyCsvTemplate"),
218
221
  handleOnClick: async () => {
219
- await downloadFromUrl(CSVS.Teacher, "teacher-template.csv");
222
+ var _a;
223
+ await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1);
220
224
  },
221
225
  },
222
226
  { id: "2", title: t("moreActionsAddYourDataToTheCsv") },
@@ -231,7 +235,7 @@ export const TeacherMoreActions = () => {
231
235
  title: t("moreActionsDownloadPopulatedCsvTemplate"),
232
236
  handleOnClick: async () => {
233
237
  var _a;
234
- await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "");
238
+ await handleGetAllRecords(((_a = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _a === void 0 ? void 0 : _a.id) || "", 1000);
235
239
  },
236
240
  },
237
241
  { id: "2", title: t("moreActionsUpdateYourDataToTheCsv") },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.2.31",
3
+ "version": "0.2.33",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",