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/next/pages/vouchers/notes.tsx
Views: 687
import { useState } from "react";1import Markdown from "@cocalc/frontend/editors/slate/static-markdown";2import apiPost from "lib/api/post";3import { Alert, Button, Input, Space, Tooltip } from "antd";4import { Icon } from "@cocalc/frontend/components/icon";56export default function Notes({ notes: notes0, code }) {7const [editing, setEditing] = useState<boolean>(false);8const [notes, setNotes] = useState<string>(notes0);9const [editVal, setEditVal] = useState<string>(notes);10const [error, setError] = useState<string>("");1112if (editing) {13return (14<div style={{ width: "450px" }}>15<Input.TextArea16value={editVal}17autoSize18onChange={(e) => setEditVal(e.target.value)}19/>20<Space>21<Button.Group style={{ marginTop: "5px" }}>22<Button23type="primary"24onClick={async () => {25try {26await apiPost("/vouchers/set-voucher-code-notes", {27code,28notes: editVal,29});30setNotes(editVal);31setEditing(false);32} catch (err) {33setError(`${err}`);34}35}}36>37Save38</Button>39<Button40onClick={() => {41setEditing(false);42}}43>44Cancel45</Button>46</Button.Group>47<span style={{ color: "#666" }}>48Add notes about this voucher code that only you can see (supports49markdown).50</span>51</Space>52{error && (53<Alert54type="error"55message={error}56showIcon57closable58onClose={() => setError("")}59/>60)}61</div>62);63}6465if (notes) {66return (67<Tooltip title={"Click to edit"}>68<div onClick={() => setEditing(true)} style={{ cursor: "pointer" }}>69<Markdown value={notes} />70</div>71</Tooltip>72);73}7475return (76<Tooltip title={"Click to add a private note about this voucher code"}>77{" "}78<Button type="text" onClick={() => setEditing(true)}>79<Icon name="plus" />80</Button>81</Tooltip>82);83}848586