fix: make the last acl tag removable on machines

This commit is contained in:
Aarnav Tale 2024-11-06 16:10:39 -05:00
parent 09e1b1f261
commit 6e55f442fd
No known key found for this signature in database
2 changed files with 8 additions and 4 deletions

View File

@ -3,6 +3,7 @@ import { ActionFunctionArgs, json } from '@remix-run/node'
import { del, post } from '~/utils/headscale' import { del, post } from '~/utils/headscale'
import { getSession } from '~/utils/sessions' import { getSession } from '~/utils/sessions'
import log from '~/utils/log'
export async function menuAction(request: ActionFunctionArgs['request']) { export async function menuAction(request: ActionFunctionArgs['request']) {
const session = await getSession(request.headers.get('Cookie')) const session = await getSession(request.headers.get('Cookie'))
@ -82,7 +83,9 @@ export async function menuAction(request: ActionFunctionArgs['request']) {
case 'tags': { case 'tags': {
const tags = data.get('tags')?.toString() const tags = data.get('tags')?.toString()
.split(',') ?? [] .split(',')
.filter((tag) => tag.trim() !== '')
?? []
try { try {
await post(`v1/node/${id}/tags`, session.get('hsApiKey')!, { await post(`v1/node/${id}/tags`, session.get('hsApiKey')!, {
@ -90,7 +93,8 @@ export async function menuAction(request: ActionFunctionArgs['request']) {
}) })
return json({ message: 'Tags updated' }) return json({ message: 'Tags updated' })
} catch { } catch (error) {
log.debug('APIC', 'Failed to update tags: %s', error)
return json({ message: 'Failed to update tags' }, { return json({ message: 'Failed to update tags' }, {
status: 500, status: 500,
}) })

View File

@ -1,11 +1,11 @@
import { PlusIcon, XIcon } from '@primer/octicons-react' import { PlusIcon, XIcon } from '@primer/octicons-react'
import { Form, useSubmit } from '@remix-run/react' import { Form, useSubmit } from '@remix-run/react'
import { type Dispatch, type SetStateAction, useState } from 'react' import { Dispatch, SetStateAction, useState } from 'react'
import { Button, Input } from 'react-aria-components' import { Button, Input } from 'react-aria-components'
import Dialog from '~/components/Dialog' import Dialog from '~/components/Dialog'
import Link from '~/components/Link' import Link from '~/components/Link'
import { type Machine } from '~/types' import { Machine } from '~/types'
import { cn } from '~/utils/cn' import { cn } from '~/utils/cn'
interface TagsProps { interface TagsProps {