diff --git a/app/components/ui/table-search.tsx b/app/components/ui/table-search.tsx new file mode 100644 index 0000000..c71cce5 --- /dev/null +++ b/app/components/ui/table-search.tsx @@ -0,0 +1,69 @@ +import { Field, Input, Label, Select } from '@headlessui/react' +import { MagnifyingGlassIcon } from '@heroicons/react/20/solid' +import { useState } from 'react' + +interface SearchFilterProperties { + title: string + columns?: string[] + onSearch: (value: string) => void + onStatusFilter?: (value: string) => Promise +} +export const TableSearchFilter: React.FC = ({ + onSearch, + onStatusFilter, + title, +}: SearchFilterProperties) => { + const [searchTerm, setSearchTerm] = useState('') + const [statusFilter, setStatusFilter] = useState('') + + const handleSearch = (searchValue: React.ChangeEvent) => { + setSearchTerm(searchValue.target.value) + onSearch(searchValue.target.value) + } + + const handleStatusFilter = ( + searchValue: React.ChangeEvent, + ) => { + setStatusFilter(searchValue.target.value) + onStatusFilter?.(searchValue.target.value) + } + + return ( +
+
+ + +
+ +
+ +
+
+
+
+ {onStatusFilter && ( + // will handel if filter have dropdown status +
+ + + + +
+ )} +
+ ) +} diff --git a/app/components/ui/table.tsx b/app/components/ui/table.tsx index 6d121b4..520633c 100644 --- a/app/components/ui/table.tsx +++ b/app/components/ui/table.tsx @@ -32,9 +32,9 @@ export const UiTable: React.FC = ({ thead.classList.add('text-left') }, paging: true, - searching: true, + searching: false, ordering: true, - info: true, + info: false, language: { paginate: { first: renderPaginationIcon( diff --git a/app/pages/dashboard-tags/index.tsx b/app/pages/dashboard-tags/index.tsx index fb01772..5fcd7ce 100644 --- a/app/pages/dashboard-tags/index.tsx +++ b/app/pages/dashboard-tags/index.tsx @@ -12,6 +12,7 @@ import type { TTagResponse } from '~/apis/common/get-tags' import { DialogDelete } from '~/components/dialog/delete' import { Button } from '~/components/ui/button' import { UiTable } from '~/components/ui/table' +import { TableSearchFilter } from '~/components/ui/table-search' import { TitleDashboard } from '~/components/ui/title-dashboard' import type { loader } from '~/routes/_admin.lg-admin._dashboard' @@ -19,6 +20,7 @@ export const TagsPage = () => { const loaderData = useRouteLoaderData( 'routes/_admin.lg-admin._dashboard', ) + const [searchTerm, setSearchTerm] = useState('') const [selectedTag, setSelectedTag] = useState() const { tagsData: dataTable } = loaderData || {} @@ -73,16 +75,27 @@ export const TagsPage = () => { } const dataOptions: Config = { paging: true, - searching: true, - ordering: true, info: true, } - + const filteredData = dataTable?.filter((item) => { + const matchesSearch = Object.keys(item).some((key) => + item[key as keyof TTagResponse] + ?.toString() + .toLowerCase() + .includes(searchTerm.toLowerCase()), + ) + return matchesSearch + }) return (
-
{/* TODO: Filter */}
+
+ +