Skip to content

Commit

Permalink
fix: uncontrolled input errors (partial) & code formatting
Browse files Browse the repository at this point in the history
queries & messages in the sidebar still have this error. should be fixed
when they get zod schemas
  • Loading branch information
rmrt1n committed Mar 20, 2024
1 parent 440bc4c commit db2e2c4
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/components/sheets/edit-entity-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ export function EditEntityGroupSheet({ entityGroup }: EditEntityGroupProps) {
return checked
? field.onChange([...field.value, o.value])
: field.onChange(
field.value?.filter((value) => value !== o.value),
)
field.value?.filter((value) => value !== o.value),
)
}}
>
{o.label}
Expand Down
5 changes: 3 additions & 2 deletions src/components/sheets/new-entity-group.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export function NewEntityGroupSheet() {
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: {
name: '',
components: [],
},
})
Expand Down Expand Up @@ -143,8 +144,8 @@ export function NewEntityGroupSheet() {
return checked
? field.onChange([...field.value, o.value])
: field.onChange(
field.value?.filter((value) => value !== o.value),
)
field.value?.filter((value) => value !== o.value),
)
}}
>
{o.label}
Expand Down
3 changes: 3 additions & 0 deletions src/components/sidebar/persona.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ export function CreatePersona() {
const queryClient = useQueryClient()
const form = useForm<z.infer<typeof formSchema>>({
resolver: zodResolver(formSchema),
defaultValues: {
personaTag: '',
},
})

const handleSubmit = async ({ personaTag }: z.infer<typeof formSchema>) => {
Expand Down
21 changes: 13 additions & 8 deletions src/components/sidebar/queries.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,23 @@ interface QueryProp {
function Query({ query }: QueryProp) {
const { cardinalUrl, isCardinalConnected } = useCardinal()
const queryClient = useQueryClient()
// TODO: fix uncontrolled component error by adding default values here, tho we need to set the
// schema first to do this. same goes to the useForm in ./messages.tsx
const form = useForm()

// @ts-ignore
const handleSubmit = (values) => {
queryClient.fetchQuery(
lastQueryQueryOptions({
cardinalUrl,
isCardinalConnected,
name: query.name,
body: values as object,
}),
).then(() => true).catch((e) => console.log(e))
queryClient
.fetchQuery(
lastQueryQueryOptions({
cardinalUrl,
isCardinalConnected,
name: query.name,
body: values as object,
}),
)
.then(() => true)
.catch((e) => console.log(e))
}

return (
Expand Down
2 changes: 1 addition & 1 deletion src/lib/cardinal-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ interface CardinalProviderProps {
// TODO: consider whether to put cardinal url/port in .env too
const storageKey = 'cardinal-url'
const defaultCardinalUrl = 'http://localhost:4040'
const defaultCardinalNamespace = import.meta.env.CARDINAL_NAMESPACE as string || 'world-1'
const defaultCardinalNamespace = (import.meta.env.CARDINAL_NAMESPACE as string) || 'world-1'
const initialState: CardinalProviderState = {
cardinalUrl: defaultCardinalUrl,
setCardinalUrl: () => null,
Expand Down

0 comments on commit db2e2c4

Please sign in to comment.