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

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
44 changes: 29 additions & 15 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";
Expand Down Expand Up @@ -83,13 +83,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: {
Expand Down Expand Up @@ -167,16 +174,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">
Expand Down
Loading