#58 code cleanup
changed unnecessary loading statements into form.formState.isLoading/submitting
This commit is contained in:
@@ -5,7 +5,6 @@ import { useForm } from "react-hook-form";
|
||||
import { Heliport, HeliportType } from "@repo/db";
|
||||
import { FileText, LocateIcon } from "lucide-react";
|
||||
import { Input } from "../../../../_components/ui/Input";
|
||||
import { useState } from "react";
|
||||
import { deleteHeliport, upsertHeliport } from "../action";
|
||||
import { Button } from "../../../../_components/ui/Button";
|
||||
import { redirect } from "next/navigation";
|
||||
@@ -16,17 +15,13 @@ export const HeliportForm = ({ heliport }: { heliport?: Heliport }) => {
|
||||
resolver: zodResolver(HeliportOptionalDefaultsSchema),
|
||||
defaultValues: heliport,
|
||||
});
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [deleteLoading, setDeleteLoading] = useState(false);
|
||||
return (
|
||||
<>
|
||||
<form
|
||||
onSubmit={form.handleSubmit(async (values) => {
|
||||
setLoading(true);
|
||||
await upsertHeliport(values, heliport?.id);
|
||||
setLoading(false);
|
||||
toast.success("Daten gespeichert");
|
||||
if (!heliport) redirect(`/admin/Heliport`);
|
||||
if (!heliport) redirect(`/admin/heliport`);
|
||||
})}
|
||||
className="flex flex-wrap gap-3"
|
||||
>
|
||||
@@ -128,16 +123,18 @@ export const HeliportForm = ({ heliport }: { heliport?: Heliport }) => {
|
||||
<div className="card bg-base-200 shadow-xl flex-[100%]">
|
||||
<div className="card-body ">
|
||||
<div className="flex w-full gap-4">
|
||||
<Button isLoading={loading} type="submit" className="btn btn-primary flex-1">
|
||||
<Button
|
||||
isLoading={form.formState.isSubmitting}
|
||||
type="submit"
|
||||
className="btn btn-primary flex-1"
|
||||
>
|
||||
Speichern
|
||||
</Button>
|
||||
{heliport && (
|
||||
<Button
|
||||
isLoading={deleteLoading}
|
||||
onClick={async () => {
|
||||
setDeleteLoading(true);
|
||||
await deleteHeliport(heliport.id);
|
||||
redirect("/admin/Heliport");
|
||||
redirect("/admin/heliport");
|
||||
}}
|
||||
className="btn btn-error"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user