CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/course/shared-project/shared-project-panel.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
import { UsergroupAddOutlined } from "@ant-design/icons";
6
import { Button, Card, Popconfirm } from "antd";
7
import { FormattedMessage, useIntl } from "react-intl";
8
9
import { AppRedux, useActions } from "@cocalc/frontend/app-framework";
10
import { Icon, Paragraph } from "@cocalc/frontend/components";
11
import { course } from "@cocalc/frontend/i18n";
12
import { CancelText } from "@cocalc/frontend/i18n/components";
13
import { CourseActions } from "../actions";
14
import { CourseSettingsRecord } from "../store";
15
import { DeleteSharedProjectPanel } from "./delete-shared-project";
16
17
interface SharedProjectPanelProps {
18
settings: CourseSettingsRecord;
19
redux: AppRedux;
20
name: string;
21
close?: Function;
22
}
23
24
export function SharedProjectPanel({
25
settings,
26
redux,
27
name,
28
close,
29
}: SharedProjectPanelProps) {
30
const intl = useIntl();
31
32
const actions = useActions<CourseActions>({ name });
33
34
const haveSharedProject = !!settings.get("shared_project_id");
35
36
function panel_header_text(): string {
37
return intl.formatMessage(
38
{
39
id: "course.shared-project-panel.header",
40
defaultMessage: `{haveSharedProject, select,
41
true {Shared project that everybody can fully use}
42
other {Optionally create a shared project for everybody}}`,
43
},
44
{ haveSharedProject },
45
);
46
}
47
48
function render_content() {
49
if (haveSharedProject) {
50
return render_has_shared_project();
51
} else {
52
return render_no_shared_project();
53
}
54
}
55
56
const icuVals = {
57
b: (c) => <b>{c}</b>,
58
i: (c) => <i>{c}</i>,
59
p: (c) => <Paragraph>{c}</Paragraph>,
60
secondary: (c) => <Paragraph type="secondary">{c}</Paragraph>,
61
};
62
63
function render_has_shared_project() {
64
return (
65
<>
66
<FormattedMessage
67
id="course.shared-project-panel.have_project.message"
68
defaultMessage={`
69
<p>
70
You created a common shared project, which everybody – students and
71
all collaborators on this project (your TAs and other instructors)
72
– have <b>write</b> access to. Use this project for collaborative
73
in-class labs, course-wide chat rooms, and making miscellaneous
74
materials available for students to experiment with together.
75
</p>
76
<secondary>
77
When you created the shared project, everybody who has already
78
created an account is added as a collaborator to the project.
79
Whenever you re-open this course, any students or collaborators on
80
the project that contains this course will be added to the shared
81
project.
82
</secondary>`}
83
values={icuVals}
84
/>
85
<br />
86
<div style={{ textAlign: "center" }}>
87
<Button onClick={open_project} size={"large"} type={"primary"}>
88
<FormattedMessage
89
id="course.shared-project-panel.have_project.button"
90
defaultMessage={"Open shared project"}
91
/>
92
</Button>
93
</div>
94
<hr />
95
<DeleteSharedProjectPanel
96
settings={settings}
97
actions={actions}
98
close={close}
99
/>
100
</>
101
);
102
}
103
104
function open_project(): void {
105
redux.getActions("projects").open_project({
106
project_id: settings.get("shared_project_id"),
107
});
108
close?.();
109
}
110
111
function render_no_shared_project() {
112
return (
113
<div>
114
<FormattedMessage
115
id="course.shared-project-panel.create_project.message"
116
defaultMessage={`
117
<p>
118
<i>Optionally</i> create a single common shared project, which
119
everybody – students and all collaborators on this project (your
120
TAs and other instructors) – will have <b>write</b> access to. This
121
can be useful for collaborative in-class labs, course-wide chat
122
rooms, and making miscellanous materials available for students to
123
experiment with together.
124
</p>
125
<secondary>
126
When you create the shared project, everybody who has already
127
created an account is added as a collaborator to the project.
128
Whenever you re-open this course, any students or collaborators on
129
the project that contains this course will be added to the shared
130
project.
131
</secondary>
132
<secondary>
133
After you create the shared project, you should upgrade that project via a license as well.
134
</secondary>`}
135
values={icuVals}
136
/>
137
<br />
138
<Popconfirm
139
title={
140
<div style={{ maxWidth: "400px" }}>
141
<FormattedMessage
142
id="course.shared-project-panel.create_project.confirmation"
143
defaultMessage={`Are you sure you want to create a shared project
144
and add all students in this course as collaborators?`}
145
/>
146
</div>
147
}
148
onConfirm={() => {
149
const actions = redux.getActions(name) as CourseActions;
150
if (actions != null) {
151
actions.shared_project.create();
152
close?.();
153
}
154
}}
155
okText={intl.formatMessage(course.create_shared_project)}
156
cancelText={<CancelText />}
157
>
158
<Button size={"large"} icon={<UsergroupAddOutlined />}>
159
{intl.formatMessage(course.create_shared_project)}...
160
</Button>
161
</Popconfirm>
162
</div>
163
);
164
}
165
166
return (
167
<div className="smc-vfill" style={{ overflow: "auto" }}>
168
<Card
169
style={{ maxWidth: "800px", margin: "auto" }}
170
title={
171
<>
172
<Icon name="users" /> {panel_header_text()}
173
</>
174
}
175
>
176
{render_content()}
177
</Card>
178
</div>
179
);
180
}
181
182