mirror of
https://github.com/Sonny93/my-links.git
synced 2025-12-10 07:25:35 +00:00
feat: recreate admin dashboard using mantine
This commit is contained in:
39
inertia/components/admin/users/utils.ts
Normal file
39
inertia/components/admin/users/utils.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
import {
|
||||
UsersWithCounts,
|
||||
UserWithCounts,
|
||||
} from '~/components/admin/users/users_table';
|
||||
|
||||
export function filterData(data: UsersWithCounts, search: string) {
|
||||
const query = search.toLowerCase().trim();
|
||||
return data.filter((item) =>
|
||||
['email', 'name', 'nickName', 'fullname'].some((key) => {
|
||||
const value = item[key as keyof UserWithCounts];
|
||||
return typeof value === 'string' && value.toLowerCase().includes(query);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
export function sortData(
|
||||
data: UsersWithCounts,
|
||||
payload: {
|
||||
sortBy: keyof UserWithCounts | null;
|
||||
reversed: boolean;
|
||||
search: string;
|
||||
}
|
||||
) {
|
||||
const { sortBy } = payload;
|
||||
|
||||
if (!sortBy) {
|
||||
return filterData(data, payload.search);
|
||||
}
|
||||
|
||||
return filterData(
|
||||
[...data].sort((a, b) => {
|
||||
if (payload.reversed) {
|
||||
return b[sortBy] > a[sortBy] ? 1 : -1;
|
||||
}
|
||||
return a[sortBy] > b[sortBy] ? 1 : -1;
|
||||
}),
|
||||
payload.search
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user