This commit is contained in:
rizky 2024-04-01 07:22:38 -07:00
parent 59f10f944a
commit b5531a74d1
3 changed files with 56 additions and 36 deletions

View File

@ -38,7 +38,8 @@ export const Field: FC<{
| "datetime"
| "money"
| "slider"
| "master-link";
| "master-link"
| "custom";
required: "y" | "n";
options: FieldOptions;
slider: () => Promise<SliderOptions>;
@ -76,7 +77,8 @@ export const Field: FC<{
rel_table,
rel_query,
}) => {
const value = form?.hook.getValues()[name];
const values = form?.hook.getValues();
const value = values[name];
const local = useLocal({
date: {
// label: "",
@ -177,6 +179,15 @@ export const Field: FC<{
</FormLabel>
<FormControl>
<>
{type === "custom" && (
<div
className={cx(
"flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50"
)}
>
{custom}
</div>
)}
{type === "slider" && (
<div className="c-flex-1 c-min-h-[40px] c-flex">
<div className="c-flex c-flex-col c-items-center">

View File

@ -1,7 +1,7 @@
import { Form as FForm } from "@/comps/ui/form";
import { Toaster } from "@/comps/ui/sonner";
import { useLocal } from "@/utils/use-local";
import { FC, useEffect } from "react";
import { FC, useEffect, useState } from "react";
import { createPortal } from "react-dom";
import { useForm } from "react-hook-form";
import { toast } from "sonner";
@ -9,6 +9,7 @@ import { FormHook } from "./utils/utils";
import { AlertTriangle, Check, Loader2 } from "lucide-react";
import { cn } from "@/utils";
import { Skeleton } from "../ui/skeleton";
import { getPathname } from "../../..";
export const Form: FC<{
on_init: (arg: { submit: any; reload: any }) => any;
@ -88,10 +89,14 @@ export const Form: FC<{
}
}
await on_submit({
const res = on_submit({
form: data,
error: form.hook.formState.errors,
});
await res;
toast.dismiss();
setTimeout(() => {
toast.dismiss();
if (Object.keys(form.hook.formState.errors).length > 0) {
@ -123,6 +128,7 @@ export const Form: FC<{
}
);
}
}, 100);
}, 300);
};
@ -141,11 +147,13 @@ export const Form: FC<{
local.render();
},
});
const res = on_load();
const loaded = (values: any) => {
setTimeout(() => {
toast.dismiss();
});
if (!!values) {
for (const [k, v] of Object.entries(values)) {
form.hook.setValue(k, v);
@ -224,7 +232,8 @@ export const Form: FC<{
} else {
local.layout = "2-col";
}
local.render();
local.render(true);
}
}}
className={cx(