diff --git a/app/routes/_data.acls._index/route.tsx b/app/routes/_data.acls._index/route.tsx index d466560..5c8b901 100644 --- a/app/routes/_data.acls._index/route.tsx +++ b/app/routes/_data.acls._index/route.tsx @@ -1,9 +1,10 @@ /* eslint-disable @typescript-eslint/no-non-null-assertion */ import { BeakerIcon, EyeIcon, IssueDraftIcon, PencilIcon } from '@primer/octicons-react' -import { type ActionFunctionArgs, json, LoaderFunctionArgs } from '@remix-run/node' +import { ActionFunctionArgs, json, LoaderFunctionArgs } from '@remix-run/node' import { useFetcher, useLoaderData } from '@remix-run/react' import { useEffect, useState } from 'react' import { Tab, TabList, TabPanel, Tabs } from 'react-aria-components' +import { setTimeout } from 'node:timers/promises' import Button from '~/components/Button' import Code from '~/components/Code' @@ -75,6 +76,7 @@ export async function action({ request }: ActionFunctionArgs) { policy: acl, }) + await setTimeout(250) return json({ success: true }) } catch (error) { return json({ success: false }, { diff --git a/app/routes/_data.machines._index/action.tsx b/app/routes/_data.machines._index/action.tsx index ae68781..ffc12b1 100644 --- a/app/routes/_data.machines._index/action.tsx +++ b/app/routes/_data.machines._index/action.tsx @@ -97,6 +97,35 @@ export async function menuAction(request: ActionFunctionArgs['request']) { } } + case 'register': { + const key = data.get('mkey')?.toString() + const user = data.get('user')?.toString() + + if (!key) { + return json({ message: 'No machine key provided' }, { + status: 400, + }) + } + + if (!user) { + return json({ message: 'No user provided' }, { + status: 400, + }) + } + + try { + await post('v1/node/register', session.get('hsApiKey')!, { + user, key, + }) + + return json({ message: 'Machine registered' }) + } catch { + return json({ message: 'Failed to register machine' }, { + status: 500, + }) + } + } + default: { return json({ message: 'Invalid method' }, { status: 400, diff --git a/app/routes/_data.machines._index/dialogs/new.tsx b/app/routes/_data.machines._index/dialogs/new.tsx new file mode 100644 index 0000000..5db7622 --- /dev/null +++ b/app/routes/_data.machines._index/dialogs/new.tsx @@ -0,0 +1,115 @@ +import { Form, useSubmit } from '@remix-run/react' +import { Dispatch, SetStateAction, useState } from 'react' +import { PlusIcon, ServerIcon, KeyIcon } from '@primer/octicons-react' +import { cn } from '~/utils/cn' + +import Code from '~/components/Code' +import Dialog from '~/components/Dialog' +import TextField from '~/components/TextField' +import Select from '~/components/Select' +import Menu from '~/components/Menu' +import { Machine, User } from '~/types' + +export interface NewProps { + server: string + users: User[] +} + +export default function New(data: NewProps) { + const submit = useSubmit() + const mkeyState = useState(false) + const pkeyState = useState(false) + const [mkey, setMkey] = useState('') + const [user, setUser] = useState(data.users[0].id) + + return ( + <> + + + {close => ( + <> + + Register Machine Key + + + The machine key is given when you run + {' '} + + tailscale up --login-server= + + + {data.server} + + {' '} + on your device. + +
{ + submit(e.currentTarget) + }} + > + + + + +
+ + Cancel + + + Register + +
+ + + )} +
+
+ + + Add Device + + + + + Register Machine Key + + + + Generate Pre-auth Key + + + + + ) +} diff --git a/app/routes/_data.machines._index/route.tsx b/app/routes/_data.machines._index/route.tsx index cd7dbac..203f274 100644 --- a/app/routes/_data.machines._index/route.tsx +++ b/app/routes/_data.machines._index/route.tsx @@ -15,6 +15,7 @@ import { useLiveData } from '~/utils/useLiveData' import { menuAction } from './action' import MachineRow from './machine' +import NewMachine from './dialogs/new' export async function loader({ request }: LoaderFunctionArgs) { const session = await getSession(request.headers.get('Cookie')) @@ -43,6 +44,7 @@ export async function loader({ request }: LoaderFunctionArgs) { routes: routes.routes, users: users.users, magic, + server: context.headscaleUrl, } } @@ -56,7 +58,10 @@ export default function Page() { return ( <> -

Machines

+
+

Machines

+ +