From afce1ad391644ca8143e9115ef753674e07df590 Mon Sep 17 00:00:00 2001 From: Chris Whited Date: Tue, 3 Jun 2025 12:48:36 -1000 Subject: [PATCH 1/2] feat(typesync | create app form): switch to use @tanstack/react-form. component cleanup --- .../SchemaBuilder/SchemaBrowser.tsx | 6 +- .../SchemaBuilder/TypeCombobox.tsx | 38 +- .../App/CreateAppForm/useCreateAppForm.tsx | 24 + .../SchemaPreview.tsx | 4 +- .../App/{SchemaBuilder => Schema}/utils.ts | 26 +- .../App/SchemaBuilder/SchemaBuilder.tsx | 237 -------- .../src/Components/App/SchemaBuilder/types.ts | 21 - .../FormComponents/ErrorMessages.tsx | 17 + .../src/Components/FormComponents/Input.tsx | 52 ++ .../Components/FormComponents/RadioGroup.tsx | 37 ++ .../FormComponents/SubmitButton.tsx | 53 ++ .../Components/FormComponents/TextArea.tsx | 44 ++ .../src/Components/FormComponents/index.ts | 5 + apps/typesync/client/src/context/form.ts | 8 + apps/typesync/client/src/generated/gql.ts | 3 +- apps/typesync/client/src/generated/graphql.ts | 2 +- apps/typesync/client/src/routes/__root.tsx | 4 +- .../client/src/routes/apps/$appId/details.tsx | 17 +- .../client/src/routes/apps/create.tsx | 548 ++++++++++-------- apps/typesync/package.json | 3 +- apps/typesync/tsconfig.client.json | 9 +- pnpm-lock.yaml | 99 ++-- 22 files changed, 660 insertions(+), 597 deletions(-) rename apps/typesync/client/src/Components/App/{ => CreateAppForm}/SchemaBuilder/SchemaBrowser.tsx (96%) rename apps/typesync/client/src/Components/App/{ => CreateAppForm}/SchemaBuilder/TypeCombobox.tsx (80%) create mode 100644 apps/typesync/client/src/Components/App/CreateAppForm/useCreateAppForm.tsx rename apps/typesync/client/src/Components/App/{SchemaBuilder => Schema}/SchemaPreview.tsx (97%) rename apps/typesync/client/src/Components/App/{SchemaBuilder => Schema}/utils.ts (84%) delete mode 100644 apps/typesync/client/src/Components/App/SchemaBuilder/SchemaBuilder.tsx delete mode 100644 apps/typesync/client/src/Components/App/SchemaBuilder/types.ts create mode 100644 apps/typesync/client/src/Components/FormComponents/ErrorMessages.tsx create mode 100644 apps/typesync/client/src/Components/FormComponents/Input.tsx create mode 100644 apps/typesync/client/src/Components/FormComponents/RadioGroup.tsx create mode 100644 apps/typesync/client/src/Components/FormComponents/SubmitButton.tsx create mode 100644 apps/typesync/client/src/Components/FormComponents/TextArea.tsx create mode 100644 apps/typesync/client/src/Components/FormComponents/index.ts create mode 100644 apps/typesync/client/src/context/form.ts diff --git a/apps/typesync/client/src/Components/App/SchemaBuilder/SchemaBrowser.tsx b/apps/typesync/client/src/Components/App/CreateAppForm/SchemaBuilder/SchemaBrowser.tsx similarity index 96% rename from apps/typesync/client/src/Components/App/SchemaBuilder/SchemaBrowser.tsx rename to apps/typesync/client/src/Components/App/CreateAppForm/SchemaBuilder/SchemaBrowser.tsx index 837c332f..ddc2b118 100644 --- a/apps/typesync/client/src/Components/App/SchemaBuilder/SchemaBrowser.tsx +++ b/apps/typesync/client/src/Components/App/CreateAppForm/SchemaBuilder/SchemaBrowser.tsx @@ -6,9 +6,9 @@ import { useQuery } from '@tanstack/react-query'; import { Array as EffectArray, Order, pipe } from 'effect'; import { useState } from 'react'; -import type { SchemaBrowserTypesQuery } from '../../../generated/graphql'; -import { schemaBrowserQueryOptions } from '../../../hooks/useSchemaBrowserQuery'; -import { Loading } from '../../Loading'; +import type { SchemaBrowserTypesQuery } from '../../../../generated/graphql'; +import { schemaBrowserQueryOptions } from '../../../../hooks/useSchemaBrowserQuery'; +import { Loading } from '../../../Loading'; export type SchemaBrowserType = NonNullable['types'][number]; type ExtendedSchemaBrowserType = SchemaBrowserType & { slug: string }; diff --git a/apps/typesync/client/src/Components/App/SchemaBuilder/TypeCombobox.tsx b/apps/typesync/client/src/Components/App/CreateAppForm/SchemaBuilder/TypeCombobox.tsx similarity index 80% rename from apps/typesync/client/src/Components/App/SchemaBuilder/TypeCombobox.tsx rename to apps/typesync/client/src/Components/App/CreateAppForm/SchemaBuilder/TypeCombobox.tsx index 2b574fb1..a0211b04 100644 --- a/apps/typesync/client/src/Components/App/SchemaBuilder/TypeCombobox.tsx +++ b/apps/typesync/client/src/Components/App/CreateAppForm/SchemaBuilder/TypeCombobox.tsx @@ -3,10 +3,9 @@ import { Label, Listbox, ListboxButton, ListboxOption, ListboxOptions } from '@headlessui/react'; import { CheckIcon, ChevronUpDownIcon } from '@heroicons/react/16/solid'; import { Array as EffectArray, String as EffectString, Schema, pipe } from 'effect'; -import type { UseFormSetValue } from 'react-hook-form'; -import type { InsertAppSchema } from '../../../schema.js'; -import { classnames } from '../../../utils/classnames.js'; +import { useFieldContext } from '../../../../context/form.js'; +import { classnames } from '../../../../utils/classnames.js'; class TypeOption extends Schema.Class('/hypergraph/typesync/models/TypeOption')({ id: Schema.NonEmptyTrimmedString, @@ -27,20 +26,12 @@ const typeOptions: Array = [ ]; export function TypeCombobox({ - typePropertyIdx, - typeIdx, - value, - onTypeSelected, + id, + name, schemaTypes = [], }: Readonly<{ - /** the index of this type selection field in the properties array. Types.AppSchemaForm.types[idx].properties[typeInputIdx] */ - typePropertyIdx: number; - /** the index of the type within the schema array Types.AppSchemaForm.types[typeIdx] */ - typeIdx: number; - /** the current value */ - value: string; - /** set the value in the form when the user selects a value */ - onTypeSelected: UseFormSetValue; + id: string; + name: string; /** * A list of types within the defined schema that the user can use as a relation * This allows the user to specify the property as a relationship to a type in the schema @@ -49,6 +40,8 @@ export function TypeCombobox({ */ schemaTypes?: Array | undefined; }>) { + const field = useFieldContext(); + const relationTypeOptions = pipe( schemaTypes, EffectArray.filter((_type) => EffectString.isNonEmpty(_type)), @@ -60,23 +53,20 @@ export function TypeCombobox({ return ( { if (value) { - onTypeSelected(`types.${typeIdx}.properties.${typePropertyIdx}.type_name`, value, { - shouldDirty: true, - shouldTouch: true, - shouldValidate: true, - }); + field.handleChange(value); } }} >
- {value} + {field.state.value}