"use client"; import { useForm } from "@tanstack/react-form"; import { z } from "zod"; import { Textarea } from "@/components/ui/textarea"; import { Label } from "@/components/ui/label"; import { Checkbox } from "@/components/ui/checkbox"; import { Alert, AlertDescription } from "@/components/ui/alert"; import { Info } from "lucide-react"; import { useState } from "react"; export interface ShellCommandData { command: string; qos: 0 | 1 | 2; isRetained: boolean; } interface ShellCommandFormProps { command: string; onCommandChange: (value: string) => void; qos?: 0 | 1 | 2; onQoSChange?: (value: 0 | 1 | 2) => void; isRetained?: boolean; onIsRetainedChange?: (value: boolean) => void; disabled?: boolean; } const QoSDescriptions = { 0: { name: "At Most Once (Fire and Forget)", description: "Gửi lệnh một lần mà không đảm bảo. Nhanh nhất, tiêu tốn ít tài nguyên.", }, 1: { name: "At Least Once", description: "Đảm bảo lệnh sẽ được nhận ít nhất một lần. Cân bằng giữa tốc độ và độ tin cậy.", }, 2: { name: "Exactly Once", description: "Đảm bảo lệnh được nhận chính xác một lần. Chậm nhất nhưng đáng tin cậy nhất.", }, }; export function ShellCommandForm({ command, onCommandChange, qos = 0, onQoSChange, isRetained = false, onIsRetainedChange, disabled, }: ShellCommandFormProps) { const [selectedQoS, setSelectedQoS] = useState<0 | 1 | 2>(qos); const form = useForm({ defaultValues: { command }, onSubmit: () => {}, }); const handleQoSChange = (value: string) => { const newQoS = Number(value) as 0 | 1 | 2; setSelectedQoS(newQoS); onQoSChange?.(newQoS); }; const handleRetainedChange = (checked: boolean) => { onIsRetainedChange?.(checked); }; return (
Broker MQTT sẽ lưu lệnh này và gửi cho client mới khi kết nối. Hữu ích cho các lệnh cấu hình cần duy trì trạng thái.