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: Make user detail support `UserCenterAgent`

haitaoo934b82de3042
diff --git a/ui/src/pages/Users/Personal/components/UserInfo/index.tsx b/ui/src/pages/Users/Personal/components/UserInfo/index.tsx
index 3ff91bbf..5125d7f4 100644
--- a/ui/src/pages/Users/Personal/components/UserInfo/index.tsx
+++ b/ui/src/pages/Users/Personal/components/UserInfo/index.tsx
@@ -1,10 +1,15 @@
-import { FC, memo } from 'react';
+import { FC, memo, useEffect, useState } from 'react';
import { OverlayTrigger, Tooltip } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';
import { Link } from 'react-router-dom';
+import classnames from 'classnames';
+
import { Avatar, Icon } from '@/components';
import type { UserInfoRes } from '@/common/interface';
+import { getUcBranding, UcBrandingEntry } from '@/services';
+import { userCenterStore } from '@/stores';
+import { base64ToSvg } from '@/utils';
interface Props {
data: UserInfoRes;
@@ -12,6 +17,22 @@ interface Props {
const Index: FC<Props> = ({ data }) => {
const { t } = useTranslation('translation', { keyPrefix: 'personal' });
+ const { agent: ucAgent } = userCenterStore();
+ const [ucBranding, setUcBranding] = useState<UcBrandingEntry[]>([]);
+
+ const initData = () => {
+ if (ucAgent?.enabled && data?.username) {
+ getUcBranding(data.username).then((resp) => {
+ if (resp.enabled && Array.isArray(resp.personal_branding)) {
+ setUcBranding(resp.personal_branding);
+ }
+ });
+ }
+ };
+
+ useEffect(() => {
+ initData();
+ }, [data?.username]);
if (!data?.username) {
return null;
}
@@ -65,27 +86,54 @@ const Index: FC<Props> = ({ data }) => {
</div>
<div className="d-flex text-secondary">
- {data.location && (
- <div className="d-flex align-items-center me-3">
- <Icon name="geo-alt-fill" className="me-2" />
- <span>{data.location}</span>
- </div>
- )}
-
- {data.website && (
- <div className="d-flex align-items-center">
- <Icon name="house-door-fill" className="me-2" />
- <a
- className="link-secondary"
- href={
- data.website?.includes('http')
- ? data.website
- : `http://${data.website}`
- }>
- {data?.website.replace(/(http|https):\/\//, '').split('/')?.[0]}
- </a>
- </div>
- )}
+ {!ucAgent?.enabled ? (
+ <>
+ {data.location && (
+ <div className="d-flex align-items-center me-3">
+ <Icon name="geo-alt-fill" className="me-2" />
+ <span>{data.location}</span>
+ </div>
+ )}
+ {data.website && (
+ <div className="d-flex align-items-center">
+ <Icon name="house-door-fill" className="me-2" />
+ <a
+ className="link-secondary"
+ href={
+ data.website?.includes('http')
+ ? data.website
+ : `http://${data.website}`
+ }>
+ {
+ data?.website
+ .replace(/(http|https):\/\//, '')
+ .split('/')?.[0]
+ }
+ </a>
+ </div>
+ )}
+ </>
+ ) : null}
+ {ucBranding.map((b, i) => {
+ return (
+ <div
+ key={b.name}
+ className={classnames('d-flex', 'align-items-center', {
+ 'ms-3': i > 0,
+ })}>
+ {b.icon ? (
+ <span
+ dangerouslySetInnerHTML={{
+ __html: base64ToSvg(b.icon),
+ }}
+ />
+ ) : null}
+ <a className="link-secondary" href={b.url}>
+ {b.label}
+ </a>
+ </div>
+ );
+ })}
</div>
</div>
</div>
diff --git a/ui/src/pages/Users/Personal/index.tsx b/ui/src/pages/Users/Personal/index.tsx
index 662e0e7a..45ce56bf 100644
--- a/ui/src/pages/Users/Personal/index.tsx
+++ b/ui/src/pages/Users/Personal/index.tsx
@@ -47,14 +47,16 @@ const Personal: FC = () => {
},
tabName,
);
+ const { count = 0, list = [] } = listData?.[tabName] || {};
+
let pageTitle = '';
if (userInfo?.username) {
pageTitle = `${userInfo?.display_name} (${userInfo?.username})`;
}
- const { count = 0, list = [] } = listData?.[tabName] || {};
usePageTags({
title: pageTitle,
});
+
return (
<Container className="pt-4 mt-2 mb-5">
<Row className="justify-content-center">
diff --git a/ui/src/services/user-center/index.ts b/ui/src/services/user-center/index.ts
index 7feabde9..583783a6 100644
--- a/ui/src/services/user-center/index.ts
+++ b/ui/src/services/user-center/index.ts
@@ -26,6 +26,17 @@ export interface UcSettings {
account_setting_agent: UcSettingAgent;
}
+export interface UcBrandingEntry {
+ icon: string;
+ name: string;
+ label: string;
+ url: string;
+}
+export interface UcBranding {
+ enabled: boolean;
+ personal_branding: UcBrandingEntry[];
+}
+
export const getUcAgent = () => {
const apiUrl = `/answer/api/v1/user-center/agent`;
return request.get<UcAgent>(apiUrl);
@@ -35,3 +46,8 @@ export const getUcSettings = () => {
const apiUrl = `/answer/api/v1/user-center/user/settings`;
return request.get<UcSettings>(apiUrl);
};
+
+export const getUcBranding = (username: string) => {
+ const apiUrl = `/answer/api/v1/user-center/personal/branding?username=${username}`;
+ return request.get<UcBranding>(apiUrl);
+};