All files / apps/huella-legal/layers/forms/app/composables useErrorSummary.ts

100% Statements 6/6
100% Branches 4/4
100% Functions 3/3
100% Lines 6/6

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15      10x 102x   102x 82x 56x       102x    
import type { FormErrorWithId } from "@nuxt/ui";
import type { FieldError } from "../types/FieldError";
 
export const useErrorSummary = (label: (field: string) => string) => {
    const errors = ref<FieldError[]>([]);
 
    const list = (formErrors: readonly FormErrorWithId[]): void => {
        errors.value = formErrors.flatMap(({ id, name, message }) =>
            id && name ? [{ id, label: label(name), message }] : [],
        );
    };
 
    return { errors: readonly(errors), list };
};