Repository navigation
Expand file tree
/
Copy pathAddToSlack.tsx
More file actions
90 lines (83 loc) · 1.92 KB
/
Copy pathAddToSlack.tsx
File metadata and controls
90 lines (83 loc) · 1.92 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
import { useState } from "react";
import Modal, { hideModal, showModal } from "./Modal";
import ClientApi from "@/lib/api/ClientApi";
const SLACK_WEBHOOK_INSTALL_URL =
"https://my.slack.com/services/new/incoming-webhook/";
const api = new ClientApi();
function AddToSlackModal({ teamId }: { teamId: string }) {
const [webhookUrl, setWebhookUrl] = useState<string>();
const [errorMsg, setErrorMsg] = useState<string>("");
function save() {
if (!webhookUrl) {
setErrorMsg("Webhook URL is required");
return;
}
api
.setSlackWebhook(teamId, webhookUrl)
.catch((err) => setErrorMsg(err.message))
.then(() => hideModal("add-to-slack"));
}
return (
<Modal
id="add-to-slack"
showCloseButton={false}
className="flex flex-col gap-4"
>
<h2 className="text-xl">Add Gearbox to Slack</h2>
<div>
Install the Incoming Webhooks app here:{" "}
<a
href={SLACK_WEBHOOK_INSTALL_URL}
target="_blank"
className="link link-accent"
>
{SLACK_WEBHOOK_INSTALL_URL}
</a>
</div>
<div>
Enter the Webhook URL here:
<input
value={webhookUrl}
onChange={(e) => setWebhookUrl(e.target.value)}
type="url"
placeholder="Webhook URL"
className="input input-bordered ml-2"
/>
</div>
<div className="flex gap-4 w-full justify-end">
<button
className="btn btn-primary"
onClick={save}
>
Save
</button>
<button
className="btn"
onClick={() => hideModal("add-to-slack")}
>
Cancel
</button>
</div>
{errorMsg && <div className="text-red-500">{errorMsg}</div>}
</Modal>
);
}
export default function AddToSlack({
edit,
teamId,
}: {
edit: boolean;
teamId: string;
}) {
return (
<>
<button
className="btn btn-accent btn-sm"
onClick={() => showModal("add-to-slack")}
>
{edit ? "Change Slack Webhook" : "Add Gearbox to Slack"}
</button>
<AddToSlackModal teamId={teamId} />
</>
);
}