Skip to content

Commit d148e76

Browse files
committed
refactor: use ZodTypeLike from libjs
1 parent 125999c commit d148e76

File tree

3 files changed

+5
-38
lines changed

3 files changed

+5
-38
lines changed

src/components/Form/Form.stories.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import { useEffect, useState } from 'react';
44

55
import { sleep } from '@douglasneuroinformatics/libjs';
6+
import type { ZodTypeLike } from '@douglasneuroinformatics/libjs';
67
import type { FormFields } from '@douglasneuroinformatics/libui-form-types';
78
import type FormTypes from '@douglasneuroinformatics/libui-form-types';
89
import type { Meta, StoryObj } from '@storybook/react';
@@ -12,8 +13,6 @@ import { z } from 'zod/v4';
1213
import { Heading } from '../Heading';
1314
import { Form } from './Form';
1415

15-
import type { ZodTypeLike } from './types';
16-
1716
const DISABLED = false;
1817

1918
const $ExampleFormData = z.object({

src/components/Form/Form.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useEffect, useState } from 'react';
22

3+
import type { ZodErrorLike, ZodTypeLike } from '@douglasneuroinformatics/libjs';
34
import type {
45
FormContent,
56
FormDataType,
@@ -21,9 +22,9 @@ import { ErrorMessage } from './ErrorMessage';
2122
import { FieldsComponent } from './FieldsComponent';
2223
import { getInitialValues } from './utils';
2324

24-
import type { FormErrors, ZodErrorLike, ZodTypeLike } from './types';
25+
import type { FormErrors } from './types';
2526

26-
type FormProps<TSchema extends ZodTypeLike<FormDataType>, TData extends TSchema['_input'] = TSchema['_input']> = {
27+
type FormProps<TSchema extends ZodTypeLike<FormDataType>, TData extends TSchema['_output'] = TSchema['_output']> = {
2728
[key: `data-${string}`]: unknown;
2829
additionalButtons?: {
2930
left?: React.ReactNode;
@@ -52,7 +53,7 @@ type FormProps<TSchema extends ZodTypeLike<FormDataType>, TData extends TSchema[
5253
validationSchema: ZodTypeLike<TData>;
5354
};
5455

55-
const Form = <TSchema extends ZodTypeLike<FormDataType>, TData extends TSchema['_input'] = TSchema['_input']>({
56+
const Form = <TSchema extends ZodTypeLike<FormDataType>, TData extends TSchema['_output'] = TSchema['_output']>({
5657
additionalButtons,
5758
className,
5859
content,

src/components/Form/types.ts

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,36 +25,3 @@ export type BaseFieldComponentProps<TValue extends FormFieldValue = FormFieldVal
2525
export type FormErrors<TData extends FormDataType = FormDataType> = {
2626
[K in keyof TData]?: FieldError<TData[K]>;
2727
};
28-
29-
export type ZodIssueLike = {
30-
[key: string]: any;
31-
readonly code: string;
32-
readonly message: string;
33-
readonly path: PropertyKey[];
34-
};
35-
36-
export type ZodErrorLike = {
37-
cause?: unknown;
38-
issues: ZodIssueLike[];
39-
name: string;
40-
};
41-
42-
export type ZodSafeParseResultLike<T> = ZodSafeParseErrorLike | ZodSafeParseSuccessLike<T>;
43-
44-
export type ZodSafeParseSuccessLike<TOutput> = {
45-
data: TOutput;
46-
error?: never;
47-
success: true;
48-
};
49-
50-
export type ZodSafeParseErrorLike = {
51-
data?: never;
52-
error: ZodErrorLike;
53-
success: false;
54-
};
55-
56-
export type ZodTypeLike<TOutput, TInput = TOutput> = {
57-
readonly _input: TInput;
58-
readonly _output: TOutput;
59-
safeParseAsync: (data: unknown) => Promise<ZodSafeParseResultLike<TOutput>>;
60-
};

0 commit comments

Comments
 (0)