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: move services types to common/interface

shuai158402b9c8c2
diff --git a/ui/src/common/interface.ts b/ui/src/common/interface.ts
index 1d205691..4838588c 100644
--- a/ui/src/common/interface.ts
+++ b/ui/src/common/interface.ts
@@ -7,3 +7,302 @@ export interface FormValue<T = any> {
export interface FormDataType {
[prop: string]: FormValue;
}
+
+export interface Paging {
+ page: number;
+ page_size?: number;
+}
+
+export type ReportType = 'question' | 'answer' | 'comment' | 'user';
+export type ReportAction = 'close' | 'flag' | 'review';
+export interface ReportParams {
+ type: ReportType;
+ action: ReportAction;
+}
+
+export interface TagBase {
+ display_name: string;
+ slug_name: string;
+}
+
+export interface Tag extends TagBase {
+ main_tag_slug_name?: string;
+ original_text?: string;
+ parsed_text?: string;
+}
+
+export interface SynonymsTag extends Tag {
+ tag_id: string;
+ tag?: string;
+}
+
+export interface TagInfo extends TagBase {
+ tag_id: string;
+ original_text: string;
+ parsed_text: string;
+ follow_count: number;
+ question_count: number;
+ is_follower: boolean;
+ member_actions;
+ created_at?;
+ updated_at?;
+ main_tag_slug_name?: string;
+ excerpt?;
+}
+export interface QuestionParams {
+ title: string;
+ content: string;
+ html: string;
+ tags: Tag[];
+}
+
+export interface ListResult<T = any> {
+ count: number;
+ list: T[];
+}
+
+export interface AnswerParams {
+ content: string;
+ html: string;
+ question_id: string;
+ id: string;
+}
+
+export interface LoginReqParams {
+ e_mail: string;
+ /** password */
+ pass: string;
+ captcha_id?: string;
+ captcha_code?: string;
+}
+
+export interface RegisterReqParams extends LoginReqParams {
+ name: string;
+}
+
+export interface ModifyPassReq {
+ old_pass: string;
+ pass: string;
+}
+
+/** User */
+export interface ModifyUserReq {
+ display_name: string;
+ username?: string;
+ avatar: string;
+ bio: string;
+ bio_html?: string;
+ location: string;
+ website: string;
+}
+
+export interface UserInfoBase {
+ avatar: string;
+ username: string;
+ display_name: string;
+ rank: number;
+ website: string;
+ location: string;
+ ip_info?: string;
+ /** 'forbidden' | 'normal' | 'delete'
+ */
+ status?: string;
+ /** roles */
+ is_admin?: true;
+}
+
+export interface UserInfoRes extends UserInfoBase {
+ bio: string;
+ bio_html: string;
+ create_time?: string;
+ /** value = 1 active; value = 2 inactivated
+ */
+ mail_status: number;
+ e_mail?: string;
+ [prop: string]: any;
+}
+
+export interface AvatarUploadReq {
+ file: FormData;
+}
+
+export interface ImgCodeReq {
+ captcha_id?: string;
+ captcha_code?: string;
+}
+
+export interface ImgCodeRes {
+ captcha_id: string;
+ captcha_img: string;
+ verify: boolean;
+}
+
+export interface PssRetReq extends ImgCodeReq {
+ e_mail: string;
+}
+
+export interface CheckImgReq {
+ action: 'login' | 'e_mail' | 'find_pass';
+}
+
+export interface NoticeSetReq {
+ notice_switch: boolean;
+}
+
+export interface QuDetailRes {
+ id: string;
+ title: string;
+ content: string;
+ html: string;
+ tags: any[];
+ view_count: number;
+ unique_view_count?: number;
+ answer_count: number;
+ favorites_count: number;
+ follow_counts: 0;
+ accepted_answer_id: string;
+ last_answer_id: string;
+ create_time: string;
+ update_time: string;
+ user_info: UserInfoBase;
+ answered: boolean;
+ collected: boolean;
+
+ [prop: string]: any;
+}
+
+export interface AnswersReq extends Paging {
+ order?: 'default' | 'updated';
+ question_id: string;
+}
+
+export interface AnswerItem {
+ id: string;
+ question_id: string;
+ content: string;
+ html: string;
+ create_time: string;
+ update_time: string;
+ user_info: UserInfoBase;
+
+ [prop: string]: any;
+}
+
+export interface PostAnswerReq {
+ content: string;
+ html: string;
+ question_id: string;
+}
+
+export interface PageUser {
+ id;
+ displayName;
+ userName?;
+ avatar_url?;
+}
+
+export interface LangsType {
+ label: string;
+ value: string;
+}
+
+/**
+ * @description interface for Question
+ */
+export type QuestionOrderBy =
+ | 'newest'
+ | 'active'
+ | 'frequent'
+ | 'score'
+ | 'unanswered';
+
+export interface QueryQuestionsReq extends Paging {
+ order: QuestionOrderBy;
+ tags?: string[];
+}
+
+export type AdminQuestionStatus = 'available' | 'closed' | 'deleted';
+
+export type AdminContentsFilterBy = 'normal' | 'closed' | 'deleted';
+
+export interface AdminContentsReq extends Paging {
+ status: AdminContentsFilterBy;
+}
+
+/**
+ * @description interface for Answer
+ */
+export type AdminAnswerStatus = 'available' | 'deleted';
+
+/**
+ * @description interface for Users
+ */
+export type UserFilterBy = 'all' | 'inactive' | 'suspended' | 'deleted';
+
+/**
+ * @description interface for Flags
+ */
+export type FlagStatus = 'pending' | 'completed';
+export type FlagType = 'all' | 'question' | 'answer' | 'comment';
+export interface AdminFlagsReq extends Paging {
+ status: FlagStatus;
+ object_type: FlagType;
+}
+
+/**
+ * @description interface for Admin Settings
+ */
+export interface AdminSettingsGeneral {
+ name: string;
+ short_description: string;
+ description: string;
+}
+
+export interface AdminSettingsInterface {
+ logo: string;
+ language: string;
+ theme: string;
+}
+
+export interface SiteSettings {
+ general: AdminSettingsGeneral;
+ interface: AdminSettingsInterface;
+}
+/**
+ * @description interface for Activity
+ */
+export interface FollowParams {
+ is_cancel: boolean;
+ object_id: string;
+}
+
+/**
+ * @description search request params
+ */
+export interface SearchParams {
+ q: string;
+ order: string;
+ page: number;
+ size?: number;
+}
+
+/**
+ * @description search response data
+ */
+export interface SearchResItem {
+ object_type: string;
+ object: {
+ id: string;
+ title: string;
+ excerpt: string;
+ created_at: number;
+ user_info: UserInfoBase;
+ vote_count: number;
+ answer_count: number;
+ accepted: boolean;
+ tags: TagBase[];
+ };
+}
+export interface SearchRes extends ListResult<SearchResItem> {
+ extra: any;
+}
diff --git a/ui/src/components/Comment/index.tsx b/ui/src/components/Comment/index.tsx
index 020f2e7d..0051cc4f 100644
--- a/ui/src/components/Comment/index.tsx
+++ b/ui/src/components/Comment/index.tsx
@@ -7,6 +7,7 @@ import classNames from 'classnames';
import { unionBy } from 'lodash';
import { marked } from 'marked';
+import * as Types from '@answer/common/interface';
import {
useQueryComments,
addComment,
@@ -16,7 +17,6 @@ import {
} from '@answer/api';
import { Modal } from '@answer/components';
import { usePageUsers, useReportModal } from '@answer/hooks';
-import * as Types from '@answer/services/types';
import { matchedUsers, parseUserInfo, isLogin } from '@answer/utils';
import { Form, ActionBar, Reply } from './components';
diff --git a/ui/src/components/Mentions/index.tsx b/ui/src/components/Mentions/index.tsx
index 4332d5cd..2aeb7667 100644
--- a/ui/src/components/Mentions/index.tsx
+++ b/ui/src/components/Mentions/index.tsx
@@ -1,7 +1,7 @@
import React, { useEffect, useRef, useState, FC } from 'react';
import { Dropdown } from 'react-bootstrap';
-import * as Types from '@answer/services/types';
+import * as Types from '@answer/common/interface';
interface IProps {
children: React.ReactNode;
diff --git a/ui/src/components/Modal/PicAuthCodeModal.tsx b/ui/src/components/Modal/PicAuthCodeModal.tsx
index f67cad91..f0fe2091 100644
--- a/ui/src/components/Modal/PicAuthCodeModal.tsx
+++ b/ui/src/components/Modal/PicAuthCodeModal.tsx
@@ -3,8 +3,11 @@ import { Modal, Form, Button, InputGroup } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';
import { Icon } from '@answer/components';
-import type { FormValue, FormDataType } from '@answer/common/interface';
-import type { ImgCodeRes } from '@answer/services/types';
+import type {
+ FormValue,
+ FormDataType,
+ ImgCodeRes,
+} from '@answer/common/interface';
interface IProps {
/** control visible */
diff --git a/ui/src/components/Questions/index.tsx b/ui/src/components/Questions/index.tsx
index a3b13739..1824f7c1 100644
--- a/ui/src/components/Questions/index.tsx
+++ b/ui/src/components/Questions/index.tsx
@@ -4,7 +4,7 @@ import { NavLink, useParams, useSearchParams } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { useQuestionList } from '@answer/api';
-import type * as Type from '@answer/services/types';
+import type * as Type from '@answer/common/interface';
import { Icon, Tag, Pagination, FormatTime, Empty } from '@answer/components';
const QuestionOrderKeys: Type.QuestionOrderBy[] = [
diff --git a/ui/src/components/TagSelector/index.tsx b/ui/src/components/TagSelector/index.tsx
index ba913e62..12142e9f 100644
--- a/ui/src/components/TagSelector/index.tsx
+++ b/ui/src/components/TagSelector/index.tsx
@@ -8,7 +8,7 @@ import classNames from 'classnames';
import { Icon } from '@answer/components';
import { useTagModal } from '@answer/hooks';
import { queryTags } from '@answer/api';
-import type * as Type from '@answer/services/types';
+import type * as Type from '@answer/common/interface';
import './index.scss';
diff --git a/ui/src/components/Unactivate/index.tsx b/ui/src/components/Unactivate/index.tsx
index fdba9a31..03635f1d 100644
--- a/ui/src/components/Unactivate/index.tsx
+++ b/ui/src/components/Unactivate/index.tsx
@@ -4,8 +4,11 @@ import { Trans, useTranslation } from 'react-i18next';
import { emailReSend, checkImgCode } from '@answer/api';
import { PicAuthCodeModal } from '@answer/components/Modal';
-import type { ImgCodeRes, ImgCodeReq } from '@answer/services/types';
-import type { FormDataType } from '@answer/common/interface';
+import type {
+ ImgCodeRes,
+ ImgCodeReq,
+ FormDataType,
+} from '@answer/common/interface';
import { userInfoStore } from '@answer/stores';
interface IProps {
diff --git a/ui/src/hooks/usePageUsers/index.tsx b/ui/src/hooks/usePageUsers/index.tsx
index f21b0153..681a988f 100644
--- a/ui/src/hooks/usePageUsers/index.tsx
+++ b/ui/src/hooks/usePageUsers/index.tsx
@@ -2,7 +2,7 @@ import { useState } from 'react';
import { uniqBy } from 'lodash';
-import * as Types from '@answer/services/types';
+import * as Types from '@answer/common/interface';
let globalUsers: Types.PageUser[] = [];
const usePageUsers = () => {
diff --git a/ui/src/hooks/useReportModal/index.tsx b/ui/src/hooks/useReportModal/index.tsx
index 62359d8b..88b975f6 100644
--- a/ui/src/hooks/useReportModal/index.tsx
+++ b/ui/src/hooks/useReportModal/index.tsx
@@ -6,7 +6,7 @@ import ReactDOM from 'react-dom/client';
import { reportList, postReport, closeQuestion, putReport } from '@answer/api';
import { useToast } from '@answer/hooks';
-import type * as Type from '@answer/services/types';
+import type * as Type from '@answer/common/interface';
interface Params {
isBackend?: boolean;
diff --git a/ui/src/pages/Admin/Answers/index.tsx b/ui/src/pages/Admin/Answers/index.tsx
index e364d978..b6d59b28 100644
--- a/ui/src/pages/Admin/Answers/index.tsx
+++ b/ui/src/pages/Admin/Answers/index.tsx
@@ -21,8 +21,7 @@ import {
import { ADMIN_LIST_STATUS } from '@answer/common/constants';
import { useEditStatusModal } from '@answer/hooks';
import { useAnswerSearch, changeAnswerStatus } from '@answer/api';
-
-import * as Type from '@/services/types';
+import * as Type from '@answer/common/interface';
import '../index.scss';
diff --git a/ui/src/pages/Admin/Flags/index.tsx b/ui/src/pages/Admin/Flags/index.tsx
index 17a6b959..433c8693 100644
--- a/ui/src/pages/Admin/Flags/index.tsx
+++ b/ui/src/pages/Admin/Flags/index.tsx
@@ -10,7 +10,7 @@ import {
Pagination,
} from '@answer/components';
import { useReportModal } from '@answer/hooks';
-import * as Type from '@answer/services/types';
+import * as Type from '@answer/common/interface';
import { useFlagSearch } from '@answer/api';
import '../index.scss';
diff --git a/ui/src/pages/Admin/General/index.tsx b/ui/src/pages/Admin/General/index.tsx
index 63fe681e..7e40f9d2 100644
--- a/ui/src/pages/Admin/General/index.tsx
+++ b/ui/src/pages/Admin/General/index.tsx
@@ -2,13 +2,11 @@ import React, { FC, useEffect, useState } from 'react';
import { Form, Button } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';
-import type * as Type from '@answer/services/types';
+import type * as Type from '@answer/common/interface';
import { useToast } from '@answer/hooks';
import { siteInfoStore } from '@answer/stores';
import { useGeneralSetting, updateGeneralSetting } from '@answer/api';
-import { FormDataType } from '@/common/interface';
-
import '../index.scss';
const General: FC = () => {
@@ -19,7 +17,7 @@ const General: FC = () => {
const updateSiteInfo = siteInfoStore((state) => state.update);
const { data: setting } = useGeneralSetting();
- const [formData, setFormData] = useState<FormDataType>({
+ const [formData, setFormData] = useState<Type.FormDataType>({
name: {
value: '',
isInvalid: false,
@@ -101,7 +99,7 @@ const General: FC = () => {
if (!formData[fieldName]) {
return;
}
- const fieldData: FormDataType = {
+ const fieldData: Type.FormDataType = {
[fieldName]: {
value: fieldValue,
isInvalid: false,
diff --git a/ui/src/pages/Admin/Interface/index.tsx b/ui/src/pages/Admin/Interface/index.tsx
index f82cbc2b..329d3419 100644
--- a/ui/src/pages/Admin/Interface/index.tsx
+++ b/ui/src/pages/Admin/Interface/index.tsx
@@ -3,9 +3,11 @@ import { Form, Button, Image, Stack } from 'react-bootstrap';
import { Trans, useTranslation } from 'react-i18next';
import { useToast } from '@answer/hooks';
-import * as Type from '@answer/services/types';
-import { LangsType } from '@answer/services/types';
-import { FormDataType } from '@answer/common/interface';
+import {
+ LangsType,
+ FormDataType,
+ AdminSettingsInterface,
+} from '@answer/common/interface';
import {
languages,
uploadAvatar,
@@ -110,7 +112,7 @@ const Interface: FC = () => {
if (checkValidated() === false) {
return;
}
- const reqParams: Type.AdminSettingsInterface = {
+ const reqParams: AdminSettingsInterface = {
logo: formData.logo.value,
theme: formData.theme.value,
language: formData.language.value,
diff --git a/ui/src/pages/Admin/Questions/index.tsx b/ui/src/pages/Admin/Questions/index.tsx
index 877605f8..1d333e22 100644
--- a/ui/src/pages/Admin/Questions/index.tsx
+++ b/ui/src/pages/Admin/Questions/index.tsx
@@ -25,8 +25,7 @@ import {
changeQuestionStatus,
questionDelete,
} from '@answer/api';
-
-import * as Type from '@/services/types';
+import * as Type from '@answer/common/interface';
import '../index.scss';
diff --git a/ui/src/pages/Admin/Users/index.tsx b/ui/src/pages/Admin/Users/index.tsx
index 81fc1ef9..4411236f 100644
--- a/ui/src/pages/Admin/Users/index.tsx
+++ b/ui/src/pages/Admin/Users/index.tsx
@@ -10,7 +10,7 @@ import {
BaseUserCard,
Empty,
} from '@answer/components';
-import * as Type from '@answer/services/types';
+import * as Type from '@answer/common/interface';
import { useChangeModal } from '@answer/hooks';
import '../index.scss';
diff --git a/ui/src/pages/Questions/Ask/index.tsx b/ui/src/pages/Questions/Ask/index.tsx
index df4fc106..0cf6dac6 100644
--- a/ui/src/pages/Questions/Ask/index.tsx
+++ b/ui/src/pages/Questions/Ask/index.tsx
@@ -15,7 +15,7 @@ import {
postAnswer,
useQueryQuestionByTitle,
} from '@answer/api';
-import type * as Type from '@/services/types';
+import type * as Type from '@answer/common/interface';
import SearchQuestion from './components/SearchQuestion';
diff --git a/ui/src/pages/Questions/Detail/components/Answer/index.tsx b/ui/src/pages/Questions/Detail/components/Answer/index.tsx
index 5d59c8ca..0761d381 100644
--- a/ui/src/pages/Questions/Detail/components/Answer/index.tsx
+++ b/ui/src/pages/Questions/Detail/components/Answer/index.tsx
@@ -12,8 +12,7 @@ import {
} from '@answer/components';
import { acceptanceAnswer } from '@answer/api';
import { scrollTop } from '@answer/utils';
-
-import { AnswerItem } from '@/services/types';
+import { AnswerItem } from '@answer/common/interface';
interface Props {
data: AnswerItem;
diff --git a/ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsx b/ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsx
index de6dfdde..1f6934e6 100644
--- a/ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsx
+++ b/ui/src/pages/Questions/Detail/components/WriteAnswer/index.tsx
@@ -6,8 +6,7 @@ import { marked } from 'marked';
import { Editor, Modal } from '@answer/components';
import { postAnswer } from '@answer/api';
-
-import { FormDataType } from '@/common/interface';
+import { FormDataType } from '@answer/common/interface';
interface Props {
visible?: boolean;
diff --git a/ui/src/pages/Questions/Detail/index.tsx b/ui/src/pages/Questions/Detail/index.tsx
index fab8b103..e1c50c42 100644
--- a/ui/src/pages/Questions/Detail/index.tsx
+++ b/ui/src/pages/Questions/Detail/index.tsx
@@ -7,6 +7,11 @@ import { Pagination, PageTitle } from '@answer/components';
import { userInfoStore } from '@answer/stores';
import { scrollTop } from '@answer/utils';
import { usePageUsers } from '@answer/hooks';
+import type {
+ ListResult,
+ QuDetailRes,
+ AnswerItem,
+} from '@answer/common/interface';
import {
Question,
@@ -17,8 +22,6 @@ import {
Alert,
} from './components';
-import type { ListResult, QuDetailRes, AnswerItem } from '@/services/types';
-
import './index.scss';
const Index = () => {
diff --git a/ui/src/pages/Questions/EditAnswer/index.tsx b/ui/src/pages/Questions/EditAnswer/index.tsx
index 455b903e..2e9ca74b 100644
--- a/ui/src/pages/Questions/EditAnswer/index.tsx
+++ b/ui/src/pages/Questions/EditAnswer/index.tsx
@@ -12,7 +12,7 @@ import {
modifyAnswer,
useQueryRevisions,
} from '@answer/api';
-import type * as Type from '@/services/types';
+import type * as Type from '@answer/common/interface';
import './index.scss';
diff --git a/ui/src/pages/Search/components/SearchItem/index.tsx b/ui/src/pages/Search/components/SearchItem/index.tsx
index d2ebaf54..88dafe18 100644
--- a/ui/src/pages/Search/components/SearchItem/index.tsx
+++ b/ui/src/pages/Search/components/SearchItem/index.tsx
@@ -2,7 +2,7 @@ import { memo, FC } from 'react';
import { ListGroupItem, Badge } from 'react-bootstrap';
import { Icon, Tag, FormatTime } from '@answer/components';
-import type { SearchResItem } from '@answer/services/types';
+import type { SearchResItem } from '@answer/common/interface';
import { formatCount } from '@answer/utils';
interface Props {
diff --git a/ui/src/pages/Tags/Detail/index.tsx b/ui/src/pages/Tags/Detail/index.tsx
index 10d7d05b..2d87712b 100644
--- a/ui/src/pages/Tags/Detail/index.tsx
+++ b/ui/src/pages/Tags/Detail/index.tsx
@@ -3,7 +3,7 @@ import { Container, Row, Col, Button } from 'react-bootstrap';
import { useParams, Link, useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
-import * as Type from '@/services/types';
+import * as Type from '@answer/common/interface';
import { PageTitle, FollowingTags } from '@answer/components';
import { useTagInfo, useFollow } from '@answer/api';
diff --git a/ui/src/pages/Users/AccountForgot/components/sendEmail.tsx b/ui/src/pages/Users/AccountForgot/components/sendEmail.tsx
index 2e599404..049f62ca 100644
--- a/ui/src/pages/Users/AccountForgot/components/sendEmail.tsx
+++ b/ui/src/pages/Users/AccountForgot/components/sendEmail.tsx
@@ -3,8 +3,12 @@ import { Form, Button } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';
import { passRetrieve, checkImgCode } from '@answer/api';
-import type { FormDataType } from '@/common/interface';
-import type { ImgCodeRes, PssRetReq } from '@/services/types';
+import type {
+ ImgCodeRes,
+ PssRetReq,
+ FormDataType,
+} from '@answer/common/interface';
+
import { PicAuthCodeModal } from '@/components/Modal';
interface IProps {
diff --git a/ui/src/pages/Users/Login/index.tsx b/ui/src/pages/Users/Login/index.tsx
index f605e216..fe535c10 100644
--- a/ui/src/pages/Users/Login/index.tsx
+++ b/ui/src/pages/Users/Login/index.tsx
@@ -3,13 +3,17 @@ import { Container, 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 { login, checkImgCode } from '@answer/api';
-import type { LoginReqParams, ImgCodeRes } from '@/services/types';
+import type {
+ LoginReqParams,
+ ImgCodeRes,
+ FormDataType,
+} from '@answer/common/interface';
import { PageTitle, Unactivate } from '@answer/components';
-import { PicAuthCodeModal } from '@/components/Modal';
import { userInfoStore } from '@answer/stores';
import { isLogin, getQueryString } from '@answer/utils';
+
+import { PicAuthCodeModal } from '@/components/Modal';
import Storage from '@/utils/storage';
const Index: React.FC = () => {
diff --git a/ui/src/pages/Users/PasswordReset/index.tsx b/ui/src/pages/Users/PasswordReset/index.tsx
index 3cd9d876..3024a445 100644
--- a/ui/src/pages/Users/PasswordReset/index.tsx
+++ b/ui/src/pages/Users/PasswordReset/index.tsx
@@ -3,12 +3,12 @@ import { Container, Col, Form, Button } from 'react-bootstrap';
import { Link } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
-import type { FormDataType } from '@/common/interface';
import { passRetrieveSet } from '@answer/api';
import { userInfoStore } from '@answer/stores';
-import Storage from '@/utils/storage';
import { getQueryString, isLogin } from '@answer/utils';
+import type { FormDataType } from '@answer/common/interface';
+import Storage from '@/utils/storage';
import { PageTitle } from '@/components';
const Index: React.FC = () => {
diff --git a/ui/src/pages/Users/Personal/components/UserInfo/index.tsx b/ui/src/pages/Users/Personal/components/UserInfo/index.tsx
index db2bf3ba..530fa429 100644
--- a/ui/src/pages/Users/Personal/components/UserInfo/index.tsx
+++ b/ui/src/pages/Users/Personal/components/UserInfo/index.tsx
@@ -3,7 +3,7 @@ import { Badge, OverlayTrigger, Tooltip } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';
import { Avatar, Icon } from '@answer/components';
-import type { UserInfoRes } from '@/services/types';
+import type { UserInfoRes } from '@answer/common/interface';
interface Props {
data: UserInfoRes;
diff --git a/ui/src/pages/Users/Register/components/SignUpForm/index.tsx b/ui/src/pages/Users/Register/components/SignUpForm/index.tsx
index 549f93b2..072093b9 100644
--- a/ui/src/pages/Users/Register/components/SignUpForm/index.tsx
+++ b/ui/src/pages/Users/Register/components/SignUpForm/index.tsx
@@ -4,7 +4,8 @@ import { Link } from 'react-router-dom';
import { Trans, useTranslation } from 'react-i18next';
import { register } from '@answer/api';
-import type { FormDataType } from '@/common/interface';
+import type { FormDataType } from '@answer/common/interface';
+
import userStore from '@/stores/userInfo';
interface Props {
diff --git a/ui/src/pages/Users/Settings/Account/components/ModifyEmail/index.tsx b/ui/src/pages/Users/Settings/Account/components/ModifyEmail/index.tsx
index d363a0e3..84182a53 100644
--- a/ui/src/pages/Users/Settings/Account/components/ModifyEmail/index.tsx
+++ b/ui/src/pages/Users/Settings/Account/components/ModifyEmail/index.tsx
@@ -2,8 +2,7 @@ import React, { FC, FormEvent, useEffect, useState } from 'react';
import { Form, Button } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';
-import type { FormDataType } from '@/common/interface';
-import type * as Type from '@/services/types';
+import type * as Type from '@answer/common/interface';
import { getUserInfo, changeEmail } from '@answer/api';
import { useToast } from '@answer/hooks';
@@ -14,7 +13,7 @@ const Index: FC = () => {
keyPrefix: 'settings.account',
});
const [step, setStep] = useState(1);
- const [formData, setFormData] = useState<FormDataType>({
+ const [formData, setFormData] = useState<Type.FormDataType>({
e_mail: {
value: '',
isInvalid: false,
@@ -29,7 +28,7 @@ const Index: FC = () => {
});
}, []);
- const handleChange = (params: FormDataType) => {
+ const handleChange = (params: Type.FormDataType) => {
setFormData({ ...formData, ...params });
};
diff --git a/ui/src/pages/Users/Settings/Account/components/ModifyPass/index.tsx b/ui/src/pages/Users/Settings/Account/components/ModifyPass/index.tsx
index a59efaf1..23265763 100644
--- a/ui/src/pages/Users/Settings/Account/components/ModifyPass/index.tsx
+++ b/ui/src/pages/Users/Settings/Account/components/ModifyPass/index.tsx
@@ -2,9 +2,9 @@ import React, { FC, FormEvent, useState } from 'react';
import { Form, Button } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';
-import type { FormDataType } from '@/common/interface';
import { modifyPassword } from '@answer/api';
import { useToast } from '@answer/hooks';
+import type { FormDataType } from '@answer/common/interface';
const Index: FC = () => {
const { t } = useTranslation('translation', {
diff --git a/ui/src/pages/Users/Settings/Interface/index.tsx b/ui/src/pages/Users/Settings/Interface/index.tsx
index 05cdaa89..ca7ce38d 100644
--- a/ui/src/pages/Users/Settings/Interface/index.tsx
+++ b/ui/src/pages/Users/Settings/Interface/index.tsx
@@ -7,9 +7,9 @@ import en from 'dayjs/locale/en';
import zh from 'dayjs/locale/zh-cn';
import { languages } from '@answer/api';
-import type { FormDataType } from '@/common/interface';
-import type { LangsType } from '@/services/types';
+import type { LangsType, FormDataType } from '@answer/common/interface';
import { useToast } from '@answer/hooks';
+
import Storage from '@/utils/storage';
const Index = () => {
diff --git a/ui/src/pages/Users/Settings/Notification/index.tsx b/ui/src/pages/Users/Settings/Notification/index.tsx
index 454bfcd1..ed72a72e 100644
--- a/ui/src/pages/Users/Settings/Notification/index.tsx
+++ b/ui/src/pages/Users/Settings/Notification/index.tsx
@@ -2,7 +2,7 @@ import React, { useState, FormEvent, useEffect } from 'react';
import { Form, Button } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';
-import type { FormDataType } from '@/common/interface';
+import type { FormDataType } from '@answer/common/interface';
import { noticeSet, getUserInfo } from '@answer/api';
import { useToast } from '@answer/hooks';
diff --git a/ui/src/pages/Users/Settings/Profile/index.tsx b/ui/src/pages/Users/Settings/Profile/index.tsx
index 6ffcd2f0..24c1b12a 100644
--- a/ui/src/pages/Users/Settings/Profile/index.tsx
+++ b/ui/src/pages/Users/Settings/Profile/index.tsx
@@ -5,7 +5,7 @@ import { Trans, useTranslation } from 'react-i18next';
import { marked } from 'marked';
import { modifyUserInfo, uploadAvatar, getUserInfo } from '@answer/api';
-import type { FormDataType } from '@/common/interface';
+import type { FormDataType } from '@answer/common/interface';
import { UploadImg, Avatar } from '@answer/components';
import { userInfoStore } from '@answer/stores';
import { useToast } from '@answer/hooks';
diff --git a/ui/src/pages/Users/Settings/index.tsx b/ui/src/pages/Users/Settings/index.tsx
index 65962058..a2e8418a 100644
--- a/ui/src/pages/Users/Settings/index.tsx
+++ b/ui/src/pages/Users/Settings/index.tsx
@@ -4,7 +4,7 @@ import { useTranslation } from 'react-i18next';
import { Outlet } from 'react-router-dom';
import { getUserInfo } from '@answer/api';
-import type { FormDataType } from '@/common/interface';
+import type { FormDataType } from '@answer/common/interface';
import Nav from './components/Nav';
diff --git a/ui/src/services/admin/answer.ts b/ui/src/services/admin/answer.ts
index 5f96aafa..6fd0fbb6 100644
--- a/ui/src/services/admin/answer.ts
+++ b/ui/src/services/admin/answer.ts
@@ -2,7 +2,7 @@ import useSWR from 'swr';
import qs from 'qs';
import request from '@answer/utils/request';
-import type * as Type from '../types';
+import type * as Type from '@answer/common/interface';
export const useAnswerSearch = (params: Type.AdminContentsReq) => {
const apiUrl = `/answer/admin/api/answer/page?${qs.stringify(params)}`;
diff --git a/ui/src/services/admin/flag.ts b/ui/src/services/admin/flag.ts
index 7f5cda80..710cb447 100644
--- a/ui/src/services/admin/flag.ts
+++ b/ui/src/services/admin/flag.ts
@@ -2,7 +2,7 @@ import useSWR from 'swr';
import qs from 'qs';
import request from '@answer/utils/request';
-import type * as Type from '../types';
+import type * as Type from '@answer/common/interface';
export const putReport = (params) => {
return request.instance.put('/answer/admin/api/report', params);
diff --git a/ui/src/services/admin/question.ts b/ui/src/services/admin/question.ts
index a06c9a82..a6308bf6 100644
--- a/ui/src/services/admin/question.ts
+++ b/ui/src/services/admin/question.ts
@@ -2,7 +2,7 @@ import qs from 'qs';
import useSWR from 'swr';
import request from '@answer/utils/request';
-import type * as Type from '../types';
+import type * as Type from '@answer/common/interface';
export const changeUserStatus = (params) => {
return request.put('/answer/admin/api/user/status', params);
diff --git a/ui/src/services/admin/settings.ts b/ui/src/services/admin/settings.ts
index a7f8abf2..ca7950ff 100644
--- a/ui/src/services/admin/settings.ts
+++ b/ui/src/services/admin/settings.ts
@@ -1,7 +1,7 @@
import useSWR from 'swr';
import request from '@answer/utils/request';
-import type * as Type from '../types';
+import type * as Type from '@answer/common/interface';
export const useGeneralSetting = () => {
const apiUrl = `/answer/admin/api/siteinfo/general`;
diff --git a/ui/src/services/client/activity.ts b/ui/src/services/client/activity.ts
index 5da1946a..7b7b539c 100644
--- a/ui/src/services/client/activity.ts
+++ b/ui/src/services/client/activity.ts
@@ -1,7 +1,7 @@
import useSWR from 'swr';
import request from '@answer/utils/request';
-import type * as Type from '../types';
+import type * as Type from '@answer/common/interface';
export const useFollow = (params?: Type.FollowParams) => {
const apiUrl = '/answer/api/v1/follow';
diff --git a/ui/src/services/client/notification.ts b/ui/src/services/client/notification.ts
index 64aa40e3..89dfaaad 100644
--- a/ui/src/services/client/notification.ts
+++ b/ui/src/services/client/notification.ts
@@ -3,7 +3,7 @@ import qs from 'qs';
import request from '@answer/utils/request';
import { isLogin } from '@answer/utils';
-import type * as Type from '../types';
+import type * as Type from '@answer/common/interface';
export const useQueryNotifications = (params) => {
const apiUrl = `/answer/api/v1/notification/page?${qs.stringify(params, {
diff --git a/ui/src/services/client/personal.ts b/ui/src/services/client/personal.ts
index fe62814c..b84e260f 100644
--- a/ui/src/services/client/personal.ts
+++ b/ui/src/services/client/personal.ts
@@ -2,7 +2,7 @@ import useSWR from 'swr';
import qs from 'qs';
import request from '@answer/utils/request';
-import type * as Type from '../types';
+import type * as Type from '@answer/common/interface';
export const usePersonalInfoByName = (username: string) => {
const apiUrl = '/answer/api/v1/personal/user/info';
diff --git a/ui/src/services/client/question.ts b/ui/src/services/client/question.ts
index 779f4f07..c35fe544 100644
--- a/ui/src/services/client/question.ts
+++ b/ui/src/services/client/question.ts
@@ -2,7 +2,7 @@ import useSWR from 'swr';
import qs from 'qs';
import request from '@answer/utils/request';
-import type * as Type from '../types';
+import type * as Type from '@answer/common/interface';
export const useQuestionList = (params: Type.QueryQuestionsReq) => {
const apiUrl = `/answer/api/v1/question/page?${qs.stringify(params)}`;
diff --git a/ui/src/services/client/search.ts b/ui/src/services/client/search.ts
index 0168da36..f5fe86fe 100644
--- a/ui/src/services/client/search.ts
+++ b/ui/src/services/client/search.ts
@@ -2,7 +2,7 @@ import useSWR from 'swr';
import qs from 'qs';
import request from '@answer/utils/request';
-import type * as Type from '../types';
+import type * as Type from '@answer/common/interface';
export const useSearch = (params?: Type.SearchParams) => {
const apiUrl = '/answer/api/v1/search';
diff --git a/ui/src/services/client/tag.ts b/ui/src/services/client/tag.ts
index b8830029..87e46743 100644
--- a/ui/src/services/client/tag.ts
+++ b/ui/src/services/client/tag.ts
@@ -2,7 +2,7 @@ import useSWR from 'swr';
import request from '@answer/utils/request';
import { isLogin } from '@answer/utils';
-import type * as Type from '../types';
+import type * as Type from '@answer/common/interface';
export const deleteTag = (id) => {
return request.delete('/answer/api/v1/tag', {
diff --git a/ui/src/services/common.ts b/ui/src/services/common.ts
index 913a8fab..21fa3916 100644
--- a/ui/src/services/common.ts
+++ b/ui/src/services/common.ts
@@ -2,8 +2,7 @@ import qs from 'qs';
import useSWR from 'swr';
import request from '@answer/utils/request';
-
-import type * as Type from './types';
+import type * as Type from '@answer/common/interface';
export const uploadImage = (file) => {
const form = new FormData();
diff --git a/ui/src/services/types.ts b/ui/src/services/types.ts
deleted file mode 100644
index 642c3326..00000000
--- a/ui/src/services/types.ts
+++ /dev/null
@@ -1,298 +0,0 @@
-export interface Paging {
- page: number;
- page_size?: number;
-}
-
-export type ReportType = 'question' | 'answer' | 'comment' | 'user';
-export type ReportAction = 'close' | 'flag' | 'review';
-export interface ReportParams {
- type: ReportType;
- action: ReportAction;
-}
-
-export interface TagBase {
- display_name: string;
- slug_name: string;
-}
-
-export interface Tag extends TagBase {
- main_tag_slug_name?: string;
- original_text?: string;
- parsed_text?: string;
-}
-
-export interface SynonymsTag extends Tag {
- tag_id: string;
- tag?: string;
-}
-
-export interface TagInfo extends TagBase {
- tag_id: string;
- original_text: string;
- parsed_text: string;
- follow_count: number;
- question_count: number;
- is_follower: boolean;
- member_actions;
- created_at?;
- updated_at?;
- main_tag_slug_name?: string;
- excerpt?;
-}
-export interface QuestionParams {
- title: string;
- content: string;
- html: string;
- tags: Tag[];
-}
-
-export interface ListResult<T = any> {
- count: number;
- list: T[];
-}
-
-export interface AnswerParams {
- content: string;
- html: string;
- question_id: string;
- id: string;
-}
-
-export interface LoginReqParams {
- e_mail: string;
- /** password */
- pass: string;
- captcha_id?: string;
- captcha_code?: string;
-}
-
-export interface RegisterReqParams extends LoginReqParams {
- name: string;
-}
-
-export interface ModifyPassReq {
- old_pass: string;
- pass: string;
-}
-
-/** User */
-export interface ModifyUserReq {
- display_name: string;
- username?: string;
- avatar: string;
- bio: string;
- bio_html?: string;
- location: string;
- website: string;
-}
-
-export interface UserInfoBase {
- avatar: string;
- username: string;
- display_name: string;
- rank: number;
- website: string;
- location: string;
- ip_info?: string;
- /** 'forbidden' | 'normal' | 'delete'
- */
- status?: string;
- /** roles */
- is_admin?: true;
-}
-
-export interface UserInfoRes extends UserInfoBase {
- bio: string;
- bio_html: string;
- create_time?: string;
- /** value = 1 active; value = 2 inactivated
- */
- mail_status: number;
- e_mail?: string;
- [prop: string]: any;
-}
-
-export interface AvatarUploadReq {
- file: FormData;
-}
-
-export interface ImgCodeReq {
- captcha_id?: string;
- captcha_code?: string;
-}
-
-export interface ImgCodeRes {
- captcha_id: string;
- captcha_img: string;
- verify: boolean;
-}
-
-export interface PssRetReq extends ImgCodeReq {
- e_mail: string;
-}
-
-export interface CheckImgReq {
- action: 'login' | 'e_mail' | 'find_pass';
-}
-
-export interface NoticeSetReq {
- notice_switch: boolean;
-}
-
-export interface QuDetailRes {
- id: string;
- title: string;
- content: string;
- html: string;
- tags: any[];
- view_count: number;
- unique_view_count?: number;
- answer_count: number;
- favorites_count: number;
- follow_counts: 0;
- accepted_answer_id: string;
- last_answer_id: string;
- create_time: string;
- update_time: string;
- user_info: UserInfoBase;
- answered: boolean;
- collected: boolean;
-
- [prop: string]: any;
-}
-
-export interface AnswersReq extends Paging {
- order?: 'default' | 'updated';
- question_id: string;
-}
-
-export interface AnswerItem {
- id: string;
- question_id: string;
- content: string;
- html: string;
- create_time: string;
- update_time: string;
- user_info: UserInfoBase;
-
- [prop: string]: any;
-}
-
-export interface PostAnswerReq {
- content: string;
- html: string;
- question_id: string;
-}
-
-export interface PageUser {
- id;
- displayName;
- userName?;
- avatar_url?;
-}
-
-export interface LangsType {
- label: string;
- value: string;
-}
-
-/**
- * @description interface for Question
- */
-export type QuestionOrderBy =
- | 'newest'
- | 'active'
- | 'frequent'
- | 'score'
- | 'unanswered';
-
-export interface QueryQuestionsReq extends Paging {
- order: QuestionOrderBy;
- tags?: string[];
-}
-
-export type AdminQuestionStatus = 'available' | 'closed' | 'deleted';
-
-export type AdminContentsFilterBy = 'normal' | 'closed' | 'deleted';
-
-export interface AdminContentsReq extends Paging {
- status: AdminContentsFilterBy;
-}
-
-/**
- * @description interface for Answer
- */
-export type AdminAnswerStatus = 'available' | 'deleted';
-
-/**
- * @description interface for Users
- */
-export type UserFilterBy = 'all' | 'inactive' | 'suspended' | 'deleted';
-
-/**
- * @description interface for Flags
- */
-export type FlagStatus = 'pending' | 'completed';
-export type FlagType = 'all' | 'question' | 'answer' | 'comment';
-export interface AdminFlagsReq extends Paging {
- status: FlagStatus;
- object_type: FlagType;
-}
-
-/**
- * @description interface for Admin Settings
- */
-export interface AdminSettingsGeneral {
- name: string;
- short_description: string;
- description: string;
-}
-
-export interface AdminSettingsInterface {
- logo: string;
- language: string;
- theme: string;
-}
-
-export interface SiteSettings {
- general: AdminSettingsGeneral;
- interface: AdminSettingsInterface;
-}
-/**
- * @description interface for Activity
- */
-export interface FollowParams {
- is_cancel: boolean;
- object_id: string;
-}
-
-/**
- * @description search request params
- */
-export interface SearchParams {
- q: string;
- order: string;
- page: number;
- size?: number;
-}
-
-/**
- * @description search response data
- */
-export interface SearchResItem {
- object_type: string;
- object: {
- id: string;
- title: string;
- excerpt: string;
- created_at: number;
- user_info: UserInfoBase;
- vote_count: number;
- answer_count: number;
- accepted: boolean;
- tags: TagBase[];
- };
-}
-export interface SearchRes extends ListResult<SearchResItem> {
- extra: any;
-}
diff --git a/ui/src/stores/userInfo.ts b/ui/src/stores/userInfo.ts
index d18e2d30..bbfb640e 100644
--- a/ui/src/stores/userInfo.ts
+++ b/ui/src/stores/userInfo.ts
@@ -1,6 +1,6 @@
import create from 'zustand';
-import type { UserInfoRes } from '@answer/services/types';
+import type { UserInfoRes } from '@answer/common/interface';
import Storage from '@answer/utils/storage';
interface UserInfoStore {