Rocky_Mountain_Vending/.pnpm-store/v10/files/21/aac8d50246cf39f48e32f6e00b3e62c3794ecf093034aa85d4266b78dd3e4332063f59479aeb819050e1ce962a7b60be0df3cb9f89f720579904dc4ecd42ec
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

46 lines
1.1 KiB
Text

import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import type { ShapeErrors } from 'nope-validator/lib/cjs/types';
import type { FieldError, FieldErrors } from 'react-hook-form';
import type { Resolver } from './types';
const parseErrors = (
errors: ShapeErrors,
parsedErrors: FieldErrors = {},
path = '',
) => {
return Object.keys(errors).reduce((acc, key) => {
const _path = path ? `${path}.${key}` : key;
const error = errors[key];
if (typeof error === 'string') {
acc[_path] = {
message: error,
} as FieldError;
} else {
parseErrors(error, acc, _path);
}
return acc;
}, parsedErrors);
};
export const nopeResolver: Resolver =
(
schema,
schemaOptions = {
abortEarly: false,
},
) =>
(values, context, options) => {
const result = schema.validate(values, context, schemaOptions) as
| ShapeErrors
| undefined;
if (result) {
return { values: {}, errors: toNestErrors(parseErrors(result), options) };
}
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
return { values, errors: {} };
};