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(agreements): tos and pricacy done!

haitao(lj)741a2d1f9c16
diff --git a/ui/README.md b/ui/README.md
index cb7f7f72..42639ec5 100644
--- a/ui/README.md
+++ b/ui/README.md
@@ -30,7 +30,7 @@ clone the repo locally and run following command in your terminal:
$ git clone [email protected]:answerdev/answer.git answer
$ cd answer/ui
$ pnpm install
-$ pnpm run start
+$ pnpm start
```
now, your browser should already open automatically, and autoload `http://localhost:3000`.
diff --git a/ui/src/common/constants.ts b/ui/src/common/constants.ts
index 7bd2fc19..0f5b55d0 100644
--- a/ui/src/common/constants.ts
+++ b/ui/src/common/constants.ts
@@ -43,7 +43,7 @@ export const ADMIN_NAV_MENUS = [
},
{
name: 'contents',
- child: [{ name: 'questions' }, { name: 'answers' }],
+ children: [{ name: 'questions' }, { name: 'answers' }],
},
{
name: 'users',
@@ -54,7 +54,7 @@ export const ADMIN_NAV_MENUS = [
},
{
name: 'settings',
- child: [
+ children: [
{ name: 'general' },
{ name: 'interface' },
{ name: 'branding' },
@@ -65,6 +65,8 @@ export const ADMIN_NAV_MENUS = [
},
];
+export const ADMIN_LEGAL_MENUS = [{ name: 'tos' }, { name: 'privacy' }];
+
export const TIMEZONES = [
{
label: 'Africa',
diff --git a/ui/src/common/interface.ts b/ui/src/common/interface.ts
index 37f56a32..ee00a801 100644
--- a/ui/src/common/interface.ts
+++ b/ui/src/common/interface.ts
@@ -291,8 +291,10 @@ export interface SiteSettings {
}
export interface AdminSettingsLegal {
- terms_of_service: string;
- privacy_policy: string;
+ privacy_policy_original_text?: string;
+ privacy_policy_parsed_text?: string;
+ terms_of_service_original_text?: string;
+ terms_of_service_parsed_text?: string;
}
export interface AdminSettingsWrite {
diff --git a/ui/src/components/AccordionNav/index.tsx b/ui/src/components/AccordionNav/index.tsx
index b3403bc8..cf5620c2 100644
--- a/ui/src/components/AccordionNav/index.tsx
+++ b/ui/src/components/AccordionNav/index.tsx
@@ -8,7 +8,7 @@ import { useAccordionButton } from 'react-bootstrap/AccordionButton';
import { Icon } from '@/components';
function MenuNode({ menu, callback, activeKey, isLeaf = false }) {
- const { t } = useTranslation('translation', { keyPrefix: 'admin.nav_menus' });
+ const { t } = useTranslation('translation', { keyPrefix: 'nav_menus' });
const accordionClick = useAccordionButton(menu.name);
const menuOnClick = (evt) => {
evt.preventDefault();
@@ -44,30 +44,45 @@ function MenuNode({ menu, callback, activeKey, isLeaf = false }) {
interface AccordionProps {
menus: any[];
+ path?: string;
}
-const AccordionNav: FC<AccordionProps> = ({ menus }) => {
+const AccordionNav: FC<AccordionProps> = ({ menus, path = '/' }) => {
const navigate = useNavigate();
- let activeKey = menus[0].name;
- const pathMatch = useMatch('/admin/*');
+ const pathMatch = useMatch(`${path}*`);
+ if (!menus.length) {
+ return null;
+ }
+ // auto set menu fields
+ menus.forEach((m) => {
+ if (!Array.isArray(m.children)) {
+ m.children = [];
+ }
+ m.children.forEach((sm) => {
+ if (!Array.isArray(sm.children)) {
+ sm.children = [];
+ }
+ });
+ });
const splat = pathMatch && pathMatch.params['*'];
+ let activeKey = menus[0].name;
if (splat) {
activeKey = splat;
}
const menuClick = (clickedMenu) => {
const menuKey = clickedMenu.name;
- if (Array.isArray(clickedMenu.child) && clickedMenu.child.length) {
+ if (clickedMenu.children.length) {
return;
}
if (activeKey !== menuKey) {
- const routePath = `/admin/${menuKey}`;
+ const routePath = `${path}${menuKey}`;
navigate(routePath);
}
};
let defaultOpenKey;
menus.forEach((li) => {
- if (Array.isArray(li.child) && li.child.length) {
- const matchedChild = li.child.find((el) => {
+ if (li.children.length) {
+ const matchedChild = li.children.find((el) => {
return el.name === activeKey;
});
if (matchedChild) {
@@ -83,10 +98,10 @@ const AccordionNav: FC<AccordionProps> = ({ menus }) => {
return (
<React.Fragment key={li.name}>
<MenuNode menu={li} callback={menuClick} activeKey={activeKey} />
- {Array.isArray(li.child) ? (
+ {li.children.length ? (
<Accordion.Collapse eventKey={li.name} className="ms-4">
<Stack direction="vertical" gap={1}>
- {li.child?.map((leaf) => {
+ {li.children.map((leaf) => {
return (
<MenuNode
menu={leaf}
diff --git a/ui/src/hooks/useChangeModal/index.tsx b/ui/src/hooks/useChangeModal/index.tsx
index 529f7a3a..767618b6 100644
--- a/ui/src/hooks/useChangeModal/index.tsx
+++ b/ui/src/hooks/useChangeModal/index.tsx
@@ -1,4 +1,4 @@
-import { useState } from 'react';
+import { useLayoutEffect, useState } from 'react';
import { Modal, Form, Button, FormCheck } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';
@@ -141,69 +141,70 @@ const useChangeModal = ({ callback }: Props) => {
setDefaultType(params.type);
setShow(true);
};
+ useLayoutEffect(() => {
+ root.render(
+ <Modal show={show} onHide={onClose}>
+ <Modal.Header closeButton>
+ <Modal.Title as="h5">{t('title')}</Modal.Title>
+ </Modal.Header>
+ <Modal.Body>
+ <Form>
+ {list.map((item) => {
+ if (
+ defaultType === 'inactive' &&
+ (item.type === 'suspended' || item.type === 'deleted')
+ ) {
+ return null;
+ }
- root.render(
- <Modal show={show} onHide={onClose}>
- <Modal.Header closeButton>
- <Modal.Title as="h5">{t('title')}</Modal.Title>
- </Modal.Header>
- <Modal.Body>
- <Form>
- {list.map((item) => {
- if (
- defaultType === 'inactive' &&
- (item.type === 'suspended' || item.type === 'deleted')
- ) {
- return null;
- }
-
- if (defaultType === 'suspended' && item.type === 'inactive') {
- return null;
- }
- return (
- <div key={item?.type}>
- <Form.Group
- controlId={item.type}
- className={`${
- item.have_content && changeType === item.type
- ? 'mb-2'
- : 'mb-3'
- }`}>
- <FormCheck>
- <FormCheck.Input
- id={item.type}
- type="radio"
- checked={changeType.type === item.type}
- onChange={() => handleRadio(item)}
- isInvalid={isInvalid}
- />
- <FormCheck.Label htmlFor={item.type}>
- <span className="fw-bold">{item?.name}</span>
- <br />
- <span className="text-secondary">
- {item?.description}
- </span>
- </FormCheck.Label>
- <Form.Control.Feedback type="invalid">
- {t('msg.empty')}
- </Form.Control.Feedback>
- </FormCheck>
- </Form.Group>
- </div>
- );
- })}
- </Form>
- </Modal.Body>
- <Modal.Footer>
- <Button variant="link" onClick={() => onClose()}>
- {t('btn_cancel')}
- </Button>
- <Button variant="primary" onClick={handleSubmit}>
- {t('btn_submit')}
- </Button>
- </Modal.Footer>
- </Modal>,
- );
+ if (defaultType === 'suspended' && item.type === 'inactive') {
+ return null;
+ }
+ return (
+ <div key={item?.type}>
+ <Form.Group
+ controlId={item.type}
+ className={`${
+ item.have_content && changeType === item.type
+ ? 'mb-2'
+ : 'mb-3'
+ }`}>
+ <FormCheck>
+ <FormCheck.Input
+ id={item.type}
+ type="radio"
+ checked={changeType.type === item.type}
+ onChange={() => handleRadio(item)}
+ isInvalid={isInvalid}
+ />
+ <FormCheck.Label htmlFor={item.type}>
+ <span className="fw-bold">{item?.name}</span>
+ <br />
+ <span className="text-secondary">
+ {item?.description}
+ </span>
+ </FormCheck.Label>
+ <Form.Control.Feedback type="invalid">
+ {t('msg.empty')}
+ </Form.Control.Feedback>
+ </FormCheck>
+ </Form.Group>
+ </div>
+ );
+ })}
+ </Form>
+ </Modal.Body>
+ <Modal.Footer>
+ <Button variant="link" onClick={() => onClose()}>
+ {t('btn_cancel')}
+ </Button>
+ <Button variant="primary" onClick={handleSubmit}>
+ {t('btn_submit')}
+ </Button>
+ </Modal.Footer>
+ </Modal>,
+ );
+ });
return {
onClose,
diff --git a/ui/src/pages/Admin/Legal/index.tsx b/ui/src/pages/Admin/Legal/index.tsx
index 1f494bbc..76a0bc7f 100644
--- a/ui/src/pages/Admin/Legal/index.tsx
+++ b/ui/src/pages/Admin/Legal/index.tsx
@@ -1,22 +1,20 @@
import React, { FC, useEffect, useState } from 'react';
import { useTranslation } from 'react-i18next';
-import { SchemaForm, JSONSchema, initFormData, UISchema } from '@/components';
-import type * as Type from '@/common/interface';
-// import { useToast } from '@/hooks';
-// import { siteInfoStore } from '@/stores';
-import { useGeneralSetting } from '@/services';
+import { marked } from 'marked';
+import type * as Type from '@/common/interface';
+import { SchemaForm, JSONSchema, initFormData, UISchema } from '@/components';
+import { useToast } from '@/hooks';
+import { getLegalSetting, putLegalSetting } from '@/services';
import '../index.scss';
const Legal: FC = () => {
const { t } = useTranslation('translation', {
keyPrefix: 'admin.legal',
});
- // const Toast = useToast();
- // const updateSiteInfo = siteInfoStore((state) => state.update);
+ const Toast = useToast();
- const { data: setting } = useGeneralSetting();
const schema: JSONSchema = {
title: t('page_title'),
required: ['terms_of_service', 'privacy_policy'],
@@ -54,38 +52,39 @@ const Legal: FC = () => {
evt.stopPropagation();
const reqParams: Type.AdminSettingsLegal = {
- terms_of_service: formData.terms_of_service.value,
- privacy_policy: formData.privacy_policy.value,
+ terms_of_service_original_text: formData.terms_of_service.value,
+ terms_of_service_parsed_text: marked.parse(
+ formData.terms_of_service.value,
+ ),
+ privacy_policy_original_text: formData.privacy_policy.value,
+ privacy_policy_parsed_text: marked.parse(formData.privacy_policy.value),
};
- console.log(reqParams);
- // updateGeneralSetting(reqParams)
- // .then(() => {
- // Toast.onShow({
- // msg: t('update', { keyPrefix: 'toast' }),
- // variant: 'success',
- // });
- // updateSiteInfo(reqParams);
- // })
- // .catch((err) => {
- // if (err.isError && err.key) {
- // formData[err.key].isInvalid = true;
- // formData[err.key].errorMsg = err.value;
- // }
- // setFormData({ ...formData });
- // });
+ putLegalSetting(reqParams)
+ .then(() => {
+ Toast.onShow({
+ msg: t('update', { keyPrefix: 'toast' }),
+ variant: 'success',
+ });
+ })
+ .catch((err) => {
+ if (err.isError && err.key) {
+ formData[err.key].isInvalid = true;
+ formData[err.key].errorMsg = err.value;
+ }
+ setFormData({ ...formData });
+ });
};
useEffect(() => {
- if (!setting) {
- return;
- }
- const formMeta = {};
- Object.keys(setting).forEach((k) => {
- formMeta[k] = { ...formData[k], value: setting[k] };
+ getLegalSetting().then((setting) => {
+ const formMeta = { ...formData };
+ formMeta.terms_of_service.value = setting.terms_of_service_original_text;
+ formMeta.privacy_policy.value = setting.privacy_policy_original_text;
+
+ setFormData(formMeta);
});
- setFormData({ ...formData, ...formMeta });
- }, [setting]);
+ }, []);
const handleOnChange = (data) => {
setFormData(data);
diff --git a/ui/src/pages/Admin/index.tsx b/ui/src/pages/Admin/index.tsx
index f8abfc74..a61c1030 100644
--- a/ui/src/pages/Admin/index.tsx
+++ b/ui/src/pages/Admin/index.tsx
@@ -17,7 +17,7 @@ const formPaths = [
'write',
];
-const Dashboard: FC = () => {
+const Index: FC = () => {
const { t } = useTranslation('translation', { keyPrefix: 'page_title' });
const { pathname } = useLocation();
return (
@@ -27,7 +27,7 @@ const Dashboard: FC = () => {
<Container className="admin-container">
<Row>
<Col lg={2}>
- <AccordionNav menus={ADMIN_NAV_MENUS} />
+ <AccordionNav menus={ADMIN_NAV_MENUS} path="/admin/" />
</Col>
<Col lg={formPaths.find((v) => pathname.includes(v)) ? 6 : 10}>
<Outlet />
@@ -38,4 +38,4 @@ const Dashboard: FC = () => {
);
};
-export default Dashboard;
+export default Index;
diff --git a/ui/src/pages/Legal/Privacy/index.tsx b/ui/src/pages/Legal/Privacy/index.tsx
new file mode 100644
index 00000000..90e0610f
--- /dev/null
+++ b/ui/src/pages/Legal/Privacy/index.tsx
@@ -0,0 +1,17 @@
+import { FC } from 'react';
+
+import { useLegalPrivacy } from '@/services';
+
+const Index: FC = () => {
+ const { data: privacy } = useLegalPrivacy();
+ return (
+ <div
+ className="fmt fs-14"
+ dangerouslySetInnerHTML={{
+ __html: privacy?.privacy_policy_parsed_text || '',
+ }}
+ />
+ );
+};
+
+export default Index;
diff --git a/ui/src/pages/Legal/Tos/index.tsx b/ui/src/pages/Legal/Tos/index.tsx
new file mode 100644
index 00000000..bfd788e1
--- /dev/null
+++ b/ui/src/pages/Legal/Tos/index.tsx
@@ -0,0 +1,17 @@
+import { FC } from 'react';
+
+import { useLegalTos } from '@/services';
+
+const Index: FC = () => {
+ const { data: tos } = useLegalTos();
+ return (
+ <div
+ className="fmt fs-14"
+ dangerouslySetInnerHTML={{
+ __html: tos?.terms_of_service_parsed_text || '',
+ }}
+ />
+ );
+};
+
+export default Index;
diff --git a/ui/src/pages/Legal/index.scss b/ui/src/pages/Legal/index.scss
new file mode 100644
index 00000000..12582a98
--- /dev/null
+++ b/ui/src/pages/Legal/index.scss
@@ -0,0 +1,4 @@
+.sub-container {
+ padding-top: 2rem;
+ padding-bottom: 2rem;
+}
diff --git a/ui/src/pages/Legal/index.tsx b/ui/src/pages/Legal/index.tsx
new file mode 100644
index 00000000..2a7d5a7b
--- /dev/null
+++ b/ui/src/pages/Legal/index.tsx
@@ -0,0 +1,25 @@
+import { FC } from 'react';
+import { Container, Row, Col } from 'react-bootstrap';
+import { Outlet } from 'react-router-dom';
+
+import { AccordionNav } from '@/components';
+import { ADMIN_LEGAL_MENUS } from '@/common/constants';
+
+import './index.scss';
+
+const Index: FC = () => {
+ return (
+ <Container className="sub-container">
+ <Row>
+ <Col lg={2}>
+ <AccordionNav menus={ADMIN_LEGAL_MENUS} />
+ </Col>
+ <Col lg={6}>
+ <Outlet />
+ </Col>
+ </Row>
+ </Container>
+ );
+};
+
+export default Index;
diff --git a/ui/src/pages/Users/Register/components/SignUpForm/index.tsx b/ui/src/pages/Users/Register/components/SignUpForm/index.tsx
index 0d92c5fa..61ccbb2e 100644
--- a/ui/src/pages/Users/Register/components/SignUpForm/index.tsx
+++ b/ui/src/pages/Users/Register/components/SignUpForm/index.tsx
@@ -1,10 +1,10 @@
-import React, { FormEvent, useState } from 'react';
+import React, { FormEvent, MouseEvent, useState } from 'react';
import { Form, Button, Col } from 'react-bootstrap';
import { Link } from 'react-router-dom';
import { Trans, useTranslation } from 'react-i18next';
import type { FormDataType } from '@/common/interface';
-import { register } from '@/services';
+import { register, useLegalTos, useLegalPrivacy } from '@/services';
import userStore from '@/stores/userInfo';
interface Props {
@@ -82,6 +82,26 @@ const Index: React.FC<Props> = ({ callback }) => {
});
return bol;
};
+ const { data: tos } = useLegalTos();
+ const { data: privacy } = useLegalPrivacy();
+ const argumentClick = (evt: MouseEvent, type: 'tos' | 'privacy') => {
+ evt.stopPropagation();
+ const contentText =
+ type === 'tos'
+ ? tos?.terms_of_service_original_text
+ : privacy?.privacy_policy_original_text;
+ let matchUrl: URL | undefined;
+ try {
+ if (contentText) {
+ matchUrl = new URL(contentText);
+ }
+ // eslint-disable-next-line no-empty
+ } catch (ex) {}
+ if (matchUrl) {
+ evt.preventDefault();
+ window.open(matchUrl.toString());
+ }
+ };
const handleSubmit = async (event: FormEvent) => {
event.preventDefault();
@@ -185,7 +205,29 @@ const Index: React.FC<Props> = ({ callback }) => {
</Button>
</div>
</Form>
-
+ <div className="text-center fs-14 mt-3">
+ <Trans i18nKey="login.agreements" ns="translation">
+ By registering, you agree to the
+ <Link
+ to="/privacy"
+ onClick={(evt) => {
+ argumentClick(evt, 'privacy');
+ }}
+ target="_blank">
+ privacy policy
+ </Link>
+ and
+ <Link
+ to="/tos"
+ onClick={(evt) => {
+ argumentClick(evt, 'tos');
+ }}
+ target="_blank">
+ terms of service
+ </Link>
+ .
+ </Trans>
+ </div>
<div className="text-center mt-5">
<Trans i18nKey="login.info_login" ns="translation">
Already have an account? <Link to="/users/login">Log in</Link>
diff --git a/ui/src/router/index.tsx b/ui/src/router/index.tsx
index e5aa2797..6892f403 100644
--- a/ui/src/router/index.tsx
+++ b/ui/src/router/index.tsx
@@ -10,7 +10,7 @@ const routes: RouteObject[] = [];
const routeWrapper = (routeNodes: RouteNode[], root: RouteObject[]) => {
routeNodes.forEach((rn) => {
- if (rn.path === '/') {
+ if (rn.page === 'pages/Layout') {
rn.element = <Layout />;
rn.errorElement = <ErrorBoundary />;
} else {
@@ -31,7 +31,7 @@ const routeWrapper = (routeNodes: RouteNode[], root: RouteObject[]) => {
const refLoader = rn.loader;
const refGuard = rn.guard;
rn.loader = async (args) => {
- const gr = await refGuard();
+ const gr = await refGuard(args);
if (gr?.redirect && floppyNavigation.differentCurrent(gr.redirect)) {
return redirect(gr.redirect);
}
diff --git a/ui/src/router/routes.ts b/ui/src/router/routes.ts
index 32e8644c..7336b995 100644
--- a/ui/src/router/routes.ts
+++ b/ui/src/router/routes.ts
@@ -1,4 +1,4 @@
-import { RouteObject } from 'react-router-dom';
+import { LoaderFunctionArgs, RouteObject } from 'react-router-dom';
import { guard } from '@/utils';
import type { TGuardResult } from '@/utils/guard';
@@ -13,7 +13,7 @@ export interface RouteNode extends RouteObject {
* if guard returned the `TGuardResult` has `redirect` field,
* then auto redirect route to the `redirect` target.
*/
- guard?: () => Promise<TGuardResult>;
+ guard?: (args: LoaderFunctionArgs) => Promise<TGuardResult>;
}
const routes: RouteNode[] = [
@@ -31,7 +31,6 @@ const routes: RouteNode[] = [
},
{
path: 'questions',
- index: true,
page: 'pages/Questions',
},
{
@@ -275,6 +274,25 @@ const routes: RouteNode[] = [
},
],
},
+ {
+ path: '/',
+ page: 'pages/Layout',
+ children: [
+ {
+ page: 'pages/Legal',
+ children: [
+ {
+ path: 'tos',
+ page: 'pages/Legal/Tos',
+ },
+ {
+ path: 'privacy',
+ page: 'pages/Legal/Privacy',
+ },
+ ],
+ },
+ ],
+ },
{
path: '/install',
page: 'pages/Install',
diff --git a/ui/src/services/admin/dashboard.ts b/ui/src/services/admin/dashboard.ts
new file mode 100644
index 00000000..580c6583
--- /dev/null
+++ b/ui/src/services/admin/dashboard.ts
@@ -0,0 +1,17 @@
+import useSWR from 'swr';
+
+import * as Type from '@/common/interface';
+import request from '@/utils/request';
+
+export const useDashBoard = () => {
+ const apiUrl = `/answer/admin/api/dashboard`;
+ const { data, error } = useSWR<Type.AdminDashboard, Error>(
+ [apiUrl],
+ request.instance.get,
+ );
+ return {
+ data,
+ isLoading: !data && !error,
+ error,
+ };
+};
diff --git a/ui/src/services/admin/index.ts b/ui/src/services/admin/index.ts
index be55c163..09811f2e 100644
--- a/ui/src/services/admin/index.ts
+++ b/ui/src/services/admin/index.ts
@@ -2,3 +2,5 @@ export * from './answer';
export * from './flag';
export * from './question';
export * from './settings';
+export * from './users';
+export * from './dashboard';
diff --git a/ui/src/services/admin/question.ts b/ui/src/services/admin/question.ts
index 9e8d726a..bdd5aeb0 100644
--- a/ui/src/services/admin/question.ts
+++ b/ui/src/services/admin/question.ts
@@ -4,24 +4,6 @@ import useSWR from 'swr';
import request from '@/utils/request';
import type * as Type from '@/common/interface';
-export const changeUserStatus = (params) => {
- return request.put('/answer/admin/api/user/status', params);
-};
-
-export const useQueryUsers = (params) => {
- const apiUrl = `/answer/admin/api/users/page?${qs.stringify(params)}`;
- const { data, error, mutate } = useSWR<Type.ListResult, Error>(
- apiUrl,
- request.instance.get,
- );
- return {
- data,
- isLoading: !data && !error,
- error,
- mutate,
- };
-};
-
export const useQuestionSearch = (params: Type.AdminContentsReq) => {
const apiUrl = `/answer/admin/api/question/page?${qs.stringify(params)}`;
const { data, error, mutate } = useSWR<Type.ListResult, Error>(
diff --git a/ui/src/services/admin/settings.ts b/ui/src/services/admin/settings.ts
index 3e627284..3ccec1ac 100644
--- a/ui/src/services/admin/settings.ts
+++ b/ui/src/services/admin/settings.ts
@@ -71,19 +71,6 @@ export const updateSmtpSetting = (params: Type.AdminSettingsSmtp) => {
return request.put(apiUrl, params);
};
-export const useDashBoard = () => {
- const apiUrl = `/answer/admin/api/dashboard`;
- const { data, error } = useSWR<Type.AdminDashboard, Error>(
- [apiUrl],
- request.instance.get,
- );
- return {
- data,
- isLoading: !data && !error,
- error,
- };
-};
-
export const getAdminLanguageOptions = () => {
const apiUrl = `/answer/admin/api/language/options`;
return request.get<Type.LangsType[]>(apiUrl);
@@ -96,3 +83,13 @@ export const getBrandSetting = () => {
export const brandSetting = (params: Type.BrandReqParams) => {
return request.put('/answer/admin/api/siteinfo/branding', params);
};
+
+export const getLegalSetting = () => {
+ return request.get<Type.AdminSettingsLegal>(
+ '/answer/admin/api/siteinfo/legal',
+ );
+};
+
+export const putLegalSetting = (params: Type.AdminSettingsLegal) => {
+ return request.put('/answer/admin/api/siteinfo/legal', params);
+};
diff --git a/ui/src/services/admin/users.ts b/ui/src/services/admin/users.ts
new file mode 100644
index 00000000..0cbc787a
--- /dev/null
+++ b/ui/src/services/admin/users.ts
@@ -0,0 +1,23 @@
+import qs from 'qs';
+import useSWR from 'swr';
+
+import request from '@/utils/request';
+import type * as Type from '@/common/interface';
+
+export const changeUserStatus = (params) => {
+ return request.put('/answer/admin/api/user/status', params);
+};
+
+export const useQueryUsers = (params) => {
+ const apiUrl = `/answer/admin/api/users/page?${qs.stringify(params)}`;
+ const { data, error, mutate } = useSWR<Type.ListResult, Error>(
+ apiUrl,
+ request.instance.get,
+ );
+ return {
+ data,
+ isLoading: !data && !error,
+ error,
+ mutate,
+ };
+};
diff --git a/ui/src/services/client/index.ts b/ui/src/services/client/index.ts
index 17cfb7e0..2777d9ef 100644
--- a/ui/src/services/client/index.ts
+++ b/ui/src/services/client/index.ts
@@ -5,3 +5,4 @@ export * from './question';
export * from './search';
export * from './tag';
export * from './settings';
+export * from './legal';
diff --git a/ui/src/services/client/legal.ts b/ui/src/services/client/legal.ts
new file mode 100644
index 00000000..d294f1df
--- /dev/null
+++ b/ui/src/services/client/legal.ts
@@ -0,0 +1,32 @@
+import useSWR from 'swr';
+
+import request from '@/utils/request';
+import type * as Type from '@/common/interface';
+
+export const useLegalTos = () => {
+ const apiUrl = '/answer/api/v1/siteinfo/legal?info_type=tos';
+ const { data, error, mutate } = useSWR<Type.AdminSettingsLegal, Error>(
+ [apiUrl],
+ request.instance.get,
+ );
+ return {
+ data,
+ isLoading: !data && !error,
+ error,
+ mutate,
+ };
+};
+
+export const useLegalPrivacy = () => {
+ const apiUrl = '/answer/api/v1/siteinfo/legal?info_type=privacy';
+ const { data, error, mutate } = useSWR<Type.AdminSettingsLegal, Error>(
+ [apiUrl],
+ request.instance.get,
+ );
+ return {
+ data,
+ isLoading: !data && !error,
+ error,
+ mutate,
+ };
+};