Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 12x 9x 31x 31x 31x 31x 31x 31x 9x 2x | import { Collapse, styled } from "@mui/material";
import Alert from "components/Alert";
import CenteredSpinner from "components/CenteredSpinner/CenteredSpinner";
import HtmlMeta from "components/HtmlMeta";
import Snackbar from "components/Snackbar";
import { ProfileUserProvider } from "features/profile/hooks/useProfileUser";
import NewHostRequest from "features/profile/view/NewHostRequest";
import Overview from "features/profile/view/Overview";
import useUserByUsername from "features/userQueries/useUserByUsername";
import { useTranslation } from "i18n";
import { PROFILE } from "i18n/namespaces";
import { useRouter } from "next/router";
import { useLayoutEffect, useState } from "react";
import { routeToUser, UserTab } from "routes";
import UserCard from "./UserCard";
const REQUEST_ID = "request";
export const StyledProfileRoot = styled("div")(({ theme }) => ({
padding: theme.spacing(1),
[theme.breakpoints.up("sm")]: {
display: "grid",
gridTemplateColumns: "2fr 3fr",
gap: theme.spacing(3),
margin: theme.spacing(0, 3),
padding: 0,
paddingTop: theme.spacing(3),
paddingBottom: theme.spacing(3),
},
[theme.breakpoints.up("md")]: {
gridTemplateColumns: "2fr 4fr",
maxWidth: "61.5rem",
margin: "0 auto",
},
}));
export default function UserPage({
username,
tab = "about",
}: {
username: string;
tab?: UserTab;
}) {
const { t } = useTranslation(PROFILE);
const router = useRouter();
const { data: user, isLoading, error } = useUserByUsername(username, true);
const [isRequesting, setIsRequesting] = useState(false);
const [isSuccessRequest, setIsSuccessRequest] = useState(false);
useLayoutEffect(() => {
Iif (isRequesting) {
const requestEl = document.getElementById(REQUEST_ID);
requestEl?.scrollIntoView();
}
}, [isRequesting]);
return (
<>
<HtmlMeta title={user?.name} />
{isSuccessRequest && (
<Snackbar severity="success">{t("request_form.success")}</Snackbar>
)}
{error && <Alert severity="error">{error}</Alert>}
{isLoading ? (
<CenteredSpinner />
) : user ? (
<ProfileUserProvider user={user}>
<StyledProfileRoot>
<Overview setIsRequesting={setIsRequesting} tab={tab} />
<UserCard
tab={tab}
onTabChange={(newTab) => {
router.push(routeToUser(user.username, newTab));
}}
top={
<Collapse in={isRequesting}>
<NewHostRequest
setIsRequesting={setIsRequesting}
setIsRequestSuccess={setIsSuccessRequest}
/>
</Collapse>
}
/>
</StyledProfileRoot>
</ProfileUserProvider>
) : null}
</>
);
}
|