refactor(FE-361,363): Add sort order selector to PurchasesPerSupplierTab

This commit is contained in:
rstubryan
2025-12-18 13:57:58 +07:00
parent 1be596921a
commit 81d242bd1d
@@ -102,6 +102,14 @@ const PurchasesPerSupplierTab = () => {
[] []
); );
const sortByOptions = useMemo(
() => [
{ value: 'ASC', label: 'Ascending' },
{ value: 'DESC', label: 'Descending' },
],
[]
);
const areaChangeHandler = useCallback( const areaChangeHandler = useCallback(
(val: OptionType | OptionType[] | null) => { (val: OptionType | OptionType[] | null) => {
const arr = Array.isArray(val) ? val : val ? [val] : []; const arr = Array.isArray(val) ? val : val ? [val] : [];
@@ -163,6 +171,16 @@ const PurchasesPerSupplierTab = () => {
[updateFilter] [updateFilter]
); );
const sortByHandler = useCallback(
(val: OptionType | OptionType[] | null) => {
const newVal = val as OptionType;
const sortValue = (newVal?.value as 'ASC' | 'DESC') || 'ASC';
updateFilter('sort_by', sortValue);
setIsSubmitted(false);
},
[updateFilter]
);
const startDateChangeHandler = useCallback< const startDateChangeHandler = useCallback<
ChangeEventHandler<HTMLInputElement> ChangeEventHandler<HTMLInputElement>
>( >(
@@ -843,19 +861,34 @@ const PurchasesPerSupplierTab = () => {
isLoading={isLoadingProductCategories} isLoading={isLoadingProductCategories}
isClearable isClearable
/> />
<SelectInput <div className='md:flex md:flex-row grid grid-cols-1 gap-4'>
label='Filter Berdasarkan' <SelectInput
placeholder='Pilih Filter Berdasarkan' label='Filter Berdasarkan'
options={dataTypeOptions} placeholder='Pilih Filter Berdasarkan'
value={ options={dataTypeOptions}
dataTypeOptions?.find( value={
(option) => option.value === tableFilterState.filter_by dataTypeOptions?.find(
) || null (option) => option.value === tableFilterState.filter_by
} ) || null
onChange={dataTypeChangeHandler} }
isLoading={false} onChange={dataTypeChangeHandler}
isClearable={false} isLoading={false}
/> isClearable={false}
/>
<SelectInput
label='Urutkan Berdasarkan'
placeholder='Pilih Urutkan Berdasarkan'
options={sortByOptions}
value={
sortByOptions?.find(
(option) => option.value === tableFilterState.sort_by
) || null
}
onChange={sortByHandler}
isLoading={false}
isClearable={false}
/>
</div>
<div className='md:flex md:flex-row grid grid-cols-1 gap-4'> <div className='md:flex md:flex-row grid grid-cols-1 gap-4'>
<DateInput <DateInput
label='Tanggal Awal' label='Tanggal Awal'