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 8 commits into
base: develop
Choose a base branch
from
42 changes: 30 additions & 12 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 @@ -159,22 +166,33 @@ export default function ResourceCreate(props: ResourceProps) {
title={t("create_resource_request")}
crumbsReplacements={{
[facilityId]: { name: facilityData?.name || "" },
resource: { style: "pointer-events-none" },
resource: {
uri: `/resource`,
style: "pointer-events-none",
},
Comment on lines +169 to +172
Copy link
Member

Choose a reason for hiding this comment

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

this will be changed in #10308

}}
backUrl={`/facility/${facilityId}`}
>
<div className="container mx-auto max-w-4xl">
<Card className="mt-4">
<Form {...form}>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-6">
{related_patient && (
{patientData && (
<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>
<Link
href={`/facility/${facilityId}/patient/${related_patient}/demography`}
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>
</Link>
</div>
</Alert>
)}
Expand Down
Loading