refactor(custom-metrics): read a refused save in one helper

Matching the name clash by its code grew the form component past its
size baseline. The refusal's sentence now comes from a helper beside it.
This commit is contained in:
Marc-André Bombeck committed 2026-11-12 12:58:37 +01:00
1 parent e71b1b9fd4
commit 31c4440154
1 file changed
+12 -7
@@ -60,6 +60,17 @@ interface CustomMetricFormProps {
footerSlot?: HTMLElement | null;
}
/**
* The sentence for a refused save. A name clash is read by its code: a 409
* can also be the first save still running under the same key.
*/
function saveRefusal(err: unknown, t: (key: string) => string): string {
return err instanceof ApiError &&
err.meta?.errorCode === "customMetric.name_taken"
? t("customMetrics.form.nameTaken")
: localizedApiError(err, t, "customMetrics.form.saveError");
}
/**
* v1.25.5 — define or edit a custom metric.
*
@@ -132,13 +143,7 @@ export function CustomMetricForm({
);
onSuccess?.(saved);
} catch (err) {
// By its code: a 409 can also be the first save still running.
setError(
err instanceof ApiError &&
err.meta?.errorCode === "customMetric.name_taken"
? t("customMetrics.form.nameTaken")
: localizedApiError(err, t, "customMetrics.form.saveError"),
);
setError(saveRefusal(err, t));
} finally {
setSubmitting(false);
}