Rocky_Mountain_Vending/.pnpm-store/v10/files/bc/85a6f6b1f5fbf699593eab6b0f86a3c19af73b49820a05784b233d912461012ffc505f3fb4b367c069042952df4a34add55a254a7215eb79a26ffef42476e1
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

68 lines
1.8 KiB
Text

import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import { SimpleErrorReporter, errors } from '@vinejs/vine';
import { FieldError, FieldErrors, appendErrors } from 'react-hook-form';
import type { Resolver } from './types';
const parseErrorSchema = (
vineErrors: SimpleErrorReporter['errors'],
validateAllFieldCriteria: boolean,
) => {
const schemaErrors: Record<string, FieldError> = {};
for (; vineErrors.length; ) {
const error = vineErrors[0];
const path = error.field;
if (!(path in schemaErrors)) {
schemaErrors[path] = { message: error.message, type: error.rule };
}
if (validateAllFieldCriteria) {
const { types } = schemaErrors[path];
const messages = types && types[error.rule];
schemaErrors[path] = appendErrors(
path,
validateAllFieldCriteria,
schemaErrors,
error.rule,
messages ? [...(messages as string[]), error.message] : error.message,
) as FieldError;
}
vineErrors.shift();
}
return schemaErrors;
};
export const vineResolver: Resolver =
(schema, schemaOptions, resolverOptions = {}) =>
async (values, _, options) => {
try {
const data = await schema.validate(values, schemaOptions);
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
return {
errors: {} as FieldErrors,
values: resolverOptions.raw ? values : data,
};
} catch (error: any) {
if (error instanceof errors.E_VALIDATION_ERROR) {
return {
values: {},
errors: toNestErrors(
parseErrorSchema(
error.messages,
!options.shouldUseNativeValidation &&
options.criteriaMode === 'all',
),
options,
),
};
}
throw error;
}
};