MCPcopy Create free account
hub / github.com/dailydotdev/apps / applyZodErrorsToForm

Function applyZodErrorsToForm

packages/shared/src/lib/form.ts:74–97  ·  view source on GitHub ↗
({
  error: originalError,
  setError,
}: {
  error: GraphQLError;
  setError: UseFormSetError<TFieldValues>;
})

Source from the content-addressed store, hash-verified

72}
73
74export const applyZodErrorsToForm = <TFieldValues extends FieldValues>({
75 error: originalError,
76 setError,
77}: {
78 error: GraphQLError;
79 setError: UseFormSetError<TFieldValues>;
80}) => {
81 if (
82 originalError.response?.errors?.[0]?.extensions?.code ===
83 ApiError.ZodValidationError
84 ) {
85 const apiError = originalError.response
86 .errors[0] as ApiResponseError<ApiZodErrorExtension>;
87
88 apiError.extensions.issues.forEach((issue) => {
89 if (issue.path?.length) {
90 setError(issue.path.join('.') as Path<TFieldValues>, {
91 type: issue.code,
92 message: issue.message,
93 });
94 }
95 });
96 }
97};

Callers 8

OpportunityEditInfoModalFunction · 0.90
InlineRoleInfoEditorFunction · 0.90
InlineContentEditorFunction · 0.90
useUserExperienceFormFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected