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