Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(project): support delete account #1577

Merged
merged 2 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions desktop/renderer-app/src/api-middleware/flatServer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,3 +681,15 @@ export async function removeBinding(target: LoginPlatform): Promise<RemoveBindin
target,
});
}

export interface DeleteAccountValidateResult {
alreadyJoinedRoomCount: number;
}

export async function deleteAccountValidate(): Promise<DeleteAccountValidateResult> {
return await post<{}, DeleteAccountValidateResult>("user/deleteAccount/validate", {});
}

export async function deleteAccount(): Promise<void> {
await post<{}, {}>("user/deleteAccount", {});
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import "./style.less";

import React, { useContext, useEffect, useState } from "react";
import { Checkbox, Input, message, Radio, RadioChangeEvent } from "antd";
import { Button, Checkbox, Input, message, Modal, Radio, RadioChangeEvent } from "antd";
import { observer } from "mobx-react-lite";
import { useTranslation } from "react-i18next";
import { AppearancePicker, FlatPrefersColorScheme } from "flat-components";
Expand All @@ -10,12 +10,19 @@ import { UserSettingLayoutContainer } from "../UserSettingLayoutContainer";
import { ipcSyncByApp, ipcAsyncByApp } from "../../../utils/ipc";
import { ConfigStoreContext, GlobalStoreContext } from "../../../components/StoreProvider";
import { useSafePromise } from "../../../utils/hooks/lifecycle";
import { loginCheck, rename } from "../../../api-middleware/flatServer";
import {
deleteAccount,
deleteAccountValidate,
loginCheck,
rename,
} from "../../../api-middleware/flatServer";
import { ConfirmButtons } from "./ConfirmButtons";
import { UploadAvatar, uploadAvatar } from "./UploadAvatar";
import { useBindingList } from "./binding";
import { BindWeChat } from "./binding/WeChat";
import { BindGitHub } from "./binding/GitHub";
import { RouteNameType, usePushHistory } from "../../../utils/routes";
import { errorTips } from "../../../components/Tips/ErrorTips";

enum SelectLanguage {
Chinese,
Expand All @@ -24,6 +31,7 @@ enum SelectLanguage {

export const GeneralSettingPage = observer(function GeneralSettingPage() {
const sp = useSafePromise();
const pushHistory = usePushHistory();
const { t, i18n } = useTranslation();
const [openAtLogin, setOpenAtLogin] = useState(false);
const configStore = useContext(ConfigStoreContext);
Expand Down Expand Up @@ -81,6 +89,26 @@ export const GeneralSettingPage = observer(function GeneralSettingPage() {
configStore.updatePrefersColorScheme(prefersColorScheme);
};

async function removeAccount(): Promise<void> {
const { alreadyJoinedRoomCount } = await sp(deleteAccountValidate());
if (alreadyJoinedRoomCount > 0) {
message.error(t("quit-all-rooms-before-delete-account"));
return;
}
Modal.confirm({
content: t("confirm-delete-account"),
onOk: async () => {
try {
await sp(deleteAccount());
globalStore.updateUserInfo(null);
pushHistory(RouteNameType.LoginPage);
} catch (err) {
errorTips(err);
}
},
});
}

return (
<UserSettingLayoutContainer>
<div className="general-setting-container">
Expand Down Expand Up @@ -146,6 +174,14 @@ export const GeneralSettingPage = observer(function GeneralSettingPage() {
defaultValue={configStore.prefersColorScheme}
/>
</div>
<div className="general-setting-user-account">
<span className="general-setting-title">{t("delete-account")}</span>
<div>
<Button danger onClick={removeAccount}>
{t("delete-account")}
</Button>
</div>
</div>
</div>
</UserSettingLayoutContainer>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@
}
}

.general-setting-binding-profile {
.general-setting-binding-profile,
.general-setting-user-account {
padding-top: 12px;
}

Expand Down
5 changes: 4 additions & 1 deletion packages/flat-i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -465,5 +465,8 @@
"is-bind": "is bind",
"not-bind": "not bind",
"unbind-confirm": "Are you sure to unbind?",
"unbind-success": "Unbind success"
"unbind-success": "Unbind success",
"delete-account": "Delete Account",
"confirm-delete-account": "Are you sure to delete your account?",
"quit-all-rooms-before-delete-account": "Please quit all rooms before deleting account."
}
5 changes: 4 additions & 1 deletion packages/flat-i18n/locales/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -465,5 +465,8 @@
"is-bind": "已绑定",
"not-bind": "未绑定",
"unbind-confirm": "确定解除绑定吗?",
"unbind-success": "解绑成功"
"unbind-success": "解绑成功",
"delete-account": "账号注销",
"confirm-delete-account": "确定注销账号吗?",
"quit-all-rooms-before-delete-account": "请先退出所有房间"
}
12 changes: 12 additions & 0 deletions web/flat-web/src/api-middleware/flatServer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,3 +681,15 @@ export async function removeBinding(target: LoginPlatform): Promise<RemoveBindin
target,
});
}

export interface DeleteAccountValidateResult {
alreadyJoinedRoomCount: number;
}

export async function deleteAccountValidate(): Promise<DeleteAccountValidateResult> {
return await post<{}, DeleteAccountValidateResult>("user/deleteAccount/validate", {});
}

export async function deleteAccount(): Promise<void> {
await post<{}, {}>("user/deleteAccount", {});
}
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,8 @@
padding-bottom: 3px;
}

.general-setting-binding-profile {
.general-setting-binding-profile,
.general-setting-user-account {
padding-top: 12px;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@ import "./index.less";

import React, { useContext, useState } from "react";
import { observer } from "mobx-react-lite";
import { Checkbox, Input, message, Radio } from "antd";
import { Button, Checkbox, Input, message, Modal, Radio } from "antd";
import { FlatPrefersColorScheme, AppearancePicker } from "flat-components";
import { UserSettingLayoutContainer } from "../UserSettingLayoutContainer";
import { useTranslation } from "react-i18next";

import { ConfigStoreContext, GlobalStoreContext } from "../../../components/StoreProvider";
import { useSafePromise } from "../../../utils/hooks/lifecycle";
import { loginCheck, rename } from "../../../api-middleware/flatServer";
import {
deleteAccount,
deleteAccountValidate,
loginCheck,
rename,
} from "../../../api-middleware/flatServer";
import { ConfirmButtons } from "./ConfirmButtons";
import { uploadAvatar, UploadAvatar } from "./UploadAvatar";
import { BindWeChat } from "./binding/WeChat";
import { useBindingList } from "./binding";
import { BindGitHub } from "./binding/GitHub";
import { errorTips } from "../../../components/Tips/ErrorTips";
import { RouteNameType, usePushHistory } from "../../../utils/routes";

enum SelectLanguage {
Chinese,
Expand All @@ -28,6 +35,7 @@ export const GeneralSettingPage = observer(function GeneralSettingPage() {
const configStore = useContext(ConfigStoreContext);

const sp = useSafePromise();
const pushHistory = usePushHistory();
const { t, i18n } = useTranslation();

const [name, setName] = useState(globalStore.userName || "");
Expand Down Expand Up @@ -65,6 +73,26 @@ export const GeneralSettingPage = observer(function GeneralSettingPage() {
configStore.updatePrefersColorScheme(prefersColorScheme);
};

async function removeAccount(): Promise<void> {
const { alreadyJoinedRoomCount } = await sp(deleteAccountValidate());
if (alreadyJoinedRoomCount > 0) {
message.error(t("quit-all-rooms-before-delete-account"));
return;
}
Modal.confirm({
content: t("confirm-delete-account"),
onOk: async () => {
try {
await sp(deleteAccount());
globalStore.updateUserInfo(null);
pushHistory(RouteNameType.LoginPage);
} catch (err) {
errorTips(err);
}
},
});
}

return (
<UserSettingLayoutContainer>
<div className="general-setting-container">
Expand Down Expand Up @@ -134,6 +162,14 @@ export const GeneralSettingPage = observer(function GeneralSettingPage() {
<span className="checkbox-item-inner">{t("turn-on-device-test")}</span>
</Checkbox>
</div>
<div className="general-setting-user-account">
<span className="general-setting-title">{t("delete-account")}</span>
<div>
<Button danger onClick={removeAccount}>
{t("delete-account")}
</Button>
</div>
</div>
</div>
</UserSettingLayoutContainer>
);
Expand Down