🎨 style: refactor and re-styling filter form component
This commit is contained in:
parent
6a108c1a1b
commit
87307381cb
@ -1,10 +1,10 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { DateRange } from 'react-day-picker';
|
|
||||||
|
|
||||||
import { IconButton, Option, Select } from '@material-tailwind/react';
|
import { Input } from 'components/shared/Input';
|
||||||
|
import { CrossCircleIcon, SearchIcon } from 'components/shared/CustomIcon';
|
||||||
import SearchBar from '../../../SearchBar';
|
import { DatePicker } from 'components/shared/DatePicker';
|
||||||
import DatePicker from '../../../DatePicker';
|
import { Value } from 'react-calendar/dist/cjs/shared/types';
|
||||||
|
import { Select, SelectOption } from 'components/shared/Select';
|
||||||
|
|
||||||
export enum StatusOptions {
|
export enum StatusOptions {
|
||||||
ALL_STATUS = 'All status',
|
ALL_STATUS = 'All status',
|
||||||
@ -16,7 +16,7 @@ export enum StatusOptions {
|
|||||||
export interface FilterValue {
|
export interface FilterValue {
|
||||||
searchedBranch: string;
|
searchedBranch: string;
|
||||||
status: StatusOptions;
|
status: StatusOptions;
|
||||||
updateAtRange?: DateRange;
|
updateAtRange?: Value;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface FilterFormProps {
|
interface FilterFormProps {
|
||||||
@ -27,7 +27,7 @@ interface FilterFormProps {
|
|||||||
const FilterForm = ({ value, onChange }: FilterFormProps) => {
|
const FilterForm = ({ value, onChange }: FilterFormProps) => {
|
||||||
const [searchedBranch, setSearchedBranch] = useState(value.searchedBranch);
|
const [searchedBranch, setSearchedBranch] = useState(value.searchedBranch);
|
||||||
const [selectedStatus, setSelectedStatus] = useState(value.status);
|
const [selectedStatus, setSelectedStatus] = useState(value.status);
|
||||||
const [dateRange, setDateRange] = useState<DateRange>();
|
const [dateRange, setDateRange] = useState<Value>();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
onChange({
|
onChange({
|
||||||
@ -43,46 +43,50 @@ const FilterForm = ({ value, onChange }: FilterFormProps) => {
|
|||||||
setDateRange(value.updateAtRange);
|
setDateRange(value.updateAtRange);
|
||||||
}, [value]);
|
}, [value]);
|
||||||
|
|
||||||
|
const statusOptions = Object.values(StatusOptions)
|
||||||
|
.map((status) => ({
|
||||||
|
label: status,
|
||||||
|
value: status,
|
||||||
|
}))
|
||||||
|
.filter((status) => status.value !== StatusOptions.ALL_STATUS);
|
||||||
|
|
||||||
|
const handleReset = () => {
|
||||||
|
setSearchedBranch('');
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="grid grid-cols-8 gap-2 text-sm text-gray-600">
|
<div className="xl:grid xl:grid-cols-8 flex flex-col xl:gap-3 gap-0">
|
||||||
<div className="col-span-4">
|
<div className="col-span-4 flex items-center">
|
||||||
<SearchBar
|
<Input
|
||||||
placeholder="Search branches"
|
placeholder="Search branches"
|
||||||
|
leftIcon={<SearchIcon />}
|
||||||
|
rightIcon={
|
||||||
|
searchedBranch && <CrossCircleIcon onClick={handleReset} />
|
||||||
|
}
|
||||||
value={searchedBranch}
|
value={searchedBranch}
|
||||||
onChange={(event) => setSearchedBranch(event.target.value)}
|
onChange={(e) => setSearchedBranch(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-span-2">
|
<div className="col-span-2 flex items-center">
|
||||||
<DatePicker mode="range" selected={dateRange} onSelect={setDateRange} />
|
<DatePicker
|
||||||
|
className="w-full"
|
||||||
|
selectRange
|
||||||
|
value={dateRange}
|
||||||
|
onChange={setDateRange}
|
||||||
|
onReset={() => setDateRange(undefined)}
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-span-2 relative">
|
<div className="col-span-2 flex items-center">
|
||||||
<Select
|
<Select
|
||||||
value={selectedStatus}
|
options={statusOptions}
|
||||||
onChange={(value) => setSelectedStatus(value as StatusOptions)}
|
clearable
|
||||||
placeholder="All status"
|
placeholder="All status"
|
||||||
>
|
value={{ label: selectedStatus, value: selectedStatus }}
|
||||||
{Object.values(StatusOptions).map((status) => (
|
onChange={(item) =>
|
||||||
<Option
|
setSelectedStatus((item as SelectOption).value as StatusOptions)
|
||||||
className={status === StatusOptions.ALL_STATUS ? 'hidden' : ''}
|
}
|
||||||
key={status}
|
onClear={() => setSelectedStatus(StatusOptions.ALL_STATUS)}
|
||||||
value={status}
|
/>
|
||||||
>
|
|
||||||
^ {status}
|
|
||||||
</Option>
|
|
||||||
))}
|
|
||||||
</Select>
|
|
||||||
{selectedStatus !== StatusOptions.ALL_STATUS && (
|
|
||||||
<div className="absolute end-1 inset-y-0 my-auto h-8">
|
|
||||||
<IconButton
|
|
||||||
onClick={() => setSelectedStatus(StatusOptions.ALL_STATUS)}
|
|
||||||
className="rounded-full"
|
|
||||||
size="sm"
|
|
||||||
placeholder={''}
|
|
||||||
>
|
|
||||||
X
|
|
||||||
</IconButton>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user