2021-06-19 17:37:12 -04:00
|
|
|
import { Text } from "preact-i18n";
|
|
|
|
import styles from "./Panes.module.scss";
|
|
|
|
import Tip from "../../../components/ui/Tip";
|
|
|
|
import Button from "../../../components/ui/Button";
|
|
|
|
import { Users } from "revolt.js/dist/api/objects";
|
|
|
|
import { Link, useHistory } from "react-router-dom";
|
|
|
|
import Overline from "../../../components/ui/Overline";
|
2021-07-04 15:33:05 -04:00
|
|
|
import { Envelope, Key } from "@styled-icons/boxicons-solid";
|
|
|
|
import { At } from "@styled-icons/boxicons-regular";
|
2021-06-19 17:37:12 -04:00
|
|
|
import { useContext, useEffect, useState } from "preact/hooks";
|
2021-06-20 15:30:42 -04:00
|
|
|
import UserIcon from "../../../components/common/user/UserIcon";
|
|
|
|
import { useForceUpdate, useSelf } from "../../../context/revoltjs/hooks";
|
2021-06-19 17:37:12 -04:00
|
|
|
import { useIntermediate } from "../../../context/intermediate/Intermediate";
|
2021-06-20 15:30:42 -04:00
|
|
|
import { ClientStatus, StatusContext } from "../../../context/revoltjs/RevoltClient";
|
2021-06-19 17:37:12 -04:00
|
|
|
|
|
|
|
export function Account() {
|
|
|
|
const { openScreen } = useIntermediate();
|
|
|
|
const status = useContext(StatusContext);
|
|
|
|
|
|
|
|
const ctx = useForceUpdate();
|
|
|
|
const user = useSelf(ctx);
|
|
|
|
if (!user) return null;
|
|
|
|
|
|
|
|
const [email, setEmail] = useState("...");
|
|
|
|
const [profile, setProfile] = useState<undefined | Users.Profile>(
|
|
|
|
undefined
|
|
|
|
);
|
|
|
|
const history = useHistory();
|
|
|
|
|
|
|
|
function switchPage(to: string) {
|
|
|
|
history.replace(`/settings/${to}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
if (email === "..." && status === ClientStatus.ONLINE) {
|
|
|
|
ctx.client
|
|
|
|
.req("GET", "/auth/user")
|
|
|
|
.then(account => setEmail(account.email));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (profile === undefined && status === ClientStatus.ONLINE) {
|
|
|
|
ctx.client.users
|
|
|
|
.fetchProfile(user._id)
|
|
|
|
.then(profile => setProfile(profile ?? {}));
|
|
|
|
}
|
|
|
|
}, [status]);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.user}>
|
|
|
|
<div className={styles.banner}>
|
2021-07-04 15:33:05 -04:00
|
|
|
<UserIcon className={styles.avatar} target={user} size={72} onClick={() => switchPage("profile")}/>
|
2021-06-19 17:37:12 -04:00
|
|
|
<div className={styles.username}>@{user.username}</div>
|
|
|
|
</div>
|
|
|
|
<div className={styles.details}>
|
2021-07-04 07:09:39 -04:00
|
|
|
{([
|
2021-06-27 06:17:59 -04:00
|
|
|
["username", user.username, <At size={24} />],
|
|
|
|
["email", email, <Envelope size={24} />],
|
2021-06-19 17:37:12 -04:00
|
|
|
["password", "*****", <Key size={24} />]
|
2021-07-04 07:09:39 -04:00
|
|
|
] as const).map(([field, value, icon]) => (
|
2021-06-19 17:37:12 -04:00
|
|
|
<div>
|
|
|
|
{icon}
|
|
|
|
<div className={styles.detail}>
|
|
|
|
<Overline>
|
|
|
|
<Text id={`login.${field}`} />
|
|
|
|
</Overline>
|
|
|
|
<p>{value}</p>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<Button
|
|
|
|
onClick={() =>
|
|
|
|
openScreen({
|
|
|
|
id: "modify_account",
|
2021-07-04 07:09:39 -04:00
|
|
|
field: field
|
2021-06-19 17:37:12 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
contrast
|
|
|
|
>
|
|
|
|
<Text id="app.settings.pages.account.change_field" />
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
))}
|
|
|
|
</div>
|
|
|
|
<Tip>
|
|
|
|
<span>
|
|
|
|
<Text id="app.settings.tips.account.a" />
|
|
|
|
</span>{" "}
|
|
|
|
<a onClick={() => switchPage("profile")}>
|
|
|
|
<Text id="app.settings.tips.account.b" />
|
|
|
|
</a>
|
|
|
|
</Tip>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|