Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/src/packages/frontend/admin/system-notifications.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { Map } from "immutable";6import { Alert, Button, Card, Input, Popconfirm, Space } from "antd";7import { Icon, Loading, Title } from "@cocalc/frontend/components";8import { plural } from "@cocalc/util/misc";9import { useState } from "react";10import { useActions, useRedux } from "@cocalc/frontend/app-framework";1112export function SystemNotifications({}) {13const [state, setState] = useState<"view" | "edit">("view");14const [mesg, setMesg] = useState<string>("");15const notifications = useRedux("system_notifications", "notifications");16const actions = useActions("system_notifications");1718function render_mark_done() {19if (!notifications) return;20let open = 0;21notifications.map((mesg: Map<string, any>) => {22if (mesg && !mesg.get("done")) {23open += 1;24}25});26if (open > 0) {27return (28<Button onClick={() => mark_all_done()}>29Mark {open} {plural(open, "Notification")} Done30</Button>31);32} else {33return <Button disabled={true}>No Outstanding Notifications</Button>;34}35}3637function render_buttons() {38return (39<Space>40<Button41onClick={() => {42setState("edit");43setMesg("");44}}45>46Compose...47</Button>48{render_mark_done()}49</Space>50);51}5253function render_editor() {54return (55<Card>56<Input.TextArea57autoFocus58value={mesg}59rows={3}60onChange={(e) => setMesg(e.target.value)}61/>62<Space style={{ marginTop: "15px" }}>63<Button onClick={() => setState("view")}>Cancel</Button>64<Popconfirm65title="Send notification?"66description={67<div style={{ width: "400px" }}>68Everyone that uses CoCalc will see the following notification69once in the upper right until you explicitly mark it done (they70can dismiss it).71<hr />72<Alert message={mesg} />73</div>74}75onConfirm={() => {76send();77}}78>79<Button danger>80<Icon name="paper-plane" /> Send81</Button>82</Popconfirm>83</Space>84</Card>85);86}8788function send(): void {89setState("view");90if (!mesg) return;91actions.send_message({92text: mesg.trim(),93priority: "high",94});95}9697function mark_all_done(): void {98actions.mark_all_done();99}100101function render_body() {102if (notifications == null) {103return <Loading />;104}105switch (state) {106case "view":107return render_buttons();108case "edit":109return render_editor();110}111}112113return (114<div>115<Title level={4}>System Notifications</Title>116{render_body()}117</div>118);119}120121122