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

Fix: Clear All Filters Badge Visibility in Resource page #9557

Closed
Closed
Changes from 5 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
100 changes: 55 additions & 45 deletions src/components/Resource/ResourceFilter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useQuery } from "@tanstack/react-query";
import dayjs from "dayjs";
import { useEffect } from "react";

import FiltersSlideover from "@/CAREUI/interactive/FiltersSlideover";

Expand All @@ -16,7 +18,7 @@ import { RESOURCE_FILTER_ORDER } from "@/common/constants";
import { RESOURCE_CHOICES } from "@/common/constants";

import routes from "@/Utils/request/api";
import useTanStackQueryInstead from "@/Utils/request/useQuery";
import query from "@/Utils/request/query";
import { dateQueryString } from "@/Utils/utils";

const getDate = (value: any) =>
Expand All @@ -31,7 +33,7 @@ export default function ListFilter(props: any) {
approving_facility_ref: null,
assigned_facility: filter.assigned_facility || "",
assigned_facility_ref: null,
emergency: filter.emergency || "--",
emergency: filter.emergency || "",
created_date_before: filter.created_date_before || null,
created_date_after: filter.created_date_after || null,
modified_date_before: filter.modified_date_before || null,
Expand All @@ -40,51 +42,59 @@ export default function ListFilter(props: any) {
status: filter.status || null,
});

const { loading: orginFacilityLoading } = useTanStackQueryInstead(
routes.getAnyFacility,
{
prefetch: filter.origin_facility !== undefined,
pathParams: { id: filter.origin_facility },
onResponse: ({ res, data }) => {
if (res && data) {
setFilterState({
origin_facility_ref: filter.origin_facility === "" ? "" : data,
});
}
},
},
);
const { isLoading: orginFacilityLoading, data: originFacilityData } =
useQuery({
queryKey: [routes.getAnyFacility.path, filter.origin_facility],
Mahendar0701 marked this conversation as resolved.
Show resolved Hide resolved
queryFn: query(routes.getAnyFacility, {
pathParams: { id: filter.origin_facility },
}),
enabled: filter.origin_facility !== undefined,
});

const { loading: resourceFacilityLoading } = useTanStackQueryInstead(
routes.getAnyFacility,
{
prefetch: filter.approving_facility !== undefined,
pathParams: { id: filter.approving_facility },
onResponse: ({ res, data }) => {
if (res && data) {
setFilterState({
approving_facility_ref:
filter.approving_facility === "" ? "" : data,
});
}
},
},
);
useEffect(() => {
if (originFacilityData) {
setFilterState({
origin_facility_ref:
filter.origin_facility === "" ? "" : originFacilityData,
});
}
}, [originFacilityData]);

const { loading: assignedFacilityLoading } = useTanStackQueryInstead(
routes.getAnyFacility,
{
pathParams: { id: filter.assigned_facility },
prefetch: filter.assigned_facility !== undefined,
onResponse: ({ res, data }) => {
if (res && data) {
setFilterState({
assigned_facility_ref: filter.assigned_facility === "" ? "" : data,
});
}
},
},
);
const { isLoading: resourceFacilityLoading, data: resourceFacilityData } =
useQuery({
queryKey: [routes.getAnyFacility.path, filter.approving_facility],
queryFn: query(routes.getAnyFacility, {
pathParams: { id: filter.approving_facility },
}),
enabled: filter.approving_facility !== undefined,
});

useEffect(() => {
if (resourceFacilityData) {
setFilterState({
approving_facility_ref:
filter.approving_facility === "" ? "" : resourceFacilityData,
});
}
}, [resourceFacilityData]);

const { isLoading: assignedFacilityLoading, data: assignedFacilityData } =
useQuery({
queryKey: [routes.getAnyFacility.path, filter.assigned_facility],
queryFn: query(routes.getAnyFacility, {
pathParams: { id: filter.assigned_facility },
}),
enabled: filter.assigned_facility !== undefined,
});

useEffect(() => {
if (assignedFacilityData) {
setFilterState({
assigned_facility_ref:
filter.assigned_facility === "" ? "" : assignedFacilityData,
});
}
}, [assignedFacilityData]);

const setFacility = (selected: any, name: string) => {
setFilterState({
Expand Down
Loading