This repository was archived by the owner on Apr 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathOverview.tsx
More file actions
113 lines (100 loc) · 3 KB
/
Copy pathOverview.tsx
File metadata and controls
113 lines (100 loc) · 3 KB
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
import Alert from "components/Alert";
import Button from "components/Button";
import UserOverview from "components/UserOverview/UserOverview";
import { useAuthContext } from "features/auth/AuthProvider";
import FlagButton from "features/FlagButton";
import FriendActions from "features/profile/actions/FriendActions";
import MessageUserButton from "features/profile/actions/MessageUserButton";
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 makeStyles from "utils/makeStyles";
import { useProfileUser } from "../hooks/useProfileUser";
const useStyles = makeStyles((theme) => ({
flagButton: {
alignSelf: "center",
},
}));
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 (
<>
<Link href={routeToEditProfile(getEditTab(tab))} passHref>
<Button component="a" color="primary">
{t("global:edit")}
</Button>
</Link>
<Link href={connectionsRoute} passHref>
<Button component="a" variant="outlined">
{t("profile:my_connections")}
</Button>
</Link>
</>
);
}
function DefaultActions({
setIsRequesting,
}: {
setIsRequesting: (value: boolean) => void;
}) {
const { t } = useTranslation([GLOBAL, PROFILE]);
const classes = useStyles();
const user = useProfileUser();
const disableHosting =
user.hostingStatus === HostingStatus.HOSTING_STATUS_CANT_HOST;
const [mutationError, setMutationError] = useState("");
return (
<>
<Button onClick={() => setIsRequesting(true)} disabled={disableHosting}>
{disableHosting
? t("global:hosting_status.cant_host")
: t("profile:actions.request")}
</Button>
<MessageUserButton user={user} setMutationError={setMutationError} />
<FriendActions user={user} setMutationError={setMutationError} />
<FlagButton
className={classes.flagButton}
contentRef={`profile/${user.userId}`}
authorUser={user.userId}
/>
{mutationError && <Alert severity="error">{mutationError}</Alert>}
</>
);
}
export 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} />
)
}
/>
);
}