Skip to content

A Q&A platform software for teams at any scales. Whether it's a community forum, help center, or knowledge management platform, you can always count on Apache Answer.

Merge branch 'feat/ui-1.1.0' into sf-site-migration/ui

haitaoocfd017de26bf
diff --cc ui/src/router/RouteGuard.tsx
index 78fc19f2,153bca51..3000ab9a
--- a/ui/src/router/RouteGuard.tsx
+++ b/ui/src/router/RouteGuard.tsx
@@@ -4,28 -4,37 +4,38 @@@ import { useLocation, useNavigate, useL
import { floppyNavigation } from '@/utils';
import { TGuardFunc } from '@/utils/guard';
- const Index: FC<{
+ import RouteErrorBoundary from './RouteErrorBoundary';
+
+ const RouteGuard: FC<{
children: ReactNode;
- onEnter?: TGuardFunc;
+ onEnter: TGuardFunc;
path?: string;
- }> = ({
- children,
- onEnter,
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
- path,
- }) => {
+ page?: string;
+ }> = ({ children, onEnter, path, page }) => {
const navigate = useNavigate();
const location = useLocation();
- const callGuards = () => {
- if (onEnter) {
- const gr = onEnter();
- const redirectUrl = gr.redirect;
- if (redirectUrl) {
- floppyNavigation.navigate(redirectUrl, {
- handler: navigate,
- options: { replace: true },
- });
- }
+ const loaderData = useLoaderData();
+ const gr = onEnter({
+ loaderData,
+ path,
+ page,
+ });
+
+ let guardError;
+ const errCode = gr.error?.code;
+ if (errCode === '403' || errCode === '404' || errCode === '50X') {
+ guardError = {
+ code: errCode,
+ msg: gr.error?.msg,
+ };
+ }
+ const handleGuardRedirect = () => {
+ const redirectUrl = gr.redirect;
+ if (redirectUrl) {
- floppyNavigation.navigate(redirectUrl, () => {
- navigate(redirectUrl, { replace: true });
++ floppyNavigation.navigate(redirectUrl, {
++ handler: navigate,
++ options: { replace: true },
+ });
}
};
useEffect(() => {
diff --cc ui/src/stores/index.ts
index a87bbbcb,23bf204b..4740e25f
--- a/ui/src/stores/index.ts
+++ b/ui/src/stores/index.ts
@@@ -24,6 -24,5 +24,6 @@@ export
themeSettingStore,
seoSettingStore,
loginToContinueStore,
- errorCode,
+ errorCodeStore,
+ userCenterStore,
};
diff --cc ui/src/stores/loggedUserInfo.ts
index 2f7a35f4,5ccbcb96..d08cce44
--- a/ui/src/stores/loggedUserInfo.ts
+++ b/ui/src/stores/loggedUserInfo.ts
@@@ -28,10 -31,10 +28,10 @@@ const initUser: UserInfoRes =
role_id: 1,
};
-const loggedUserInfoStore = create<UserInfoStore>((set) => ({
+const loggedUserInfo = create<UserInfoStore>((set) => ({
user: initUser,
update: (params) => {
- if (!params.language) {
+ if (!params?.language) {
params.language = 'Default';
}
set(() => {
diff --cc ui/src/utils/request.ts
index eb49e076,e2b706a4..739d3b1b
--- a/ui/src/utils/request.ts
+++ b/ui/src/utils/request.ts
@@@ -114,11 -120,10 +120,10 @@@ class Request
}
if (status === 403) {
// Permission interception
- errorCode.getState().reset();
if (data?.type === 'url_expired') {
// url expired
- floppyNavigation.navigate(RouteAlias.activationFailed, () => {
- window.location.replace(RouteAlias.activationFailed);
+ floppyNavigation.navigate(RouteAlias.activationFailed, {
+ handler: 'replace',
});
return Promise.reject(false);
}