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 23 commits into
base: develop
Choose a base branch
from
Open
Changes from 13 commits
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
37 changes: 26 additions & 11 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,14 +174,22 @@ export default function ResourceCreate(props: ResourceProps) {
<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`}
Rishith25 marked this conversation as resolved.
Show resolved Hide resolved
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