(null);
const [isDeleteLoading, setIsDeleteLoading] = useState(false);
@@ -197,27 +202,18 @@ const FinanceTable = () => {
FinanceApi.getAllFetcher
);
- // ===== Options =====
- const transactionTypeOptions = useMemo(() => {
- return [
- { label: 'Customer', value: 'CUSTOMER' },
- { label: 'Supplier', value: 'SUPPLIER' },
- ];
- }, []);
const {
- options: partyTypeOptions,
- isLoadingOptions: partyTypeIsLoadingOptions,
- setInputValue: partyTypeInputValue,
- loadMore: partyTypeLoadMore,
- } = useSelect(
- selectedTransactionType
- ? selectedTransactionType.value === 'CUSTOMER'
- ? CustomerApi.basePath
- : SupplierApi.basePath
- : '',
- 'id',
- 'name'
- );
+ options: customerOptions,
+ isLoadingOptions: customerIsLoadingOptions,
+ setInputValue: customerInputValue,
+ loadMore: customerLoadMore,
+ } = useSelect(CustomerApi.basePath, 'id', 'name');
+ const {
+ options: supplierOptions,
+ isLoadingOptions: supplierIsLoadingOptions,
+ setInputValue: supplierInputValue,
+ loadMore: supplierLoadMore,
+ } = useSelect(SupplierApi.basePath, 'id', 'name');
const sortByOptions = useMemo(() => {
return [
{ label: 'Tanggal Pembayaran', value: 'payment_date' },
@@ -238,24 +234,47 @@ const FinanceTable = () => {
const transactionTypeChangeHandler = (
val: OptionType | OptionType[] | null
) => {
- setSelectedTransactionType(val as OptionType);
+ setSelectedTransactionType(val);
setPendingFilters((prev) => ({
...prev,
- transactionType: val ? ((val as OptionType).value as string) : '',
+ transactionType: val
+ ? Array.isArray(val)
+ ? val.map((item) => item.value).join(',')
+ : (val.value as string)
+ : '',
}));
};
const bankChangeHandler = (val: OptionType | OptionType[] | null) => {
- setSelectedBank(val as OptionType);
+ setSelectedBank(val);
setPendingFilters((prev) => ({
...prev,
- bankId: val ? ((val as OptionType).value as string) : '',
+ bankId: val
+ ? Array.isArray(val)
+ ? val.map((item) => item.value).join(',')
+ : (val.value as string)
+ : '',
}));
};
- const partyTypeChangeHandler = (val: OptionType | OptionType[] | null) => {
- setSelectedPartyType(val as OptionType);
+ const customerIdChangeHandler = (val: OptionType | OptionType[] | null) => {
+ setSelectedCustomerId(val);
setPendingFilters((prev) => ({
...prev,
- partyType: val ? ((val as OptionType).value as string) : '',
+ customerId: val
+ ? Array.isArray(val)
+ ? val.map((item) => item.value).join(',')
+ : (val.value as string)
+ : '',
+ }));
+ };
+ const supplierIdChangeHandler = (val: OptionType | OptionType[] | null) => {
+ setSelectedSupplierId(val);
+ setPendingFilters((prev) => ({
+ ...prev,
+ supplierId: val
+ ? Array.isArray(val)
+ ? val.map((item) => item.value).join(',')
+ : (val.value as string)
+ : '',
}));
};
const sortByChangeHandler = (val: OptionType | OptionType[] | null) => {
@@ -279,7 +298,8 @@ const FinanceTable = () => {
updateFilter('search', pendingFilters.search);
updateFilter('transactionType', pendingFilters.transactionType);
updateFilter('bankId', pendingFilters.bankId);
- updateFilter('partyType', pendingFilters.partyType);
+ updateFilter('customerId', pendingFilters.customerId);
+ updateFilter('supplierId', pendingFilters.supplierId);
updateFilter('sortBy', pendingFilters.sortBy);
updateFilter('startDate', pendingFilters.startDate);
updateFilter('endDate', pendingFilters.endDate);
@@ -287,14 +307,16 @@ const FinanceTable = () => {
const resetFilterHandler = () => {
setSelectedTransactionType(null);
setSelectedBank(null);
- setSelectedPartyType(null);
+ setSelectedCustomerId(null);
+ setSelectedSupplierId(null);
setSelectedSortBy(null);
const emptyFilters = {
search: '',
transactionType: '',
bankId: '',
- partyType: '',
+ customerId: '',
+ supplierId: '',
sortBy: '',
startDate: '',
endDate: '',
@@ -304,7 +326,8 @@ const FinanceTable = () => {
updateFilter('search', '');
updateFilter('transactionType', '');
updateFilter('bankId', '');
- updateFilter('partyType', '');
+ updateFilter('customerId', '');
+ updateFilter('supplierId', '');
updateFilter('sortBy', '');
updateFilter('startDate', '');
updateFilter('endDate', '');
@@ -477,27 +500,34 @@ const FinanceTable = () => {
>
+
{
onInputChange={bankInputValue}
onMenuScrollToBottom={bankLoadMore}
isClearable
- />
-
{
value={pendingFilters.endDate}
onChange={endDateChangeHandler}
/>
+
diff --git a/src/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance.tsx b/src/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance.tsx
index e1a31415..cb46c0e1 100644
--- a/src/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance.tsx
+++ b/src/components/pages/finance/add/initial-balance/FormFinanceAddInitialBalance.tsx
@@ -245,7 +245,11 @@ const FormFinanceAddInitialBalance = ({
}
required
isClearable
- isDisabled={!formik.values.party_type_option?.value}
+ isDisabled={
+ !formik.values.party_type_option?.value ||
+ (type === 'edit' &&
+ formik.values.party_type_option?.value == 'SUPPLIER')
+ }
/>