Skip to content

Commit

Permalink
feat: add wallet filter to growers (Greenstand#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquemoreiraa authored Dec 12, 2022
1 parent 2da76a4 commit c21cafd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 34 deletions.
13 changes: 13 additions & 0 deletions src/components/FilterTopGrower.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ function FilterTopGrower(props) {
);
const [email, setEmail] = useState(filter?.email || '');
const [phone, setPhone] = useState(filter?.phone || '');
const [wallet, setWallet] = useState(filter?.wallet || '');
const [deviceIdentifier, setDeviceIdentifier] = useState(
filter?.deviceIdentifier || ''
);
Expand All @@ -70,6 +71,7 @@ function FilterTopGrower(props) {
email: email.trim(),
phone: phone.trim(),
deviceIdentifier,
wallet: wallet.trim(),
});
props.onSubmit && props.onSubmit(filter);
}
Expand All @@ -84,6 +86,7 @@ function FilterTopGrower(props) {
setEmail('');
setPhone('');
setDeviceIdentifier('');
setWallet('');

const filter = new FilterModel();
props.onSubmit && props.onSubmit(filter);
Expand Down Expand Up @@ -156,6 +159,16 @@ function FilterTopGrower(props) {
onChange={(e) => setLastName(e.target.value)}
onKeyDown={handleEnterPress}
/>
<TextField
className={`${classes.textField} ${classes.filterElement}`}
label="Wallet"
htmlFor="Wallet"
id="Wallet"
placeholder="Wallet"
value={wallet}
onChange={(e) => setWallet(e.target.value)}
onKeyDown={handleEnterPress}
/>
<TextField
className={`${classes.textField} ${classes.filterElement}`}
label="Email"
Expand Down
40 changes: 6 additions & 34 deletions src/models/FilterGrower.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ export default class Filter {
where.person_id = this.personId;
}

if (this.wallet) {
where.wallet = this.wallet;
}

if (this.id) {
where.id = this.id;
}
Expand Down Expand Up @@ -57,40 +61,8 @@ export default class Filter {
* A fn to count the number of current applied filters
*/
countAppliedFilters() {
let numFilters = 0;

if (this.id) {
numFilters += 1;
}

if (this.personId) {
numFilters += 1;
}

if (this.deviceIdentifier) {
numFilters += 1;
}

if (this.firstName) {
numFilters += 1;
if (this.organizationId) {
return Object.keys(this.getWhereObj()).length;
}

if (this.lastName) {
numFilters += 1;
}

if (this.email) {
numFilters += 1;
}

if (this.phone) {
numFilters += 1;
}

if (this.organizationId && this.organizationId !== ALL_ORGANIZATIONS) {
numFilters += 1;
}

return numFilters;
}
}

0 comments on commit c21cafd

Please sign in to comment.