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

Added a last online filter for users #8175

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions src/Common/constants.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ export const USER_TYPE_OPTIONS = [
{ id: "StateAdmin", role: "State Admin", readOnly: false },
] as const;

export const USER_LAST_ACTIVE_OPTIONS = [
{ id: 1, text: "24 hours" },
{ id: 7, text: "7 days" },
{ id: 30, text: "30 days" },
{ id: 90, text: "90 days" },
{ id: 365, text: "1 Year" },
{ id: "never", text: "Never" },
];

export type UserRole = (typeof USER_TYPE_OPTIONS)[number]["id"];

export const USER_TYPES = USER_TYPE_OPTIONS.map((o) => o.id);
Expand Down
8 changes: 8 additions & 0 deletions src/Components/Users/ManageUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export default function ManageUsers() {
user_type: qParams.user_type,
district_id: qParams.district,
home_facility: qParams.home_facility,
last_active_days: qParams.last_active_days,
},
});

Expand Down Expand Up @@ -557,6 +558,13 @@ export default function ManageUsers() {
"home_facility",
qParams.home_facility ? homeFacilityData?.name || "" : "",
),
value(
"Last Active",
"last_active_days",
qParams.last_active_days === "never"
? "Never"
: `in the last ${qParams.last_active_days} day${qParams.last_active_days > 1 ? "s" : ""}`,
),
]}
/>
</div>
Expand Down
23 changes: 22 additions & 1 deletion src/Components/Users/UserFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import { parsePhoneNumber } from "../../Utils/utils";
import TextFormField from "../Form/FormFields/TextFormField";
import SelectMenuV2 from "../Form/SelectMenuV2";
import { FieldLabel } from "../Form/FormFields/FormField";
import { USER_TYPE_OPTIONS } from "../../Common/constants";
import {
USER_LAST_ACTIVE_OPTIONS,
USER_TYPE_OPTIONS,
} from "../../Common/constants";
import useMergeState from "../../Common/hooks/useMergeState";
import PhoneNumberFormField from "../Form/FormFields/PhoneNumberFormField";
import FiltersSlideover from "../../CAREUI/interactive/FiltersSlideover";
Expand Down Expand Up @@ -35,6 +38,7 @@ export default function UserFilter(props: any) {
state: filter.state || "",
home_facility: filter.home_facility || "",
home_facility_ref: null,
last_active_days: filter.last_active_days || "",
});

useQuery(routes.getAnyFacility, {
Expand All @@ -53,6 +57,7 @@ export default function UserFilter(props: any) {
district,
state,
home_facility,
last_active_days,
} = filterState;
const data = {
first_name: first_name || "",
Expand All @@ -63,6 +68,7 @@ export default function UserFilter(props: any) {
district: district || "",
state: district ? state || "" : "",
home_facility: home_facility || "",
last_active_days: last_active_days || "",
};
if (state && !district) {
Notify.Warn({
Expand Down Expand Up @@ -142,6 +148,21 @@ export default function UserFilter(props: any) {
/>
</div>

<div className="w-full flex-none">
<FieldLabel>Active in last...</FieldLabel>
<SelectMenuV2
id="last_active_days"
placeholder="Anytime"
options={USER_LAST_ACTIVE_OPTIONS}
optionLabel={(o) => o.text}
optionValue={(o) => o.id}
value={filterState.last_active_days}
onChange={(v) =>
setFilterState({ ...filterState, last_active_days: v })
}
/>
</div>

<StateAutocompleteFormField {...field("state")} errorClassName="hidden" />
<DistrictAutocompleteFormField
errorClassName="hidden"
Expand Down
Loading