Rocky_Mountain_Vending/.pnpm-store/v10/files/62/9ac5279634ddd1876006c5ac38a19bb2dc19a5807637f312d3ac9f4d9bfe292be65c9b63e324077a0dc5e9dfc15101219c009a73d0142c7fdb3afde67b5811
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

51 lines
1.4 KiB
Text

import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import { FieldError } from 'react-hook-form';
import promisify from 'vest/promisify';
import type { Resolver, VestErrors } from './types';
const parseErrorSchema = (
vestError: VestErrors,
validateAllFieldCriteria: boolean,
) => {
const errors: Record<string, FieldError> = {};
for (const path in vestError) {
if (!errors[path]) {
errors[path] = { message: vestError[path][0], type: '' };
}
if (validateAllFieldCriteria) {
errors[path].types = vestError[path].reduce<Record<number, string>>(
(acc, message, index) => (acc[index] = message) && acc,
{},
);
}
}
return errors;
};
export const vestResolver: Resolver =
(schema, _, resolverOptions = {}) =>
async (values, context, options) => {
const result =
resolverOptions.mode === 'sync'
? schema(values, options.names, context)
: await promisify(schema)(values, options.names, context);
if (result.hasErrors()) {
return {
values: {},
errors: toNestErrors(
parseErrorSchema(
result.getErrors(),
!options.shouldUseNativeValidation &&
options.criteriaMode === 'all',
),
options,
),
};
}
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
return { values, errors: {} };
};