-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(UI-1171): add custom error page and improve organization switchi…
…ng logic
- Loading branch information
Showing
7 changed files
with
82 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 35 additions & 6 deletions
41
src/components/organisms/settings/organization/switchOrganization.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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="/" />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters