Fix a bug with opening and closing sections in task form (#889)
This commit is contained in:
@@ -117,9 +117,9 @@ function CreateNewTaskForm({ initialValues }: Props) {
|
|||||||
const { toast } = useToast();
|
const { toast } = useToast();
|
||||||
const credentialGetter = useCredentialGetter();
|
const credentialGetter = useCredentialGetter();
|
||||||
const apiCredential = useApiCredential();
|
const apiCredential = useApiCredential();
|
||||||
const [sections, setSections] = useState<
|
const [section, setSection] = useState<"base" | "extraction" | "advanced">(
|
||||||
Array<"base" | "extraction" | "advanced">
|
"base",
|
||||||
>(["base"]);
|
);
|
||||||
|
|
||||||
const form = useForm<CreateNewTaskFormValues>({
|
const form = useForm<CreateNewTaskFormValues>({
|
||||||
resolver: zodResolver(createNewTaskFormSchema),
|
resolver: zodResolver(createNewTaskFormSchema),
|
||||||
@@ -195,37 +195,22 @@ function CreateNewTaskForm({ initialValues }: Props) {
|
|||||||
mutation.mutate(values);
|
mutation.mutate(values);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toggleSectionVisibility(
|
|
||||||
section: "base" | "extraction" | "advanced",
|
|
||||||
) {
|
|
||||||
setSections((sections) => {
|
|
||||||
if (sections.includes(section)) {
|
|
||||||
return sections.filter((s) => s !== section);
|
|
||||||
}
|
|
||||||
return [...sections, section];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function isActive(section: "base" | "extraction" | "advanced") {
|
|
||||||
return sections.includes(section);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||||
<TaskFormSection
|
<TaskFormSection
|
||||||
index={1}
|
index={1}
|
||||||
title="Base Content"
|
title="Base Content"
|
||||||
active={isActive("base")}
|
active={section === "base"}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
toggleSectionVisibility("base");
|
setSection("base");
|
||||||
}}
|
}}
|
||||||
hasError={
|
hasError={
|
||||||
typeof errors.url !== "undefined" ||
|
typeof errors.url !== "undefined" ||
|
||||||
typeof errors.navigationGoal !== "undefined"
|
typeof errors.navigationGoal !== "undefined"
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{isActive("base") && (
|
{section === "base" && (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<FormField
|
<FormField
|
||||||
@@ -288,16 +273,16 @@ function CreateNewTaskForm({ initialValues }: Props) {
|
|||||||
<TaskFormSection
|
<TaskFormSection
|
||||||
index={2}
|
index={2}
|
||||||
title="Extraction"
|
title="Extraction"
|
||||||
active={isActive("extraction")}
|
active={section === "extraction"}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
toggleSectionVisibility("extraction");
|
setSection("extraction");
|
||||||
}}
|
}}
|
||||||
hasError={
|
hasError={
|
||||||
typeof errors.dataExtractionGoal !== "undefined" ||
|
typeof errors.dataExtractionGoal !== "undefined" ||
|
||||||
typeof errors.extractedInformationSchema !== "undefined"
|
typeof errors.extractedInformationSchema !== "undefined"
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{isActive("extraction") && (
|
{section === "extraction" && (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<FormField
|
<FormField
|
||||||
@@ -370,9 +355,9 @@ function CreateNewTaskForm({ initialValues }: Props) {
|
|||||||
<TaskFormSection
|
<TaskFormSection
|
||||||
index={3}
|
index={3}
|
||||||
title="Advanced Settings"
|
title="Advanced Settings"
|
||||||
active={isActive("advanced")}
|
active={section === "advanced"}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
toggleSectionVisibility("advanced");
|
setSection("advanced");
|
||||||
}}
|
}}
|
||||||
hasError={
|
hasError={
|
||||||
typeof errors.navigationPayload !== "undefined" ||
|
typeof errors.navigationPayload !== "undefined" ||
|
||||||
@@ -380,7 +365,7 @@ function CreateNewTaskForm({ initialValues }: Props) {
|
|||||||
typeof errors.webhookCallbackUrl !== "undefined"
|
typeof errors.webhookCallbackUrl !== "undefined"
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
{isActive("advanced") && (
|
{section === "advanced" && (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<FormField
|
<FormField
|
||||||
|
|||||||
Reference in New Issue
Block a user