Skip to content
This repository was archived by the owner on Oct 30, 2025. It is now read-only.

Commit 701e2da

Browse files
committed
Removes community component, modifies create button and EmbedBadgeDialog
1 parent a8c452b commit 701e2da

7 files changed

Lines changed: 64 additions & 384 deletions

File tree

client/src/components/ChannelInfo/index.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export default function ChannelInfo(props) {
6969
url: `${githubApiDomain}/repos/${repository}/issues`,
7070
headers: headers,
7171
});
72-
// GitHub treats both PRs and issues as issues except that PRs can be
72+
// GitHub treats both PRs and issues as issues except that PRs can be
7373
// distinguished by the presence of a pull_request key
7474
setIssuesCount(
7575
ghIssuesResponse.data.filter((issue) => !issue.pull_request).length
@@ -84,9 +84,12 @@ export default function ChannelInfo(props) {
8484
}, [props.location.pathname]);
8585

8686
const [activeTab, setActiveTab] = useState(0);
87-
const repoURL = `https://github.com/${props.location.pathname
88-
.split("/")[2]
89-
.replace("_", "/")}`;
87+
// Covers case where pathname is /channel
88+
const repoURL = `https://github.com/${
89+
props.location.pathname.split("/")[2]
90+
? props.location.pathname.split("/")[2].replace("_", "/")
91+
: ""
92+
}`;
9093

