Skip to content

Commit

Permalink
fix: payments filter not working (Greenstand#937)
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquemoreiraa authored Nov 14, 2022
1 parent 7df20de commit 48dd41d
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions src/components/common/CustomTableFilter/CustomTableFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const PAYMENT_STATUS = ['calculated', 'cancelled', 'paid', 'all'];
function CustomTableFilter(props) {
// console.warn('orgList', orgList);
const initialFilter = {
organization_id: '',
// organization_id: '',
grower: '',
payment_status: 'all',
earnings_status: 'all',
Expand Down Expand Up @@ -75,9 +75,11 @@ function CustomTableFilter(props) {
e.preventDefault();
const filtersToSubmit = {
...filter,
...localFilter,
grower: localFilter.grower.trim(),
phone: localFilter.phone.trim(),
grower: localFilter.grower ? localFilter.grower.trim() : undefined,
phone: localFilter.phone ? localFilter.phone.trim() : undefined,
payment_status: disablePaymentStatus
? undefined
: localFilter.payment_status,
};

if (filtersToSubmit.organization_id === ALL_ORGANIZATIONS) {
Expand All @@ -100,7 +102,12 @@ function CustomTableFilter(props) {

const handleOnFilterFormReset = (e) => {
e.preventDefault();
setFilter(initialFilter);
disablePaymentStatus
? setFilter({
payment_status: undefined,
grower: undefined,
})
: setFilter({ ...initialFilter, grower: '' });
setLocalFilter(initialFilter);
setIsFilterOpen(false);
};
Expand Down Expand Up @@ -170,23 +177,25 @@ function CustomTableFilter(props) {
</FormControl>
)}

<FormControl
variant="outlined"
className={classes.customTableFilterSelectFormControl}
>
<SelectOrg
orgId={localFilter?.organization_id}
defaultOrgs={[
{
id: ALL_ORGANIZATIONS,
stakeholder_uuid: ALL_ORGANIZATIONS,
name: 'All',
value: 'All',
},
]}
handleSelection={handleOnFormControlChange}
/>
</FormControl>
{!disablePaymentStatus && (
<FormControl
variant="outlined"
className={classes.customTableFilterSelectFormControl}
>
<SelectOrg
orgId={localFilter?.organization_id}
defaultOrgs={[
{
id: ALL_ORGANIZATIONS,
stakeholder_uuid: ALL_ORGANIZATIONS,
name: 'All',
value: 'All',
},
]}
handleSelection={handleOnFormControlChange}
/>
</FormControl>
)}

<FormControl
variant="outlined"
Expand Down

0 comments on commit 48dd41d

Please sign in to comment.