2021-07-04 15:33:05 -04:00
|
|
|
import { At } from "@styled-icons/boxicons-regular";
|
2021-07-06 07:16:29 -04:00
|
|
|
import { Envelope, Key, HelpCircle } from "@styled-icons/boxicons-solid";
|
2021-07-05 06:23:23 -04:00
|
|
|
import { Link, useHistory } from "react-router-dom";
|
|
|
|
import { Users } from "revolt.js/dist/api/objects";
|
|
|
|
|
|
|
|
import styles from "./Panes.module.scss";
|
|
|
|
import { Text } from "preact-i18n";
|
2021-06-19 17:37:12 -04:00
|
|
|
import { useContext, useEffect, useState } from "preact/hooks";
|
2021-07-05 06:23:23 -04:00
|
|
|
|
2021-06-19 17:37:12 -04:00
|
|
|
import { useIntermediate } from "../../../context/intermediate/Intermediate";
|
2021-07-05 06:23:23 -04:00
|
|
|
import {
|
2021-07-05 06:25:20 -04:00
|
|
|
ClientStatus,
|
|
|
|
StatusContext,
|
2021-07-05 06:23:23 -04:00
|
|
|
} from "../../../context/revoltjs/RevoltClient";
|
|
|
|
import { useForceUpdate, useSelf } from "../../../context/revoltjs/hooks";
|
|
|
|
|
|
|
|
import UserIcon from "../../../components/common/user/UserIcon";
|
|
|
|
import Button from "../../../components/ui/Button";
|
|
|
|
import Overline from "../../../components/ui/Overline";
|
2021-07-06 07:36:32 -04:00
|
|
|
import Tooltip from "../../../components/common/Tooltip";
|
2021-07-05 06:23:23 -04:00
|
|
|
import Tip from "../../../components/ui/Tip";
|
2021-06-19 17:37:12 -04:00
|
|
|
|
|
|
|
export function Account() {
|
2021-07-05 06:25:20 -04:00
|
|
|
const { openScreen } = useIntermediate();
|
|
|
|
const status = useContext(StatusContext);
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
const ctx = useForceUpdate();
|
|
|
|
const user = useSelf(ctx);
|
|
|
|
if (!user) return null;
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
const [email, setEmail] = useState("...");
|
|
|
|
const [profile, setProfile] = useState<undefined | Users.Profile>(
|
|
|
|
undefined,
|
|
|
|
);
|
|
|
|
const history = useHistory();
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
function switchPage(to: string) {
|
|
|
|
history.replace(`/settings/${to}`);
|
|
|
|
}
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
useEffect(() => {
|
|
|
|
if (email === "..." && status === ClientStatus.ONLINE) {
|
|
|
|
ctx.client
|
|
|
|
.req("GET", "/auth/user")
|
|
|
|
.then((account) => setEmail(account.email));
|
|
|
|
}
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
if (profile === undefined && status === ClientStatus.ONLINE) {
|
|
|
|
ctx.client.users
|
|
|
|
.fetchProfile(user._id)
|
|
|
|
.then((profile) => setProfile(profile ?? {}));
|
|
|
|
}
|
|
|
|
}, [status]);
|
2021-06-19 17:37:12 -04:00
|
|
|
|
2021-07-05 06:25:20 -04:00
|
|
|
return (
|
|
|
|
<div className={styles.user}>
|
|
|
|
<div className={styles.banner}>
|
|
|
|
<UserIcon
|
|
|
|
className={styles.avatar}
|
|
|
|
target={user}
|
|
|
|
size={72}
|
|
|
|
onClick={() => switchPage("profile")}
|
|
|
|
/>
|
2021-07-06 07:16:29 -04:00
|
|
|
<div className={styles.userDetail}>
|
|
|
|
<div className={styles.username}>@{user.username}</div>
|
2021-07-06 07:36:32 -04:00
|
|
|
<div className={styles.userid}>
|
2021-07-06 08:24:24 -04:00
|
|
|
<Tooltip content={<Text id="app.settings.pages.account.tooltip_ulid" />}>
|
2021-07-06 07:36:32 -04:00
|
|
|
<HelpCircle size={16} />
|
|
|
|
</Tooltip>
|
|
|
|
{user._id}
|
|
|
|
</div>
|
2021-07-06 07:16:29 -04:00
|
|
|
</div>
|
2021-07-05 06:25:20 -04:00
|
|
|
</div>
|
|
|
|
<div className={styles.details}>
|
|
|
|
{(
|
|
|
|
[
|
|
|
|
["username", user.username, <At size={24} />],
|
|
|
|
["email", email, <Envelope size={24} />],
|
2021-07-05 17:49:57 -04:00
|
|
|
["password", "***********", <Key size={24} />],
|
2021-07-05 06:25:20 -04:00
|
|
|
] as const
|
|
|
|
).map(([field, value, icon]) => (
|
|
|
|
<div>
|
|
|
|
{icon}
|
|
|
|
<div className={styles.detail}>
|
2021-07-05 17:49:57 -04:00
|
|
|
<div className={styles.subtext}>
|
2021-07-05 06:25:20 -04:00
|
|
|
<Text id={`login.${field}`} />
|
2021-07-05 17:49:57 -04:00
|
|
|
</div>
|
2021-07-05 06:25:20 -04:00
|
|
|
<p>{value}</p>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<Button
|
|
|
|
onClick={() =>
|
|
|
|
openScreen({
|
|
|
|
id: "modify_account",
|
|
|
|
field: field,
|
|
|
|
})
|
|
|
|
}
|
|
|
|
contrast>
|
|
|
|
<Text id="app.settings.pages.account.change_field" />
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
2021-07-06 08:24:24 -04:00
|
|
|
{/*<h3><Text id="app.settings.pages.account.two_factor_auth.title" /></h3>
|
|
|
|
<h5><Text id="app.settings.pages.account.two_factor_auth.description" /></h5>
|
|
|
|
<Button accent compact>
|
|
|
|
<Text id="app.settings.pages.account.two_factor_auth.add_auth" />
|
2021-07-05 17:49:57 -04:00
|
|
|
</Button>*/}
|
2021-07-06 08:24:24 -04:00
|
|
|
<h3><Text id="app.settings.pages.account.account_management.title" /></h3>
|
|
|
|
<h5><Text id="app.settings.pages.account.account_management.description" /></h5>
|
|
|
|
<div className={styles.buttons}>
|
|
|
|
{/*<Button error compact>
|
|
|
|
<Text id="app.settings.pages.account.account_management.disable_account" />
|
|
|
|
</Button>*/}
|
|
|
|
<Button error compact>
|
|
|
|
<Text id="app.settings.pages.account.account_management.delete_account" />
|
|
|
|
</Button>
|
|
|
|
</div>
|
2021-07-05 06:25:20 -04: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-06-19 17:37:12 -04:00
|
|
|
}
|