Rocky_Mountain_Vending/.pnpm-store/v10/files/05/d398fb9a6bb290236d203c3a364778c363ddeb6d2f0a4cd70e16a874669b1b8c75b0165fc4bbe02ce1e1f6cb500e82344626bdf415ccfc19f9f4c49dac1133
DMleadgen 46d973904b
Initial commit: Rocky Mountain Vending website
Next.js website for Rocky Mountain Vending company featuring:
- Product catalog with Stripe integration
- Service areas and parts pages
- Admin dashboard with Clerk authentication
- SEO optimized pages with JSON-LD structured data

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-02-12 16:22:15 -07:00

44 lines
1.1 KiB
Text

import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import type { FieldError, FieldErrors } from 'react-hook-form';
import type { Resolver } from './types';
const parseErrors = (errors: string[], parsedErrors: FieldErrors = {}) => {
return errors.reduce((acc, error) => {
const fieldIndex = error.indexOf(':');
const field = error.slice(1, fieldIndex);
const message = error.slice(fieldIndex + 1).trim();
acc[field] = {
message,
} as FieldError;
return acc;
}, parsedErrors);
};
export const typanionResolver: Resolver =
(validator, validatorOptions = {}) =>
(values, _, options) => {
const rawErrors: string[] = [];
const isValid = validator(
values,
Object.assign(
{},
{
errors: rawErrors,
},
validatorOptions,
),
);
const parsedErrors = parseErrors(rawErrors);
if (isValid) {
options.shouldUseNativeValidation &&
validateFieldsNatively(parsedErrors, options);
return { values, errors: {} };
}
return { values: {}, errors: toNestErrors(parsedErrors, options) };
};