mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-20 13:32:00 +00:00
refactor(FE): Remove date_type filter and hardcode filter_by
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import { useState, useMemo, useCallback } from 'react';
|
import { useState, useMemo, useCallback } from 'react';
|
||||||
import { ChangeEventHandler } from 'react';
|
|
||||||
import useSWR from 'swr';
|
import useSWR from 'swr';
|
||||||
import { Icon } from '@iconify/react';
|
import { Icon } from '@iconify/react';
|
||||||
import Card from '@/components/Card';
|
import Card from '@/components/Card';
|
||||||
@@ -18,7 +17,6 @@ import {
|
|||||||
CustomerPaymentSummary,
|
CustomerPaymentSummary,
|
||||||
} from '@/types/api/report/customer-payment';
|
} from '@/types/api/report/customer-payment';
|
||||||
import { isResponseSuccess } from '@/lib/api-helper';
|
import { isResponseSuccess } from '@/lib/api-helper';
|
||||||
import { useTableFilter } from '@/services/hooks/useTableFilter';
|
|
||||||
import Pagination from '@/components/Pagination';
|
import Pagination from '@/components/Pagination';
|
||||||
import Button from '@/components/Button';
|
import Button from '@/components/Button';
|
||||||
import Dropdown from '@/components/Dropdown';
|
import Dropdown from '@/components/Dropdown';
|
||||||
@@ -46,12 +44,10 @@ const CustomerPaymentTab = () => {
|
|||||||
// ===== FILTER STATE =====
|
// ===== FILTER STATE =====
|
||||||
const [filterCustomer, setFilterCustomer] = useState<OptionType[]>([]);
|
const [filterCustomer, setFilterCustomer] = useState<OptionType[]>([]);
|
||||||
const [filterSales, setFilterSales] = useState<OptionType[]>([]);
|
const [filterSales, setFilterSales] = useState<OptionType[]>([]);
|
||||||
const [filterDateType, setFilterDateType] = useState<OptionType | null>(null);
|
|
||||||
const [filterStartDate, setFilterStartDate] = useState('');
|
const [filterStartDate, setFilterStartDate] = useState('');
|
||||||
const [filterEndDate, setFilterEndDate] = useState('');
|
const [filterEndDate, setFilterEndDate] = useState('');
|
||||||
const [filterErrors, setFilterErrors] = useState<Record<string, string>>({});
|
const [filterErrors, setFilterErrors] = useState<Record<string, string>>({});
|
||||||
|
|
||||||
// Filter Modal
|
|
||||||
const filterModal = useModal();
|
const filterModal = useModal();
|
||||||
|
|
||||||
const { options: customerOptions, isLoadingOptions: isLoadingCustomers } =
|
const { options: customerOptions, isLoadingOptions: isLoadingCustomers } =
|
||||||
@@ -68,10 +64,7 @@ const CustomerPaymentTab = () => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const dataTypeOptions = useMemo(
|
const dataTypeOptions = useMemo(
|
||||||
() => [
|
() => [{ value: 'do_date', label: 'Tanggal Jual' }],
|
||||||
{ value: 'do_date', label: 'Tanggal Jual' },
|
|
||||||
{ value: 'payment_date', label: 'Tanggal Bayar' },
|
|
||||||
],
|
|
||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -80,7 +73,6 @@ const CustomerPaymentTab = () => {
|
|||||||
setIsSubmitted(false);
|
setIsSubmitted(false);
|
||||||
setFilterCustomer([]);
|
setFilterCustomer([]);
|
||||||
setFilterSales([]);
|
setFilterSales([]);
|
||||||
setFilterDateType(null);
|
|
||||||
setFilterStartDate('');
|
setFilterStartDate('');
|
||||||
setFilterEndDate('');
|
setFilterEndDate('');
|
||||||
setFilterErrors({});
|
setFilterErrors({});
|
||||||
@@ -118,10 +110,7 @@ const CustomerPaymentTab = () => {
|
|||||||
filterSales.length > 0
|
filterSales.length > 0
|
||||||
? filterSales.map((v) => String(v.value)).join(',')
|
? filterSales.map((v) => String(v.value)).join(',')
|
||||||
: undefined,
|
: undefined,
|
||||||
date_type: filterDateType?.value as
|
filter_by: 'do_date' as const,
|
||||||
| 'do_date'
|
|
||||||
| 'payment_date'
|
|
||||||
| undefined,
|
|
||||||
start_date: filterStartDate || undefined,
|
start_date: filterStartDate || undefined,
|
||||||
end_date: filterEndDate || undefined,
|
end_date: filterEndDate || undefined,
|
||||||
page: currentPage,
|
page: currentPage,
|
||||||
@@ -135,7 +124,7 @@ const CustomerPaymentTab = () => {
|
|||||||
FinanceApi.getCustomerPaymentReport(
|
FinanceApi.getCustomerPaymentReport(
|
||||||
params.customer_id,
|
params.customer_id,
|
||||||
params.sales,
|
params.sales,
|
||||||
params.date_type,
|
params.filter_by,
|
||||||
params.start_date,
|
params.start_date,
|
||||||
params.end_date,
|
params.end_date,
|
||||||
params.page,
|
params.page,
|
||||||
@@ -169,10 +158,7 @@ const CustomerPaymentTab = () => {
|
|||||||
filterSales.length > 0
|
filterSales.length > 0
|
||||||
? filterSales.map((v) => String(v.value)).join(',')
|
? filterSales.map((v) => String(v.value)).join(',')
|
||||||
: undefined,
|
: undefined,
|
||||||
date_type: filterDateType?.value as
|
filter_by: 'do_date' as const,
|
||||||
| 'do_date'
|
|
||||||
| 'payment_date'
|
|
||||||
| undefined,
|
|
||||||
start_date: filterStartDate || undefined,
|
start_date: filterStartDate || undefined,
|
||||||
end_date: filterEndDate || undefined,
|
end_date: filterEndDate || undefined,
|
||||||
limit: 100,
|
limit: 100,
|
||||||
@@ -182,7 +168,7 @@ const CustomerPaymentTab = () => {
|
|||||||
const response = await FinanceApi.getCustomerPaymentReport(
|
const response = await FinanceApi.getCustomerPaymentReport(
|
||||||
params.customer_id,
|
params.customer_id,
|
||||||
params.sales,
|
params.sales,
|
||||||
params.date_type,
|
params.filter_by,
|
||||||
params.start_date,
|
params.start_date,
|
||||||
params.end_date,
|
params.end_date,
|
||||||
params.page,
|
params.page,
|
||||||
@@ -192,13 +178,7 @@ const CustomerPaymentTab = () => {
|
|||||||
return isResponseSuccess(response)
|
return isResponseSuccess(response)
|
||||||
? (response.data as unknown as CustomerPaymentReport[])
|
? (response.data as unknown as CustomerPaymentReport[])
|
||||||
: null;
|
: null;
|
||||||
}, [
|
}, [filterCustomer, filterSales, filterStartDate, filterEndDate]);
|
||||||
filterCustomer,
|
|
||||||
filterSales,
|
|
||||||
filterDateType,
|
|
||||||
filterStartDate,
|
|
||||||
filterEndDate,
|
|
||||||
]);
|
|
||||||
|
|
||||||
// ===== EXPORT HANDLERS =====
|
// ===== EXPORT HANDLERS =====
|
||||||
const handleExportExcel = useCallback(async () => {
|
const handleExportExcel = useCallback(async () => {
|
||||||
@@ -622,11 +602,8 @@ const CustomerPaymentTab = () => {
|
|||||||
label='Filter Berdasarkan'
|
label='Filter Berdasarkan'
|
||||||
placeholder='Pilih Filter Berdasarkan'
|
placeholder='Pilih Filter Berdasarkan'
|
||||||
options={dataTypeOptions}
|
options={dataTypeOptions}
|
||||||
value={filterDateType}
|
value={dataTypeOptions[0]}
|
||||||
onChange={(val) => {
|
isDisabled={true}
|
||||||
setFilterDateType(val as OptionType | null);
|
|
||||||
}}
|
|
||||||
isClearable={false}
|
|
||||||
className={{ wrapper: 'w-full' }}
|
className={{ wrapper: 'w-full' }}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ export class FinanceApiService extends BaseApiService<
|
|||||||
async getCustomerPaymentReport(
|
async getCustomerPaymentReport(
|
||||||
customer_id?: string,
|
customer_id?: string,
|
||||||
sales?: string,
|
sales?: string,
|
||||||
date_type?: 'do_date' | 'payment_date',
|
filter_by?: 'do_date',
|
||||||
start_date?: string,
|
start_date?: string,
|
||||||
end_date?: string,
|
end_date?: string,
|
||||||
page?: number,
|
page?: number,
|
||||||
@@ -27,7 +27,7 @@ export class FinanceApiService extends BaseApiService<
|
|||||||
params: {
|
params: {
|
||||||
customer_id: customer_id,
|
customer_id: customer_id,
|
||||||
sales: sales,
|
sales: sales,
|
||||||
date_type: date_type,
|
filter_by: filter_by,
|
||||||
start_date: start_date,
|
start_date: start_date,
|
||||||
end_date: end_date,
|
end_date: end_date,
|
||||||
page: page,
|
page: page,
|
||||||
|
|||||||
Reference in New Issue
Block a user