mirror of
https://gitlab.com/mbugroup/lti-web-client.git
synced 2026-05-25 15:55:48 +00:00
fix: adjust ExpensesFilterSchema for location and vendor select input
This commit is contained in:
@@ -51,7 +51,9 @@ type ExpenseTableFilters = {
|
|||||||
transactionDate: string;
|
transactionDate: string;
|
||||||
realizationDate: string;
|
realizationDate: string;
|
||||||
locationId: string;
|
locationId: string;
|
||||||
|
locationName: string;
|
||||||
vendorId: string;
|
vendorId: string;
|
||||||
|
vendorName: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -235,6 +237,7 @@ const ExpensesTable = () => {
|
|||||||
setPage,
|
setPage,
|
||||||
setPageSize,
|
setPageSize,
|
||||||
toQueryString: getTableFilterQueryString,
|
toQueryString: getTableFilterQueryString,
|
||||||
|
reset: resetFilter,
|
||||||
} = useTableFilter<ExpenseTableFilters>({
|
} = useTableFilter<ExpenseTableFilters>({
|
||||||
initial: {
|
initial: {
|
||||||
page: 1,
|
page: 1,
|
||||||
@@ -244,7 +247,9 @@ const ExpensesTable = () => {
|
|||||||
transactionDate: '',
|
transactionDate: '',
|
||||||
realizationDate: '',
|
realizationDate: '',
|
||||||
locationId: '',
|
locationId: '',
|
||||||
|
locationName: '',
|
||||||
vendorId: '',
|
vendorId: '',
|
||||||
|
vendorName: '',
|
||||||
userId: '',
|
userId: '',
|
||||||
},
|
},
|
||||||
paramMap: {
|
paramMap: {
|
||||||
@@ -254,7 +259,9 @@ const ExpensesTable = () => {
|
|||||||
transactionDate: 'transaction_date',
|
transactionDate: 'transaction_date',
|
||||||
realizationDate: 'realization_date',
|
realizationDate: 'realization_date',
|
||||||
locationId: 'location_id',
|
locationId: 'location_id',
|
||||||
|
locationName: 'location_name',
|
||||||
vendorId: 'vendor_id',
|
vendorId: 'vendor_id',
|
||||||
|
vendorName: 'vendor_name',
|
||||||
userId: 'user_id',
|
userId: 'user_id',
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -740,20 +747,31 @@ const ExpensesTable = () => {
|
|||||||
const handleFilterSubmit = (values: {
|
const handleFilterSubmit = (values: {
|
||||||
transaction_date?: string | null;
|
transaction_date?: string | null;
|
||||||
realization_date?: string | null;
|
realization_date?: string | null;
|
||||||
location_id?: string | null;
|
location?: { value: number; label: string } | null;
|
||||||
vendor_id?: string | null;
|
vendor?: { value: number; label: string } | null;
|
||||||
}) => {
|
}) => {
|
||||||
updateFilter('transactionDate', values.transaction_date || '');
|
updateFilter('transactionDate', values.transaction_date || '');
|
||||||
updateFilter('realizationDate', values.realization_date || '');
|
updateFilter('realizationDate', values.realization_date || '');
|
||||||
updateFilter('locationId', values.location_id || '');
|
updateFilter(
|
||||||
updateFilter('vendorId', values.vendor_id || '');
|
'locationId',
|
||||||
|
values.location?.value ? String(values.location?.value) : ''
|
||||||
|
);
|
||||||
|
updateFilter(
|
||||||
|
'locationName',
|
||||||
|
values.location?.label ? String(values.location?.label) : ''
|
||||||
|
);
|
||||||
|
updateFilter(
|
||||||
|
'vendorId',
|
||||||
|
values.vendor?.value ? String(values.vendor?.value) : ''
|
||||||
|
);
|
||||||
|
updateFilter(
|
||||||
|
'vendorName',
|
||||||
|
values.vendor?.label ? String(values.vendor?.label) : ''
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleFilterReset = () => {
|
const handleFilterReset = () => {
|
||||||
updateFilter('transactionDate', '');
|
resetFilter();
|
||||||
updateFilter('realizationDate', '');
|
|
||||||
updateFilter('locationId', '');
|
|
||||||
updateFilter('vendorId', '');
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// track sorting
|
// track sorting
|
||||||
@@ -927,6 +945,8 @@ const ExpensesTable = () => {
|
|||||||
'search',
|
'search',
|
||||||
'nameSort',
|
'nameSort',
|
||||||
'userId',
|
'userId',
|
||||||
|
'locationName',
|
||||||
|
'vendorName',
|
||||||
]}
|
]}
|
||||||
onClick={handleFilterModalOpen}
|
onClick={handleFilterModalOpen}
|
||||||
className='px-3 py-2.5'
|
className='px-3 py-2.5'
|
||||||
@@ -1245,6 +1265,24 @@ const ExpensesTable = () => {
|
|||||||
ref={filterModal.ref}
|
ref={filterModal.ref}
|
||||||
onSubmit={handleFilterSubmit}
|
onSubmit={handleFilterSubmit}
|
||||||
onReset={handleFilterReset}
|
onReset={handleFilterReset}
|
||||||
|
initialValues={{
|
||||||
|
location:
|
||||||
|
tableFilterState.locationId && tableFilterState.locationName
|
||||||
|
? {
|
||||||
|
value: Number(tableFilterState.locationId),
|
||||||
|
label: tableFilterState.locationName,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
vendor:
|
||||||
|
tableFilterState.vendorId && tableFilterState.vendorName
|
||||||
|
? {
|
||||||
|
value: Number(tableFilterState.vendorId),
|
||||||
|
label: tableFilterState.vendorName,
|
||||||
|
}
|
||||||
|
: null,
|
||||||
|
realization_date: tableFilterState.realizationDate,
|
||||||
|
transaction_date: tableFilterState.transactionDate,
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import * as yup from 'yup';
|
|||||||
export type ExpensesFilterType = {
|
export type ExpensesFilterType = {
|
||||||
transaction_date: string | null;
|
transaction_date: string | null;
|
||||||
realization_date: string | null;
|
realization_date: string | null;
|
||||||
location_id: string | null;
|
location: { value: number; label: string } | null;
|
||||||
vendor_id: string | null;
|
vendor: { value: number; label: string } | null;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const ExpensesFilterSchema = yup.object({
|
export const ExpensesFilterSchema = yup.object({
|
||||||
@@ -21,8 +21,18 @@ export const ExpensesFilterSchema = yup.object({
|
|||||||
return new Date(value) >= new Date(transaction_date);
|
return new Date(value) >= new Date(transaction_date);
|
||||||
}
|
}
|
||||||
),
|
),
|
||||||
location_id: yup.string().nullable(),
|
location: yup
|
||||||
vendor_id: yup.string().nullable(),
|
.object({
|
||||||
|
value: yup.number().required(),
|
||||||
|
label: yup.string().required(),
|
||||||
|
})
|
||||||
|
.nullable(),
|
||||||
|
vendor: yup
|
||||||
|
.object({
|
||||||
|
value: yup.number().required(),
|
||||||
|
label: yup.string().required(),
|
||||||
|
})
|
||||||
|
.nullable(),
|
||||||
});
|
});
|
||||||
|
|
||||||
export type ExpensesFilterValues = yup.InferType<typeof ExpensesFilterSchema>;
|
export type ExpensesFilterValues = yup.InferType<typeof ExpensesFilterSchema>;
|
||||||
|
|||||||
Reference in New Issue
Block a user