@appcorp/fusion-storybook 0.2.42 → 0.2.44

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.
@@ -67,13 +67,17 @@ async function pollBulkJob(jobId, signal, onProgress) {
67
67
  }
68
68
  }
69
69
  }
70
- function formatErrorSummary(errors) {
70
+ function formatErrorSummary(
71
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
72
+ t, errors) {
71
73
  if (!(errors === null || errors === void 0 ? void 0 : errors.length))
72
74
  return "";
73
- const lines = errors.slice(0, 5).map((e) => `Row ${e.row}: ${e.error}`);
75
+ const lines = errors
76
+ .slice(0, 5)
77
+ .map((e) => t("messagesBulkRowError", { row: e.row, error: e.error }));
74
78
  const remaining = errors.length - 5;
75
79
  if (remaining > 0)
76
- lines.push(`...and ${remaining} more`);
80
+ lines.push(t("messagesBulkMoreRows", { count: remaining }));
77
81
  return lines.join("\n");
78
82
  }
79
83
  export const SubjectMoreActions = () => {
@@ -106,7 +110,7 @@ export const SubjectMoreActions = () => {
106
110
  const text = await file.text();
107
111
  const records = converter.csv2json(text);
108
112
  if (!Array.isArray(records) || records.length === 0) {
109
- showErrorToast("CSV file is empty or invalid");
113
+ showErrorToast(t("messagesBulkCsvEmpty"));
110
114
  return;
111
115
  }
112
116
  // Client-side validation — basic required field check
@@ -116,53 +120,71 @@ export const SubjectMoreActions = () => {
116
120
  const msgs = [];
117
121
  if (method === "POST") {
118
122
  if (!((_b = row.code) === null || _b === void 0 ? void 0 : _b.trim()))
119
- msgs.push("code is required");
123
+ msgs.push(t("validationRequiredCode"));
120
124
  if (!((_c = row.name) === null || _c === void 0 ? void 0 : _c.trim()))
121
- msgs.push("name is required");
125
+ msgs.push(t("validationRequiredName"));
122
126
  }
123
127
  else {
124
128
  if (!((_d = row.id) === null || _d === void 0 ? void 0 : _d.trim()))
125
- msgs.push("id is required for update");
129
+ msgs.push(t("validationRequiredIdForUpdate"));
126
130
  }
127
131
  if (msgs.length > 0) {
128
132
  validationErrors.push({ row: i + 1, messages: msgs });
129
133
  }
130
134
  }
131
135
  if (validationErrors.length > 0) {
132
- const summary = validationErrors
136
+ const errorsList = validationErrors
133
137
  .slice(0, 5)
134
- .map((e) => `Row ${e.row}: ${e.messages.join("; ")}`)
138
+ .map((e) => t("messagesBulkRowError", {
139
+ row: e.row,
140
+ error: e.messages.join("; "),
141
+ }))
135
142
  .join("\n");
136
143
  const remaining = validationErrors.length - 5;
137
- showErrorToast(`Validation failed for ${validationErrors.length} row(s).\n${summary}${remaining > 0 ? `\n...and ${remaining} more` : ""}`);
144
+ const errorsStr = remaining > 0
145
+ ? `${errorsList}\n${t("messagesBulkMoreRows", { count: remaining })}`
146
+ : errorsList;
147
+ showErrorToast(t("messagesBulkValidationFailed", {
148
+ count: validationErrors.length,
149
+ errors: errorsStr,
150
+ }));
138
151
  return;
139
152
  }
140
153
  try {
141
- showInfoToast(`Bulk ${label} job queued (${records.length} records). Processing...`);
154
+ showInfoToast(t("messagesBulkJobQueued", { action: label, count: records.length }));
142
155
  let jobId;
143
156
  try {
144
157
  jobId = await submitBulkJob(text, method, signal);
145
158
  }
146
159
  catch (submitError) {
147
- showErrorToast(`Failed to submit ${label} job: ${submitError instanceof Error ? submitError.message : "Unknown error"}`);
160
+ showErrorToast(t("messagesBulkJobSubmitFailed", {
161
+ action: label,
162
+ error: submitError instanceof Error
163
+ ? submitError.message
164
+ : t("unknownError"),
165
+ }));
148
166
  return;
149
167
  }
150
168
  const status = await pollBulkJob(jobId, signal, (processed, total) => {
151
- showInfoToast(`Processing ${processed}/${total} subjects...`);
169
+ showInfoToast(t("messagesBulkProgress", { processed, total }));
152
170
  });
153
171
  if (signal.aborted)
154
172
  return;
155
173
  if (status.status === "completed") {
156
174
  const r = status.results;
157
175
  if (r && ((_e = r.errors) === null || _e === void 0 ? void 0 : _e.length) > 0) {
158
- const summary = formatErrorSummary(r.errors);
159
- showSuccessToast(`Created ${r.created} | Updated ${r.updated} | Skipped ${r.skipped}\n${summary}`);
176
+ const summary = formatErrorSummary(t, r.errors);
177
+ showSuccessToast(`${t("messagesBulkResults", { created: r.created, updated: r.updated, skipped: r.skipped })}\n${summary}`);
160
178
  }
161
179
  else if (r) {
162
- showSuccessToast(`Created ${r.created} | Updated ${r.updated} | Skipped ${r.skipped}`);
180
+ showSuccessToast(t("messagesBulkResults", {
181
+ created: r.created,
182
+ updated: r.updated,
183
+ skipped: r.skipped,
184
+ }));
163
185
  }
164
186
  else {
165
- showSuccessToast("Bulk operation completed successfully");
187
+ showSuccessToast(t("messagesBulkSuccess"));
166
188
  }
167
189
  const schoolId = ((_f = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _f === void 0 ? void 0 : _f.id) || "";
168
190
  fetch(`${SUBJECT_API_ROUTES.LIST}?currentPage=1&pageLimit=${pageLimit}&schoolId=${schoolId}`, {
@@ -189,17 +211,20 @@ export const SubjectMoreActions = () => {
189
211
  else {
190
212
  const r = status.results;
191
213
  const detail = ((_g = r === null || r === void 0 ? void 0 : r.errors) === null || _g === void 0 ? void 0 : _g.length)
192
- ? formatErrorSummary(r.errors)
193
- : "Unknown error";
194
- showErrorToast(`Bulk ${label} failed.\n${detail}`);
214
+ ? formatErrorSummary(t, r.errors)
215
+ : t("unknownError");
216
+ showErrorToast(`${t("messagesBulkFailed", { action: label })}\n${detail}`);
195
217
  }
196
218
  }
197
219
  catch (error) {
198
220
  if (error.message === "Polling cancelled")
199
221
  return;
200
- showErrorToast(`Bulk ${label} failed: ${error instanceof Error ? error.message : "Unknown error"}`);
222
+ showErrorToast(t("messagesBulkFailedDetail", {
223
+ action: label,
224
+ error: error instanceof Error ? error.message : t("unknownError"),
225
+ }));
201
226
  }
202
- }, [dispatch]);
227
+ }, [dispatch, t]);
203
228
  const handleBulkCreate = useCallback((files) => handleBulkFlow(files, "POST"), [handleBulkFlow]);
204
229
  const handleBulkUpdate = useCallback((files) => handleBulkFlow(files, "PUT"), [handleBulkFlow]);
205
230
  const create = [
@@ -76,13 +76,15 @@ async function pollBulkJob(jobId, signal, onProgress) {
76
76
  }
77
77
  }
78
78
  }
79
- function formatErrorSummary(errors) {
79
+ function formatErrorSummary(t, errors) {
80
80
  if (!(errors === null || errors === void 0 ? void 0 : errors.length))
81
81
  return "";
82
- const lines = errors.slice(0, 5).map((e) => `Row ${e.row}: ${e.error}`);
82
+ const lines = errors
83
+ .slice(0, 5)
84
+ .map((e) => t("messagesBulkRowError", { row: e.row, error: e.error }));
83
85
  const remaining = errors.length - 5;
84
86
  if (remaining > 0)
85
- lines.push(`...and ${remaining} more`);
87
+ lines.push(t("messagesBulkMoreRows", { count: remaining }));
86
88
  return lines.join("\n");
87
89
  }
88
90
  export const TeacherMoreActions = () => {
@@ -115,7 +117,7 @@ export const TeacherMoreActions = () => {
115
117
  const text = await file.text();
116
118
  const records = converter.csv2json(text);
117
119
  if (!Array.isArray(records) || records.length === 0) {
118
- showErrorToast("CSV file is empty or invalid");
120
+ showErrorToast(t("messagesBulkCsvEmpty"));
119
121
  return;
120
122
  }
121
123
  // Client-side validation — fast feedback, saves worker round-trip
@@ -131,7 +133,7 @@ export const TeacherMoreActions = () => {
131
133
  }
132
134
  else {
133
135
  if (!((_b = row.id) === null || _b === void 0 ? void 0 : _b.trim()))
134
- msgs.push("id is required for update");
136
+ msgs.push(t("validationRequiredIdForUpdate"));
135
137
  }
136
138
  if (msgs.length > 0) {
137
139
  validationErrors.push({ row: i + 1, messages: msgs });
@@ -140,38 +142,58 @@ export const TeacherMoreActions = () => {
140
142
  if (validationErrors.length > 0) {
141
143
  const summary = validationErrors
142
144
  .slice(0, 5)
143
- .map((e) => `Row ${e.row}: ${e.messages.join("; ")}`)
145
+ .map((e) => t("messagesBulkRowError", {
146
+ row: e.row,
147
+ error: e.messages.join("; "),
148
+ }))
144
149
  .join("\n");
145
- const remaining = validationErrors.length - 5;
146
- showErrorToast(`Validation failed for ${validationErrors.length} row(s).\n${summary}${remaining > 0 ? `\n...and ${remaining} more` : ""}`);
150
+ showErrorToast(t("messagesBulkValidationFailed", {
151
+ count: validationErrors.length,
152
+ errors: summary,
153
+ }));
147
154
  return;
148
155
  }
149
156
  try {
150
- showInfoToast(`Bulk ${label} job queued (${records.length} records). Processing...`);
157
+ showInfoToast(t("messagesBulkJobQueued", { action: label, count: records.length }));
151
158
  let jobId;
152
159
  try {
153
160
  jobId = await submitBulkJob(text, method, signal);
154
161
  }
155
162
  catch (submitError) {
156
- showErrorToast(`Failed to submit ${label} job: ${submitError instanceof Error ? submitError.message : "Unknown error"}`);
163
+ showErrorToast(t("messagesBulkJobSubmitFailed", {
164
+ action: label,
165
+ error: submitError instanceof Error
166
+ ? submitError.message
167
+ : t("unknownError"),
168
+ }));
157
169
  return;
158
170
  }
159
171
  const status = await pollBulkJob(jobId, signal, (processed, total) => {
160
- showInfoToast(`Processing ${processed}/${total} teachers...`);
172
+ showInfoToast(t("messagesBulkProgress", { processed, total }));
161
173
  });
162
174
  if (signal.aborted)
163
175
  return;
164
176
  if (status.status === "completed") {
165
177
  const r = status.results;
166
178
  if (r && ((_c = r.errors) === null || _c === void 0 ? void 0 : _c.length) > 0) {
167
- const summary = formatErrorSummary(r.errors);
168
- showSuccessToast(`Created ${r.created} | Updated ${r.updated} | Skipped ${r.skipped}\n${summary}`);
179
+ const summary = formatErrorSummary(t, r.errors);
180
+ showSuccessToast(t("messagesBulkResults", {
181
+ created: r.created,
182
+ updated: r.updated,
183
+ skipped: r.skipped,
184
+ }) +
185
+ "\n" +
186
+ summary);
169
187
  }
170
188
  else if (r) {
171
- showSuccessToast(`Created ${r.created} | Updated ${r.updated} | Skipped ${r.skipped}`);
189
+ showSuccessToast(t("messagesBulkResults", {
190
+ created: r.created,
191
+ updated: r.updated,
192
+ skipped: r.skipped,
193
+ }));
172
194
  }
173
195
  else {
174
- showSuccessToast("Bulk operation completed successfully");
196
+ showSuccessToast(t("messagesBulkSuccess"));
175
197
  }
176
198
  const schoolId = ((_d = workspace === null || workspace === void 0 ? void 0 : workspace.school) === null || _d === void 0 ? void 0 : _d.id) || "";
177
199
  fetch(`${TEACHER_API_ROUTES.LIST}?currentPage=1&pageLimit=${pageLimit}&schoolId=${schoolId}`, {
@@ -199,17 +221,20 @@ export const TeacherMoreActions = () => {
199
221
  else {
200
222
  const r = status.results;
201
223
  const detail = ((_e = r === null || r === void 0 ? void 0 : r.errors) === null || _e === void 0 ? void 0 : _e.length)
202
- ? formatErrorSummary(r.errors)
203
- : "Unknown error";
204
- showErrorToast(`Bulk ${label} failed.\n${detail}`);
224
+ ? formatErrorSummary(t, r.errors)
225
+ : t("unknownError");
226
+ showErrorToast(t("messagesBulkFailed", { action: label }) + "\n" + detail);
205
227
  }
206
228
  }
207
229
  catch (error) {
208
230
  if (error.message === "Polling cancelled")
209
231
  return;
210
- showErrorToast(`Bulk ${label} failed: ${error instanceof Error ? error.message : "Unknown error"}`);
232
+ showErrorToast(t("messagesBulkFailedDetail", {
233
+ action: label,
234
+ error: error instanceof Error ? error.message : t("unknownError"),
235
+ }));
211
236
  }
212
- }, [dispatch]);
237
+ }, [dispatch, t]);
213
238
  const handleBulkCreate = useCallback((files) => handleBulkFlow(files, "POST"), [handleBulkFlow]);
214
239
  const handleBulkUpdate = useCallback((files) => handleBulkFlow(files, "PUT"), [handleBulkFlow]);
215
240
  const create = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@appcorp/fusion-storybook",
3
- "version": "0.2.42",
3
+ "version": "0.2.44",
4
4
  "scripts": {
5
5
  "build-storybook": "storybook build",
6
6
  "build:next": "next build",