diff --git a/src/App.tsx b/src/App.tsx index c36d1a97491..19d8b5dab7d 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -12,7 +12,6 @@ import ProductionWarningBanner from "@/components/Common/ProductionWarningBanner import Integrations from "@/Integrations"; import PluginEngine from "@/PluginEngine"; import AuthUserProvider from "@/Providers/AuthUserProvider"; -import HistoryAPIProvider from "@/Providers/HistoryAPIProvider"; import Routers from "@/Routers"; import { displayCareConsoleArt } from "@/Utils/consoleArt"; import queryClient from "@/Utils/request/queryClient"; @@ -42,14 +41,12 @@ const App = () => { - - } - otpAuthorized={} - > - - - + } + otpAuthorized={} + > + + {props.showBackButton !== false && ( - + )} ); } diff --git a/src/components/Common/Drawings/ExcalidrawEditor.tsx b/src/components/Common/Drawings/ExcalidrawEditor.tsx index 96e13cfe7d3..3bd22d0412f 100644 --- a/src/components/Common/Drawings/ExcalidrawEditor.tsx +++ b/src/components/Common/Drawings/ExcalidrawEditor.tsx @@ -31,8 +31,6 @@ import { Input } from "@/components/ui/input"; import Loading from "@/components/Common/Loading"; -import useAppHistory from "@/hooks/useAppHistory"; - import mutate from "@/Utils/request/mutate"; import query from "@/Utils/request/query"; import metaArtifactApi from "@/types/metaArtifact/metaArtifactApi"; @@ -57,7 +55,6 @@ export default function ExcalidrawEditor({ const [name, setName] = useState(""); const [isDirty, setIsDirty] = useState(false); const [isAlertOpen, setIsAlertOpen] = useState(false); - const { goBack } = useAppHistory(); const { mutate: saveDrawing } = useMutation({ mutationFn: mutate(metaArtifactApi.upsert), @@ -65,7 +62,7 @@ export default function ExcalidrawEditor({ queryClient.invalidateQueries({ queryKey: ["drawing", drawingId, associatingId], }); - goBack(); + history.back(); }, }); @@ -119,7 +116,7 @@ export default function ExcalidrawEditor({ if (isDirty) { setIsAlertOpen(true); } else { - goBack(); + history.back(); } }; @@ -148,7 +145,7 @@ export default function ExcalidrawEditor({ className="bg-red-500 text-gray-50 shadow-xs hover:bg-red-500/90" onClick={() => { setIsAlertOpen(false); - goBack(); + history.back(); }} > {t("discard_changes")} diff --git a/src/components/ErrorPages/DefaultErrorPage.tsx b/src/components/ErrorPages/DefaultErrorPage.tsx index 4599db5130b..64d8a0577e8 100644 --- a/src/components/ErrorPages/DefaultErrorPage.tsx +++ b/src/components/ErrorPages/DefaultErrorPage.tsx @@ -6,7 +6,7 @@ import { cn } from "@/lib/utils"; import { Button } from "@/components/ui/button"; -import useAppHistory from "@/hooks/useAppHistory"; +import { navigate } from "raviger"; type ErrorType = "PAGE_NOT_FOUND" | "PAGE_LOAD_ERROR" | "CUSTOM_ERROR"; @@ -32,7 +32,6 @@ export default function ErrorPage({ ...props }: ErrorPageProps) { const { t } = useTranslation(); - const { goBack } = useAppHistory(); const [mousePos, setMousePos] = useState({ x: 0, y: 0 }); const containerRef = useRef(null); const [isHovering, setIsHovering] = useState(false); @@ -176,7 +175,7 @@ export default function ErrorPage({
+ {isDraftSaveable && (
- + {t("cancel")}
)}
- + + {/* Header */}
diff --git a/src/pages/Appointments/AppointmentDetail.tsx b/src/pages/Appointments/AppointmentDetail.tsx index 93edb18a551..cc8e8f9e696 100644 --- a/src/pages/Appointments/AppointmentDetail.tsx +++ b/src/pages/Appointments/AppointmentDetail.tsx @@ -101,7 +101,6 @@ import { Separator } from "@/components/ui/separator"; import { Textarea } from "@/components/ui/textarea"; import { usePermissions } from "@/context/PermissionContext"; import { useShortcutSubContext } from "@/context/ShortcutContext"; -import useAppHistory from "@/hooks/useAppHistory"; import { cn } from "@/lib/utils"; import { AppointmentDateSelection } from "@/pages/Appointments/BookAppointment/AppointmentDateSelection"; import { AppointmentSlotPicker } from "@/pages/Appointments/BookAppointment/AppointmentSlotPicker"; @@ -124,7 +123,6 @@ export default function AppointmentDetail(props: Props) { const queryClient = useQueryClient(); const { facility, facilityId, isFacilityLoading } = useCurrentFacility(); const { hasPermission } = usePermissions(); - const { goBack } = useAppHistory(); const [params, setQueryParams] = useQueryParams(); const { showSuccess } = params; const [{ from_queue }] = useQueryParams(); @@ -158,14 +156,14 @@ export default function AppointmentDetail(props: Props) { // If facility query failed (no access to facility) if (!facility) { toast.error(t("no_permission_to_view_page")); - goBack(`/`); + navigate(`/`); return; } // If facility is loaded but user doesn't have permission to view appointments if (facility && !canViewAppointments) { toast.error(t("no_permission_to_view_page")); - goBack(`/facility/${facility.id}/overview`); + navigate(`/facility/${facility.id}/overview`); return; } // eslint-disable-next-line react-hooks/exhaustive-deps @@ -207,7 +205,7 @@ export default function AppointmentDetail(props: Props) {
- +

diff --git a/src/pages/Appointments/AppointmentsPage.tsx b/src/pages/Appointments/AppointmentsPage.tsx index add64c3eddd..c7302c6d8b6 100644 --- a/src/pages/Appointments/AppointmentsPage.tsx +++ b/src/pages/Appointments/AppointmentsPage.tsx @@ -57,7 +57,6 @@ import { TableSkeleton, } from "@/components/Common/SkeletonLoading"; -import useAppHistory from "@/hooks/useAppHistory"; import useFilters, { FilterState } from "@/hooks/useFilters"; import { getPermissions } from "@/common/Permissions"; @@ -208,7 +207,6 @@ export default function AppointmentsPage({ resourceType, resourceId }: Props) { .filter(Boolean) as TagConfig[]; const { hasPermission } = usePermissions(); - const { goBack } = useAppHistory(); const { canViewAppointments } = getPermissions( hasPermission, @@ -315,7 +313,7 @@ export default function AppointmentsPage({ resourceType, resourceId }: Props) { useEffect(() => { if (!isFacilityLoading && !canViewAppointments && !facility) { toast.error(t("no_permission_to_view_page")); - goBack("/"); + navigate("/"); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [canViewAppointments, facility, isFacilityLoading]); diff --git a/src/pages/Encounters/EncounterShow.tsx b/src/pages/Encounters/EncounterShow.tsx index dabc3ae57d9..c06e3ba2c87 100644 --- a/src/pages/Encounters/EncounterShow.tsx +++ b/src/pages/Encounters/EncounterShow.tsx @@ -19,7 +19,6 @@ import { Card } from "@/components/ui/card"; import { CommandShortcut } from "@/components/ui/command"; import { NavTabs } from "@/components/ui/nav-tabs"; import { Skeleton } from "@/components/ui/skeleton"; -import useAppHistory from "@/hooks/useAppHistory"; import useBreakpoints from "@/hooks/useBreakpoints"; import { useCareAppEncounterTabs } from "@/hooks/useCareApps"; import { useSidebarAutoCollapse } from "@/hooks/useSidebarAutoCollapse"; @@ -82,7 +81,6 @@ export const EncounterShow = (props: Props) => { const { t } = useTranslation(); const pluginTabs = useCareAppEncounterTabs(); - const { goBack } = useAppHistory(); const showMoreAfterIndex = useBreakpoints({ default: 2, xs: 2, @@ -107,7 +105,7 @@ export const EncounterShow = (props: Props) => { useEffect(() => { if (!isPrimaryEncounterLoading && !isPatientLoading && !canAccess) { toast.error(t("permission_denied_encounter")); - goBack("/"); + navigate("/"); } // eslint-disable-next-line react-hooks/exhaustive-deps }, [isPrimaryEncounterLoading, isPatientLoading]); diff --git a/src/pages/Encounters/ReportViewer.tsx b/src/pages/Encounters/ReportViewer.tsx index 916fcd8083f..284399b57dc 100644 --- a/src/pages/Encounters/ReportViewer.tsx +++ b/src/pages/Encounters/ReportViewer.tsx @@ -52,16 +52,12 @@ const POLL_INTERVAL_MS = 2000; const POLL_TIMEOUT_MS = 30000; interface ReportViewerProps { - facilityId: string; - patientId: string; encounterId: string; templateSlug?: string; reportId?: string; } export default function ReportViewer({ - facilityId: facilityId, - patientId: patientId, encounterId, templateSlug, reportId, @@ -385,7 +381,7 @@ export default function ReportViewer({ icon={} title={t("template_not_found")} action={ - + {t("back")} } @@ -402,11 +398,7 @@ export default function ReportViewer({ hideTitleOnPage componentRight={
- +

{template.name}

diff --git a/src/pages/Facility/FacilityDetailsPage.tsx b/src/pages/Facility/FacilityDetailsPage.tsx index 859aa06f4ef..9c6b0ca74da 100644 --- a/src/pages/Facility/FacilityDetailsPage.tsx +++ b/src/pages/Facility/FacilityDetailsPage.tsx @@ -4,7 +4,6 @@ import { toast } from "sonner"; import CareIcon from "@/CAREUI/icons/CareIcon"; -import { Button } from "@/components/ui/button"; import { Card } from "@/components/ui/card"; import { Markdown } from "@/components/ui/markdown"; @@ -14,12 +13,12 @@ import { CardGridSkeleton } from "@/components/Common/SkeletonLoading"; import { FacilityMapsLink } from "@/components/Facility/FacilityMapLink"; import { Skeleton } from "@/components/ui/skeleton"; -import useAppHistory from "@/hooks/useAppHistory"; import useFilters from "@/hooks/useFilters"; import query from "@/Utils/request/query"; import publicFacilityApi from "@/types/facility/publicFacilityApi"; +import BackButton from "@/components/Common/BackButton"; import { FeatureBadge } from "./Utils"; import { UserCard } from "./components/UserCard"; @@ -29,7 +28,6 @@ interface Props { export function FacilityDetailsPage({ id }: Props) { const { t } = useTranslation(); - const { goBack } = useAppHistory(); const { data: facilityResponse, isLoading } = useQuery({ queryKey: ["facility", id], queryFn: query(publicFacilityApi.getAny, { @@ -85,13 +83,9 @@ export function FacilityDetailsPage({ id }: Props) {

{t("facility_not_found")}

- +
); @@ -100,14 +94,10 @@ export function FacilityDetailsPage({ id }: Props) { return (
- +
diff --git a/src/pages/Facility/billing/account/CreateInvoice.tsx b/src/pages/Facility/billing/account/CreateInvoice.tsx index 258394ace07..f37e14668d9 100644 --- a/src/pages/Facility/billing/account/CreateInvoice.tsx +++ b/src/pages/Facility/billing/account/CreateInvoice.tsx @@ -79,7 +79,6 @@ import { PaginatedResponse } from "@/Utils/request/types"; import { formatDateTime, formatName } from "@/Utils/utils"; import { EditInvoiceDialog } from "@/components/Billing/Invoice/EditInvoiceDialog"; -import BackButton from "@/components/Common/BackButton"; import { ResourceDefinitionCategoryPicker } from "@/components/Common/ResourceDefinitionCategoryPicker"; import { ResourceCategoryResourceType } from "@/types/base/resourceCategory/resourceCategory"; import { @@ -915,16 +914,22 @@ export function CreateInvoicePage({
- { + if (onCancel) { + onCancel(); + } else { + history.back(); + } + }} disabled={createMutation.isPending} data-shortcut-id="go-back" > {t("cancel")} - + {dispenseOrderId && ( + {t("go_back")}
); } diff --git a/src/pages/Facility/billing/paymentReconciliation/PaymentReconciliationShow.tsx b/src/pages/Facility/billing/paymentReconciliation/PaymentReconciliationShow.tsx index 1d91b004be4..21623b9617e 100644 --- a/src/pages/Facility/billing/paymentReconciliation/PaymentReconciliationShow.tsx +++ b/src/pages/Facility/billing/paymentReconciliation/PaymentReconciliationShow.tsx @@ -22,8 +22,7 @@ import { Separator } from "@/components/ui/separator"; import CriticalActionConfirmationDialog from "@/components/Common/CriticalActionConfirmationDialog"; import { TableSkeleton } from "@/components/Common/SkeletonLoading"; -import useAppHistory from "@/hooks/useAppHistory"; - +import BackButton from "@/components/Common/BackButton"; import { useShortcutSubContext } from "@/context/ShortcutContext"; import { PAYMENT_RECONCILIATION_METHOD_MAP, @@ -60,7 +59,6 @@ export function PaymentReconciliationShow({ paymentReconciliationId: string; }) { const { t } = useTranslation(); - const { goBack } = useAppHistory(); const queryClient = useQueryClient(); const [cancelDialogOpen, setCancelDialogOpen] = useState(false); const [errorDialogOpen, setErrorDialogOpen] = useState(false); @@ -522,17 +520,13 @@ export function PaymentReconciliationShow({ /> )} - +

{deliveryOrder.name}

diff --git a/src/pages/Facility/services/inventory/externalSupply/requestOrder/RequestOrderForm.tsx b/src/pages/Facility/services/inventory/externalSupply/requestOrder/RequestOrderForm.tsx index 1cf8bcab54e..4bec2a8036c 100644 --- a/src/pages/Facility/services/inventory/externalSupply/requestOrder/RequestOrderForm.tsx +++ b/src/pages/Facility/services/inventory/externalSupply/requestOrder/RequestOrderForm.tsx @@ -214,7 +214,9 @@ export default function RequestOrderForm({ onSuccess: (requestOrder: RequestOrderRetrieve) => { queryClient.invalidateQueries({ queryKey: ["requestOrders"] }); toast.success(t("order_created")); - navigate(returnPath + requestOrder.id); + navigate(returnPath + requestOrder.id, { + replace: true, + }); }, }); @@ -228,7 +230,9 @@ export default function RequestOrderForm({ onSuccess: (requestOrder: RequestOrderRetrieve) => { queryClient.invalidateQueries({ queryKey: ["requestOrders"] }); toast.success(t("order_updated")); - navigate(returnPath + requestOrder.id); + navigate(returnPath + requestOrder.id, { + replace: true, + }); }, }); @@ -551,13 +555,7 @@ export default function RequestOrderForm({ +

{(!request?.activity_definition?.diagnostic_report_codes || diff --git a/src/pages/Facility/settings/activityDefinition/ActivityDefinitionForm.tsx b/src/pages/Facility/settings/activityDefinition/ActivityDefinitionForm.tsx index 04327152316..c4fef1cd37e 100644 --- a/src/pages/Facility/settings/activityDefinition/ActivityDefinitionForm.tsx +++ b/src/pages/Facility/settings/activityDefinition/ActivityDefinitionForm.tsx @@ -40,6 +40,7 @@ import { HealthcareServiceSelector } from "@/pages/Facility/services/HealthcareS import { CodeSchema } from "@/types/base/code/code"; import chargeItemDefinitionApi from "@/types/billing/chargeItemDefinition/chargeItemDefinitionApi"; +import BackButton from "@/components/Common/BackButton"; import ObservationDefinitionForm from "@/pages/Facility/settings/observationDefinition/ObservationDefinitionForm"; import SpecimenDefinitionForm from "@/pages/Facility/settings/specimen-definitions/SpecimenDefinitionForm"; import { ResourceCategoryResourceType } from "@/types/base/resourceCategory/resourceCategory"; @@ -360,7 +361,9 @@ function ActivityDefinitionFormContent({ queryKey: ["activityDefinition", activityDefinitionSlug], }); toast.success(t("activity_definition_created_successfully")); - navigate(`/facility/${facilityId}/settings/activity_definitions`); + navigate(`/facility/${facilityId}/settings/activity_definitions`, { + replace: true, + }); }, }); @@ -382,6 +385,9 @@ function ActivityDefinitionFormContent({ toast.success(t("activity_definition_updated_successfully")); navigate( `/facility/${facilityId}/settings/activity_definitions/${activityDefinition.slug}`, + { + replace: true, + }, ); }, }); @@ -1067,17 +1073,7 @@ function ActivityDefinitionFormContent({
- + {t("cancel")} + diff --git a/src/pages/Facility/settings/healthcareService/HealthcareServiceForm.tsx b/src/pages/Facility/settings/healthcareService/HealthcareServiceForm.tsx index 14b1ced913f..935dd2a5e81 100644 --- a/src/pages/Facility/settings/healthcareService/HealthcareServiceForm.tsx +++ b/src/pages/Facility/settings/healthcareService/HealthcareServiceForm.tsx @@ -173,7 +173,9 @@ function HealthcareServiceFormContent({ queryKey: ["healthcareService", healthcareServiceId], }); toast.success(t("healthcare_service_created_successfully")); - navigate(`/facility/${facilityId}/settings/healthcare_services`); + navigate(`/facility/${facilityId}/settings/healthcare_services`, { + replace: true, + }); }, }); @@ -190,6 +192,9 @@ function HealthcareServiceFormContent({ toast.success(t("healthcare_service_updated_successfully")); navigate( `/facility/${facilityId}/settings/healthcare_services/${healthcareServiceId}`, + { + replace: true, + }, ); }, }); diff --git a/src/pages/Facility/settings/product/ProductForm.tsx b/src/pages/Facility/settings/product/ProductForm.tsx index f4a7a60d793..8ab88be4ead 100644 --- a/src/pages/Facility/settings/product/ProductForm.tsx +++ b/src/pages/Facility/settings/product/ProductForm.tsx @@ -144,13 +144,11 @@ export function ProductFormContent({ slug, containerClassName, onSuccess = (product: ProductRead) => - navigate(`/facility/${facilityId}/settings/product/${product.id}`), + navigate(`/facility/${facilityId}/settings/product/${product.id}`, { + replace: true, + }), onCancel = () => { - if (productId) { - navigate(`/facility/${facilityId}/settings/product/${productId}`); - } else { - navigate(`/facility/${facilityId}/settings/product`); - } + history.back(); }, disableButtons = false, enabled = true, diff --git a/src/pages/Facility/settings/productKnowledge/ProductKnowledgeView.tsx b/src/pages/Facility/settings/productKnowledge/ProductKnowledgeView.tsx index 0e36812f443..c9cc81cb1a9 100644 --- a/src/pages/Facility/settings/productKnowledge/ProductKnowledgeView.tsx +++ b/src/pages/Facility/settings/productKnowledge/ProductKnowledgeView.tsx @@ -137,9 +137,7 @@ export default function ProductKnowledgeView({ facilityId, slug }: Props) { return (
- + {t("back")} diff --git a/src/pages/Patient/PatientHome.tsx b/src/pages/Patient/PatientHome.tsx index e5338ef8c0b..2ea789b9799 100644 --- a/src/pages/Patient/PatientHome.tsx +++ b/src/pages/Patient/PatientHome.tsx @@ -16,6 +16,7 @@ import { useState } from "react"; import { pharmacyDispenseServiceAtom } from "@/atoms/pharmacy"; import { getPermissions } from "@/common/Permissions"; +import BackButton from "@/components/Common/BackButton"; import CreateEncounterForm from "@/components/Encounter/CreateEncounterForm"; import { PatientInfoCard } from "@/components/Patient/PatientInfoCard"; import CreateTokenForm from "@/components/Tokens/CreateTokenForm"; @@ -23,7 +24,6 @@ import PatientTokensList from "@/components/Tokens/PatientTokensList"; import { Button } from "@/components/ui/button"; import { usePermissions } from "@/context/PermissionContext"; import { useShortcutSubContext } from "@/context/ShortcutContext"; -import useAppHistory from "@/hooks/useAppHistory"; import useBreakpoints from "@/hooks/useBreakpoints"; import BookAppointmentSheet from "@/pages/Appointments/BookAppointment/BookAppointmentSheet"; import { UpcomingAppointmentCard } from "@/pages/Appointments/components/UpcomingAppointmentCard"; @@ -53,7 +53,6 @@ export default function PatientHome() { useQueryParams(); const queryClient = useQueryClient(); - const { goBack } = useAppHistory(); const { facility, facilityId } = useCurrentFacility(); const pharmacyDispenseService = useAtomValue( @@ -272,13 +271,9 @@ export default function PatientHome() {

{t("please_enter_correct_birth_year")}

- +
) diff --git a/src/pages/PublicAppointments/Schedule.tsx b/src/pages/PublicAppointments/Schedule.tsx index 54c2c31c5ad..193957f8db4 100644 --- a/src/pages/PublicAppointments/Schedule.tsx +++ b/src/pages/PublicAppointments/Schedule.tsx @@ -19,12 +19,12 @@ import { Textarea } from "@/components/ui/textarea"; import { Avatar } from "@/components/Common/Avatar"; import Loading from "@/components/Common/Loading"; -import useAppHistory from "@/hooks/useAppHistory"; import { usePatientContext } from "@/hooks/usePatientUser"; import mutate from "@/Utils/request/mutate"; import query from "@/Utils/request/query"; import { dateQueryString, formatName } from "@/Utils/utils"; +import BackButton from "@/components/Common/BackButton"; import { TokenSlotButton } from "@/pages/Appointments/BookAppointment/AppointmentSlotPicker"; import { groupSlotsByAvailability } from "@/pages/Appointments/utils"; import publicFacilityApi from "@/types/facility/publicFacilityApi"; @@ -44,7 +44,6 @@ interface AppointmentsProps { export function ScheduleAppointment(props: AppointmentsProps) { const { t } = useTranslation(); - const { goBack } = useAppHistory(); const { facilityId, staffId, appointmentId } = props; const [selectedMonth, setSelectedMonth] = useState(new Date()); const [selectedDate, setSelectedDate] = useState(new Date()); @@ -228,13 +227,9 @@ export function ScheduleAppointment(props: AppointmentsProps) {
- +
diff --git a/src/pages/PublicAppointments/auth/PatientLogin.tsx b/src/pages/PublicAppointments/auth/PatientLogin.tsx index c589f0514cf..e9f4ce936c8 100644 --- a/src/pages/PublicAppointments/auth/PatientLogin.tsx +++ b/src/pages/PublicAppointments/auth/PatientLogin.tsx @@ -30,7 +30,6 @@ import { PhoneInput } from "@/components/ui/phone-input"; import CircularProgress from "@/components/Common/CircularProgress"; -import useAppHistory from "@/hooks/useAppHistory"; import { useAuthContext } from "@/hooks/useAuthUser"; import mutate from "@/Utils/request/mutate"; @@ -52,7 +51,6 @@ export default function PatientLogin({ staffId: string; page: string; }) { - const { goBack } = useAppHistory(); const { t } = useTranslation(); const [phoneNumber, setPhoneNumber] = useState(""); const [error, setError] = useState(""); @@ -243,7 +241,7 @@ export default function PatientLogin({ className="border border-secondary-400" onClick={() => page === "send" - ? goBack(`/facility/${facilityId}`) + ? navigate(`/facility/${facilityId}`) : navigate( `/facility/${facilityId}/appointments/${staffId}/otp/send`, )