Skip to content

Commit 19eca49

Browse files
author
shuai
committed
fix: move the settings -> users section in admin to Interface #1360
1 parent a963f5a commit 19eca49

10 files changed

Lines changed: 141 additions & 254 deletions

File tree

ui/src/common/constants.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ export const ADMIN_NAV_MENUS = [
126126
{ name: 'write' },
127127
{ name: 'seo' },
128128
{ name: 'login' },
129-
{ name: 'users', path: 'settings-users' },
130129
{ name: 'privileges' },
131130
],
132131
},
@@ -660,3 +659,46 @@ export const SYSTEM_AVATAR_OPTIONS = [
660659
export const TAG_SLUG_NAME_MAX_LENGTH = 35;
661660

662661
export const DEFAULT_THEME_COLOR = '#0033ff';
662+
663+
export const SUSPENSE_USER_TIME = [
664+
{
665+
label: 'hours',
666+
value: '24',
667+
},
668+
{
669+
label: 'hours',
670+
value: '48',
671+
},
672+
{
673+
label: 'hours',
674+
value: '72',
675+
},
676+
{
677+
label: 'days',
678+
value: '7',
679+
},
680+
{
681+
label: 'days',
682+
value: '14',
683+
},
684+
{
685+
label: 'months',
686+
value: '1',
687+
},
688+
{
689+
label: 'months',
690+
value: '2',
691+
},
692+
{
693+
label: 'months',
694+
value: '3',
695+
},
696+
{
697+
label: 'months',
698+
value: '6',
699+
},
700+
{
701+
label: 'year',
702+
value: '1',
703+
},
704+
];

ui/src/common/interface.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,8 @@ export interface HelmetUpdate extends Omit<HelmetBase, 'pageTitle'> {
382382
export interface AdminSettingsInterface {
383383
language: string;
384384
time_zone?: string;
385+
default_avatar: string;
386+
gravatar_base_url: string;
385387
}
386388

387389
export interface AdminSettingsSmtp {
@@ -403,8 +405,6 @@ export interface AdminSettingsUsers {
403405
allow_update_location: boolean;
404406
allow_update_username: boolean;
405407
allow_update_website: boolean;
406-
default_avatar: string;
407-
gravatar_base_url: string;
408408
}
409409

410410
export interface SiteSettings {

ui/src/pages/Admin/Interface/index.tsx

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import {
2828
} from '@/common/interface';
2929
import { interfaceStore, loggedUserInfoStore } from '@/stores';
3030
import { JSONSchema, SchemaForm, UISchema } from '@/components';
31-
import { DEFAULT_TIMEZONE } from '@/common/constants';
31+
import { DEFAULT_TIMEZONE, SYSTEM_AVATAR_OPTIONS } from '@/common/constants';
3232
import {
3333
updateInterfaceSetting,
3434
useInterfaceSetting,
@@ -59,20 +59,35 @@ const Interface: FC = () => {
5959
description: t('language.text'),
6060
enum: langs?.map((lang) => lang.value),
6161
enumNames: langs?.map((lang) => lang.label),
62-
default: setting?.language || storeInterface.language,
62+
default:
63+
setting?.language || storeInterface.language || langs?.[0]?.value,
6364
},
6465
time_zone: {
6566
type: 'string',
6667
title: t('time_zone.label'),
6768
description: t('time_zone.text'),
6869
default: setting?.time_zone || DEFAULT_TIMEZONE,
6970
},
71+
default_avatar: {
72+
type: 'string',
73+
title: t('avatar.label'),
74+
description: t('avatar.text'),
75+
enum: SYSTEM_AVATAR_OPTIONS?.map((v) => v.value),
76+
enumNames: SYSTEM_AVATAR_OPTIONS?.map((v) => v.label),
77+
default: setting?.default_avatar || 'system',
78+
},
79+
gravatar_base_url: {
80+
type: 'string',
81+
title: t('gravatar_base_url.label'),
82+
description: t('gravatar_base_url.text'),
83+
default: setting?.gravatar_base_url || '',
84+
},
7085
},
7186
};
7287

7388
const [formData, setFormData] = useState<FormDataType>({
7489
language: {
75-
value: setting?.language || storeInterface.language,
90+
value: setting?.language || storeInterface.language || langs?.[0]?.value,
7691
isInvalid: false,
7792
errorMsg: '',
7893
},
@@ -81,6 +96,16 @@ const Interface: FC = () => {
8196
isInvalid: false,
8297
errorMsg: '',
8398
},
99+
default_avatar: {
100+
value: setting?.default_avatar || 'system',
101+
isInvalid: false,
102+
errorMsg: '',
103+
},
104+
gravatar_base_url: {
105+
value: setting?.gravatar_base_url || '',
106+
isInvalid: false,
107+
errorMsg: '',
108+
},
84109
});
85110

86111
const uiSchema: UISchema = {
@@ -90,6 +115,15 @@ const Interface: FC = () => {
90115
time_zone: {
91116
'ui:widget': 'timezone',
92117
},
118+
default_avatar: {
119+
'ui:widget': 'select',
120+
},
121+
gravatar_base_url: {
122+
'ui:widget': 'input',
123+
'ui:options': {
124+
placeholder: 'https://www.gravatar.com/avatar/',
125+
},
126+
},
93127
};
94128
const getLangs = async () => {
95129
const res: LangsType[] = await loadLanguageOptions(true);
@@ -122,6 +156,8 @@ const Interface: FC = () => {
122156
const reqParams: AdminSettingsInterface = {
123157
language: formData.language.value,
124158
time_zone: formData.time_zone.value,
159+
default_avatar: formData.default_avatar.value,
160+
gravatar_base_url: formData.gravatar_base_url.value,
125161
};
126162

127163
updateInterfaceSetting(reqParams)
@@ -151,7 +187,14 @@ const Interface: FC = () => {
151187
if (setting) {
152188
const formMeta = {};
153189
Object.keys(setting).forEach((k) => {
154-
formMeta[k] = { ...formData[k], value: setting[k] };
190+
let v = setting[k];
191+
if (k === 'default_avatar' && !v) {
192+
v = 'system';
193+
}
194+
if (k === 'gravatar_base_url' && !v) {
195+
v = '';
196+
}
197+
formMeta[k] = { ...formData[k], value: v };
155198
});
156199
setFormData({ ...formData, ...formMeta });
157200
}

ui/src/pages/Admin/SettingsUsers/index.tsx

Lines changed: 0 additions & 218 deletions
This file was deleted.

0 commit comments

Comments
 (0)