Skip to content

Commit

Permalink
feat(UI-1171): add custom error page and improve organization switchi…
Browse files Browse the repository at this point in the history
…ng logic
  • Loading branch information
J1za committed Jan 13, 2025
1 parent b68fbea commit 3fa9789
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 14 deletions.
15 changes: 14 additions & 1 deletion src/app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,16 @@ import {
import { EventsList } from "@components/organisms/shared";
import { AddTrigger, EditTrigger, TriggersTable } from "@components/organisms/triggers";
import { AddVariable, EditVariable, VariablesTable } from "@components/organisms/variables";
import { Connections, Dashboard, Internal404, Intro, Project, Triggers, Variables } from "@components/pages";
import {
Connections,
CustomError,
Dashboard,
Internal404,
Intro,
Project,
Triggers,
Variables,
} from "@components/pages";
import { AppLayout, EventsLayout } from "@components/templates";
import { SettingsLayout } from "@components/templates/settingsLayout";

Expand Down Expand Up @@ -262,6 +271,10 @@ export const App = () => {
</Route>

<Route element={<Navigate replace to="/404" />} path="*" />

<Route element={<AppLayout hideTopbar />} path="error">
<Route element={<CustomError />} index />
</Route>
</AKRoutes>
);
};
Original file line number Diff line number Diff line change
@@ -1,19 +1,48 @@
import React, { useEffect } from "react";
import React, { useCallback, useEffect, useMemo, useState } from "react";

import { Navigate, useParams } from "react-router-dom";
import { useTranslation } from "react-i18next";
import { Navigate, useNavigate, useParams } from "react-router-dom";

import { useOrganizationStore } from "@src/store";
import { useOrganizationStore, useProjectStore } from "@src/store";

import { Loader } from "@components/atoms";

export const SwitchOrganization = () => {
const { t } = useTranslation("errors");
const { organizationId } = useParams();
const { setCurrentOrganizationId } = useOrganizationStore();
const [isProcessing, setIsProcessing] = useState(true);
const { organizationsList, setCurrentOrganizationId } = useOrganizationStore();
const { getProjectsList } = useProjectStore();
const navigate = useNavigate();

const currentOrganization = useMemo(
() => organizationsList?.find((organization) => organization.orgId === organizationId),
[organizationId, organizationsList]
);

const switchProjectList = useCallback(async () => {
try {
if (organizationId) {
await getProjectsList(organizationId);
}
} finally {
setIsProcessing(false);
}
}, [organizationId, getProjectsList]);

useEffect(() => {
if (organizationId) {
if (organizationId && currentOrganization) {
setCurrentOrganizationId(organizationId);
switchProjectList();
} else if (!currentOrganization) {
navigate("/error", { state: { error: t("organizationNotFound") } });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
}, [organizationId, currentOrganization]);

if (isProcessing) {
return <Loader isCenter size="lg" />;
}

return <Navigate state={{ organizationId }} to="/" />;
};
24 changes: 24 additions & 0 deletions src/components/pages/customError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from "react";

import { useTranslation } from "react-i18next";
import { Link, useLocation } from "react-router-dom";

import { homepageURL } from "@constants/global.constants";

export const CustomError = () => {
const { t } = useTranslation("global", { keyPrefix: "customError" });
const location = useLocation();
const stateError = location.state as { error?: string };

return (
<div className="flex w-full flex-1 flex-col items-center justify-center py-5">
<div className="mt-16 font-fira-code text-lg text-black">
{t("error")}: {stateError?.error}
</div>

<Link className="mt-4 font-fira-code text-lg font-bold text-black" to={homepageURL}>
{t("goToHomepage")}
</Link>
</div>
);
};
8 changes: 2 additions & 6 deletions src/components/pages/dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import React, { useEffect, useId, useMemo } from "react";

import { useLocation } from "react-router-dom";

import { useResize, useWindowDimensions } from "@src/hooks";
import { useProjectStore } from "@src/store";

Expand All @@ -15,12 +13,10 @@ export const Dashboard = () => {
const [leftSideWidth] = useResize({ direction: "horizontal", initial: 70, max: 70, min: 30, id: resizeId });
const { isMobile } = useWindowDimensions();
const { getProjectsList, isLoadingProjectsList, projectsList } = useProjectStore();
const location = useLocation();
const state = location.state as { organizationId?: string };

useEffect(() => {
if ((!projectsList.length && isMobile) || state?.organizationId) {
getProjectsList(state?.organizationId);
if (!projectsList.length && isMobile) {
getProjectsList();
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
Expand Down
1 change: 1 addition & 0 deletions src/components/pages/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export { Connections } from "@components/pages/connections";
export { CustomError } from "@components/pages/customError";
export { Dashboard } from "@components/pages/dashboard";
export { External404 } from "@components/pages/external404";
export { Internal404 } from "@components/pages/internal404";
Expand Down
3 changes: 2 additions & 1 deletion src/locales/en/errors/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,6 @@
"errorFetchingIntegrations": "Error fetching integrations",
"errorSendingFeedback": "Error sending feedback",
"errorSendingFeedbackExtended": "Error sending feedback, error: {{error}}",
"errorCreateNewOrganization": "Error creating a new organization"
"errorCreateNewOrganization": "Error creating a new organization",
"organizationNotFound": "Organization not found"
}
4 changes: 4 additions & 0 deletions src/locales/en/global/translation.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,9 @@
},
"error": "Something went wrong, please try again later"
}
},
"customError": {
"goToHomepage": "Back to Homepage",
"error": "Error"
}
}

0 comments on commit 3fa9789

Please sign in to comment.