-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathBridgeDeploy.tsx
More file actions
104 lines (92 loc) · 3.51 KB
/
BridgeDeploy.tsx
File metadata and controls
104 lines (92 loc) · 3.51 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
import {useState} from "react";
export default function BridgeDeploy({beeperToken, flyToken, onCreate}: any) {
const [deployInProgress, setDeployInProgress] = useState(false)
const [errorMessage, setErrorMessage] = useState("")
const regions: Record<string, string> = {
ams: 'Amsterdam, Netherlands',
arn: 'Stockholm, Sweden',
atl: 'Atlanta, Georgia (US)',
bog: 'Bogotá, Colombia',
bos: 'Boston, Massachusetts (US)',
cdg: 'Paris, France',
den: 'Denver, Colorado (US)',
dfw: 'Dallas, Texas (US)',
ewr: 'Secaucus, NJ (US)',
eze: 'Ezeiza, Argentina',
gdl: 'Guadalajara, Mexico',
gig: 'Rio de Janeiro, Brazil',
gru: 'Sao Paulo, Brazil',
hkg: 'Hong Kong, Hong Kong',
iad: 'Ashburn, Virginia (US)',
jnb: 'Johannesburg, South Africa',
lax: 'Los Angeles, California (US)',
lhr: 'London, United Kingdom',
mad: 'Madrid, Spain',
mia: 'Miami, Florida (US)',
nrt: 'Tokyo, Japan',
ord: 'Chicago, Illinois (US)',
otp: 'Bucharest, Romania',
phx: 'Phoenix, Arizona (US)',
qro: 'Querétaro, Mexico',
scl: 'Santiago, Chile',
sea: 'Seattle, Washington (US)',
sin: 'Singapore, Singapore',
sjc: 'San Jose, California (US)',
syd: 'Sydney, Australia',
waw: 'Warsaw, Poland',
yul: 'Montreal, Canada',
yyz: 'Toronto, Canada'
};
const bridges: Record<string, string> = {
whatsapp: "WhatsApp",
gmessages: "Google Messages",
instagramgo: "Instagram",
facebookgo: "Facebook",
signal: "Signal",
discord: "Discord",
slack: "Slack",
telegram: "Telegram",
}
async function deploy(event: any) {
event.preventDefault();
setDeployInProgress(true)
const res = await fetch("/api/deploy", {
method: 'POST',
body: JSON.stringify({
beeperToken: beeperToken,
flyToken: flyToken,
bridge: event.target.bridge.value,
region: event.target.region.value
})
})
if (res.status === 500) {
const error_data = await res.json();
setErrorMessage(error_data.error);
return;
}
setDeployInProgress(false)
onCreate();
}
return (
<div className="m-20">
<p className="text-center text-2xl font-bold">Deploy a new bridge</p>
<form onSubmit={deploy} className="text-center">
<select className="border-2 p-2 m-2" name="bridge" defaultValue="whatsapp">
{Object.keys(bridges).map((bridge) => (
<option key={bridge} value={bridge}>{bridges[bridge]}</option>
))}
</select>
<select className="border-2 p-2 m-2" name="region" defaultValue="iad">
{Object.keys(regions).map((region) => (
<option key={region} value={region}>{regions[region]}</option>
))}
</select>
{!deployInProgress ? <button
className="p-2 rounded-md m-4 bg-purple-600 border-0 text-white hover:bg-purple-500">Deploy</button> :
<button className="p-2 rounded-md m-4 bg-purple-300 border-0 text-white"
disabled={true}>Deploying...</button>}
{errorMessage}
</form>
</div>
)
}