diff --git a/comps/form/Form.tsx b/comps/form/Form.tsx index 882d4c1..e910382 100755 --- a/comps/form/Form.tsx +++ b/comps/form/Form.tsx @@ -1,15 +1,14 @@ import { Form as FForm } from "@/comps/ui/form"; import { Toaster } from "@/comps/ui/sonner"; +import { cn } from "@/utils"; import { useLocal } from "@/utils/use-local"; -import { FC, useEffect, useState } from "react"; +import { AlertTriangle, Check, Loader2 } from "lucide-react"; +import { FC, useEffect } from "react"; import { createPortal } from "react-dom"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; -import { FormHook } from "./utils/utils"; -import { AlertTriangle, Check, Loader2 } from "lucide-react"; -import { cn } from "@/utils"; import { Skeleton } from "../ui/skeleton"; -import { getPathname } from "../../.."; +import { FormHook } from "./utils/utils"; export const Form: FC<{ on_init: (arg: { submit: any; reload: any }) => any; @@ -19,6 +18,7 @@ export const Form: FC<{ form: FormHook; PassProp: any; cache: () => any; + sonar: "on" | "off"; layout: "auto" | "1-col" | "2-col"; }> = ({ on_init, @@ -29,6 +29,7 @@ export const Form: FC<{ on_submit, cache, layout: _layout, + sonar, }) => { const form_hook = useForm({ defaultValues: {}, @@ -62,18 +63,20 @@ export const Form: FC<{ const submit = () => { clearTimeout(local.submit_timeout); local.submit_timeout = setTimeout(async () => { - toast.loading( - <> - - Processing ... - , - { - dismissible: true, - className: css` - background: #e4f7ff; - `, - } - ); + if (sonar === "on") { + toast.loading( + <> + + Processing ... + , + { + dismissible: true, + className: css` + background: #e4f7ff; + `, + } + ); + } const data = form.hook.getValues(); form.hook.clearErrors(); for (const [k, v] of Object.entries(form.validation)) { @@ -96,39 +99,42 @@ export const Form: FC<{ await res; toast.dismiss(); - setTimeout(() => { - toast.dismiss(); - if (Object.keys(form.hook.formState.errors).length > 0) { - toast.error( -
- - Save Failed, please correct{" "} - {Object.keys(form.hook.formState.errors).length} errors. -
, - { - dismissible: true, - className: css` - background: #ffecec; - border: 2px solid red; - `, - } - ); - } else { - toast.success( -
- - Done -
, - { - className: css` - background: #e4f5ff; - border: 2px solid blue; - `, - } - ); - } - }, 100); + if (sonar === "on") { + setTimeout(() => { + toast.dismiss(); + + if (Object.keys(form.hook.formState.errors).length > 0) { + toast.error( +
+ + Save Failed, please correct{" "} + {Object.keys(form.hook.formState.errors).length} errors. +
, + { + dismissible: true, + className: css` + background: #ffecec; + border: 2px solid red; + `, + } + ); + } else { + toast.success( +
+ + Done +
, + { + className: css` + background: #e4f5ff; + border: 2px solid blue; + `, + } + ); + } + }, 100); + } }, 300); }; @@ -163,7 +169,7 @@ export const Form: FC<{ }; if (res instanceof Promise) { setTimeout(() => { - if (!isEditor) { + if (!isEditor && sonar === "on") { toast.loading( <>