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.

feat: add check user status

shuai79b145b562d8
diff --git a/ui/src/i18n/init.ts b/ui/src/i18n/init.ts
index 12887fa9..495ecc1d 100644
--- a/ui/src/i18n/init.ts
+++ b/ui/src/i18n/init.ts
@@ -20,7 +20,7 @@ i18next
translation: zh,
},
},
- debug: process.env.NODE_ENV === 'development',
+ // debug: process.env.NODE_ENV === 'development',
fallbackLng: process.env.REACT_APP_LANG || 'en_US',
interpolation: {
escapeValue: false,
diff --git a/ui/src/pages/Layout/index.tsx b/ui/src/pages/Layout/index.tsx
index 796c6eb6..bcd3587a 100644
--- a/ui/src/pages/Layout/index.tsx
+++ b/ui/src/pages/Layout/index.tsx
@@ -12,6 +12,7 @@ import {
toastStore,
} from '@answer/stores';
import { Header, AdminHeader, Footer, Toast } from '@answer/components';
+import { useCheckUserStatus } from '@answer/services/user.api';
import { useSiteSettings } from '@/services/api';
import Storage from '@/utils/storage';
@@ -21,6 +22,8 @@ const Layout: FC = () => {
const { siteInfo, update: siteStoreUpdate } = siteInfoStore();
const { update: interfaceStoreUpdate } = interfaceStore();
const { data: siteSettings } = useSiteSettings();
+ const { data: userStatus } = useCheckUserStatus();
+ const user = Storage.get('userInfo');
useEffect(() => {
if (siteSettings) {
siteStoreUpdate(siteSettings.general);
@@ -36,7 +39,6 @@ const Layout: FC = () => {
};
if (!isMounted) {
isMounted = true;
- const user = Storage.get('userInfo');
const lang = Storage.get('LANG');
if (user) {
updateUser(user);
@@ -46,6 +48,11 @@ const Layout: FC = () => {
}
}
+ if (userStatus?.status && userStatus.status !== user.status) {
+ user.status = userStatus?.status;
+ updateUser(user);
+ }
+
return (
<>
<Helmet>
diff --git a/ui/src/services/user.api.ts b/ui/src/services/user.api.ts
new file mode 100644
index 00000000..abe9ee3a
--- /dev/null
+++ b/ui/src/services/user.api.ts
@@ -0,0 +1,17 @@
+import useSWR from 'swr';
+
+import request from '@answer/utils/request';
+
+export const useCheckUserStatus = () => {
+ const apiUrl = '/answer/api/v1/user/status';
+ const hasToken = localStorage.getItem('token');
+ const { data, error } = useSWR<{ status: string }, Error>(
+ hasToken ? apiUrl : null,
+ request.instance.get,
+ );
+ return {
+ data,
+ isLoading: !data && !error,
+ error,
+ };
+};