2023-06-15 06:45:21 +00:00
|
|
|
import React from "react";
|
2023-08-09 06:28:37 +00:00
|
|
|
import {
|
|
|
|
Route,
|
|
|
|
RouterProvider,
|
|
|
|
createBrowserRouter,
|
|
|
|
createRoutesFromElements,
|
|
|
|
} from "react-router-dom";
|
2023-06-06 14:39:47 +00:00
|
|
|
import "./App.css";
|
|
|
|
import { AuthApi } from "./api/AuthApi";
|
2023-07-08 10:51:03 +00:00
|
|
|
import { DeleteAccountRoute } from "./routes/DeleteAccountRoute";
|
|
|
|
import { FamiliesListRoute } from "./routes/FamiliesListRoute";
|
2023-06-06 14:39:47 +00:00
|
|
|
import { NotFoundRoute } from "./routes/NotFound";
|
2023-06-15 06:45:21 +00:00
|
|
|
import { ProfileRoute } from "./routes/ProfileRoute";
|
2023-06-09 08:45:01 +00:00
|
|
|
import { LoginRoute } from "./routes/auth/LoginRoute";
|
2023-06-15 06:45:21 +00:00
|
|
|
import { NewAccountRoute } from "./routes/auth/NewAccountRoute";
|
2023-06-09 08:45:01 +00:00
|
|
|
import { OIDCCbRoute } from "./routes/auth/OIDCCbRoute";
|
2023-06-09 16:55:36 +00:00
|
|
|
import { PasswordForgottenRoute } from "./routes/auth/PasswordForgottenRoute";
|
2023-06-12 14:25:38 +00:00
|
|
|
import { ResetPasswordRoute } from "./routes/auth/ResetPasswordRoute";
|
2024-05-16 19:15:15 +00:00
|
|
|
import { FamilyHomeRoute } from "./routes/family/genealogy/FamilyHomeRoute";
|
2023-08-08 11:55:51 +00:00
|
|
|
import {
|
|
|
|
FamilyCreateMemberRoute,
|
2023-08-08 13:21:05 +00:00
|
|
|
FamilyEditMemberRoute,
|
2023-08-08 11:55:51 +00:00
|
|
|
FamilyMemberRoute,
|
2024-05-16 19:15:15 +00:00
|
|
|
} from "./routes/family/genealogy/FamilyMemberRoute";
|
2023-08-10 10:10:09 +00:00
|
|
|
import { FamilySettingsRoute } from "./routes/family/FamilySettingsRoute";
|
|
|
|
import { FamilyUsersListRoute } from "./routes/family/FamilyUsersListRoute";
|
|
|
|
import { BaseAuthenticatedPage } from "./widgets/BaseAuthenticatedPage";
|
|
|
|
import { BaseFamilyRoute } from "./widgets/BaseFamilyRoute";
|
|
|
|
import { BaseLoginPage } from "./widgets/BaseLoginpage";
|
2024-05-16 19:15:15 +00:00
|
|
|
import { FamilyMembersListRoute } from "./routes/family/genealogy/FamilyMembersListRoute";
|
2023-08-16 10:17:04 +00:00
|
|
|
import {
|
|
|
|
FamilyCoupleRoute,
|
|
|
|
FamilyCreateCoupleRoute,
|
|
|
|
FamilyEditCoupleRoute,
|
2024-05-16 19:15:15 +00:00
|
|
|
} from "./routes/family/genealogy/FamilyCoupleRoute";
|
|
|
|
import { FamilyCouplesListRoute } from "./routes/family/genealogy/FamilyCouplesListRoute";
|
|
|
|
import { FamilyTreeRoute } from "./routes/family/genealogy/FamilyTreeRoute";
|
|
|
|
import { FamilyMemberTreeRoute } from "./routes/family/genealogy/FamilyMemberTreeRoute";
|
|
|
|
import { GenealogyHomeRoute } from "./routes/family/genealogy/GenealogyHomeRoute";
|
|
|
|
import { BaseGenealogyRoute } from "./widgets/genealogy/BaseGenealogyRoute";
|
|
|
|
import { GenalogySettingsRoute } from "./routes/family/genealogy/GenalogySettingsRoute";
|
2023-06-15 06:45:21 +00:00
|
|
|
|
|
|
|
interface AuthContext {
|
|
|
|
signedIn: boolean;
|
|
|
|
setSignedIn: (signedIn: boolean) => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
const AuthContextK = React.createContext<AuthContext | null>(null);
|
2023-06-06 08:52:50 +00:00
|
|
|
|
2023-06-09 16:55:36 +00:00
|
|
|
/**
|
|
|
|
* Core app
|
|
|
|
*/
|
2023-06-15 06:45:21 +00:00
|
|
|
export function App(): React.ReactElement {
|
|
|
|
const [signedIn, setSignedIn] = React.useState(AuthApi.SignedIn);
|
|
|
|
|
|
|
|
const context: AuthContext = {
|
|
|
|
signedIn: signedIn,
|
|
|
|
setSignedIn: (s) => setSignedIn(s),
|
|
|
|
};
|
2023-06-09 08:45:01 +00:00
|
|
|
|
2023-08-09 06:28:37 +00:00
|
|
|
const router = createBrowserRouter(
|
|
|
|
createRoutesFromElements(
|
|
|
|
<>
|
2023-07-08 14:54:26 +00:00
|
|
|
<Route path="delete_account" element={<DeleteAccountRoute />} />
|
2023-06-15 07:33:41 +00:00
|
|
|
|
2023-07-08 14:54:26 +00:00
|
|
|
{signedIn ? (
|
|
|
|
<Route path="*" element={<BaseAuthenticatedPage />}>
|
|
|
|
<Route path="" element={<FamiliesListRoute />} />
|
|
|
|
<Route path="profile" element={<ProfileRoute />} />
|
|
|
|
<Route path="family/:familyId/*" element={<BaseFamilyRoute />}>
|
|
|
|
<Route path="" element={<FamilyHomeRoute />} />
|
2023-08-16 10:17:04 +00:00
|
|
|
|
2024-05-16 19:15:15 +00:00
|
|
|
<Route path="genealogy/*" element={<BaseGenealogyRoute />}>
|
|
|
|
<Route path="" element={<GenealogyHomeRoute />} />
|
2023-08-16 10:17:04 +00:00
|
|
|
|
2024-05-16 19:15:15 +00:00
|
|
|
<Route path="members" element={<FamilyMembersListRoute />} />
|
|
|
|
<Route
|
|
|
|
path="member/create"
|
|
|
|
element={<FamilyCreateMemberRoute />}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="member/:memberId"
|
|
|
|
element={<FamilyMemberRoute />}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="member/:memberId/edit"
|
|
|
|
element={<FamilyEditMemberRoute />}
|
|
|
|
/>
|
2023-08-16 10:17:04 +00:00
|
|
|
|
2024-05-16 19:15:15 +00:00
|
|
|
<Route path="couples" element={<FamilyCouplesListRoute />} />
|
|
|
|
<Route
|
|
|
|
path="couple/create"
|
|
|
|
element={<FamilyCreateCoupleRoute />}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="couple/:coupleId"
|
|
|
|
element={<FamilyCoupleRoute />}
|
|
|
|
/>
|
|
|
|
<Route
|
|
|
|
path="couple/:coupleId/edit"
|
|
|
|
element={<FamilyEditCoupleRoute />}
|
|
|
|
/>
|
|
|
|
|
|
|
|
<Route path="tree" element={<FamilyTreeRoute />} />
|
|
|
|
<Route
|
|
|
|
path="tree/:memberId"
|
|
|
|
element={<FamilyMemberTreeRoute />}
|
|
|
|
/>
|
|
|
|
<Route path="settings" element={<GenalogySettingsRoute />} />
|
|
|
|
<Route path="*" element={<NotFoundRoute />} />
|
|
|
|
</Route>
|
2023-08-21 10:45:37 +00:00
|
|
|
|
2023-07-12 15:44:39 +00:00
|
|
|
<Route path="settings" element={<FamilySettingsRoute />} />
|
2023-07-09 15:02:43 +00:00
|
|
|
<Route path="users" element={<FamilyUsersListRoute />} />
|
2023-07-08 09:59:55 +00:00
|
|
|
<Route path="*" element={<NotFoundRoute />} />
|
|
|
|
</Route>
|
2023-07-08 14:54:26 +00:00
|
|
|
<Route path="*" element={<NotFoundRoute />} />
|
|
|
|
</Route>
|
|
|
|
) : (
|
|
|
|
<Route path="*" element={<BaseLoginPage />}>
|
|
|
|
<Route path="" element={<LoginRoute />} />
|
|
|
|
<Route path="oidc_cb" element={<OIDCCbRoute />} />
|
|
|
|
<Route path="new-account" element={<NewAccountRoute />} />
|
|
|
|
<Route
|
|
|
|
path="password_forgotten"
|
|
|
|
element={<PasswordForgottenRoute />}
|
|
|
|
/>
|
|
|
|
<Route path="reset_password" element={<ResetPasswordRoute />} />
|
|
|
|
<Route path="*" element={<NotFoundRoute />} />
|
|
|
|
</Route>
|
|
|
|
)}
|
2023-08-09 06:28:37 +00:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<AuthContextK.Provider value={context}>
|
|
|
|
<RouterProvider router={router} />
|
2023-07-08 14:54:26 +00:00
|
|
|
</AuthContextK.Provider>
|
2023-06-06 08:52:50 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-06-15 06:45:21 +00:00
|
|
|
export function useAuth(): AuthContext {
|
|
|
|
return React.useContext(AuthContextK)!;
|
|
|
|
}
|