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

chore: code optimisations #326

Merged
merged 1 commit into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
41 changes: 41 additions & 0 deletions src/components/statics/error.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from "react";
import { Container, Card, Button } from "react-bootstrap";
import { useRouteError } from "react-router-dom";

interface ErrorPageProps {
onRetry?: () => void;
}

const GenericErrorPage: React.FC<ErrorPageProps> = ({ onRetry }) => {
const error = useRouteError() as Error;
const title = "An Error Occurred";
const message = "We are sorry, something went wrong.";

return (
<Container className="container-main">
<Card className="card-main">
<Card.Img
alt="Ministry Mapper logo"
className="mm-logo"
src="/android-chrome-192x192.png"
/>
<Card.Body>
<Card.Title className="text-center">{title}</Card.Title>
<Card.Text className="text-center">{message}</Card.Text>
{error && (
<Card.Text className="text-center">
<small>{error.message}</small>
</Card.Text>
)}
{onRetry && (
<div className="text-center">
<Button onClick={onRetry}>Retry</Button>
</div>
)}
</Card.Body>
</Card>
</Container>
);
};

export default GenericErrorPage;
35 changes: 13 additions & 22 deletions src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,16 @@
import { StrictMode } from "react";
import { createRoot } from "react-dom/client";
import Main from "./pages/index";
import { BrowserRouter } from "react-router-dom";
import { StrictMode } from "react";
import NiceModal from "@ebay/nice-modal-react";
import RollbarMiddleware from "./components/middlewares/rollbar";
import MapsMiddleware from "./components/middlewares/googlemap";
import PostHogMiddleware from "./components/middlewares/posthog";

const root = createRoot(document.getElementById("root") as HTMLElement);
root.render(
<StrictMode>
<RollbarMiddleware>
<PostHogMiddleware>
<MapsMiddleware>
<NiceModal.Provider>
<BrowserRouter>
<Main />
</BrowserRouter>
</NiceModal.Provider>
</MapsMiddleware>
</PostHogMiddleware>
</RollbarMiddleware>
</StrictMode>
);
const rootElement = document.getElementById("root");

if (rootElement) {
const root = createRoot(rootElement);
root.render(
<StrictMode>
<Main />
</StrictMode>
);
} else {
console.error("Root element not found");
}
Loading
Loading