@krak-stack/registry 0.1.48 → 0.1.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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,16 @@
|
|
|
1
1
|
# @krak-stack/registry
|
|
2
2
|
|
|
3
|
+
## 0.1.49
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- e026d8d: Fix silent form submission failures in `SubmitError`, including typed HTTP errors such as `Forbidden` whose messages are empty.
|
|
8
|
+
- Display a non-empty server or domain error message first, when available.
|
|
9
|
+
- Otherwise, display an English or French message for recognized HTTP errors, then a generic failure message if no useful message or recognized status is available.
|
|
10
|
+
- Use localized HTTP status messages instead of raw HTTP-client diagnostics for recognized statuses.
|
|
11
|
+
- Support the provider locale and explicit `locale` and `messages` overrides.
|
|
12
|
+
- Continue displaying schema validation errors beside their fields rather than in the submission error display.
|
|
13
|
+
|
|
3
14
|
## 0.1.48
|
|
4
15
|
|
|
5
16
|
### Patch Changes
|
|
@@ -18,6 +18,14 @@ export type EffectFormMessages = {
|
|
|
18
18
|
nameRequired: string;
|
|
19
19
|
revert: string;
|
|
20
20
|
submit: string;
|
|
21
|
+
submitBadRequest: string;
|
|
22
|
+
submitUnauthorized: string;
|
|
23
|
+
submitForbidden: string;
|
|
24
|
+
submitNotFound: string;
|
|
25
|
+
submitConflict: string;
|
|
26
|
+
submitRateLimited: string;
|
|
27
|
+
submitUnavailable: string;
|
|
28
|
+
submitFailed: string;
|
|
21
29
|
suggestedImageSize: (width: string, height: string) => string;
|
|
22
30
|
value: string;
|
|
23
31
|
};
|
|
@@ -44,8 +52,10 @@ export declare const FieldWrapper: ({ children, description, editingLocale, lege
|
|
|
44
52
|
export declare const ErrorMessage: ({ text }: {
|
|
45
53
|
text: string;
|
|
46
54
|
}) => JSX.Element;
|
|
47
|
-
export declare const SubmitError: <A, E>({ result, }: {
|
|
55
|
+
export declare const SubmitError: <A, E>({ result, locale, messages, }: {
|
|
48
56
|
result: AsyncResult.AsyncResult<A, E>;
|
|
57
|
+
locale?: string;
|
|
58
|
+
messages?: EffectFormMessageTranslations;
|
|
49
59
|
}) => JSX.Element | null;
|
|
50
60
|
export type SubmitForm<A, E> = {
|
|
51
61
|
isDirty: Atom.Atom<boolean>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { useAtomSet, useAtomValue } from "@effect/atom-react";
|
|
3
3
|
import { Block } from "@tanstack/react-router";
|
|
4
4
|
import { Cause, Option, Schema as Schema2 } from "effect";
|
|
5
|
+
import { HttpClientError } from "effect/http";
|
|
5
6
|
import { AsyncResult } from "effect/reactivity";
|
|
6
7
|
import { Languages, Loader2, Plus, Trash } from "lucide-react";
|
|
7
8
|
|
|
@@ -1288,6 +1289,14 @@ var messages3 = {
|
|
|
1288
1289
|
nameRequired: "Name is required",
|
|
1289
1290
|
revert: "Revert to default",
|
|
1290
1291
|
submit: "Submit",
|
|
1292
|
+
submitBadRequest: "The submitted information is invalid.",
|
|
1293
|
+
submitUnauthorized: "Please sign in to submit this form.",
|
|
1294
|
+
submitForbidden: "You do not have permission to submit this form.",
|
|
1295
|
+
submitNotFound: "The requested resource could not be found.",
|
|
1296
|
+
submitConflict: "Your changes conflict with the current state. Please refresh and try again.",
|
|
1297
|
+
submitRateLimited: "Too many requests. Please try again later.",
|
|
1298
|
+
submitUnavailable: "The service is temporarily unavailable. Please try again later.",
|
|
1299
|
+
submitFailed: "Your changes could not be saved. Please try again.",
|
|
1291
1300
|
suggestedImageSize: (width, height) => `Suggested image size: ${width} x ${height}`,
|
|
1292
1301
|
value: "Value"
|
|
1293
1302
|
},
|
|
@@ -1305,6 +1314,14 @@ var messages3 = {
|
|
|
1305
1314
|
nameRequired: "Le nom est obligatoire",
|
|
1306
1315
|
revert: "Revenir aux paramètres par défaut",
|
|
1307
1316
|
submit: "Soumettre",
|
|
1317
|
+
submitBadRequest: "Les informations soumises sont invalides.",
|
|
1318
|
+
submitUnauthorized: "Veuillez vous connecter pour soumettre ce formulaire.",
|
|
1319
|
+
submitForbidden: "Vous n’avez pas la permission de soumettre ce formulaire.",
|
|
1320
|
+
submitNotFound: "La ressource demandée est introuvable.",
|
|
1321
|
+
submitConflict: "Vos modifications sont en conflit avec l’état actuel. Veuillez actualiser la page et réessayer.",
|
|
1322
|
+
submitRateLimited: "Trop de requêtes. Veuillez réessayer plus tard.",
|
|
1323
|
+
submitUnavailable: "Le service est temporairement indisponible. Veuillez réessayer plus tard.",
|
|
1324
|
+
submitFailed: "Vos modifications n’ont pas pu être enregistrées. Veuillez réessayer.",
|
|
1308
1325
|
suggestedImageSize: (width, height) => `Taille de l'image suggérée : ${width} x ${height}`,
|
|
1309
1326
|
value: "Valeur"
|
|
1310
1327
|
}
|
|
@@ -1315,9 +1332,46 @@ var effectFormMessages = (locale = "en", translations) => ({
|
|
|
1315
1332
|
...translations?.[locale]
|
|
1316
1333
|
});
|
|
1317
1334
|
var useEffectFormMessages = (locale, translations) => effectFormMessages(useKrakstackLocale3(locale), translations);
|
|
1318
|
-
var
|
|
1335
|
+
var SubmitErrorDetails = Schema2.Struct({
|
|
1336
|
+
_tag: Schema2.optional(Schema2.String),
|
|
1337
|
+
status: Schema2.optional(Schema2.Number),
|
|
1338
|
+
statusCode: Schema2.optional(Schema2.Number)
|
|
1339
|
+
}).annotate({ identifier: "SubmitErrorDetails" });
|
|
1340
|
+
var submitErrorStatuses = new Map([
|
|
1341
|
+
["BadRequest", 400],
|
|
1342
|
+
["Unauthorized", 401],
|
|
1343
|
+
["Forbidden", 403],
|
|
1344
|
+
["NotFound", 404],
|
|
1345
|
+
["Conflict", 409],
|
|
1346
|
+
["TooManyRequests", 429],
|
|
1347
|
+
["InternalServerError", 500],
|
|
1348
|
+
["NotImplemented", 501],
|
|
1349
|
+
["ServiceUnavailable", 503]
|
|
1350
|
+
]);
|
|
1351
|
+
var getCauseErrorMessage = (cause, labels) => {
|
|
1319
1352
|
const error = Cause.squash(cause);
|
|
1320
|
-
|
|
1353
|
+
const isHttpClientError = HttpClientError.isHttpClientError(error);
|
|
1354
|
+
if (!isHttpClientError && error instanceof Error && error.message.trim()) {
|
|
1355
|
+
return error.message.trim();
|
|
1356
|
+
}
|
|
1357
|
+
const details = Option.getOrUndefined(Schema2.decodeUnknownOption(SubmitErrorDetails)(error));
|
|
1358
|
+
const status = isHttpClientError ? error.response?.status : details?.status ?? details?.statusCode ?? submitErrorStatuses.get(details?._tag ?? "");
|
|
1359
|
+
const statusMessage = new Map([
|
|
1360
|
+
[400, labels.submitBadRequest],
|
|
1361
|
+
[401, labels.submitUnauthorized],
|
|
1362
|
+
[403, labels.submitForbidden],
|
|
1363
|
+
[404, labels.submitNotFound],
|
|
1364
|
+
[409, labels.submitConflict],
|
|
1365
|
+
[429, labels.submitRateLimited],
|
|
1366
|
+
[500, labels.submitFailed],
|
|
1367
|
+
[501, labels.submitFailed],
|
|
1368
|
+
[503, labels.submitUnavailable]
|
|
1369
|
+
]).get(status ?? 0);
|
|
1370
|
+
if (statusMessage)
|
|
1371
|
+
return statusMessage;
|
|
1372
|
+
if (error instanceof Error)
|
|
1373
|
+
return error.message.trim() || labels.submitFailed;
|
|
1374
|
+
return Option.getOrElse(Schema2.decodeUnknownOption(Schema2.String)(error), () => "").trim() || labels.submitFailed;
|
|
1321
1375
|
};
|
|
1322
1376
|
var FieldWrapper = ({
|
|
1323
1377
|
children,
|
|
@@ -1355,9 +1409,12 @@ var ErrorMessage = ({ text }) => /* @__PURE__ */ jsx13("em", {
|
|
|
1355
1409
|
children: text
|
|
1356
1410
|
});
|
|
1357
1411
|
var SubmitError = ({
|
|
1358
|
-
result
|
|
1412
|
+
result,
|
|
1413
|
+
locale,
|
|
1414
|
+
messages
|
|
1359
1415
|
}) => {
|
|
1360
|
-
const
|
|
1416
|
+
const labels = useEffectFormMessages(locale, messages);
|
|
1417
|
+
const message = AsyncResult.isFailure(result) ? Schema2.isSchemaError(Cause.squash(result.cause)) ? undefined : getCauseErrorMessage(result.cause, labels) : undefined;
|
|
1361
1418
|
return message ? /* @__PURE__ */ jsx13(ErrorMessage, {
|
|
1362
1419
|
text: message
|
|
1363
1420
|
}) : null;
|