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

Fixes AppRoutes type #9890

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
16 changes: 1 addition & 15 deletions src/Routers/AppRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import PatientRoutes from "@/Routers/routes/PatientRoutes";
import ResourceRoutes from "@/Routers/routes/ResourceRoutes";
import ScheduleRoutes from "@/Routers/routes/ScheduleRoutes";
import UserRoutes from "@/Routers/routes/UserRoutes";
import { AppRoutes } from "@/Routers/types";
import { PermissionProvider } from "@/context/PermissionContext";
import { PlugConfigEdit } from "@/pages/Apps/PlugConfigEdit";
import { PlugConfigList } from "@/pages/Apps/PlugConfigList";
Expand All @@ -30,21 +31,6 @@ import QuestionnaireRoutes from "./routes/questionnaireRoutes";
// List of paths where the sidebar should be hidden
const PATHS_WITHOUT_SIDEBAR = ["/", "/session-expired"];

export type RouteParams<T extends string> =
T extends `${string}:${infer Param}/${infer Rest}`
? { [K in Param | keyof RouteParams<Rest>]: string }
: T extends `${string}:${infer Param}`
? { [K in Param]: string }
: Record<string, never>;

export type RouteFunction<T extends string> = (
params: RouteParams<T>,
) => JSX.Element;

export type AppRoutes = {
[K in string]: RouteFunction<K>;
};

const Routes: AppRoutes = {
"/": () => <UserDashboard />,
// ...AssetRoutes,
Expand Down
2 changes: 1 addition & 1 deletion src/Routers/routes/ConsultationRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import EncounterQuestionnaire from "@/components/Patient/EncounterQuestionnaire"
import FileUploadPage from "@/components/Patient/FileUploadPage";
import PatientConsentRecords from "@/components/Patient/PatientConsentRecords";

import { AppRoutes } from "@/Routers/AppRouter";
import { AppRoutes } from "@/Routers/types";
import { EncounterShow } from "@/pages/Encounters/EncounterShow";
import { PrintPrescription } from "@/pages/Encounters/PrintPrescription";

Expand Down
2 changes: 1 addition & 1 deletion src/Routers/routes/FacilityRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { FacilityHome } from "@/components/Facility/FacilityHome";
import FacilityUsers from "@/components/Facility/FacilityUsers";
import ResourceCreate from "@/components/Resource/ResourceCreate";

import { AppRoutes } from "@/Routers/AppRouter";
import { AppRoutes } from "@/Routers/types";
import FacilityOrganizationIndex from "@/pages/FacilityOrganization/FacilityOrganizationIndex";
import FacilityOrganizationUsers from "@/pages/FacilityOrganization/FacilityOrganizationUsers";
import FacilityOrganizationView from "@/pages/FacilityOrganization/FacilityOrganizationView";
Expand Down
2 changes: 1 addition & 1 deletion src/Routers/routes/OrganizationRoutes.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AppRoutes } from "@/Routers/AppRouter";
import { AppRoutes } from "@/Routers/types";
import OrganizationFacilities from "@/pages/Organization/OrganizationFacilities";
import OrganizationIndex from "@/pages/Organization/OrganizationIndex";
import OrganizationPatients from "@/pages/Organization/OrganizationPatients";
Expand Down
2 changes: 1 addition & 1 deletion src/Routers/routes/PatientRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PatientHome } from "@/components/Patient/PatientHome";
import PatientIndex from "@/components/Patient/PatientIndex";
import PatientRegistration from "@/components/Patient/PatientRegistration";

import { AppRoutes } from "@/Routers/AppRouter";
import { AppRoutes } from "@/Routers/types";
import { EncounterList } from "@/pages/Encounters/EncounterList";
import VerifyPatient from "@/pages/Patients/VerifyPatient";

Expand Down
2 changes: 1 addition & 1 deletion src/Routers/routes/ResourceRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import ResourceDetails from "@/components/Resource/ResourceDetails";
import { ResourceDetailsUpdate } from "@/components/Resource/ResourceDetailsUpdate";
import ListView from "@/components/Resource/ResourceList";

import { AppRoutes } from "@/Routers/AppRouter";
import { AppRoutes } from "@/Routers/types";

const getDefaultView = () =>
localStorage.getItem("defaultResourceView") === "list" ? "list" : "board";
Expand Down
15 changes: 1 addition & 14 deletions src/Routers/routes/ScheduleRoutes.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,9 @@
import { Redirect } from "raviger";

import useAuthUser from "@/hooks/useAuthUser";

