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 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 16x 2x 5x 5x 5x 16x 16x 16x 16x 16x 16x 16x 14x 14x 14x | import { Edit } from "@mui/icons-material";
import { styled } from "@mui/material";
import Alert from "components/Alert";
import Button from "components/Button";
import ProfileIncompleteDialog from "components/ProfileIncompleteDialog/ProfileIncompleteDialog";
import { doAntibot } from "features/antibot/antibot";
import { useAuthContext } from "features/auth/AuthProvider";
import useAccountInfo from "features/auth/useAccountInfo";
import FriendActions from "features/profile/actions/FriendActions";
import MessageUserButton from "features/profile/actions/MessageUserButton";
import UserOverview from "features/profile/view/UserOverview";
import { GLOBAL, PROFILE } from "i18n/namespaces";
import Link from "next/link";
import { useTranslation } from "next-i18next";
import { HostingStatus } from "proto/api_pb";
import { useState } from "react";
import {
connectionsRoute,
EditUserTab,
routeToEditProfile,
UserTab,
} from "routes";
import { theme } from "theme";
import { useProfileUser } from "../hooks/useProfileUser";
import AdminPanelUserButton from "./AdminPanelUserButton";
import ProfileReportFlagButton from "./ProfileReportFlagButton";
const StyledModButtons = styled("div")(({ theme }) => ({
display: "flex",
flexDirection: "column",
alignItems: "center",
width: "100%",
}));
const getEditTab = (tab: UserTab): EditUserTab | undefined => {
switch (tab) {
case "about":
case "home":
return tab;
default:
return undefined;
}
};
function LoggedInUserActions({ tab }: { tab: UserTab }) {
const { t } = useTranslation([GLOBAL, PROFILE]);
return (
<>
<Button
component={Link}
color="primary"
href={routeToEditProfile(getEditTab(tab))}
startIcon={<Edit fontSize="small" sx={{ color: "common.white" }} />}
>
{t("profile:edit")}
</Button>
<Button
component={Link}
variant="outlined"
sx={{
color: theme.palette.common.black,
borderColor: theme.palette.grey[300],
"&:hover": {
borderColor: theme.palette.grey[300],
backgroundColor: "#3135390A",
},
}}
href={connectionsRoute}
>
{t("profile:my_connections")}
</Button>
</>
);
}
function DefaultActions({
setIsRequesting,
}: {
setIsRequesting: (value: boolean) => void;
}) {
const { t } = useTranslation([GLOBAL, PROFILE]);
const user = useProfileUser();
const disableHosting =
user.hostingStatus === HostingStatus.HOSTING_STATUS_CANT_HOST;
const [mutationError, setMutationError] = useState("");
const [showCantRequestDialog, setShowCantRequestDialog] =
useState<boolean>(false);
const { data: accountInfo, isLoading: isAccountInfoLoading } =
useAccountInfo();
const requestButton = () => {
doAntibot("host_request");
if (!accountInfo?.profileComplete) {
setShowCantRequestDialog(true);
} else {
setIsRequesting(true);
}
};
return (
<>
<ProfileIncompleteDialog
open={showCantRequestDialog}
onClose={() => setShowCantRequestDialog(false)}
attempted_action="send_request"
/>
<Button
onClick={requestButton}
disabled={isAccountInfoLoading || disableHosting}
>
{disableHosting
? t("global:hosting_status.cant_host")
: t("profile:actions.request")}
</Button>
<MessageUserButton user={user} setMutationError={setMutationError} />
<FriendActions user={user} setMutationError={setMutationError} />
<StyledModButtons>
<ProfileReportFlagButton
contentRef={`profile/${user.userId}`}
authorUser={user.userId}
profileUser={user}
/>
<AdminPanelUserButton username={user.username} />
</StyledModButtons>
{mutationError && <Alert severity="error">{mutationError}</Alert>}
</>
);
}
interface OverviewProps {
setIsRequesting: (value: boolean) => void;
tab: UserTab;
}
export default function Overview({ setIsRequesting, tab }: OverviewProps) {
const currentUserId = useAuthContext().authState.userId;
const user = useProfileUser();
return (
<UserOverview
showHostAndMeetAvailability
actions={
user.userId === currentUserId ? (
<LoggedInUserActions tab={tab} />
) : (
<DefaultActions setIsRequesting={setIsRequesting} />
)
}
/>
);
}
|