build: react-hook-form build failed

This commit is contained in:
ReaJason
2025-11-20 00:36:25 +08:00
parent 7649e1612a
commit eb92c2c4ff
+15 -15
View File
@@ -1,6 +1,6 @@
import type { TFunction } from "i18next"; import type { TFunction } from "i18next";
import { useCallback } from "react"; import { useCallback } from "react";
import type { FieldErrors } from "react-hook-form"; import type { FieldErrors, ResolverResult } from "react-hook-form";
import * as yup from "yup"; import * as yup from "yup";
import { ShellToolType } from "./memshell"; import { ShellToolType } from "./memshell";
@@ -29,10 +29,7 @@ export const memShellFormSchema = yup.object({
encryptor: yup.string().optional(), encryptor: yup.string().optional(),
}); });
interface ValidationResult { type ValidationResult = ResolverResult<MemShellFormSchema>;
values: MemShellFormSchema;
errors: FieldErrors<MemShellFormSchema>;
}
const urlPatternIsNeeded = (shellType: string) => { const urlPatternIsNeeded = (shellType: string) => {
if (shellType.startsWith("Agent")) { if (shellType.startsWith("Agent")) {
@@ -58,7 +55,10 @@ export const useYupValidationResolver = (
t: TFunction, t: TFunction,
) => ) =>
useCallback( useCallback(
async (data: MemShellFormSchema): Promise<ValidationResult> => { async (
data: MemShellFormSchema,
_context: any,
): Promise<ValidationResult> => {
try { try {
const values = (await validationSchema.validate(data, { const values = (await validationSchema.validate(data, {
abortEarly: false, abortEarly: false,
@@ -105,7 +105,7 @@ export const useYupValidationResolver = (
} catch (errors) { } catch (errors) {
if (errors instanceof yup.ValidationError) { if (errors instanceof yup.ValidationError) {
return { return {
values: {} as MemShellFormSchema, values: {},
errors: errors.inner.reduce( errors: errors.inner.reduce(
(allErrors, currentError) => { (allErrors, currentError) => {
allErrors[currentError.path as keyof MemShellFormSchema] = { allErrors[currentError.path as keyof MemShellFormSchema] = {
@@ -120,7 +120,7 @@ export const useYupValidationResolver = (
} }
return { return {
values: {} as MemShellFormSchema, values: {},
errors: { errors: {
server: { server: {
type: "unknown", type: "unknown",
@@ -154,17 +154,17 @@ export const probeShellFormSchema = yup.object().shape({
shrink: yup.boolean().optional(), shrink: yup.boolean().optional(),
}); });
interface ProbeValidationResult { type ProbeValidationResult = ResolverResult<ProbeShellFormSchema>;
values: ProbeShellFormSchema;
errors: FieldErrors<ProbeShellFormSchema>;
}
export const useYupValidationProbeResolver = ( export const useYupValidationProbeResolver = (
validationSchema: yup.ObjectSchema<any>, validationSchema: yup.ObjectSchema<any>,
t: TFunction, t: TFunction,
) => ) =>
useCallback( useCallback(
async (data: ProbeShellFormSchema): Promise<ProbeValidationResult> => { async (
data: ProbeShellFormSchema,
_context: any,
): Promise<ProbeValidationResult> => {
try { try {
const values = (await validationSchema.validate(data, { const values = (await validationSchema.validate(data, {
abortEarly: false, abortEarly: false,
@@ -194,7 +194,7 @@ export const useYupValidationProbeResolver = (
} catch (errors) { } catch (errors) {
if (errors instanceof yup.ValidationError) { if (errors instanceof yup.ValidationError) {
return { return {
values: {} as ProbeShellFormSchema, values: {},
errors: errors.inner.reduce( errors: errors.inner.reduce(
(allErrors, currentError) => { (allErrors, currentError) => {
allErrors[currentError.path as keyof ProbeShellFormSchema] = { allErrors[currentError.path as keyof ProbeShellFormSchema] = {
@@ -210,7 +210,7 @@ export const useYupValidationProbeResolver = (
} }
return { return {
values: {} as ProbeShellFormSchema, values: {},
errors: { errors: {
server: { server: {
type: "unknown", type: "unknown",