Skip to content
This repository has been archived by the owner on Feb 10, 2025. It is now read-only.

Commit

Permalink
chore: move form related types to types folder
Browse files Browse the repository at this point in the history
  • Loading branch information
hussedev committed Jan 17, 2025
1 parent 582ae8e commit 21871df
Show file tree
Hide file tree
Showing 15 changed files with 39 additions and 29 deletions.
2 changes: 1 addition & 1 deletion src/components/Form/Form.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meta, StoryObj } from "@storybook/react";

import { Form, FormProps } from "@/components/Form";
import { FormField } from "@/components/Form/types/fieldTypes";
import { FormField } from "@/types";

const fields: FormField[] = [
{
Expand Down
7 changes: 2 additions & 5 deletions src/components/Form/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@ import { ForwardedRef, forwardRef, useImperativeHandle } from "react";
import { FormProvider, useFormContext } from "react-hook-form";

import { useFormWithPersist } from "@/hooks";
import { FormConfig, FormField } from "@/types";

import { FormField } from "./types/fieldTypes";
import { buildSchemaFromFields } from "./utils/buildSchemaFromFields";
import { componentRegistry } from "./utils/componentRegistry";

export interface FormProps {
persistKey: string;
fields: FormField[];
defaultValues?: any;
export interface FormProps extends FormConfig {
dbName: string;
storeName: string;
}
Expand Down
1 change: 0 additions & 1 deletion src/components/Form/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
export * from "./Form";
export * from "./types";
export * from "./utils";
export * from "./FormControllers";
3 changes: 2 additions & 1 deletion src/components/Form/utils/buildSchemaFromFields.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { z } from "zod";

import { FormField } from "../types/fieldTypes";
import { FormField } from "@/types";

import { buildArraySchema } from "./validations/validateArray";
import { buildFileSchema } from "./validations/validateFile";
import { getRoundDatesSchema } from "./validations/validateRoundDates";
Expand Down
2 changes: 1 addition & 1 deletion src/components/Form/utils/validations/validateArray.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { isAddress } from "viem";
import { z } from "zod";

import { ArrayValidationConfig } from "../../types/fieldTypes";
import { ArrayValidationConfig } from "@/types";

/**
* Builds a Zod array schema, optionally:
Expand Down
2 changes: 1 addition & 1 deletion src/components/Form/utils/validations/validateFile.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// File: utils/validations/validateFile.ts
import { z } from "zod";

import { FileValidationConfig } from "../../types";
import { FileValidationConfig } from "@/types";

/**
* Builds a Zod schema for file fields.
Expand Down
2 changes: 1 addition & 1 deletion src/components/Form/utils/validations/validateString.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// File: utils/validations/validateString.ts
import { z } from "zod";

import { StringValidationConfig } from "../../types";
import { StringValidationConfig } from "@/types";

/**
* Builds a Zod string schema.
Expand Down
12 changes: 2 additions & 10 deletions src/components/GenericProgressForm/GenericProgressForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,14 @@ import { useRef } from "react";

import { CheckIcon } from "@heroicons/react/solid";

import { Form, FormProps } from "@/components/Form";
import { Form } from "@/components/Form";
import { useIndexedDB } from "@/hooks";
import { Button } from "@/primitives/Button";
import { ProgressBar } from "@/primitives/ProgressBar";
import { FormStep } from "@/types";

import { useFormProgress } from "./hooks/useFormProgress";

export interface FormStep {
name: string;
formProps: Omit<FormProps, "dbName" | "storeName">;
stepProps: {
formTitle: string;
formDescription: string;
};
}

export interface GenericProgressFormProps {
name: string;
steps: FormStep[];
Expand Down
4 changes: 1 addition & 3 deletions src/components/GenericProgressForm/mocks/RoundSetup.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import moment from "moment";

import { FormField } from "@/components/Form";

import { FormStep } from "../GenericProgressForm";
import { FormField, FormStep } from "@/types";

const program = {
chainId: 10,
Expand Down
6 changes: 3 additions & 3 deletions src/primitives/MarkdownEditor/MarkdownEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import MDEditor, { commands, EditorContext } from "@uiw/react-md-editor";
import rehypeSanitize from "rehype-sanitize";

import { cn } from "@/lib";
import { Markdown } from "@/types";

import "./markdown_editor.css";

export interface MarkdownEditorProps {
value?: string;
export interface MarkdownEditorProps extends Markdown {
onChange?: (value: string) => void;
placeholder?: string;
value?: string;
}

const WriteButton = () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { FieldArrayProps, MetricsProps } from "@/components/Form";
import { FileUploadProps } from "@/primitives/FileUpload";
import { MarkdownEditorProps } from "@/primitives/MarkdownEditor";
import { SelectProps } from "@/primitives/Select";

import { Markdown } from "../markdown";

export interface BaseValidation {
required?: boolean | string;
isObject?: boolean;
Expand Down Expand Up @@ -63,7 +64,7 @@ export interface TextareaField {
placeholder?: string;
}

export interface MarkdownEditorField extends Omit<MarkdownEditorProps, "onChange" | "value"> {
export interface MarkdownEditorField extends Markdown {
field: BaseField;
component: "MarkdownEditor";
}
Expand Down
16 changes: 16 additions & 0 deletions src/types/form/form.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { FormField } from "./fieldTypes";

export interface FormConfig {
persistKey: string;
fields: FormField[];
defaultValues?: any;
}

export interface FormStep {
name: string;
formProps: FormConfig;
stepProps: {
formTitle: string;
formDescription: string;
};
}
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from "./fieldTypes";
export * from "./form";
2 changes: 2 additions & 0 deletions src/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
export * from "./form";
export * from "./indexedDB";
export * from "./markdown";
export * from "./onClickProps";
export * from "./pool";
3 changes: 3 additions & 0 deletions src/types/markdown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export interface Markdown {
placeholder?: string;
}

0 comments on commit 21871df

Please sign in to comment.