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.

fix: branding allowed upload ico

shuaie52ef93667ab
diff --git a/ui/src/assets/images/favicon.ico b/ui/src/assets/images/favicon.ico
new file mode 100644
index 00000000..0013c7e1
Binary files /dev/null and b/ui/src/assets/images/favicon.ico differ
diff --git a/ui/src/common/interface.ts b/ui/src/common/interface.ts
index 37f56a32..8f5a9d5d 100644
--- a/ui/src/common/interface.ts
+++ b/ui/src/common/interface.ts
@@ -267,7 +267,6 @@ export interface AdminSettingsGeneral {
}
export interface AdminSettingsInterface {
- logo: string;
language: string;
theme: string;
time_zone?: string;
@@ -286,10 +285,18 @@ export interface AdminSettingsSmtp {
}
export interface SiteSettings {
+ branding: AdmingSettingBranding;
general: AdminSettingsGeneral;
interface: AdminSettingsInterface;
}
+export interface AdmingSettingBranding {
+ logo: string;
+ square_icon: string;
+ mobile_logo?: string;
+ favicon?: string;
+}
+
export interface AdminSettingsLegal {
terms_of_service: string;
privacy_policy: string;
@@ -360,10 +367,3 @@ export interface AdminDashboard {
};
};
}
-
-export interface BrandReqParams {
- logo: string;
- square_icon: string;
- mobile_logo?: string;
- favicon?: string;
-}
diff --git a/ui/src/components/BrandUpload/index.tsx b/ui/src/components/BrandUpload/index.tsx
index 99f8dcf6..c921fbdf 100644
--- a/ui/src/components/BrandUpload/index.tsx
+++ b/ui/src/components/BrandUpload/index.tsx
@@ -8,9 +8,10 @@ interface Props {
type: UploadType;
value: string;
onChange: (value: string) => void;
+ acceptType?: string;
}
-const Index: FC<Props> = ({ type = 'post', value, onChange }) => {
+const Index: FC<Props> = ({ type = 'post', value, onChange, acceptType }) => {
const onUpload = (imgPath: string) => {
onChange(imgPath);
};
@@ -24,7 +25,11 @@ const Index: FC<Props> = ({ type = 'post', value, onChange }) => {
<img src={value} alt="" height={100} />
</div>
<ButtonGroup vertical className="fit-content">
- <UploadImg type={type} uploadCallback={onUpload} className="mb-0">
+ <UploadImg
+ type={type}
+ uploadCallback={onUpload}
+ className="mb-0"
+ acceptType={acceptType}>
<Icon name="cloud-upload" />
</UploadImg>
diff --git a/ui/src/components/Header/index.tsx b/ui/src/components/Header/index.tsx
index 8681c94c..d4af750c 100644
--- a/ui/src/components/Header/index.tsx
+++ b/ui/src/components/Header/index.tsx
@@ -17,7 +17,7 @@ import {
useLocation,
} from 'react-router-dom';
-import { loggedUserInfoStore, siteInfoStore, interfaceStore } from '@/stores';
+import { loggedUserInfoStore, siteInfoStore, brandingStore } from '@/stores';
import { logout, useQueryNotificationStatus } from '@/services';
import { RouteAlias } from '@/router/alias';
@@ -33,7 +33,7 @@ const Header: FC = () => {
const q = urlSearch.get('q');
const [searchStr, setSearch] = useState('');
const siteInfo = siteInfoStore((state) => state.siteInfo);
- const { interface: interfaceInfo } = interfaceStore();
+ const brandingInfo = brandingStore((state) => state.branding);
const { data: redDot } = useQueryNotificationStatus();
const location = useLocation();
const handleInput = (val) => {
@@ -73,10 +73,10 @@ const Header: FC = () => {
<div className="d-flex justify-content-between align-items-center nav-grow flex-nowrap">
<Navbar.Brand to="/" as={Link} className="lh-1 me-0 me-sm-3">
- {interfaceInfo.logo ? (
+ {brandingInfo.logo ? (
<img
className="logo rounded-1 me-0"
- src={interfaceInfo.logo}
+ src={brandingInfo.logo}
alt=""
/>
) : (
diff --git a/ui/src/components/SchemaForm/index.tsx b/ui/src/components/SchemaForm/index.tsx
index 6967c5a6..e0d76e3c 100644
--- a/ui/src/components/SchemaForm/index.tsx
+++ b/ui/src/components/SchemaForm/index.tsx
@@ -55,6 +55,7 @@ export interface UISchema {
validator?: (value) => boolean;
textRender?: () => React.ReactElement;
imageType?: Type.UploadType;
+ acceptType?: string;
};
};
}
@@ -280,6 +281,7 @@ const SchemaForm: FC<IProps> = ({
<Form.Label>{title}</Form.Label>
<BrandUpload
type={options.imageType || 'avatar'}
+ acceptType={options.acceptType || ''}
value={formData[key]?.value}
onChange={(value) => handleUploadChange(key, value)}
/>
diff --git a/ui/src/components/UploadImg/index.tsx b/ui/src/components/UploadImg/index.tsx
index 3ac56b2a..0d3ee519 100644
--- a/ui/src/components/UploadImg/index.tsx
+++ b/ui/src/components/UploadImg/index.tsx
@@ -8,6 +8,7 @@ interface IProps {
type: Type.UploadType;
className?: string;
children?: React.ReactNode;
+ acceptType?: string;
uploadCallback: (img: string) => void;
}
@@ -15,12 +16,14 @@ const Index: React.FC<IProps> = ({
type,
uploadCallback,
children,
+ acceptType = '',
className,
}) => {
const { t } = useTranslation();
const [status, setStatus] = useState(false);
const onChange = (e: any) => {
+ console.log('uploading', e);
if (status) {
return;
}
@@ -34,6 +37,7 @@ const Index: React.FC<IProps> = ({
// return;
// }
setStatus(true);
+ console.log('uploading', e.target.files);
uploadImage({ file: e.target.files[0], type })
.then((res) => {
uploadCallback(res);
@@ -50,7 +54,7 @@ const Index: React.FC<IProps> = ({
<input
type="file"
className="d-none"
- accept="image/jpeg,image/jpg,image/png,image/webp"
+ accept={`image/jpeg,image/jpg,image/png,image/webp${acceptType}`}
onChange={onChange}
/>
</label>
diff --git a/ui/src/pages/Admin/Branding/index.tsx b/ui/src/pages/Admin/Branding/index.tsx
index bb3e857f..b517e7b5 100644
--- a/ui/src/pages/Admin/Branding/index.tsx
+++ b/ui/src/pages/Admin/Branding/index.tsx
@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
import { JSONSchema, SchemaForm, UISchema } from '@/components';
import { FormDataType } from '@/common/interface';
import { brandSetting, getBrandSetting } from '@/services';
-import { interfaceStore } from '@/stores';
+import { brandingStore } from '@/stores';
import { useToast } from '@/hooks';
const uploadType = 'branding';
@@ -12,12 +12,12 @@ const Index: FC = () => {
const { t } = useTranslation('translation', {
keyPrefix: 'admin.branding',
});
- const { interface: storeInterface, updateLogo } = interfaceStore();
+ const { branding: brandingInfo, update } = brandingStore();
const Toast = useToast();
const [formData, setFormData] = useState<FormDataType>({
logo: {
- value: storeInterface.logo,
+ value: brandingInfo.logo,
isInvalid: false,
errorMsg: '',
},
@@ -86,6 +86,7 @@ const Index: FC = () => {
favicon: {
'ui:widget': 'upload',
'ui:options': {
+ acceptType: ',image/x-icon,image/vnd.microsoft.icon',
imageType: uploadType,
},
},
@@ -105,7 +106,7 @@ const Index: FC = () => {
brandSetting(params)
.then((res) => {
console.log(res);
- updateLogo(formData.logo.value);
+ update(params);
Toast.onShow({
msg: t('update', { keyPrefix: 'toast' }),
variant: 'success',
diff --git a/ui/src/pages/Admin/Interface/index.tsx b/ui/src/pages/Admin/Interface/index.tsx
index 90f39baa..9d307cbb 100644
--- a/ui/src/pages/Admin/Interface/index.tsx
+++ b/ui/src/pages/Admin/Interface/index.tsx
@@ -1,7 +1,5 @@
-/* eslint-disable react/no-unstable-nested-components */
-import React, { FC, FormEvent, useEffect, useState } from 'react';
-import { Button } from 'react-bootstrap';
-import { Trans, useTranslation } from 'react-i18next';
+import { FC, FormEvent, useEffect, useState } from 'react';
+import { useTranslation } from 'react-i18next';
import { useToast } from '@/hooks';
import {
@@ -36,11 +34,6 @@ const Interface: FC = () => {
const schema: JSONSchema = {
title: t('page_title'),
properties: {
- logo: {
- type: 'string',
- title: t('logo.label'),
- description: t('logo.text'),
- },
theme: {
type: 'string',
title: t('theme.label'),
@@ -64,11 +57,6 @@ const Interface: FC = () => {
};
const [formData, setFormData] = useState<FormDataType>({
- logo: {
- value: setting?.logo || storeInterface.logo,
- isInvalid: false,
- errorMsg: '',
- },
theme: {
value: setting?.theme || storeInterface.theme,
isInvalid: false,
@@ -86,43 +74,20 @@ const Interface: FC = () => {
},
});
- const onChange = (fieldName, fieldValue) => {
- if (!formData[fieldName]) {
- return;
- }
- const fieldData: FormDataType = {
- [fieldName]: {
- value: fieldValue,
- isInvalid: false,
- errorMsg: '',
- },
- };
- setFormData({ ...formData, ...fieldData });
- };
+ // const onChange = (fieldName, fieldValue) => {
+ // if (!formData[fieldName]) {
+ // return;
+ // }
+ // const fieldData: FormDataType = {
+ // [fieldName]: {
+ // value: fieldValue,
+ // isInvalid: false,
+ // errorMsg: '',
+ // },
+ // };
+ // setFormData({ ...formData, ...fieldData });
+ // };
const uiSchema: UISchema = {
- logo: {
- 'ui:widget': 'upload',
- 'ui:options': {
- textRender: () => {
- return (
- <Trans i18nKey="admin.interface.logo.text">
- You can upload your image or
- <Button
- variant="link"
- size="sm"
- className="p-0 mx-1"
- onClick={(evt) => {
- evt.preventDefault();
- onChange('logo', '');
- }}>
- reset it
- </Button>
- to the site title text.
- </Trans>
- );
- },
- },
- },
theme: {
'ui:widget': 'select',
},
@@ -181,7 +146,6 @@ const Interface: FC = () => {
return;
}
const reqParams: AdminSettingsInterface = {
- logo: formData.logo.value,
theme: formData.theme.value,
language: formData.language.value,
time_zone: formData.time_zone.value,
@@ -189,13 +153,13 @@ const Interface: FC = () => {
updateInterfaceSetting(reqParams)
.then(() => {
+ interfaceStore.getState().update(reqParams);
+ setupAppLanguage();
+ setupAppTimeZone();
Toast.onShow({
msg: t('update', { keyPrefix: 'toast' }),
variant: 'success',
});
- interfaceStore.getState().update(reqParams);
- setupAppLanguage();
- setupAppTimeZone();
})
.catch((err) => {
if (err.isError && err.key) {
diff --git a/ui/src/react-app-env.d.ts b/ui/src/react-app-env.d.ts
index c40b86b3..9ccf8b7f 100644
--- a/ui/src/react-app-env.d.ts
+++ b/ui/src/react-app-env.d.ts
@@ -1,2 +1,4 @@
/// <reference types="react-scripts" />
declare module '*.yaml';
+
+declare module '*.ico';
diff --git a/ui/src/services/admin/settings.ts b/ui/src/services/admin/settings.ts
index 3e627284..b901a365 100644
--- a/ui/src/services/admin/settings.ts
+++ b/ui/src/services/admin/settings.ts
@@ -93,6 +93,6 @@ export const getBrandSetting = () => {
return request.get('/answer/admin/api/siteinfo/branding');
};
-export const brandSetting = (params: Type.BrandReqParams) => {
+export const brandSetting = (params: Type.AdmingSettingBranding) => {
return request.put('/answer/admin/api/siteinfo/branding', params);
};
diff --git a/ui/src/stores/branding.ts b/ui/src/stores/branding.ts
new file mode 100644
index 00000000..343c2423
--- /dev/null
+++ b/ui/src/stores/branding.ts
@@ -0,0 +1,31 @@
+import create from 'zustand';
+
+import { AdmingSettingBranding } from '@/common/interface';
+import { DEFAULT_LANG } from '@/common/constants';
+
+interface InterfaceType {
+ branding: AdmingSettingBranding;
+ update: (params: AdmingSettingBranding) => void;
+}
+
+const interfaceSetting = create<InterfaceType>((set) => ({
+ branding: {
+ logo: '',
+ square_icon: '',
+ mobile_logo: '',
+ favicon: '',
+ },
+ interface: {
+ theme: '',
+ language: DEFAULT_LANG,
+ time_zone: '',
+ },
+ update: (params) =>
+ set(() => {
+ return {
+ branding: params,
+ };
+ }),
+}));
+
+export default interfaceSetting;
diff --git a/ui/src/stores/index.ts b/ui/src/stores/index.ts
index 6bc6377e..473bafbb 100644
--- a/ui/src/stores/index.ts
+++ b/ui/src/stores/index.ts
@@ -3,6 +3,7 @@ import loggedUserInfoStore from './userInfo';
import globalStore from './global';
import siteInfoStore from './siteInfo';
import interfaceStore from './interface';
+import brandingStore from './branding';
export {
toastStore,
@@ -10,4 +11,5 @@ export {
globalStore,
siteInfoStore,
interfaceStore,
+ brandingStore,
};
diff --git a/ui/src/stores/interface.ts b/ui/src/stores/interface.ts
index a5933509..d71a94fa 100644
--- a/ui/src/stores/interface.ts
+++ b/ui/src/stores/interface.ts
@@ -6,12 +6,10 @@ import { DEFAULT_LANG } from '@/common/constants';
interface InterfaceType {
interface: AdminSettingsInterface;
update: (params: AdminSettingsInterface) => void;
- updateLogo: (logo: string) => void;
}
const interfaceSetting = create<InterfaceType>((set) => ({
interface: {
- logo: '',
theme: '',
language: DEFAULT_LANG,
time_zone: '',
@@ -22,15 +20,6 @@ const interfaceSetting = create<InterfaceType>((set) => ({
interface: params,
};
}),
- updateLogo: (logo) =>
- set((state) => {
- return {
- interface: {
- ...state.interface,
- logo,
- },
- };
- }),
}));
export default interfaceSetting;
diff --git a/ui/src/utils/guard.ts b/ui/src/utils/guard.ts
index 5761af01..887e5257 100644
--- a/ui/src/utils/guard.ts
+++ b/ui/src/utils/guard.ts
@@ -1,5 +1,10 @@
import { getLoggedUserInfo, getAppSettings } from '@/services';
-import { loggedUserInfoStore, siteInfoStore, interfaceStore } from '@/stores';
+import {
+ loggedUserInfoStore,
+ siteInfoStore,
+ interfaceStore,
+ brandingStore,
+} from '@/stores';
import { RouteAlias } from '@/router/alias';
import Storage from '@/utils/storage';
import { LOGGED_USER_STORAGE_KEY } from '@/common/constants';
@@ -197,6 +202,7 @@ export const initAppSettingsStore = async () => {
if (appSettings) {
siteInfoStore.getState().update(appSettings.general);
interfaceStore.getState().update(appSettings.interface);
+ brandingStore.getState().update(appSettings.branding);
}
};
diff --git a/ui/src/utils/localize.ts b/ui/src/utils/localize.ts
index 5071ee9d..37b0919b 100644
--- a/ui/src/utils/localize.ts
+++ b/ui/src/utils/localize.ts
@@ -85,6 +85,7 @@ export const getCurrentLang = () => {
export const setupAppLanguage = async () => {
const lang = getCurrentLang();
+ console.log(lang);
if (!i18next.getDataByLanguage(lang)) {
await addI18nResource(lang);
}