2021-08-04 12:21:29 +02:00
|
|
|
import { At, Key } from "@styled-icons/boxicons-regular";
|
|
|
|
import { Envelope, HelpCircle } from "@styled-icons/boxicons-solid";
|
2021-07-29 15:11:21 +01:00
|
|
|
import { observer } from "mobx-react-lite";
|
2021-07-05 11:23:23 +01:00
|
|
|
import { Link, 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-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-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-07-05 11:25:20 +01:00
|
|
|
.req("GET", "/auth/user")
|
|
|
|
.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 ?? {}));
|
|
|
|
}
|
|
|
|
}, [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}>
|
|
|
|
<UserIcon
|
|
|
|
className={styles.avatar}
|
2021-07-30 20:24:53 +01:00
|
|
|
target={client.user!}
|
2021-07-05 11:25:20 +01:00
|
|
|
size={72}
|
|
|
|
onClick={() => switchPage("profile")}
|
|
|
|
/>
|
2021-07-06 13:16:29 +02:00
|
|
|
<div className={styles.userDetail}>
|
2021-08-04 11:51:53 +02:00
|
|
|
@{client.user!.username}
|
2021-07-06 13:36:32 +02:00
|
|
|
<div className={styles.userid}>
|
2021-08-04 11:51:53 +02:00
|
|
|
<Tooltip content={<Text id="app.settings.pages.account.unique_id" />}>
|
2021-07-06 13:36:32 +02:00
|
|
|
<HelpCircle size={16} />
|
|
|
|
</Tooltip>
|
2021-07-06 13:29:11 +01:00
|
|
|
<Tooltip content={<Text id="app.special.copy" />}>
|
2021-07-30 20:24:53 +01:00
|
|
|
<a onClick={() => writeClipboard(client.user!._id)}>
|
|
|
|
{client.user!._id}
|
2021-07-06 13:29:11 +01:00
|
|
|
</a>
|
|
|
|
</Tooltip>
|
2021-07-06 13:36:32 +02:00
|
|
|
</div>
|
2021-07-06 13:16:29 +02:00
|
|
|
</div>
|
2021-07-05 11:25:20 +01:00
|
|
|
</div>
|
|
|
|
<div className={styles.details}>
|
|
|
|
{(
|
|
|
|
[
|
2021-07-30 20:24:53 +01:00
|
|
|
["username", client.user!.username, <At size={24} />],
|
2021-07-05 11:25:20 +01:00
|
|
|
["email", email, <Envelope size={24} />],
|
2021-08-04 12:21:29 +02:00
|
|
|
["password", "•••••••••", <Key size={24} />],
|
2021-07-05 11:25:20 +01:00
|
|
|
] as const
|
|
|
|
).map(([field, value, icon]) => (
|
|
|
|
<div>
|
|
|
|
{icon}
|
|
|
|
<div className={styles.detail}>
|
2021-07-05 23:49:57 +02:00
|
|
|
<div className={styles.subtext}>
|
2021-07-05 11:25:20 +01:00
|
|
|
<Text id={`login.${field}`} />
|
2021-07-05 23:49:57 +02:00
|
|
|
</div>
|
2021-08-04 12:21:29 +02:00
|
|
|
<div className={styles.entry}>
|
2021-07-06 19:29:27 +01:00
|
|
|
{field === "email" ? (
|
|
|
|
revealEmail ? (
|
|
|
|
value
|
|
|
|
) : (
|
|
|
|
<>
|
2021-08-04 12:21:29 +02:00
|
|
|
•••••••••••@{value.split("@").pop()}{" "}
|
2021-07-06 19:29:27 +01:00
|
|
|
<a
|
|
|
|
onClick={() =>
|
|
|
|
setRevealEmail(true)
|
|
|
|
}>
|
|
|
|
<Text id="app.special.modals.actions.reveal" />
|
|
|
|
</a>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
) : (
|
|
|
|
value
|
|
|
|
)}
|
2021-08-04 12:21:29 +02:00
|
|
|
</div>
|
2021-07-05 11:25:20 +01:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<Button
|
|
|
|
onClick={() =>
|
|
|
|
openScreen({
|
|
|
|
id: "modify_account",
|
2021-07-10 15:57:29 +01:00
|
|
|
field,
|
2021-07-05 11:25:20 +01:00
|
|
|
})
|
|
|
|
}
|
2021-08-04 12:22:48 +02:00
|
|
|
plain>
|
2021-07-05 11:25:20 +01:00
|
|
|
<Text id="app.settings.pages.account.change_field" />
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
2021-07-06 19:29:27 +01:00
|
|
|
<h3>
|
|
|
|
<Text id="app.settings.pages.account.account_management.title" />
|
|
|
|
</h3>
|
|
|
|
<h5>
|
|
|
|
<Text id="app.settings.pages.account.account_management.description" />
|
|
|
|
</h5>
|
|
|
|
<h3>
|
|
|
|
<Text id="app.settings.pages.account.2fa.title" />
|
|
|
|
</h3>
|
|
|
|
<h5>
|
|
|
|
Currently work in progress, see{" "}
|
|
|
|
<a
|
|
|
|
href="https://gitlab.insrt.uk/insert/rauth/-/issues/2"
|
2021-07-10 15:57:29 +01:00
|
|
|
target="_blank"
|
|
|
|
rel="noreferrer">
|
2021-07-06 19:29:27 +01:00
|
|
|
tracking issue here
|
|
|
|
</a>
|
|
|
|
.
|
|
|
|
</h5>
|
2021-07-06 13:29:11 +01:00
|
|
|
{/*<h5><Text id="app.settings.pages.account.two_factor_auth.description" /></h5>
|
2021-07-06 14:24:24 +02:00
|
|
|
<Button accent compact>
|
|
|
|
<Text id="app.settings.pages.account.two_factor_auth.add_auth" />
|
2021-07-05 23:49:57 +02:00
|
|
|
</Button>*/}
|
2021-07-06 13:29:11 +01:00
|
|
|
|
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-07-06 14:24:24 +02:00
|
|
|
<div className={styles.buttons}>
|
2021-07-06 13:29:11 +01:00
|
|
|
{/* <Button contrast>
|
|
|
|
<Text id="app.settings.pages.account.manage.disable" />
|
|
|
|
</Button> */}
|
|
|
|
<a href="mailto:contact@revolt.chat?subject=Delete%20my%20account">
|
2021-07-06 15:03:48 +02:00
|
|
|
<Button error compact>
|
2021-07-06 13:29:11 +01:00
|
|
|
<Text id="app.settings.pages.account.manage.delete" />
|
|
|
|
</Button>
|
|
|
|
</a>
|
2021-07-06 14:24:24 +02:00
|
|
|
</div>
|
2021-07-06 13:29:11 +01:00
|
|
|
|
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
|
|
|
});
|