import { useStore } from '@tanstack/react-form'; import type { ColumnDef } from '@tanstack/react-table'; import { Link } from '@tanstack/react-router'; import { deleteAdminLocationInput, type AdminLocation, useDeleteAdminLocation } from '@/api/admin/locations/queries'; import Button from '@/components/elements/Button'; import { Dialog } from '@/components/elements/dialog'; import SpinnerOverlay from '@/components/elements/SpinnerOverlay'; import DataTableColumnHeader from '@/components/elements/table/DataTableColumnHeader'; import { actionsColumn, DeleteAction, EditLinkAction, RowActions } from '@/components/elements/table/RowActions'; import { Form, useAppForm } from '@/components/form'; import dayjs from '@/lib/dayjs'; interface LocationDialogProps { location: AdminLocation; open: boolean; onClose: () => void; } function DeleteLocationDialog({ location, open, onClose }: LocationDialogProps) { const { attributes } = location; const deleteLocation = useDeleteAdminLocation(); const form = useAppForm({ defaultValues: { confirm: '' }, onSubmit: async () => { try { await deleteLocation.mutateAsync(deleteAdminLocationInput(attributes.id, attributes.short)); onClose(); } catch { // Error toast is handled by the mutation. } }, }); const isSubmitting = useStore(form.store, (state) => state.isSubmitting); return (

Deleting a location is permanent. This will remove {attributes.short}.

value === attributes.short ? undefined : 'The short code must be provided.', }} > {(field) => ( )}
Cancel Delete location
); } const LocationActionsCell = ({ location }: { location: AdminLocation }) => ( ( )} > {({ open, onClose }) => } ); export const locationColumns = [ { id: 'short', accessorFn: (location) => location.attributes.short, header: ({ column }) => , cell: ({ row }) => (
{row.original.attributes.short} {row.original.attributes.long ? (

{row.original.attributes.long}

) : null}
), enableSorting: true, meta: { headerClassName: 'min-w-48', cellClassName: 'min-w-48' }, }, { id: 'nodes_count', header: 'Nodes', cell: ({ row }) => {row.original.attributes.nodes_count}, enableSorting: false, meta: { headerClassName: 'hidden w-20 @sm:table-cell', cellClassName: 'hidden w-20 @sm:table-cell' }, }, { id: 'servers_count', header: 'Servers', cell: ({ row }) => {row.original.attributes.servers_count}, enableSorting: false, meta: { headerClassName: 'hidden w-20 @lg:table-cell', cellClassName: 'hidden w-20 @lg:table-cell' }, }, { id: 'created_at', accessorFn: (location) => location.attributes.created_at, header: ({ column }) => , cell: ({ row }) => ( ), enableSorting: true, sortDescFirst: true, meta: { headerClassName: 'hidden w-28 @xl:table-cell', cellClassName: 'hidden w-28 @xl:table-cell' }, }, actionsColumn(2, (location) => ), ] satisfies ColumnDef[];