2021-12-23 16:46:50 +01:00
|
|
|
import { At, Key, Block, ListOl } from "@styled-icons/boxicons-regular";
|
2021-08-04 16:03:38 +01:00
|
|
|
import {
|
|
|
|
Envelope,
|
|
|
|
HelpCircle,
|
|
|
|
Lock,
|
|
|
|
Trash,
|
2021-12-20 20:48:37 +00:00
|
|
|
Pencil,
|
2021-08-04 16:03:38 +01:00
|
|
|
} from "@styled-icons/boxicons-solid";
|
2021-07-29 15:11:21 +01:00
|
|
|
import { observer } from "mobx-react-lite";
|
2021-08-05 14:47:00 +01:00
|
|
|
import { useHistory } from "react-router-dom";
|
2021-07-30 20:24:53 +01:00
|
|
|
import { Profile } from "revolt-api/types/Users";
|
2021-07-05 11:23:23 +01:00
|
|
|
|
|
|
|
import styles from "./Panes.module.scss";
|
|
|
|
import { Text } from "preact-i18n";
|
2021-06-19 22:37:12 +01:00
|
|
|
import { useContext, useEffect, useState } from "preact/hooks";
|
2021-07-05 11:23:23 +01:00
|
|
|
|
2021-08-04 16:03:38 +01:00
|
|
|
import { stopPropagation } from "../../../lib/stopPropagation";
|
|
|
|
|
2021-06-19 22:37:12 +01:00
|
|
|
import { useIntermediate } from "../../../context/intermediate/Intermediate";
|
2021-07-05 11:23:23 +01:00
|
|
|
import {
|
2021-07-05 11:25:20 +01:00
|
|
|
ClientStatus,
|
|
|
|
StatusContext,
|
2021-07-29 15:11:21 +01:00
|
|
|
useClient,
|
2021-07-05 11:23:23 +01:00
|
|
|
} from "../../../context/revoltjs/RevoltClient";
|
|
|
|
|
2021-07-06 19:29:27 +01:00
|
|
|
import Tooltip from "../../../components/common/Tooltip";
|
2021-07-05 11:23:23 +01:00
|
|
|
import UserIcon from "../../../components/common/user/UserIcon";
|
|
|
|
import Button from "../../../components/ui/Button";
|
|
|
|
import Tip from "../../../components/ui/Tip";
|
2021-08-04 16:03:38 +01:00
|
|
|
import CategoryButton from "../../../components/ui/fluent/CategoryButton";
|
2021-06-19 22:37:12 +01:00
|
|
|
|
2021-07-29 15:11:21 +01:00
|
|
|
export const Account = observer(() => {
|
2021-07-06 13:29:11 +01:00
|
|
|
const { openScreen, writeClipboard } = useIntermediate();
|
2021-07-05 11:25:20 +01:00
|
|
|
const status = useContext(StatusContext);
|
2021-06-19 22:37:12 +01:00
|
|
|
|
2021-07-29 15:11:21 +01:00
|
|
|
const client = useClient();
|
2021-06-19 22:37:12 +01:00
|
|
|
|
2021-07-05 11:25:20 +01:00
|
|
|
const [email, setEmail] = useState("...");
|
2021-07-06 13:29:11 +01:00
|
|
|
const [revealEmail, setRevealEmail] = useState(false);
|
2021-07-30 20:24:53 +01:00
|
|
|
const [profile, setProfile] = useState<undefined | Profile>(undefined);
|
2021-07-05 11:25:20 +01:00
|
|
|
const history = useHistory();
|
2021-06-19 22:37:12 +01:00
|
|
|
|
2021-07-05 11:25:20 +01:00
|
|
|
function switchPage(to: string) {
|
|
|
|
history.replace(`/settings/${to}`);
|
|
|
|
}
|
2021-06-19 22:37:12 +01:00
|
|
|
|
2021-07-05 11:25:20 +01:00
|
|
|
useEffect(() => {
|
|
|
|
if (email === "..." && status === ClientStatus.ONLINE) {
|
2021-07-29 15:11:21 +01:00
|
|
|
client
|
2021-09-11 17:36:23 +01:00
|
|
|
.req("GET", "/auth/account")
|
2021-07-05 11:25:20 +01:00
|
|
|
.then((account) => setEmail(account.email));
|
|
|
|
}
|
2021-06-19 22:37:12 +01:00
|
|
|
|
2021-07-05 11:25:20 +01:00
|
|
|
if (profile === undefined && status === ClientStatus.ONLINE) {
|
2021-07-30 20:24:53 +01:00
|
|
|
client
|
|
|
|
.user!.fetchProfile()
|
2021-07-05 11:25:20 +01:00
|
|
|
.then((profile) => setProfile(profile ?? {}));
|
|
|
|
}
|
2021-08-05 14:47:00 +01:00
|
|
|
}, [client, email, profile, status]);
|
2021-06-19 22:37:12 +01:00
|
|
|
|
2021-07-05 11:25:20 +01:00
|
|
|
return (
|
|
|
|
<div className={styles.user}>
|
|
|
|
<div className={styles.banner}>
|
2021-08-04 12:56:59 +02:00
|
|
|
<div className={styles.container}>
|
|
|
|
<UserIcon
|
|
|
|
className={styles.avatar}
|
|
|
|
target={client.user!}
|
|
|
|
size={72}
|
|
|
|
onClick={() => switchPage("profile")}
|
|
|
|
/>
|
|
|
|
<div className={styles.userDetail}>
|
2021-12-20 13:37:21 +00:00
|
|
|
<div className={styles.userContainer}>
|
|
|
|
<UserIcon
|
|
|
|
className={styles.tinyavatar}
|
|
|
|
target={client.user!}
|
|
|
|
size={25}
|
|
|
|
onClick={() => switchPage("profile")}
|
|
|
|
/>
|
|
|
|
<div className={styles.username}>
|
|
|
|
@{client.user!.username}
|
|
|
|
</div>
|
|
|
|
</div>
|
2021-08-04 12:56:59 +02:00
|
|
|
<div className={styles.userid}>
|
2021-08-04 16:03:38 +01:00
|
|
|
<Tooltip
|
|
|
|
content={
|
|
|
|
<Text id="app.settings.pages.account.unique_id" />
|
|
|
|
}>
|
2021-08-04 12:56:59 +02:00
|
|
|
<HelpCircle size={16} />
|
|
|
|
</Tooltip>
|
|
|
|
<Tooltip content={<Text id="app.special.copy" />}>
|
2021-08-04 16:03:38 +01:00
|
|
|
<a
|
|
|
|
onClick={() =>
|
|
|
|
writeClipboard(client.user!._id)
|
|
|
|
}>
|
2021-08-04 12:56:59 +02:00
|
|
|
{client.user!._id}
|
|
|
|
</a>
|
|
|
|
</Tooltip>
|
|
|
|
</div>
|
2021-07-06 13:36:32 +02:00
|
|
|
</div>
|
2021-07-06 13:16:29 +02:00
|
|
|
</div>
|
2021-08-04 16:03:38 +01:00
|
|
|
|
|
|
|
<Button onClick={() => switchPage("profile")} contrast>
|
|
|
|
<Text id="app.settings.pages.profile.edit_profile" />
|
2021-08-04 12:56:59 +02:00
|
|
|
</Button>
|
2021-07-05 11:25:20 +01:00
|
|
|
</div>
|
2021-08-04 16:03:38 +01:00
|
|
|
<div>
|
2021-07-05 11:25:20 +01:00
|
|
|
{(
|
|
|
|
[
|
2021-08-05 14:47:00 +01:00
|
|
|
[
|
|
|
|
"username",
|
|
|
|
client.user!.username,
|
|
|
|
<At key="at" size={24} />,
|
|
|
|
],
|
|
|
|
["email", email, <Envelope key="envelope" size={24} />],
|
|
|
|
["password", "•••••••••", <Key key="key" size={24} />],
|
2021-07-05 11:25:20 +01:00
|
|
|
] as const
|
|
|
|
).map(([field, value, icon]) => (
|
2021-08-04 16:03:38 +01:00
|
|
|
<CategoryButton
|
2021-08-05 14:47:00 +01:00
|
|
|
key={field}
|
2021-08-04 16:03:38 +01:00
|
|
|
icon={icon}
|
|
|
|
description={
|
|
|
|
field === "email" ? (
|
|
|
|
revealEmail ? (
|
|
|
|
<>
|
|
|
|
{value}{" "}
|
|
|
|
<a
|
2021-12-20 13:37:21 +00:00
|
|
|
style={{ fontSize: "13px" }}
|
2021-08-04 16:03:38 +01:00
|
|
|
onClick={(ev) =>
|
|
|
|
stopPropagation(
|
|
|
|
ev,
|
|
|
|
setRevealEmail(false),
|
|
|
|
)
|
|
|
|
}>
|
|
|
|
<Text id="app.special.modals.actions.hide" />
|
|
|
|
</a>
|
|
|
|
</>
|
2021-07-06 19:29:27 +01:00
|
|
|
) : (
|
2021-08-04 16:03:38 +01:00
|
|
|
<>
|
2021-11-14 14:26:35 +00:00
|
|
|
•••••••••••@••••••.•••{" "}
|
2021-08-04 16:03:38 +01:00
|
|
|
<a
|
2021-12-20 13:37:21 +00:00
|
|
|
style={{ fontSize: "13px" }}
|
2021-08-04 16:03:38 +01:00
|
|
|
onClick={(ev) =>
|
|
|
|
stopPropagation(
|
|
|
|
ev,
|
|
|
|
setRevealEmail(true),
|
|
|
|
)
|
|
|
|
}>
|
|
|
|
<Text id="app.special.modals.actions.reveal" />
|
|
|
|
</a>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
) : (
|
|
|
|
value
|
|
|
|
)
|
|
|
|
}
|
2021-08-04 18:33:01 +02:00
|
|
|
account
|
2021-12-20 20:48:37 +00:00
|
|
|
action={<Pencil size={20} />}
|
2021-08-04 16:03:38 +01:00
|
|
|
onClick={() =>
|
|
|
|
openScreen({
|
|
|
|
id: "modify_account",
|
|
|
|
field,
|
|
|
|
})
|
|
|
|
}>
|
2021-08-04 18:33:01 +02:00
|
|
|
<Text id={`login.${field}`} />
|
2021-08-04 16:03:38 +01:00
|
|
|
</CategoryButton>
|
2021-07-05 11:25:20 +01:00
|
|
|
))}
|
|
|
|
</div>
|
2021-12-23 16:46:50 +01:00
|
|
|
<hr />
|
2021-07-06 19:29:27 +01:00
|
|
|
<h3>
|
|
|
|
<Text id="app.settings.pages.account.2fa.title" />
|
|
|
|
</h3>
|
2021-08-04 16:03:38 +01:00
|
|
|
<h5>
|
2021-08-04 20:00:30 +02:00
|
|
|
{/*<Text id="app.settings.pages.account.2fa.description" />*/}
|
2021-08-05 14:47:00 +01:00
|
|
|
Two-factor authentication is currently work-in-progress, see{" "}
|
|
|
|
{` `}
|
2021-08-04 20:00:30 +02:00
|
|
|
<a
|
2021-09-03 10:30:27 +01:00
|
|
|
href="https://github.com/insertish/rauth/milestone/1"
|
2021-08-04 20:00:30 +02:00
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer">
|
2021-09-03 10:30:27 +01:00
|
|
|
v1 milestone here
|
2021-08-05 14:47:00 +01:00
|
|
|
</a>
|
|
|
|
.
|
2021-08-04 16:03:38 +01:00
|
|
|
</h5>
|
|
|
|
<CategoryButton
|
|
|
|
icon={<Lock size={24} color="var(--error)" />}
|
2021-12-20 20:48:37 +00:00
|
|
|
description={"Set up 2FA on your account."}
|
2021-08-04 16:43:08 +01:00
|
|
|
disabled
|
2021-12-23 16:46:50 +01:00
|
|
|
action={<Text id="general.unavailable" />}>
|
2021-08-04 20:00:30 +02:00
|
|
|
Set up Two-factor authentication
|
2021-08-04 16:03:38 +01:00
|
|
|
</CategoryButton>
|
2021-12-23 16:46:50 +01:00
|
|
|
{/*<CategoryButton
|
|
|
|
icon={<ListOl size={24} />}
|
|
|
|
description={"View and download your 2FA backup codes."}
|
|
|
|
disabled
|
|
|
|
action="chevron">
|
|
|
|
View my backup codes
|
|
|
|
</CategoryButton>*/}
|
|
|
|
<hr />
|
2021-07-06 19:29:27 +01:00
|
|
|
<h3>
|
|
|
|
<Text id="app.settings.pages.account.manage.title" />
|
|
|
|
</h3>
|
|
|
|
<h5>
|
|
|
|
<Text id="app.settings.pages.account.manage.description" />
|
|
|
|
</h5>
|
2021-08-04 16:03:38 +01:00
|
|
|
<CategoryButton
|
|
|
|
icon={<Block size={24} color="var(--error)" />}
|
|
|
|
description={
|
|
|
|
"Disable your account. You won't be able to access it unless you log back in."
|
|
|
|
}
|
2021-08-04 16:43:08 +01:00
|
|
|
disabled
|
|
|
|
action={<Text id="general.unavailable" />}>
|
2021-08-04 16:03:38 +01:00
|
|
|
<Text id="app.settings.pages.account.manage.disable" />
|
|
|
|
</CategoryButton>
|
2021-08-04 16:43:08 +01:00
|
|
|
<a href="mailto:contact@revolt.chat?subject=Delete%20my%20account">
|
|
|
|
<CategoryButton
|
|
|
|
icon={<Trash size={24} color="var(--error)" />}
|
|
|
|
description={
|
2021-09-19 13:47:25 +01:00
|
|
|
"Delete your account, including all of your data. (sends an email to contact@revolt.chat)"
|
2021-08-04 16:43:08 +01:00
|
|
|
}
|
2021-08-05 14:47:00 +01:00
|
|
|
hover
|
2021-08-04 16:43:08 +01:00
|
|
|
action="external">
|
|
|
|
<Text id="app.settings.pages.account.manage.delete" />
|
|
|
|
</CategoryButton>
|
|
|
|
</a>
|
2021-07-05 11:25:20 +01:00
|
|
|
<Tip>
|
|
|
|
<span>
|
|
|
|
<Text id="app.settings.tips.account.a" />
|
|
|
|
</span>{" "}
|
|
|
|
<a onClick={() => switchPage("profile")}>
|
|
|
|
<Text id="app.settings.tips.account.b" />
|
|
|
|
</a>
|
|
|
|
</Tip>
|
|
|
|
</div>
|
|
|
|
);
|
2021-07-29 15:11:21 +01:00
|
|
|
});
|