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(admin): Add time zone in admin background

robin50fa034095d8
diff --git a/ui/src/common/constants.ts b/ui/src/common/constants.ts
index ba74f143..b700ad54 100644
--- a/ui/src/common/constants.ts
+++ b/ui/src/common/constants.ts
@@ -56,3 +56,229 @@ export const ADMIN_NAV_MENUS = [
child: [{ name: 'general' }, { name: 'interface' }, { name: 'smtp' }],
},
];
+// timezones
+export const TIMEZONES = [
+ {
+ label: 'UTC-12',
+ value: 'UTC-12',
+ },
+ {
+ label: 'UTC-11:30',
+ value: 'UTC-11.5',
+ },
+ {
+ label: 'UTC-11',
+ value: 'UTC-11',
+ },
+ {
+ label: 'UTC-10:30',
+ value: 'UTC-10.5',
+ },
+ {
+ label: 'UTC-10',
+ value: 'UTC-10',
+ },
+ {
+ label: 'UTC-9:30',
+ value: 'UTC-9.5',
+ },
+ {
+ label: 'UTC-9',
+ value: 'UTC-9',
+ },
+ {
+ label: 'UTC-8:30',
+ value: 'UTC-8.5',
+ },
+ {
+ label: 'UTC-8',
+ value: 'UTC-8',
+ },
+ {
+ label: 'UTC-7:30',
+ value: 'UTC-7.5',
+ },
+ {
+ label: 'UTC-7',
+ value: 'UTC-7',
+ },
+ {
+ label: 'UTC-6:30',
+ value: 'UTC-6.5',
+ },
+ {
+ label: 'UTC-6',
+ value: 'UTC-6',
+ },
+ {
+ label: 'UTC-5:30',
+ value: 'UTC-5.5',
+ },
+ {
+ label: 'UTC-5',
+ value: 'UTC-5',
+ },
+ {
+ label: 'UTC-4:30',
+ value: 'UTC-4.5',
+ },
+ {
+ label: 'UTC-4',
+ value: 'UTC-4',
+ },
+ {
+ label: 'UTC-3:30',
+ value: 'UTC-3.5',
+ },
+ {
+ label: 'UTC-3',
+ value: 'UTC-3',
+ },
+ {
+ label: 'UTC-2:30',
+ value: 'UTC-2.5',
+ },
+ {
+ label: 'UTC-2',
+ value: 'UTC-2',
+ },
+ {
+ label: 'UTC-1:30',
+ value: 'UTC-1.5',
+ },
+ {
+ label: 'UTC-1',
+ value: 'UTC-1',
+ },
+ {
+ label: 'UTC-0:30',
+ value: 'UTC-0.5',
+ },
+ {
+ label: 'UTC+0',
+ value: 'UTC+0',
+ },
+ {
+ label: 'UTC+0:30',
+ value: 'UTC+0.5',
+ },
+ {
+ label: 'UTC+1',
+ value: 'UTC+1',
+ },
+ {
+ label: 'UTC+1:30',
+ value: 'UTC+1.5',
+ },
+ {
+ label: 'UTC+2',
+ value: 'UTC+2',
+ },
+ {
+ label: 'UTC+2:30',
+ value: 'UTC+2.5',
+ },
+ {
+ label: 'UTC+3',
+ value: 'UTC+3',
+ },
+ {
+ label: 'UTC+3:30',
+
+ value: 'UTC+3.5',
+ },
+ {
+ label: 'UTC+4',
+ value: 'UTC+4',
+ },
+ {
+ label: 'UTC+4:30',
+ value: 'UTC+4.5',
+ },
+ {
+ label: 'UTC+5',
+ value: 'UTC+5',
+ },
+ {
+ label: 'UTC+5:30',
+ value: 'UTC+5.5',
+ },
+ {
+ label: 'UTC+5:45',
+ value: 'UTC+5.75',
+ },
+ {
+ label: 'UTC+6',
+ value: 'UTC+6',
+ },
+ {
+ label: 'UTC+6:30',
+
+ value: 'UTC+6.5',
+ },
+ {
+ label: 'UTC+7',
+ value: 'UTC+7',
+ },
+ {
+ label: 'UTC+7:30',
+ value: 'UTC+7.5',
+ },
+ {
+ label: 'UTC+8',
+ value: 'UTC+8',
+ },
+ {
+ label: 'UTC+8:30',
+ value: 'UTC+8.5',
+ },
+ {
+ label: 'UTC+8:45',
+ value: 'UTC+8.75',
+ },
+ {
+ label: 'UTC+9',
+ value: 'UTC+9',
+ },
+ {
+ label: 'UTC+9:30',
+ value: 'UTC+9.5',
+ },
+ {
+ label: 'UTC+10',
+ value: 'UTC+10',
+ },
+ {
+ label: 'UTC+10:30',
+ value: 'UTC+10.5',
+ },
+ {
+ label: 'UTC+11',
+ value: 'UTC+11',
+ },
+ {
+ label: 'UTC+11:30',
+ value: 'UTC+11.5',
+ },
+ {
+ label: 'UTC+12',
+ value: 'UTC+12',
+ },
+ {
+ label: 'UTC+12:45',
+ value: 'UTC+12.75',
+ },
+ {
+ label: 'UTC+13',
+ value: 'UTC+13',
+ },
+ {
+ label: 'UTC+13:45',
+ value: 'UTC+13.75',
+ },
+ {
+ label: 'UTC+14',
+ value: 'UTC+14',
+ },
+];
+export const DEFAULT_TIMEZONE = 'UTC+0';
diff --git a/ui/src/pages/Admin/Interface/index.tsx b/ui/src/pages/Admin/Interface/index.tsx
index e5d68f32..deebcf9f 100644
--- a/ui/src/pages/Admin/Interface/index.tsx
+++ b/ui/src/pages/Admin/Interface/index.tsx
@@ -10,6 +10,7 @@ import {
} from '@answer/common/interface';
import { interfaceStore } from '@answer/stores';
import { UploadImg } from '@answer/components';
+import { TIMEZONES, DEFAULT_TIMEZONE } from '@answer/common/constants';
import {
languages,
@@ -28,6 +29,7 @@ const Interface: FC = () => {
const Toast = useToast();
const [langs, setLangs] = useState<LangsType[]>();
const { data: setting } = useInterfaceSetting();
+
const [formData, setFormData] = useState<FormDataType>({
logo: {
value: setting?.logo || '',
@@ -44,6 +46,11 @@ const Interface: FC = () => {
isInvalid: false,
errorMsg: '',
},
+ time_zone: {
+ value: setting?.time_zone || DEFAULT_TIMEZONE,
+ isInvalid: false,
+ errorMsg: '',
+ },
});
const getLangs = async () => {
const res: LangsType[] = await languages();
@@ -107,6 +114,7 @@ const Interface: FC = () => {
logo: formData.logo.value,
theme: formData.theme.value,
language: formData.language.value,
+ time_zone: formData.time_zone.value,
};
updateInterfaceSetting(reqParams)
@@ -159,12 +167,14 @@ const Interface: FC = () => {
Object.keys(setting).forEach((k) => {
formMeta[k] = { ...formData[k], value: setting[k] };
});
- setFormData(formMeta);
+ setFormData({ ...formData, ...formMeta });
}
}, [setting]);
useEffect(() => {
getLangs();
}, []);
+
+ console.log('formData', formData);
return (
<>
<h3 className="mb-4">{t('page_title')}</h3>
@@ -250,7 +260,27 @@ const Interface: FC = () => {
{formData.language.errorMsg}
</Form.Control.Feedback>
</Form.Group>
-
+ <Form.Group controlId="time-zone" className="mb-3">
+ <Form.Label>{t('time_zone.label')}</Form.Label>
+ <Form.Select
+ value={formData.time_zone.value}
+ isInvalid={formData.time_zone.isInvalid}
+ onChange={(evt) => {
+ onChange('time_zone', evt.target.value);
+ }}>
+ {TIMEZONES?.map((item) => {
+ return (
+ <option value={item.value} key={item.value}>
+ {item.label}
+ </option>
+ );
+ })}
+ </Form.Select>
+ <Form.Text as="div">{t('time_zone.text')}</Form.Text>
+ <Form.Control.Feedback type="invalid">
+ {formData.time_zone.errorMsg}
+ </Form.Control.Feedback>
+ </Form.Group>
<Button variant="primary" type="submit">
{t('save', { keyPrefix: 'btns' })}
</Button>