add sonar to form
This commit is contained in:
parent
c7d2e95e4a
commit
906f76698a
|
|
@ -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<any>({
|
||||
defaultValues: {},
|
||||
|
|
@ -62,6 +63,7 @@ export const Form: FC<{
|
|||
const submit = () => {
|
||||
clearTimeout(local.submit_timeout);
|
||||
local.submit_timeout = setTimeout(async () => {
|
||||
if (sonar === "on") {
|
||||
toast.loading(
|
||||
<>
|
||||
<Loader2 className="c-h-4 c-w-4 c-animate-spin" />
|
||||
|
|
@ -74,6 +76,7 @@ export const Form: FC<{
|
|||
`,
|
||||
}
|
||||
);
|
||||
}
|
||||
const data = form.hook.getValues();
|
||||
form.hook.clearErrors();
|
||||
for (const [k, v] of Object.entries(form.validation)) {
|
||||
|
|
@ -96,6 +99,8 @@ export const Form: FC<{
|
|||
|
||||
await res;
|
||||
toast.dismiss();
|
||||
|
||||
if (sonar === "on") {
|
||||
setTimeout(() => {
|
||||
toast.dismiss();
|
||||
|
||||
|
|
@ -129,6 +134,7 @@ export const Form: FC<{
|
|||
);
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
}, 300);
|
||||
};
|
||||
|
||||
|
|
@ -163,7 +169,7 @@ export const Form: FC<{
|
|||
};
|
||||
if (res instanceof Promise) {
|
||||
setTimeout(() => {
|
||||
if (!isEditor) {
|
||||
if (!isEditor && sonar === "on") {
|
||||
toast.loading(
|
||||
<>
|
||||
<Loader2 className="c-h-4 c-w-4 c-animate-spin" />
|
||||
|
|
|
|||
Loading…
Reference in New Issue