9194
const handleChange = (event, newValue) => {
9295
setActiveTab(newValue);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
.create-channel-wrapper {
2+
justify-content: center;
3+
display: flex;
4+
}
5+
6+
.create-dialog-description {
7+
color: #8e9299;
8+
}
9+
10+
.repository-autocomplete {
11+
width: 80%;
12+
}
13+
14+
.create-button {
15+
margin-bottom: 10px;
16+
}

client/src/components/CreateChannel/index.js

Lines changed: 34 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ import {
1313
} from "@material-ui/core";
1414
import RCSwitch from "../RCSwitch";
1515
import Cookies from "js-cookie";
16-
import jwt_decode from "jwt-decode";
1716
import {
1817
githubPrivateRepoAccessClientID,
1918
rcApiDomain,
2019
rc4gitDomain,
2120
} from "../../utils/constants";
2221
import EmbedBadgeDialog from "../EmbedBadgeDialog";
2322

23+
import "./index.css";
24+
2425
const Transition = React.forwardRef(function Transition(props, ref) {
2526
return <Slide direction="up" ref={ref} {...props} />;
2627
});
@@ -32,12 +33,9 @@ export default class CreateChannel extends Component {
3233
repositories: [],
3334
publicRepositories: [],
3435
privateRepositories: [],
35-
username: jwt_decode(Cookies.get("rc4git_token")).username.slice(0, -7),
36-
community: null,
3736
includePrivateRepositories: false,
3837
publicChannel: true,
3938
loading: false,
40-
communities: [],
4139
channel: null,
4240
showEmbedBadgeDialog: false,
4341
room: null,
@@ -50,31 +48,7 @@ export default class CreateChannel extends Component {
5048
}
5149

5250
handleClickChannelDialog = async () => {
53-
const { publicRepositories, privateRepositories, username } = this.state;
54-
const { organizations, rooms } = this.props;
55-
let communityChannels = [],
56-
communityMember = [];
57-
58-
communityChannels = rooms
59-
.filter((room) => {
60-
return room.name.endsWith("_community");
61-
})
62-
.map((communityRoom) =>
63-
communityRoom.name.slice(0, communityRoom.name.length - 10)
64-
);
65-
66-
//Add organizations and username to communityMember
67-
communityMember.push(username);
68-
communityMember = communityMember.concat(
69-
organizations.map((organization) => organization.value)
70-
);
71-
72-
//Intersect communityMembers and communityChannels and set as communities
73-
this.setState({
74-
communities: communityMember.filter((value) =>
75-
communityChannels.includes(value)
76-
),
77-
});
51+
const { publicRepositories, privateRepositories } = this.state;
7852

7953
//Fetch public repositories
8054
const publicRepoResponse = await axios({
@@ -116,8 +90,8 @@ export default class CreateChannel extends Component {
11690
this.setState({ ...this.state, [event.target.name]: event.target.checked });
11791
if (event.target.checked) {
11892
if (!Cookies.get("gh_private_repo_token")) {
119-
Cookies.set("gh_upgrade_prev_path", window.location.pathname)
120-
window.location.href = `https://github.com/login/oauth/authorize?scope=repo&client_id=${githubPrivateRepoAccessClientID}`
93+
Cookies.set("gh_upgrade_prev_path", window.location.pathname);
94+
window.location.href = `https://github.com/login/oauth/authorize?scope=repo&client_id=${githubPrivateRepoAccessClientID}`;
12195
}
12296
this.setState({
12397
repositories: publicRepositories.concat(privateRepositories),
@@ -128,11 +102,10 @@ export default class CreateChannel extends Component {
128102
};
129103

130104
handleCreateChannel = async () => {
131-
const { channel, community, publicChannel } = this.state;
105+
const { channel, publicChannel } = this.state;
132106
const { setSnackbar, addRoom } = this.props;
133-
const authToken = Cookies.get("gh_private_repo_token")
134-
? Cookies.get("gh_private_repo_token")
135-
: Cookies.get("gh_login_token");
107+
const authToken =
108+
Cookies.get("gh_private_repo_token") || Cookies.get("gh_login_token");
136109
let collaborators = [],
137110
description = "";
138111
this.setState({ loading: true });
@@ -142,7 +115,7 @@ export default class CreateChannel extends Component {
142115
if (Cookies.get("gh_private_repo_token")) {
143116
const ghCollaboratorsResponse = await axios({
144117
method: "get",
145-
url: `https://api.github.com/repos/${community}/${channel}/collaborators`,
118+
url: `https://api.github.com/repos/${channel}/collaborators`,
146119
headers: {
147120
accept: "application/json",
148121
Authorization: `token ${authToken}`,
@@ -158,7 +131,7 @@ export default class CreateChannel extends Component {
158131

159132
const ghRepoResponse = await axios({
160133
method: "get",
161-
url: `https://api.github.com/repos/${community}/${channel}`,
134+
url: `https://api.github.com/repos/${channel}`,
162135
headers: {
163136
accept: "application/json",
164137
Authorization: `token ${authToken}`,
@@ -175,19 +148,19 @@ export default class CreateChannel extends Component {
175148
data: {
176149
rc_token: Cookies.get("rc_token"),
177150
rc_uid: Cookies.get("rc_uid"),
178-
channel: `${community}_${channel}`,
151+
channel: channel.replace("/", "_"),
179152
members: collaborators,
180-
topic: `GitHub: https://github.com/${community}/${channel}`,
153+
topic: `GitHub: https://github.com/${channel}`,
181154
type: publicChannel ? "c" : "p",
182155
},
183156
});
184157
if (rcCreateChannelResponse.data.data.success) {
185158
let room = rcCreateChannelResponse.data.data.channel;
186-
//Add embeddable code for channel to description
159+
//Add embeddable code for community to description
187160
description = description.concat(`
188161
189162
-----
190-
Embed this channel
163+
Embed this community
191164
<pre><code>&lt;a&nbsp;href=&quot;${rc4gitDomain}/channel/${room.name}&quot;&gt;
192165
&lt;img&nbsp;src=&quot;${rcApiDomain}/images/join-chat.svg&quot;/&gt;
193166
&lt;/a&gt;</code></pre>
@@ -207,7 +180,7 @@ Embed this channel
207180
});
208181

209182
addRoom(room);
210-
setSnackbar(true, "success", "Channel created successfully!");
183+
setSnackbar(true, "success", "Community created successfully!");
211184
this.setState({
212185
loading: false,
213186
room: room,
@@ -216,12 +189,12 @@ Embed this channel
216189
});
217190
} else {
218191
this.setState({ loading: false });
219-
setSnackbar(true, "error", "Error Creating Channel!");
192+
setSnackbar(true, "error", "Error Creating Community!");
220193
}
221194
} catch (error) {
222195
console.log(error);
223196
this.setState({ loading: false });
224-
setSnackbar(true, "error", "Error Creating Channel!");
197+
setSnackbar(true, "error", "Error Creating Community!");
225198
}
226199
};
227200

@@ -230,8 +203,6 @@ Embed this channel
230203
repositories,
231204
publicChannel,
232205
includePrivateRepositories,
233-
community,
234-
communities,
235206
channel,
236207
loading,
237208
room,
@@ -241,8 +212,7 @@ Embed this channel
241212
const { setSnackbar, handleEndCreateChannel } = this.props;
242213

243214
return (
244-
<div style={{ justifyContent: "center", display: "flex" }}>
245-
215+
<div className="create-channel-wrapper">
246216
<Dialog
247217
open={openCreateChannelDialog}
248218
keepMounted
@@ -253,26 +223,12 @@ Embed this channel
253223
maxWidth="sm"
254224
fullWidth={true}
255225
>
256-
<DialogTitle>Create a New Channel</DialogTitle>
226+
<DialogTitle>Create a New Community</DialogTitle>
257227
<DialogContent>
258-
<p style={{ color: "#c0c2c6" }}>
259-
Channels are where your teams communicate.
228+
<p className="create-dialog-description">
229+
Communities are where your teams communicate.
260230
</p>
261231
<div>
262-
<br />
263-
<p>Select a community</p>
264-
<Autocomplete
265-
id="combo-box-repo"
266-
options={communities}
267-
style={{ width: 300 }}
268-
onChange={(event, value) => {
269-
this.setState({ community: value });
270-
}}
271-
renderInput={(params) => (
272-
<TextField {...params} label="Community" variant="outlined" />
273-
)}
274-
/>
275-
<br />
276232
<br />
277233
<FormControlLabel
278234
control={
@@ -284,12 +240,12 @@ Embed this channel
284240
name="publicChannel"
285241
/>
286242
}
287-
label="Public Channel"
243+
label="Public Community"
288244
/>
289-
<p style={{ color: "#c0c2c6" }}>
245+
<p className="create-dialog-description">
290246
{publicChannel
291-
? "Everyone can access this channel."
292-
: "Just invited people can access this channel."}
247+
? "Everyone can access this community."
248+
: "Just invited people can access this community."}
293249
</p>
294250
<br />
295251
<FormControlLabel
@@ -302,30 +258,18 @@ Embed this channel
302258
}
303259
label="Show All Repositories"
304260
/>
305-
<p style={{ color: "#c0c2c6" }}>
261+
<p className="create-dialog-description">
306262
Show public {includePrivateRepositories ? "and private " : ""}
307263
repositories.
308264
</p>
309265
<br />
310266
<p>Select a repository</p>
311267
<Autocomplete
312268
id="combo-box-repo"
313-
options={
314-
community
315-
? repositories
316-
.filter((repository) =>
317-
repository.startsWith(community.concat("/"))
318-
)
319-
.map((repository) =>
320-
repository.slice(
321-
community.length + 1,
322-
repository.length
323-
)
324-
)
325-
.sort()
326-
: []
327-
}
328-
style={{ width: 300 }}
269+
className="repository-autocomplete"
270+
options={repositories.sort()}
271+
getOptionLabel={(option) => option.split("/")[1]}
272+
groupBy={(option) => option.split("/")[0]}
329273
onChange={(event, value) => {
330274
this.setState({ channel: value });
331275
}}
@@ -340,17 +284,17 @@ Embed this channel
340284
<br />
341285
{channel && (
342286
<>
343-
<p style={{ color: "#8e9299" }}>
344-
Your channel would be created as{" "}
345-
<strong>{community.concat(`_${channel}`)}</strong>
287+
<p className="create-dialog-description">
288+
Your community would be created as{" "}
289+
<strong>{channel.replace("/", "_")}</strong>
346290
</p>
347291
</>
348292
)}
349293
<br />
350294
<Button
295+
className="create-button"
351296
disabled={!channel || loading}
352297
onClick={this.handleCreateChannel}
353-
style={{ marginBottom: "10px" }}
354298
variant="contained"
355299
color="primary"
356300
startIcon={
@@ -365,7 +309,6 @@ Embed this channel
365309
{showEmbedBadgeDialog && (
366310
<EmbedBadgeDialog
367311
channelURL={`${rc4gitDomain}/channel/${room.name}`}
368-
createType="channel"
369312
setSnackbar={setSnackbar}
370313
endCreate={handleEndCreateChannel}
371314
/>

client/src/components/CreateCommunity/index.css

Whitespace-only changes.

0 commit comments

Comments
 (0)