import { useQuery } from '@tanstack/react-query'; import EmptyPlaceholder from 'components/common/EmptyPlaceholder'; import { formatDistance } from 'date-fns'; import useApi from 'hooks/useApi'; import Link from 'next/link'; import { useEffect, useState } from 'react'; import { Button, Icon, Table, TableBody, TableCell, TableColumn, TableHeader, TableRow, } from 'react-basics'; import styles from './UsersTable.module.css'; const defaultColumns = [ { name: 'username', label: 'Username', style: { flex: 2 } }, { name: 'role', label: 'Role', style: { flex: 2 } }, { name: 'created', label: 'Created' }, { name: 'action', label: ' ' }, ]; export default function UsersTable({ columns = defaultColumns, onLoading, onAddKeyClick }) { const [values, setValues] = useState(null); const { get } = useApi(); const { data, isLoading, error } = useQuery(['user'], () => get(`/users`)); const hasData = data && data.length !== 0; useEffect(() => { if (data) { setValues(data); onLoading({ data, isLoading, error }); } }, [onLoading, data, isLoading, error]); return ( <> {hasData && (