Skip to content

Commit

Permalink
minor fixes/tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
Jacobjeevan committed Dec 27, 2024
1 parent c297b92 commit e4a9060
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
8 changes: 4 additions & 4 deletions src/pages/Appoinments/PatientRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -150,15 +150,15 @@ export function PatientRegistration(props: PatientRegistrationProps) {
onSuccess: (data: Appointment) => {
Notification.Success({ msg: t("appointment_created_success") });
queryClient.invalidateQueries({
queryKey: ["patients", tokenData.phoneNumber],
queryKey: [
["patients", tokenData.phoneNumber],
["appointment", tokenData.phoneNumber],
],
});
navigate(
`/facility/${props.facilityId}/appointments/${data.id}/success`,
{
replace: true,
// Added to ensure navigate only triggers once data is loaded
// Resulted in ErrorBoundary without it
state: { appointment: data },
},
);
},
Expand Down
13 changes: 9 additions & 4 deletions src/pages/Appoinments/PatientSelect.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useMutation, useQuery } from "@tanstack/react-query";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import dayjs from "dayjs";
import { navigate } from "raviger";
import { useState } from "react";
Expand Down Expand Up @@ -42,6 +42,8 @@ export default function PatientSelect({
);
const [selectedPatient, setSelectedPatient] = useState<string | null>(null);

const queryClient = useQueryClient();

if (!staffUsername) {
Notification.Error({ msg: "Staff Username Not Found" });
navigate(`/facility/${facilityId}/`);
Expand Down Expand Up @@ -79,11 +81,14 @@ export default function PatientSelect({
})(body),
onSuccess: (data: Appointment) => {
Notification.Success({ msg: t("appointment_created_success") });
queryClient.invalidateQueries({
queryKey: [
["patients", tokenData.phoneNumber],
["appointment", tokenData.phoneNumber],
],
});
navigate(`/facility/${facilityId}/appointments/${data.id}/success`, {
replace: true,
// Added to ensure navigate only triggers once data is loaded
// Sometimes resulted in ErrorBoundary without it
state: { appointment: data },
});
},
onError: (error) => {
Expand Down
20 changes: 12 additions & 8 deletions src/pages/Appoinments/Success.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,12 @@ export function AppointmentSuccess(props: { appointmentId: string }) {
{t("date")}:
</h2>
<p className="text-lg font-medium">
{format(
new Date(appointmentData?.token_slot.start_datetime ?? ""),
"do MMMM",
)}
{appointmentData?.token_slot.start_datetime
? format(
new Date(appointmentData?.token_slot.start_datetime),
"do MMMM",
)
: ""}
</p>
</div>

Expand All @@ -89,10 +91,12 @@ export function AppointmentSuccess(props: { appointmentId: string }) {
{t("time")}:
</h2>
<p className="text-lg font-medium">
{format(
new Date(appointmentData?.token_slot.start_datetime ?? ""),
"hh:mm a",
)}
{appointmentData?.token_slot.start_datetime
? format(
new Date(appointmentData?.token_slot.start_datetime),
"hh:mm a",
)
: ""}
</p>
</div>
</div>
Expand Down

0 comments on commit e4a9060

Please sign in to comment.