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: FacilityData not populating on Edit #10077

Merged
Merged
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
4 changes: 2 additions & 2 deletions public/locale/en.json
Original file line number Diff line number Diff line change
@@ -675,8 +675,8 @@
"copying_is_not_allowed": "Copying is not allowed",
"could_not_load_page": "We are facing some difficulties showing the Page you were looking for. Our Engineers have been notified and we'll make sure that this is resolved on the fly!",
"countries_travelled": "Countries travelled",
"cover_image_deleted.": "Cover image deleted.",
"cover_image_updated.": "Cover image updated.",
"cover_image_deleted": "Cover Image Deleted",
"cover_image_updated": "Cover Image Updated",
Comment on lines -678 to +679
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice find, how did this even end up here 🤣

"covid_19_cat_gov": "Covid_19 Clinical Category as per Govt. of Kerala guideline (A/B/C)",
"covid_19_death_reporting_form_1": "Covid-19 Death Reporting : Form 1",
"covid_details": "Covid Details",
7 changes: 6 additions & 1 deletion src/components/Facility/FacilityForm.tsx
Original file line number Diff line number Diff line change
@@ -119,7 +119,12 @@ export default function FacilityForm(props: FacilityProps) {
}),
onSuccess: (_data: FacilityModel) => {
toast.success(t("facility_updated_successfully"));
queryClient.invalidateQueries({ queryKey: ["organizationFacilities"] });
queryClient.invalidateQueries({
queryKey: ["organizationFacilities"],
});
queryClient.invalidateQueries({
queryKey: ["facility"],
});
form.reset();
onSubmitSuccess?.();
},
17 changes: 9 additions & 8 deletions src/components/Facility/FacilityHome.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import careConfig from "@careConfig";
import { useQuery } from "@tanstack/react-query";
import { useQuery, useQueryClient } from "@tanstack/react-query";
import { Hospital, MapPin, MoreVertical, Settings } from "lucide-react";
import { navigate } from "raviger";
import { useState } from "react";
@@ -91,12 +91,9 @@ export const FacilityHome = ({ facilityId }: Props) => {
const { t } = useTranslation();
const [openDeleteDialog, setOpenDeleteDialog] = useState(false);
const [editCoverImage, setEditCoverImage] = useState(false);
const queryClient = useQueryClient();

const {
data: facilityData,
isLoading,
refetch: facilityFetch,
} = useQuery<FacilityData>({
const { data: facilityData, isLoading } = useQuery<FacilityData>({
queryKey: ["facility", facilityId],
queryFn: query(routes.facility.show, {
pathParams: { id: facilityId },
@@ -134,7 +131,9 @@ export const FacilityHome = ({ facilityId }: Props) => {
async (xhr: XMLHttpRequest) => {
if (xhr.status === 200) {
await sleep(1000);
facilityFetch();
queryClient.invalidateQueries({
queryKey: ["facility", facilityId],
});
toast.success(t("cover_image_updated"));
setEditCoverImage(false);
} else {
@@ -154,7 +153,9 @@ export const FacilityHome = ({ facilityId }: Props) => {
});
if (res?.ok) {
toast.success(t("cover_image_deleted"));
facilityFetch();
queryClient.invalidateQueries({
queryKey: ["facility", facilityId],
});
setEditCoverImage(false);
} else {
onError();
5 changes: 0 additions & 5 deletions src/pages/Organization/components/EditFacilitySheet.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { useQueryClient } from "@tanstack/react-query";
import { t } from "i18next";
import { useState } from "react";

@@ -20,7 +19,6 @@ interface Props {
}

export default function EditFacilitySheet({ facilityId, trigger }: Props) {
const queryClient = useQueryClient();
const [open, setOpen] = useState(false);

return (
@@ -36,9 +34,6 @@ export default function EditFacilitySheet({ facilityId, trigger }: Props) {
facilityId={facilityId}
onSubmitSuccess={() => {
setOpen(false);
queryClient.invalidateQueries({
queryKey: [["facility", facilityId], "organizationFacilities"],
});
}}
/>
</div>

Unchanged files with check annotations Beta

if (queryCB) {
queryCB(query);
}
}, [query]);

Check warning on line 80 in src/CAREUI/misc/PaginatedList.tsx

GitHub Actions / cypress-run (1)

React Hook useEffect has a missing dependency: 'queryCB'. Either include it or remove the dependency array. If 'queryCB' changes too often, find the parent component that defines it and wrap that definition in useCallback
return (
<context.Provider
component: React.ComponentType<MicroPluginProps>;
routes: Array<{
path: string;
component: React.ComponentType<any>;

Check warning on line 13 in src/PluginRegistry.ts

GitHub Actions / cypress-run (1)

Unexpected any. Specify a different type
}>;
}
for (const config of configs) {
try {
// Provide React and ReactDOM to the plugin
(window as any).React = React;

Check warning on line 34 in src/PluginRegistry.ts

GitHub Actions / cypress-run (1)

Unexpected any. Specify a different type
(window as any).ReactDOM = ReactDOM;

Check warning on line 35 in src/PluginRegistry.ts

GitHub Actions / cypress-run (1)

Unexpected any. Specify a different type
await this.loadScript(config.url);
const pluginModule = (window as any)[config.name];

Check warning on line 38 in src/PluginRegistry.ts

GitHub Actions / cypress-run (1)

Unexpected any. Specify a different type
if (!pluginModule) {
throw new Error(
`Plugin ${config.name} not found after loading script`,
type Draft = {
timestamp: number;
draft: {
[key: string]: any;

Check warning on line 22 in src/Utils/AutoSave.tsx

GitHub Actions / cypress-run (1)

Unexpected any. Specify a different type
};
};
export function useAutoSaveReducer<T>(
reducer: any,

Check warning on line 27 in src/Utils/AutoSave.tsx

GitHub Actions / cypress-run (1)

Unexpected any. Specify a different type
initialState: any,

Check warning on line 28 in src/Utils/AutoSave.tsx

GitHub Actions / cypress-run (1)

Unexpected any. Specify a different type
): [FormState<T>, Dispatch<FormAction<T>>] {
const saveInterval = 1000;
const saveKey = useRef(`form_draft_${window.location.pathname}`);
return [state, dispatch];
}
export function useAutoSaveState(initialState: any) {

Check warning on line 81 in src/Utils/AutoSave.tsx

GitHub Actions / cypress-run (1)

Unexpected any. Specify a different type
const [state, dispatch] = useAutoSaveReducer((state: any, action: any) => {

Check warning on line 82 in src/Utils/AutoSave.tsx

GitHub Actions / cypress-run (1)

Unexpected any. Specify a different type
if (action.type === "set_state") {
return action.state;
}