Skip to content

Commit c960266

Browse files
committed
fix: correctly parse initial action configuration
1 parent 2ab39a1 commit c960266

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

core/actions/_lib/ActionForm.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { Button } from "ui/button";
1111
import { Field, FieldGroup } from "ui/field";
1212
import { Form } from "ui/form";
1313
import { FormSubmitButton } from "ui/submit-button";
14+
import { toast } from "ui/use-toast";
1415

1516
import type { Action } from "../types";
1617
import { ActionConfigBuilder } from "./ActionConfigBuilder";
@@ -72,9 +73,23 @@ export function ActionForm(props: ActionFormProps) {
7273
return s.getSchema();
7374
}, [props.action.config.schema, props.action.name, props.defaultFields]);
7475

76+
const defaultValues = useMemo(() => {
77+
const result = schema.partial().safeParse(props.values);
78+
if (result.success) {
79+
return result.data;
80+
}
81+
82+
toast({
83+
title: "Invalid initial values",
84+
description: `Can't parse values ${JSON.stringify(props.values)}: ${result.error.issues.map((issue) => `${issue.path.join(".")}: ${issue.message}`).join("\n")}. This is likely an issue on our end, please report this.`,
85+
variant: "destructive",
86+
});
87+
return undefined;
88+
}, [schema, props.values]);
89+
7590
const form = useForm({
7691
resolver: zodResolver(schema),
77-
defaultValues: props.action.config.schema.partial().parse(props.values),
92+
defaultValues,
7893
});
7994

8095
const onSubmit = useCallback(

0 commit comments

Comments
 (0)