Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1099] select all village added for mobile user adding #1102

Merged
merged 5 commits into from
Jan 31, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion frontend/src/components/filters/AdministrationDropdown.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect } from "react";
import "./style.scss";
import { Select, Space } from "antd";
import { Select, Space, Checkbox, Row, Col } from "antd";
import PropTypes from "prop-types";
import { store, api } from "../../lib";
import { useCallback } from "react";
Expand All @@ -16,6 +16,7 @@ const AdministrationDropdown = ({
currentId = null,
onChange,
limitLevel = false,
isSelectAllVillage = false,
...props
}) => {
const { user, administration, levels } = store.useState((state) => state);
Expand Down Expand Up @@ -73,6 +74,34 @@ const AdministrationDropdown = ({
}
};

const handleSelectAllVillage = (e) => {
if (e.target.checked) {
let admItems = null;
const multiadministration = administration?.find(
(admLevel) => admLevel.level === lowestLevel.level - 1
)?.children;
admItems = multiadministration;
store.update((s) => {
s.administration = s.administration.concat(admItems);
});
if (onChange) {
const _values = admItems.map((item) => item.id);
onChange(_values);
}
} else {
store.update((s) => {
s.administration = s.administration.filter(
(data) => data.level <= lowestLevel.level - 1
);
});
if (onChange) {
onChange(
administration.filter((data) => data.level <= lowestLevel.level - 1)
);
}
}
};

const handleClear = (index) => {
store.update((s) => {
s.administration.length = index + 1;
Expand Down Expand Up @@ -151,6 +180,15 @@ const AdministrationDropdown = ({
);
}
})}
{isSelectAllVillage && maxLevel === 5 && (
<Row className="form-row">
<Col span={24}>
<Checkbox onChange={handleSelectAllVillage}>
Select all village
</Checkbox>
</Col>
</Row>
)}
</Space>
);
}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/mobile-assignment/AddAssignment.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ const AddAssignment = () => {
}}
persist={id ? true : false}
allowMultiple
isSelectAllVillage={true}
/>
</Form.Item>
</div>
Expand Down