fix: Fix issue where the Add System button is visible to read-only users (#1442)

移除按钮的hidden类并提前检查只读用户状态返回null
This commit is contained in:
zjkal
2025-11-20 05:38:37 +08:00
committed by GitHub
parent 00fbf5c9c3
commit c7a50dd74d

View File

@@ -36,28 +36,31 @@ import { AppleIcon, DockerIcon, FreeBsdIcon, TuxIcon, WindowsIcon } from "./ui/i
import { InputCopy } from "./ui/input-copy" import { InputCopy } from "./ui/input-copy"
export function AddSystemButton({ className }: { className?: string }) { export function AddSystemButton({ className }: { className?: string }) {
const [open, setOpen] = useState(false) if (isReadOnlyUser()) {
const opened = useRef(false) return null
if (open) { }
opened.current = true const [open, setOpen] = useState(false)
} const opened = useRef(false)
if (open) {
opened.current = true
}
return ( return (
<Dialog open={open} onOpenChange={setOpen}> <Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild> <DialogTrigger asChild>
<Button <Button
variant="outline" variant="outline"
className={cn("flex gap-1 max-xs:h-[2.4rem]", className, isReadOnlyUser() && "hidden")} className={cn("flex gap-1 max-xs:h-[2.4rem]", className)}
> >
<PlusIcon className="h-4 w-4 -ms-1" /> <PlusIcon className="h-4 w-4 -ms-1" />
<Trans> <Trans>
Add <span className="hidden sm:inline">System</span> Add <span className="hidden sm:inline">System</span>
</Trans> </Trans>
</Button> </Button>
</DialogTrigger> </DialogTrigger>
{opened.current && <SystemDialog setOpen={setOpen} />} {opened.current && <SystemDialog setOpen={setOpen} />}
</Dialog> </Dialog>
) )
} }
/** /**