headplane/app/routes/machines/dialogs/new.tsx

87 lines
2.4 KiB
TypeScript
Raw Normal View History

import { Computer, FileKey2 } from 'lucide-react';
2025-01-28 16:02:47 -05:00
import { useState } from 'react';
import { useNavigate } from 'react-router';
2024-12-31 10:30:14 +05:30
import Code from '~/components/Code';
import Dialog from '~/components/Dialog';
2025-01-28 16:02:47 -05:00
import Input from '~/components/Input';
2024-12-31 10:30:14 +05:30
import Menu from '~/components/Menu';
import Select from '~/components/Select';
import type { User } from '~/types';
export interface NewMachineProps {
2024-12-31 10:30:14 +05:30
server: string;
users: User[];
isDisabled?: boolean;
disabledKeys?: string[];
}
export default function NewMachine(data: NewMachineProps) {
const [pushDialog, setPushDialog] = useState(false);
2024-12-31 10:30:14 +05:30
const [mkey, setMkey] = useState('');
2025-01-28 16:02:47 -05:00
const navigate = useNavigate();
return (
<>
<Dialog isOpen={pushDialog} onOpenChange={setPushDialog}>
<Dialog.Panel isDisabled={mkey.length < 1}>
<Dialog.Title>Register Machine Key</Dialog.Title>
<Dialog.Text className="mb-4">
The machine key is given when you run{' '}
<Code isCopyable>tailscale up --login-server={data.server}</Code> on
your device.
</Dialog.Text>
<input type="hidden" name="action_id" value="register" />
2025-01-28 16:02:47 -05:00
<Input
isRequired
label="Machine Key"
placeholder="AbCd..."
2025-01-28 16:02:47 -05:00
validationBehavior="native"
name="register_key"
2025-01-28 16:02:47 -05:00
onChange={setMkey}
/>
<Select
2025-01-28 16:02:47 -05:00
isRequired
label="Owner"
name="user"
placeholder="Select a user"
>
{data.users.map((user) => (
2025-07-11 10:54:38 +02:00
<Select.Item key={user.id}>{user.name || user.displayName || user.email || user.id}</Select.Item>
))}
</Select>
</Dialog.Panel>
</Dialog>
<Menu isDisabled={data.isDisabled} disabledKeys={data.disabledKeys}>
<Menu.Button variant="heavy">Add Device</Menu.Button>
2025-01-28 16:02:47 -05:00
<Menu.Panel
onAction={(key) => {
if (key === 'register') {
setPushDialog(true);
return;
}
if (key === 'pre-auth') {
navigate('/settings/auth-keys');
}
}}
>
<Menu.Section>
<Menu.Item key="register" textValue="Register Machine Key">
<div className="flex items-center gap-x-3">
<Computer className="w-4" />
Register Machine Key
</div>
</Menu.Item>
<Menu.Item key="pre-auth" textValue="Generate Pre-auth Key">
<div className="flex items-center gap-x-3">
<FileKey2 className="w-4" />
2025-01-28 16:02:47 -05:00
Generate Pre-auth Key
</div>
</Menu.Item>
</Menu.Section>
</Menu.Panel>
</Menu>
</>
2024-12-31 10:30:14 +05:30
);
}