Skip to content

Commit

Permalink
fix: reset
Browse files Browse the repository at this point in the history
  • Loading branch information
dadiorchen committed Apr 7, 2022
1 parent 3837ad1 commit cd9a3a8
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/components/common/CustomTableFilter/CustomTableFilter.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const PAYMENT_STATUS = ['calculated', 'cancelled', 'paid', 'all'];
*/
function CustomTableFilter(props) {
const { orgList } = React.useContext(AppContext);
console.warn('orgList', orgList);
const [localFilter, setLocalFilter] = useState({});
const {
isFilterOpen,
Expand Down Expand Up @@ -67,17 +66,20 @@ function CustomTableFilter(props) {
updateSelectedFilter(filtersToSubmit);
};

const handleOnFilterFormReset = (e) => {
const handleOnFilterFormReset = (e, filterType) => {
e.preventDefault();
if (Object.keys(localFilter).length !== 0) {
const withoutLocalFilter = Object.assign({}, filter);
delete withoutLocalFilter.earnings_status;
delete withoutLocalFilter.funder_id;
delete withoutLocalFilter.grower;
delete withoutLocalFilter.phone;
delete withoutLocalFilter.start_date;
delete withoutLocalFilter.end_date;
delete withoutLocalFilter.sub_organization;
if (filterType === 'main') {
delete withoutLocalFilter.earnings_status;
delete withoutLocalFilter.funder_id;
delete withoutLocalFilter.grower;
delete withoutLocalFilter.phone;
delete withoutLocalFilter.sub_organization;
} else {
delete withoutLocalFilter.start_date;
delete withoutLocalFilter.end_date;
}
setFilter(withoutLocalFilter);
setLocalFilter({});
}
Expand Down Expand Up @@ -257,7 +259,7 @@ function CustomTableFilter(props) {
<Button
color="primary"
variant="text"
onClick={handleOnFilterFormReset}
onClick={(e) => handleOnFilterFormReset(e, filterType)}
className={classes.customTableFilterResetButton}
>
RESET
Expand Down

0 comments on commit cd9a3a8

Please sign in to comment.