-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGroup.tsx
More file actions
199 lines (186 loc) · 6.15 KB
/
Copy pathGroup.tsx
File metadata and controls
199 lines (186 loc) · 6.15 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import { useQuery } from "@apollo/client";
import { CheckCircleOutline } from "@mui/icons-material";
import InfoIcon from "@mui/icons-material/Info";
import { Tooltip, useMediaQuery, useTheme } from "@mui/material";
import Box from "@mui/material/Box";
import Typography from "@mui/material/Typography";
import { useContext, useState } from "react";
import { generatePath, useNavigate, useParams } from "react-router-dom";
import { WatchGroupButton } from "@/components/watchButton/WatchGroupButton";
import { Route } from "@/routers/routes";
import BannerWithAvatar from "./BannerWithAvatar";
import { EvolveGroupButton } from "./EvolveGroupButton";
import { MembersList } from "./MembersList";
import Loading from "../../components/Loading";
import TabPanel from "../../components/Tables/TabPanel";
import { TabProps, Tabs } from "../../components/Tables/Tabs";
import {
FlowWatchFilter,
GroupDocument,
IzeGroupFragment,
RequestStatusFilter,
} from "../../graphql/generated/graphql";
import { SnackbarContext } from "../../hooks/contexts/SnackbarContext";
import Head from "../../layout/Head";
import PageContainer from "../../layout/PageContainer";
import { fullUUIDToShort, shortUUIDToFull } from "../../utils/inputs";
import { FlowsSearch } from "../Flows/FlowsSearch";
import { RequestSearch } from "../Requests/RequestsSearch";
export const Group = () => {
const { groupId: groupIdShort } = useParams();
const groupId = shortUUIDToFull(groupIdShort as string);
const { setSnackbarData, setSnackbarOpen } = useContext(SnackbarContext);
const navigate = useNavigate();
const theme = useTheme();
const isSmallScreenSize = useMediaQuery(theme.breakpoints.down("sm"));
const { data, loading, error } = useQuery(GroupDocument, {
variables: {
id: groupId,
},
});
const group = data?.group as IzeGroupFragment;
// console.log("group", group);
const [currentTabIndex, setTabIndex] = useState(0);
const handleChange = (_event: React.SyntheticEvent, newValue: number) => {
setTabIndex(newValue);
};
const onError = () => {
navigate("/");
setSnackbarOpen(true);
setSnackbarData({ message: "Cannot find this group", type: "error" });
};
if (error) onError();
const tabs: TabProps[] = [
{
title: "Activity",
content: !loading ? (
<RequestSearch
initialFlowWatchFilter={FlowWatchFilter.All}
groupId={groupId}
initialNeedsResponseFilter={false}
showNeedsResponseFilter={true}
showRequestStatusFilter={true}
initialRequestStatusFilter={RequestStatusFilter.Open}
/>
) : null,
},
{
title: "Flow templates",
icon: (
<Tooltip
title="Every group has watched flow templates. These are flows that the group has
collectively decided it wants to highlight and receive notifications for"
arrow
>
<InfoIcon fontSize="small" />
</Tooltip>
),
content: !loading ? (
<FlowsSearch
groupId={groupId}
onClickRow={(flow) => {
navigate(
generatePath(Route.Flow, {
flowId: fullUUIDToShort(flow.flowId),
flowVersionId: null,
}),
);
}}
/>
) : null,
},
];
return loading || !group ? (
<Loading />
) : (
<>
<Head
title={group.group.name}
description={`Where ${group.group.name} makes decisions and evolves their process`}
/>
<BannerWithAvatar
bannerUrl={""}
avatarUrl={group.group.icon ?? ""}
name={group.group.name}
color={group.group.color}
parent={
group.group.organization
? {
name: group.group.organization?.name,
avatarUrl: group.group.organization?.icon,
}
: undefined
}
id={group.group.id}
/>
<PageContainer>
<Box
sx={{
display: "flex",
flexDirection: "column",
gap: "8px",
}}
>
<Box sx={{ display: "flex", justifyContent: "space-between", alignItems: "center" }}>
<Box
sx={{
display: "flex",
alignItems: "center",
gap: "6px",
}}
>
<Typography variant="h1">{group.group.name}</Typography>
<WatchGroupButton watched={group.isWatched} groupId={group.group.id} size="medium" />
</Box>
{!isSmallScreenSize && (
<EvolveGroupButton evolveGroupFlowId={group.evolveGroupFlowId} />
)}
</Box>
<Box
sx={(theme) => ({
display: "flex",
justifyContent: "space-between",
gap: "8px",
[theme.breakpoints.down("sm")]: {
flexDirection: "column",
},
})}
>
<MembersList members={group.members} />
{group.isMember && (
<Box sx={{ display: "flex", gap: "8px" }}>
<CheckCircleOutline color="primary" fontSize="small" />
<Typography variant="description" color="primary">
You are a member
</Typography>
</Box>
)}
</Box>
{group.notificationEntity && (
<Typography variant="description" lineHeight={"24px"}>
Sends notifications to{" "}
<span style={{ fontWeight: "500" }}>{group.notificationEntity.name}</span> Telegram
group
</Typography>
)}
{group.description && (
<Typography variant="description" marginTop="8px">
{group.description}
</Typography>
)}
</Box>
<Tabs
tabs={tabs}
currentTabIndex={currentTabIndex}
handleChange={handleChange}
sx={{ marginTop: "24px" }}
/>
{tabs.map((tab: TabProps, index) => (
<TabPanel value={currentTabIndex} index={index} key={index}>
{tab.content}
</TabPanel>
))}
</PageContainer>
</>
);
};