'use client'; import { useState } from 'react'; import Link from "next/link"; const GrantSudoLink = ({ text, isCard }) => { const [isHovered, setIsHovered] = useState(false); const [showDialog, setShowDialog] = useState(false); const [username, setUsername] = useState(''); const [password, setPassword] = useState(''); // hover over eeffect const handleMouseEnter = () => { setIsHovered(true); }; const handleMouseLeave = () => { setIsHovered(false); }; const cardStyle = { boxShadow: isHovered ? '0 4px 20px rgba(0, 0, 0, 0.2)' : '0 1px 3px rgba(0, 0, 0, 0.1)', transition: 'box-shadow 0.3s ease-in-out', }; // username dialog box const openDialog = () => { setShowDialog(true); }; const closeDialog = () => { setShowDialog(false); }; const handleGrantSudoRights = async () => { try { const response = await fetch('/api/grant-sudo', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ username, password }), }); const data = await response.json(); if (response.ok) { alert('Sudo rights granted successfully.'); } else { alert(data.error); } closeDialog(); } catch (error) { alert('Error granting sudo rights'); } }; return (
{isCard ? (
{text}

You need to do this once

) : ( {text} )} {showDialog && (
Grant Sudo Rights
setUsername(e.target.value)} />
setPassword(e.target.value)} />
)}
); }; export default GrantSudoLink;