mirror of
https://github.com/fosrl/pangolin.git
synced 2026-03-04 17:56:38 +00:00
♻️ do not manually track the loading state in ConfirmDeleteDialog
This commit is contained in:
@@ -6,43 +6,22 @@ import {
|
|||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
FormLabel,
|
|
||||||
FormMessage
|
FormMessage
|
||||||
} from "@app/components/ui/form";
|
} from "@app/components/ui/form";
|
||||||
import { Input } from "@app/components/ui/input";
|
import { Input } from "@app/components/ui/input";
|
||||||
import {
|
|
||||||
Select,
|
|
||||||
SelectContent,
|
|
||||||
SelectItem,
|
|
||||||
SelectTrigger,
|
|
||||||
SelectValue
|
|
||||||
} from "@app/components/ui/select";
|
|
||||||
import { useToast } from "@app/hooks/useToast";
|
|
||||||
import { zodResolver } from "@hookform/resolvers/zod";
|
import { zodResolver } from "@hookform/resolvers/zod";
|
||||||
import {
|
import React, { useActionState } from "react";
|
||||||
InviteUserBody,
|
|
||||||
InviteUserResponse,
|
|
||||||
ListUsersResponse
|
|
||||||
} from "@server/routers/user";
|
|
||||||
import { AxiosResponse } from "axios";
|
|
||||||
import React, { useState } from "react";
|
|
||||||
import { useForm } from "react-hook-form";
|
import { useForm } from "react-hook-form";
|
||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import CopyTextBox from "@app/components/CopyTextBox";
|
|
||||||
import {
|
import {
|
||||||
Credenza,
|
Credenza,
|
||||||
CredenzaBody,
|
CredenzaBody,
|
||||||
CredenzaClose,
|
CredenzaClose,
|
||||||
CredenzaContent,
|
CredenzaContent,
|
||||||
CredenzaDescription,
|
|
||||||
CredenzaFooter,
|
CredenzaFooter,
|
||||||
CredenzaHeader,
|
CredenzaHeader,
|
||||||
CredenzaTitle
|
CredenzaTitle
|
||||||
} from "@app/components/Credenza";
|
} from "@app/components/Credenza";
|
||||||
import { useOrgContext } from "@app/hooks/useOrgContext";
|
|
||||||
import { Description } from "@radix-ui/react-toast";
|
|
||||||
import { createApiClient } from "@app/lib/api";
|
|
||||||
import { useEnvContext } from "@app/hooks/useEnvContext";
|
|
||||||
import { useTranslations } from "next-intl";
|
import { useTranslations } from "next-intl";
|
||||||
import CopyToClipboard from "./CopyToClipboard";
|
import CopyToClipboard from "./CopyToClipboard";
|
||||||
|
|
||||||
@@ -57,7 +36,7 @@ type InviteUserFormProps = {
|
|||||||
warningText?: string;
|
warningText?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function InviteUserForm({
|
export default function ConfirmDeleteDialog({
|
||||||
open,
|
open,
|
||||||
setOpen,
|
setOpen,
|
||||||
string,
|
string,
|
||||||
@@ -67,9 +46,7 @@ export default function InviteUserForm({
|
|||||||
dialog,
|
dialog,
|
||||||
warningText
|
warningText
|
||||||
}: InviteUserFormProps) {
|
}: InviteUserFormProps) {
|
||||||
const [loading, setLoading] = useState(false);
|
const [, formAction, loading] = useActionState(onSubmit, null);
|
||||||
|
|
||||||
const api = createApiClient(useEnvContext());
|
|
||||||
|
|
||||||
const t = useTranslations();
|
const t = useTranslations();
|
||||||
|
|
||||||
@@ -86,21 +63,14 @@ export default function InviteUserForm({
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function reset() {
|
async function onSubmit() {
|
||||||
form.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
async function onSubmit(values: z.infer<typeof formSchema>) {
|
|
||||||
setLoading(true);
|
|
||||||
try {
|
try {
|
||||||
await onConfirm();
|
await onConfirm();
|
||||||
setOpen(false);
|
setOpen(false);
|
||||||
reset();
|
form.reset();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
// Handle error if needed
|
// Handle error if needed
|
||||||
console.error("Confirmation failed:", error);
|
console.error("Confirmation failed:", error);
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +80,7 @@ export default function InviteUserForm({
|
|||||||
open={open}
|
open={open}
|
||||||
onOpenChange={(val) => {
|
onOpenChange={(val) => {
|
||||||
setOpen(val);
|
setOpen(val);
|
||||||
reset();
|
form.reset();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<CredenzaContent>
|
<CredenzaContent>
|
||||||
@@ -136,7 +106,7 @@ export default function InviteUserForm({
|
|||||||
</div>
|
</div>
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form
|
<form
|
||||||
onSubmit={form.handleSubmit(onSubmit)}
|
action={formAction}
|
||||||
className="space-y-4"
|
className="space-y-4"
|
||||||
id="confirm-delete-form"
|
id="confirm-delete-form"
|
||||||
>
|
>
|
||||||
|
|||||||
Reference in New Issue
Block a user