mirror of https://github.com/usual2970/certimate
feat: show loading button when pushing test notifications
parent
44497a0969
commit
8fecebc254
|
@ -123,8 +123,13 @@ const Bark = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [testing, setTesting] = useState<boolean>(false);
|
||||||
const handlePushTestClick = async () => {
|
const handlePushTestClick = async () => {
|
||||||
|
if (testing) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
setTesting(true);
|
||||||
|
|
||||||
await notifyTest("bark");
|
await notifyTest("bark");
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
|
@ -139,6 +144,8 @@ const Bark = () => {
|
||||||
description: `${t("settings.notification.push_test_message.failed.message")}: ${msg}`,
|
description: `${t("settings.notification.push_test_message.failed.message")}: ${msg}`,
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
setTesting(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -238,6 +245,7 @@ const Bark = () => {
|
||||||
<Show when={!changed && bark.id != ""}>
|
<Show when={!changed && bark.id != ""}>
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
|
loading={testing}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handlePushTestClick();
|
handlePushTestClick();
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -120,11 +120,18 @@ const DingTalk = () => {
|
||||||
description: `${t("settings.notification.config.failed.message")}: ${msg}`,
|
description: `${t("settings.notification.config.failed.message")}: ${msg}`,
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
setTesting(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [testing, setTesting] = useState<boolean>(false);
|
||||||
const handlePushTestClick = async () => {
|
const handlePushTestClick = async () => {
|
||||||
|
if (testing) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
setTesting(true);
|
||||||
|
|
||||||
await notifyTest("dingtalk");
|
await notifyTest("dingtalk");
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
|
@ -236,6 +243,7 @@ const DingTalk = () => {
|
||||||
<Show when={!changed && dingtalk.id != ""}>
|
<Show when={!changed && dingtalk.id != ""}>
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
|
loading={testing}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handlePushTestClick();
|
handlePushTestClick();
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -146,8 +146,13 @@ const Mail = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [testing, setTesting] = useState<boolean>(false);
|
||||||
const handlePushTestClick = async () => {
|
const handlePushTestClick = async () => {
|
||||||
|
if (testing) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
setTesting(true);
|
||||||
|
|
||||||
await notifyTest("email");
|
await notifyTest("email");
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
|
@ -162,6 +167,8 @@ const Mail = () => {
|
||||||
description: `${t("settings.notification.push_test_message.failed.message")}: ${msg}`,
|
description: `${t("settings.notification.push_test_message.failed.message")}: ${msg}`,
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
setTesting(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -360,6 +367,7 @@ const Mail = () => {
|
||||||
<Show when={!changed && mail.id != ""}>
|
<Show when={!changed && mail.id != ""}>
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
|
loading={testing}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handlePushTestClick();
|
handlePushTestClick();
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -116,11 +116,18 @@ const Lark = () => {
|
||||||
description: `${t("settings.notification.config.failed.message")}: ${msg}`,
|
description: `${t("settings.notification.config.failed.message")}: ${msg}`,
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
setTesting(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [testing, setTesting] = useState<boolean>(false);
|
||||||
const handlePushTestClick = async () => {
|
const handlePushTestClick = async () => {
|
||||||
|
if (testing) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
setTesting(true);
|
||||||
|
|
||||||
await notifyTest("lark");
|
await notifyTest("lark");
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
|
@ -214,6 +221,7 @@ const Lark = () => {
|
||||||
<Show when={!changed && lark.id != ""}>
|
<Show when={!changed && lark.id != ""}>
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
|
loading={testing}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handlePushTestClick();
|
handlePushTestClick();
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -130,8 +130,13 @@ const ServerChan = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [testing, setTesting] = useState<boolean>(false);
|
||||||
const handlePushTestClick = async () => {
|
const handlePushTestClick = async () => {
|
||||||
|
if (testing) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
setTesting(true);
|
||||||
|
|
||||||
await notifyTest("serverchan");
|
await notifyTest("serverchan");
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
|
@ -146,6 +151,8 @@ const ServerChan = () => {
|
||||||
description: `${t("settings.notification.push_test_message.failed.message")}: ${msg}`,
|
description: `${t("settings.notification.push_test_message.failed.message")}: ${msg}`,
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
setTesting(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -225,6 +232,7 @@ const ServerChan = () => {
|
||||||
<Show when={!changed && serverchan.id != ""}>
|
<Show when={!changed && serverchan.id != ""}>
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
|
loading={testing}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handlePushTestClick();
|
handlePushTestClick();
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -123,8 +123,13 @@ const Telegram = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [testing, setTesting] = useState<boolean>(false);
|
||||||
const handlePushTestClick = async () => {
|
const handlePushTestClick = async () => {
|
||||||
|
if (testing) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
setTesting(true);
|
||||||
|
|
||||||
await notifyTest("telegram");
|
await notifyTest("telegram");
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
|
@ -139,6 +144,8 @@ const Telegram = () => {
|
||||||
description: `${t("settings.notification.push_test_message.failed.message")}: ${msg}`,
|
description: `${t("settings.notification.push_test_message.failed.message")}: ${msg}`,
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
setTesting(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -238,6 +245,7 @@ const Telegram = () => {
|
||||||
<Show when={!changed && telegram.id != ""}>
|
<Show when={!changed && telegram.id != ""}>
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
|
loading={testing}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handlePushTestClick();
|
handlePushTestClick();
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -130,8 +130,13 @@ const Webhook = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const [testing, setTesting] = useState<boolean>(false);
|
||||||
const handlePushTestClick = async () => {
|
const handlePushTestClick = async () => {
|
||||||
|
if (testing) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
setTesting(true);
|
||||||
|
|
||||||
await notifyTest("webhook");
|
await notifyTest("webhook");
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
|
@ -146,6 +151,8 @@ const Webhook = () => {
|
||||||
description: `${t("settings.notification.push_test_message.failed.message")}: ${msg}`,
|
description: `${t("settings.notification.push_test_message.failed.message")}: ${msg}`,
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
});
|
});
|
||||||
|
} finally {
|
||||||
|
setTesting(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -225,6 +232,7 @@ const Webhook = () => {
|
||||||
<Show when={!changed && webhook.id != ""}>
|
<Show when={!changed && webhook.id != ""}>
|
||||||
<Button
|
<Button
|
||||||
variant="secondary"
|
variant="secondary"
|
||||||
|
loading={testing}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
handlePushTestClick();
|
handlePushTestClick();
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import { Slot } from "@radix-ui/react-slot";
|
import { Slot } from "@radix-ui/react-slot";
|
||||||
import { cva, type VariantProps } from "class-variance-authority";
|
import { cva, type VariantProps } from "class-variance-authority";
|
||||||
|
import { Loader2 } from "lucide-react";
|
||||||
|
|
||||||
import { cn } from "@/lib/utils";
|
import { cn } from "@/lib/utils";
|
||||||
|
|
||||||
|
@ -32,11 +33,38 @@ const buttonVariants = cva(
|
||||||
|
|
||||||
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
|
export interface ButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement>, VariantProps<typeof buttonVariants> {
|
||||||
asChild?: boolean;
|
asChild?: boolean;
|
||||||
|
loading?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(({ className, variant, size, asChild = false, ...props }, ref) => {
|
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(({ className, variant, size, loading, asChild = false, children, ...props }, ref) => {
|
||||||
const Comp = asChild ? Slot : "button";
|
if (asChild) {
|
||||||
return <Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />;
|
return (
|
||||||
|
<Slot ref={ref} {...props}>
|
||||||
|
<>
|
||||||
|
{React.Children.map(children as React.ReactElement, (child: React.ReactElement) => {
|
||||||
|
return React.cloneElement(child, {
|
||||||
|
className: cn(buttonVariants({ variant, size }), className),
|
||||||
|
children: (
|
||||||
|
<>
|
||||||
|
{loading && <Loader2 className={cn("h-4 w-4 animate-spin", children && "mr-2")} />}
|
||||||
|
{child.props.children}
|
||||||
|
</>
|
||||||
|
),
|
||||||
|
});
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
</Slot>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<button className={cn(buttonVariants({ variant, size, className }))} disabled={loading} ref={ref} {...props}>
|
||||||
|
<>
|
||||||
|
{loading && <Loader2 className={cn("h-4 w-4 animate-spin", children && "mr-2")} />}
|
||||||
|
{children}
|
||||||
|
</>
|
||||||
|
</button>
|
||||||
|
);
|
||||||
});
|
});
|
||||||
Button.displayName = "Button";
|
Button.displayName = "Button";
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue