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

Minor fixes in resource creation form #10218

Merged
merged 23 commits into from
Feb 10, 2025
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
59 changes: 34 additions & 25 deletions src/components/Resource/ResourceCreate.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { zodResolver } from "@hookform/resolvers/zod";
import { useQuery } from "@tanstack/react-query";
import { navigate, useQueryParams } from "raviger";
import { Link, navigate, useQueryParams } from "raviger";
import { useState } from "react";
import { useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
@@ -21,6 +21,7 @@ import {
FormLabel,
FormMessage,
} from "@/components/ui/form";
import { Input } from "@/components/ui/input";
import { RadioGroup, RadioGroupItem } from "@/components/ui/radio-group";
import {
Select,
@@ -30,14 +31,13 @@ import {
SelectValue,
} from "@/components/ui/select";
import { Separator } from "@/components/ui/separator";
import { Textarea } from "@/components/ui/textarea";

import { FacilitySelect } from "@/components/Common/FacilitySelect";
import Loading from "@/components/Common/Loading";
import Page from "@/components/Common/Page";
import { PhoneNumberValidator } from "@/components/Form/FieldValidators";
import PhoneNumberFormField from "@/components/Form/FormFields/PhoneNumberFormField";
import TextAreaFormField from "@/components/Form/FormFields/TextAreaFormField";
import TextFormField from "@/components/Form/FormFields/TextFormField";

import useAppHistory from "@/hooks/useAppHistory";
import useAuthUser from "@/hooks/useAuthUser";
@@ -103,13 +103,20 @@ export default function ResourceCreate(props: ResourceProps) {

const { data: facilityData } = useQuery({
queryKey: ["facility", facilityId],
queryFn: () =>
query(routes.getAnyFacility, {
pathParams: { id: String(facilityId) },
}),
queryFn: query(routes.getAnyFacility, {
pathParams: { id: String(facilityId) },
}),
enabled: !!facilityId,
});

const { data: patientData } = useQuery({
queryKey: ["patient", related_patient],
queryFn: query(routes.patient.getPatient, {
pathParams: { id: String(related_patient) },
}),
enabled: !!related_patient,
});

const form = useForm<ResourceFormValues>({
resolver: zodResolver(resourceFormSchema),
defaultValues: {
@@ -192,16 +199,23 @@ export default function ResourceCreate(props: ResourceProps) {
<Card className="mt-4">
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
{related_patient && (
<Alert>
<div className="flex items-center gap-2">
<CareIcon icon="l-user" className="h-5 w-5 text-blue-700" />
<AlertDescription className="text-sm text-blue-700">
{t("linked_patient")}:{" "}
<span className="font-medium">{related_patient}</span>
</AlertDescription>
</div>
</Alert>
{patientData && (
<Link
href={`/facility/${facilityId}/patient/${related_patient}/demography`}
>
<Alert>
<div className="flex items-center gap-2">
<CareIcon
icon="l-user"
className="h-5 w-5 text-blue-700"
/>
<AlertDescription className="text-sm text-blue-700">
{t("linked_patient")}:{" "}
<span className="font-medium">{patientData.name}</span>
</AlertDescription>
</div>
</Alert>
</Link>
)}

<div className="space-y-6">
@@ -329,10 +343,9 @@ export default function ResourceCreate(props: ResourceProps) {
<FormItem>
<FormLabel>{t("request_title")}</FormLabel>
<FormControl>
<TextFormField
<Input
{...field}
placeholder={t("request_title_placeholder")}
onChange={(value) => field.onChange(value.value)}
/>
</FormControl>
<FormDescription>
@@ -350,11 +363,10 @@ export default function ResourceCreate(props: ResourceProps) {
<FormItem>
<FormLabel>{t("request_reason")}</FormLabel>
<FormControl>
<TextAreaFormField
<Textarea
{...field}
rows={5}
placeholder={t("request_reason_placeholder")}
onChange={(value) => field.onChange(value.value)}
/>
</FormControl>
<FormDescription>
@@ -397,10 +409,7 @@ export default function ResourceCreate(props: ResourceProps) {
<FormItem>
<FormLabel>{t("contact_person")}</FormLabel>
<FormControl>
<TextFormField
{...field}
onChange={(value) => field.onChange(value.value)}
/>
<Input {...field} />
</FormControl>
<FormDescription>
{t("contact_person_description")}

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;
}