Convert /api/users.

This commit is contained in:
Mike Cao 2025-01-21 19:10:34 -08:00
parent 090abcff81
commit baa3851fb4
61 changed files with 1064 additions and 70 deletions

View file

@ -37,26 +37,26 @@ export function DataTable({
query: { error, isLoading, isFetched },
} = queryResult || {};
const { page, pageSize, count, data } = result || {};
const { query } = params || {};
const { search } = params || {};
const hasData = Boolean(!isLoading && data?.length);
const noResults = Boolean(query && !hasData);
const noResults = Boolean(search && !hasData);
const { router, renderUrl } = useNavigation();
const handleSearch = (query: string) => {
setParams({ ...params, query, page: params.page ? page : 1 });
const handleSearch = (search: string) => {
setParams({ ...params, search, page: params.page ? page : 1 });
};
const handlePageChange = (page: number) => {
setParams({ ...params, query, page });
setParams({ ...params, search, page });
router.push(renderUrl({ page }));
};
return (
<>
{allowSearch && (hasData || query) && (
{allowSearch && (hasData || search) && (
<SearchField
className={styles.search}
value={query}
value={search}
onSearch={handleSearch}
delay={searchDelay || DEFAULT_SEARCH_DELAY}
autoFocus={autoFocus}
@ -71,7 +71,7 @@ export function DataTable({
>
{hasData ? (typeof children === 'function' ? children(result) : children) : null}
{isLoading && <Loading position="page" />}
{!isLoading && !hasData && !query && (renderEmpty ? renderEmpty() : <Empty />)}
{!isLoading && !hasData && !search && (renderEmpty ? renderEmpty() : <Empty />)}
{!isLoading && noResults && <Empty message={formatMessage(messages.noResultsFound)} />}
</div>
{allowPaging && hasData && (

View file

@ -1,23 +1,16 @@
import { useEffect } from 'react';
import useStore, { setConfig } from 'store/app';
import { useApi } from '../useApi';
let loading = false;
import { getConfig } from 'app/actions/getConfig';
export function useConfig() {
const { config } = useStore();
const { get } = useApi();
const configUrl = process.env.configUrl;
async function loadConfig() {
const data = await get(configUrl);
loading = false;
setConfig(data);
setConfig(await getConfig());
}
useEffect(() => {
if (!config && !loading && configUrl) {
loading = true;
if (!config) {
loadConfig();
}
}, []);

View file

@ -11,7 +11,7 @@ export function usePagedQuery<T = any>({
}: Omit<UseQueryOptions, 'queryFn'> & { queryFn: (params?: object) => any }): PagedQueryResult<T> {
const { query: queryParams } = useNavigation();
const [params, setParams] = useState<PageParams>({
query: '',
search: '',
page: +queryParams.page || 1,
});

View file

@ -10,8 +10,3 @@
font-size: var(--font-size-md);
font-weight: 400;
}
.value {
font-weight: 600;
margin-inline-end: 4px;
}

View file

@ -24,7 +24,7 @@ export function ActiveUsers({
const count = useMemo(() => {
if (websiteId) {
return data?.x || 0;
return data?.visitors || 0;
}
return value !== undefined ? value : 0;