#58 code cleanup
changed unnecessary loading statements into form.formState.isLoading/submitting
This commit is contained in:
@@ -49,8 +49,6 @@ export const Form = ({ event }: { event?: Event }) => {
|
||||
resolver: zodResolver(ParticipantSchema),
|
||||
});
|
||||
const appointmentsTableRef = useRef<PaginatedTableRef>(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [deleteLoading, setDeleteLoading] = useState(false);
|
||||
const appointmentModal = useRef<HTMLDialogElement>(null);
|
||||
const participantModal = useRef<HTMLDialogElement>(null);
|
||||
|
||||
@@ -67,10 +65,7 @@ export const Form = ({ event }: { event?: Event }) => {
|
||||
<ParticipantModal participantForm={participantForm} ref={participantModal} />
|
||||
<form
|
||||
onSubmit={form.handleSubmit(async (values) => {
|
||||
setLoading(true);
|
||||
|
||||
await upsertEvent(values, event?.id);
|
||||
setLoading(false);
|
||||
if (!event) redirect(`/admin/event`);
|
||||
})}
|
||||
className="grid grid-cols-6 gap-3"
|
||||
@@ -305,14 +300,16 @@ export const Form = ({ event }: { event?: Event }) => {
|
||||
<div className="card bg-base-200 shadow-xl col-span-6">
|
||||
<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>
|
||||
{event && (
|
||||
<Button
|
||||
isLoading={deleteLoading}
|
||||
onClick={async () => {
|
||||
setDeleteLoading(true);
|
||||
await deleteEvent(event.id);
|
||||
redirect("/admin/event");
|
||||
}}
|
||||
|
||||
@@ -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"
|
||||
>
|
||||
|
||||
@@ -17,15 +17,12 @@ export const KeywordForm = ({ keyword }: { keyword?: Keyword }) => {
|
||||
resolver: zodResolver(KeywordOptionalDefaultsSchema),
|
||||
defaultValues: keyword,
|
||||
});
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [deleteLoading, setDeleteLoading] = useState(false);
|
||||
return (
|
||||
<>
|
||||
<form
|
||||
onSubmit={form.handleSubmit(async (values) => {
|
||||
setLoading(true);
|
||||
await upsertKeyword(values, keyword?.id);
|
||||
setLoading(false);
|
||||
toast.success("Daten gespeichert");
|
||||
if (!keyword) redirect(`/admin/keyword`);
|
||||
})}
|
||||
@@ -76,12 +73,15 @@ export const KeywordForm = ({ keyword }: { keyword?: Keyword }) => {
|
||||
<div className="card bg-base-200 shadow-xl col-span-6">
|
||||
<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>
|
||||
{keyword && (
|
||||
<Button
|
||||
isLoading={deleteLoading}
|
||||
onClick={async () => {
|
||||
setDeleteLoading(true);
|
||||
await deleteKeyword(keyword.id);
|
||||
|
||||
@@ -19,7 +19,7 @@ export const ReasonForm = ({
|
||||
defaultValues: penalty,
|
||||
resolver: zodResolver(PenaltyOptionalDefaultsSchema),
|
||||
});
|
||||
const isLoading = form.formState.isSubmitting;
|
||||
const isSubmitting = form.formState.isSubmitting;
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -74,8 +74,8 @@ export const ReasonForm = ({
|
||||
<Button
|
||||
className="btn-primary"
|
||||
type="submit"
|
||||
disabled={isLoading || !form.formState.isDirty}
|
||||
isLoading={isLoading}
|
||||
disabled={!form.formState.isDirty}
|
||||
isLoading={isSubmitting}
|
||||
>
|
||||
Speichern
|
||||
</Button>
|
||||
|
||||
@@ -11,7 +11,6 @@ import { Shield, Trash } from "lucide-react";
|
||||
import { useSession } from "next-auth/react";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { useState } from "react";
|
||||
import { useForm } from "react-hook-form";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
@@ -55,7 +54,6 @@ export const ReportAdmin = ({
|
||||
};
|
||||
}) => {
|
||||
const { Reviewer } = report;
|
||||
const [isEditLoading, setIsEditLoading] = useState(false);
|
||||
|
||||
const session = useSession();
|
||||
const router = useRouter();
|
||||
@@ -67,14 +65,12 @@ export const ReportAdmin = ({
|
||||
<form
|
||||
className="card-body"
|
||||
onSubmit={form.handleSubmit(async (values) => {
|
||||
setIsEditLoading(true);
|
||||
const newReport = await editReport(values.id, {
|
||||
reviewerUserId: session.data?.user.id,
|
||||
reviewerComment: values.reviewerComment,
|
||||
reviewed: values.reviewed,
|
||||
});
|
||||
form.reset(newReport);
|
||||
setIsEditLoading(false);
|
||||
router.refresh();
|
||||
toast.success("Deine Änderungen wurden gespeichert!", {
|
||||
style: {
|
||||
@@ -96,7 +92,7 @@ export const ReportAdmin = ({
|
||||
role="submit"
|
||||
className="btn-sm btn-wide btn-outline btn-primary"
|
||||
disabled={!form.formState.isDirty}
|
||||
isLoading={isEditLoading}
|
||||
isLoading={form.formState.isSubmitting}
|
||||
>
|
||||
Speichern
|
||||
</Button>
|
||||
|
||||
@@ -16,15 +16,12 @@ export const StationForm = ({ station }: { station?: Station }) => {
|
||||
resolver: zodResolver(StationOptionalDefaultsSchema),
|
||||
defaultValues: station,
|
||||
});
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [deleteLoading, setDeleteLoading] = useState(false);
|
||||
// const [deleteLoading, setDeleteLoading] = useState(false);
|
||||
return (
|
||||
<>
|
||||
<form
|
||||
onSubmit={form.handleSubmit(async (values) => {
|
||||
setLoading(true);
|
||||
await upsertStation(values, station?.id);
|
||||
setLoading(false);
|
||||
toast.success("Daten gespeichert");
|
||||
if (!station) redirect(`/admin/station`);
|
||||
})}
|
||||
@@ -166,14 +163,16 @@ export const StationForm = ({ station }: { station?: Station }) => {
|
||||
<div className="card bg-base-200 shadow-xl col-span-6">
|
||||
<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>
|
||||
{station && (
|
||||
<Button
|
||||
isLoading={deleteLoading}
|
||||
onClick={async () => {
|
||||
setDeleteLoading(true);
|
||||
await deleteStation(station.id);
|
||||
redirect("/admin/station");
|
||||
}}
|
||||
|
||||
@@ -62,7 +62,6 @@ interface ProfileFormProps {
|
||||
}
|
||||
|
||||
export const ProfileForm: React.FC<ProfileFormProps> = ({ user }: ProfileFormProps) => {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const session = useSession();
|
||||
const form = useForm<UserOptionalDefaults>({
|
||||
defaultValues: user,
|
||||
@@ -73,11 +72,9 @@ export const ProfileForm: React.FC<ProfileFormProps> = ({ user }: ProfileFormPro
|
||||
<form
|
||||
className="card-body"
|
||||
onSubmit={form.handleSubmit(async (values) => {
|
||||
setIsLoading(true);
|
||||
if (!values.id) return;
|
||||
await editUser(values.id, values);
|
||||
form.reset(values);
|
||||
setIsLoading(false);
|
||||
toast.success("Deine Änderungen wurden gespeichert!", {
|
||||
style: {
|
||||
background: "var(--color-base-100)",
|
||||
@@ -238,7 +235,7 @@ export const ProfileForm: React.FC<ProfileFormProps> = ({ user }: ProfileFormPro
|
||||
role="submit"
|
||||
className="btn-sm btn-wide btn-outline btn-primary"
|
||||
disabled={!form.formState.isDirty}
|
||||
isLoading={isLoading}
|
||||
isLoading={form.formState.isSubmitting}
|
||||
>
|
||||
<BookmarkIcon /> Speichern
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user