import { AppRoutes } from "@/Routers/AppRouter";
import { AppRoutes } from "@/Routers/types";
import AppointmentDetail from "@/pages/Appointments/AppointmentDetail";
import AppointmentsPage from "@/pages/Appointments/AppointmentsPage";
import BookAppointment from "@/pages/Appointments/BookAppointment";

const HomeFacilityRedirect = ({ suffix }: { suffix: string }) => {
const authUser = useAuthUser();
const facilityId = authUser.home_facility!;

return <Redirect to={`/facility/${facilityId}${suffix}`} />;
};

const ScheduleRoutes: AppRoutes = {
// Appointments
"/appointments": () => <HomeFacilityRedirect suffix="/appointments" />,
"/facility/:facilityId/appointments": ({ facilityId }) => (
<AppointmentsPage facilityId={facilityId} />
),
Expand Down
2 changes: 1 addition & 1 deletion src/Routers/routes/UserRoutes.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UserHome from "@/components/Users/UserHome";

import { AppRoutes } from "@/Routers/AppRouter";
import { AppRoutes } from "@/Routers/types";

const UserRoutes: AppRoutes = {
"/facility/:facilityId/users/:username": ({ facilityId, username }) => (
Expand Down
2 changes: 1 addition & 1 deletion src/Routers/routes/questionnaireRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { QuestionnaireList } from "@/components/Questionnaire";
import QuestionnaireEditor from "@/components/Questionnaire/QuestionnaireEditor";
import { QuestionnaireShow } from "@/components/Questionnaire/show";

import { AppRoutes } from "../AppRouter";
import { AppRoutes } from "@/Routers/types";

const QuestionnaireRoutes: AppRoutes = {
"/questionnaire": () => <QuestionnaireList />,
Expand Down
20 changes: 16 additions & 4 deletions src/Routers/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
export type RouteParams<T extends string> = Record<T, string>;
// Helper type to extract path parameters from a route string
type ExtractRouteParams<T extends string> = string extends T
? Record<string, string>
: T extends `${string}:${infer Param}/${infer Rest}`
? { [K in Param | keyof ExtractRouteParams<Rest>]: string }
: T extends `${string}:${infer Param}`
? { [K in Param]: string }
: Record<string, never>;

export interface DetailRoute {
id: string;
}
// RouteFunction type that works with Raviger
export type RouteFunction<T extends string> = (
params: ExtractRouteParams<T>,
) => JSX.Element;

export type AppRoutes = {
[Route in string]: RouteFunction<Route>;
};
2 changes: 1 addition & 1 deletion src/components/Facility/FacilityUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import useFilters from "@/hooks/useFilters";
import routes from "@/Utils/request/api";
import query from "@/Utils/request/query";

export default function FacilityUsers(props: { facilityId: number }) {
export default function FacilityUsers(props: { facilityId: string }) {
const { t } = useTranslation();
const { qParams, updateQuery, Pagination } = useFilters({
limit: 18,
Expand Down
2 changes: 1 addition & 1 deletion src/components/Resource/ResourceCreate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import { parsePhoneNumber } from "@/Utils/utils";
import { CreateResourceRequest } from "@/types/resourceRequest/resourceRequest";

interface resourceProps {
facilityId: number;
facilityId: string;
}

const initForm: Partial<CreateResourceRequest> = {
Expand Down
13 changes: 6 additions & 7 deletions src/pluginTypes.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { LazyExoticComponent } from "react";

import { FacilityModel } from "@/components/Facility/models";
import { FormContextValue } from "@/components/Form/FormContext";
import { PatientMeta } from "@/components/Patient/models";
import { QuestionnaireFormState } from "@/components/Questionnaire/QuestionnaireForm";
import { UserAssignedModel } from "@/components/Users/models";

import { AppRoutes } from "@/Routers/types";
import { EncounterTabProps } from "@/pages/Encounters/EncounterShow";

import { AppRoutes } from "./Routers/AppRouter";
import { FormContextValue } from "./components/Form/FormContext";
import { PatientMeta } from "./components/Patient/models";
import { QuestionnaireFormState } from "./components/Questionnaire/QuestionnaireForm";
import { pluginMap } from "./pluginMap";
import { PatientModel } from "./types/emr/patient";
import { pluginMap } from "@/pluginMap";
import { PatientModel } from "@/types/emr/patient";

export type PatientForm = PatientModel &
PatientMeta & { age?: number; is_postpartum?: boolean };
Expand Down
Loading