Files
sarlinkportal-webui/components/block-device-button.tsx
T
i701 c06c4fee3f Implement parental control features and enhance device management
- Added a new Parental Control page for managing device access and notifications.
- Introduced blockDevice function to handle blocking and unblocking devices based on payment status.
- Enhanced omada-actions.ts to include device blocking logic and improved error handling.
- Updated DevicesTable component to integrate BlockDeviceButton for managing device states.
- Implemented API route for checking device statuses and sending notifications for expiring devices.
- Refactored payment processing to update device statuses upon successful payment verification.
- Added new utility functions for API key validation and SMS notifications.

These changes improve user control over device management and enhance the overall functionality of the application.
2024-12-22 21:34:57 +05:00

34 lines
1.1 KiB
TypeScript

'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";
export default function BlockDeviceButton({ device }: { device: Device }) {
const [disabled, setDisabled] = useState(false);
return (
<Button
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>
)
}