Rocky_Mountain_Vending/.pnpm-store/v10/files/be/6fc32e87e6fa644e5c66f04552fe6863d60af22c0aa46f49d4405d63a3eabf789a27c08f3ddd664961430ed8408629623642e82b7bbf13e0d4612e350ff136
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

42 lines
1.1 KiB
Text

import { toNestErrors, validateFieldsNatively } from '@hookform/resolvers';
import type { ValidationError } from 'computed-types';
import type { FieldErrors } from 'react-hook-form';
import type { Resolver } from './types';
const isValidationError = (error: any): error is ValidationError =>
error.errors != null;
const parseErrorSchema = (computedTypesError: ValidationError) => {
const parsedErrors: FieldErrors = {};
return (computedTypesError.errors || []).reduce((acc, error) => {
acc[error.path.join('.')] = {
type: error.error.name,
message: error.error.message,
};
return acc;
}, parsedErrors);
};
export const computedTypesResolver: Resolver =
(schema) => async (values, _, options) => {
try {
const data = await schema(values);
options.shouldUseNativeValidation && validateFieldsNatively({}, options);
return {
errors: {},
values: data,
};
} catch (error: any) {
if (isValidationError(error)) {
return {
values: {},
errors: toNestErrors(parseErrorSchema(error), options),
};
}
throw error;
}
};