2024-12-22 21:34:57 +05:00
|
|
|
'use client'
|
|
|
|
|
|
|
|
import { blockDevice } from "@/actions/omada-actions";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
import type { Device } from "@prisma/client";
|
|
|
|
import { useState } from "react";
|
|
|
|
import { toast } from "sonner";
|
|
|
|
import { TextShimmer } from "./ui/text-shimmer";
|
|
|
|
|
2024-12-25 17:21:04 +05:00
|
|
|
export default function BlockDeviceDialog({ device }: { device: Device }) {
|
2024-12-22 21:34:57 +05:00
|
|
|
const [disabled, setDisabled] = useState(false);
|
|
|
|
return (
|
|
|
|
<Button
|
2024-12-25 17:21:04 +05:00
|
|
|
className="w-full mt-2"
|
2024-12-22 21:34:57 +05:00
|
|
|
disabled={disabled}
|
|
|
|
onClick={() => {
|
|
|
|
setDisabled(true);
|
|
|
|
toast.promise(blockDevice({ macAddress: device.mac, type: device.blocked ? "unblock" : "block" }), {
|
|
|
|
loading: device.blocked ? "Unblocking..." : "Blocking...",
|
|
|
|
success: () => {
|
|
|
|
setDisabled(false);
|
|
|
|
return `Device ${device.name} successfully ${device.blocked ? "unblocked" : "blocked"
|
|
|
|
}!`;
|
|
|
|
},
|
|
|
|
error: () => {
|
|
|
|
setDisabled(false);
|
|
|
|
return "Something went wrong";
|
|
|
|
},
|
|
|
|
});
|
|
|
|
}}
|
|
|
|
>
|
|
|
|
{disabled ? <TextShimmer>{device.blocked ? "Unblocking..." : "Blocking..."}</TextShimmer> : (device?.blocked ? "Unblock" : "Block")}
|
|
|
|
</Button>
|
|
|
|
)
|
|
|
|
}
|