2020-08-01 02:43:48 -07:00
|
|
|
import React, {useState, useEffect} from 'react';
|
|
|
|
|
import {
|
|
|
|
|
Paper,
|
|
|
|
|
IconButton,
|
|
|
|
|
Menu,
|
|
|
|
|
MenuItem,
|
|
|
|
|
Typography,
|
|
|
|
|
Grid,
|
|
|
|
|
Box,
|
|
|
|
|
Link,
|
|
|
|
|
Dialog,
|
|
|
|
|
DialogTitle,
|
|
|
|
|
DialogContent,
|
|
|
|
|
DialogContentText,
|
|
|
|
|
TextField,
|
|
|
|
|
DialogActions,
|
|
|
|
|
Button,
|
|
|
|
|
FormControl,
|
|
|
|
|
InputLabel,
|
|
|
|
|
Select,
|
|
|
|
|
} from "@material-ui/core";
|
|
|
|
|
import { MoreVert as MoreIcon } from "@material-ui/icons";
|
|
|
|
|
import {useHistory} from "react-router-dom";
|
|
|
|
|
import classnames from "classnames";
|
|
|
|
|
|
|
|
|
|
// styles
|
|
|
|
|
import useStyles from "./styles";
|
|
|
|
|
|
|
|
|
|
import Widget from "../../components/Widget";
|
|
|
|
|
import SqueakThreadItem from "../../components/SqueakThreadItem";
|
|
|
|
|
|
|
|
|
|
import {
|
|
|
|
|
CreateContactProfileRequest,
|
2020-08-01 04:52:35 -07:00
|
|
|
CreateSubscriptionRequest,
|
2020-08-01 02:43:48 -07:00
|
|
|
} from "../../proto/squeak_admin_pb"
|
|
|
|
|
import {SqueakAdminClient} from "../../proto/squeak_admin_grpc_web_pb"
|
|
|
|
|
|
|
|
|
|
var client = new SqueakAdminClient('http://' + window.location.hostname + ':8080')
|
|
|
|
|
|
|
|
|
|
export default function CreateSubscriptionDialog({
|
|
|
|
|
open,
|
|
|
|
|
handleClose,
|
|
|
|
|
...props
|
|
|
|
|
}) {
|
|
|
|
|
var classes = useStyles();
|
|
|
|
|
const history = useHistory();
|
|
|
|
|
|
|
|
|
|
var [subscriptionName, setsubscriptionName] = useState('');
|
|
|
|
|
var [host, setHost] = useState('');
|
|
|
|
|
|
|
|
|
|
const handleChangeSubscriptionName = (event) => {
|
|
|
|
|
setsubscriptionName(event.target.value);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleChangeHost = (event) => {
|
|
|
|
|
setHost(event.target.value);
|
|
|
|
|
};
|
|
|
|
|
|
2020-08-01 04:52:35 -07:00
|
|
|
const createSubscription = (subscriptionName, host, port) => {
|
2020-08-01 02:43:48 -07:00
|
|
|
console.log("called createContactProfile");
|
|
|
|
|
|
2020-08-01 04:52:35 -07:00
|
|
|
var createSubscriptionRequest = new CreateSubscriptionRequest()
|
|
|
|
|
createSubscriptionRequest.setSubscriptionName(subscriptionName);
|
|
|
|
|
createSubscriptionRequest.setHost(host);
|
2020-08-01 02:43:48 -07:00
|
|
|
// TODO: use real port here
|
|
|
|
|
// addServerRequest.setHost(0);
|
2020-08-01 04:52:35 -07:00
|
|
|
console.log(createSubscriptionRequest);
|
2020-08-01 02:43:48 -07:00
|
|
|
|
2020-08-01 04:52:35 -07:00
|
|
|
client.createSubscription(createSubscriptionRequest, {}, (err, response) => {
|
2020-08-01 02:43:48 -07:00
|
|
|
if (err) {
|
|
|
|
|
console.log(err.message);
|
|
|
|
|
alert('Error creating subscription: ' + err.message);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
console.log(response);
|
2020-08-01 04:52:35 -07:00
|
|
|
console.log(response.getSubscriptionId());
|
2020-08-01 02:43:48 -07:00
|
|
|
// goToProfilePage(response.getProfileId());
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const goToProfilePage = (profileId) => {
|
|
|
|
|
history.push("/app/profile/" + profileId);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function handleSubmit(event) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
console.log( 'subscriptionName:', subscriptionName);
|
|
|
|
|
console.log( 'host:', host);
|
|
|
|
|
if (!host) {
|
|
|
|
|
alert('Host cannot be empty.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
createSubscription(subscriptionName, host);
|
|
|
|
|
handleClose();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CreateSubscriptionNameInput() {
|
|
|
|
|
return (
|
|
|
|
|
<TextField
|
|
|
|
|
id="standard-textarea"
|
|
|
|
|
label="Subscription Name"
|
|
|
|
|
required
|
|
|
|
|
autoFocus
|
|
|
|
|
value={subscriptionName}
|
|
|
|
|
onChange={handleChangeSubscriptionName}
|
|
|
|
|
fullWidth
|
|
|
|
|
inputProps={{ maxLength: 64 }}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CreateHostInput() {
|
|
|
|
|
return (
|
|
|
|
|
<TextField required
|
|
|
|
|
id="standard-textarea"
|
|
|
|
|
label="Host"
|
|
|
|
|
required
|
|
|
|
|
value={host}
|
|
|
|
|
onChange={handleChangeHost}
|
|
|
|
|
inputProps={{ maxLength: 128 }}
|
|
|
|
|
/>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CancelButton() {
|
|
|
|
|
return (
|
|
|
|
|
<Button
|
|
|
|
|
onClick={handleClose}
|
|
|
|
|
variant="contained"
|
|
|
|
|
color="secondary"
|
|
|
|
|
>
|
|
|
|
|
Cancel
|
|
|
|
|
</Button>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function CreateSubscriptionButton() {
|
|
|
|
|
return (
|
|
|
|
|
<Button
|
|
|
|
|
type="submit"
|
|
|
|
|
variant="contained"
|
|
|
|
|
color="primary"
|
|
|
|
|
className={classes.button}
|
|
|
|
|
>
|
|
|
|
|
Create Subscription
|
|
|
|
|
</Button>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Dialog open={open} onClose={handleClose} aria-labelledby="form-dialog-title">
|
|
|
|
|
<DialogTitle id="form-dialog-title">Create Contact Profile</DialogTitle>
|
|
|
|
|
<form className={classes.root} onSubmit={handleSubmit} noValidate autoComplete="off">
|
|
|
|
|
<DialogContent>
|
|
|
|
|
{CreateSubscriptionNameInput()}
|
|
|
|
|
{CreateHostInput()}
|
|
|
|
|
</DialogContent>
|
|
|
|
|
<DialogActions>
|
|
|
|
|
{CancelButton()}
|
|
|
|
|
{CreateSubscriptionButton()}
|
|
|
|
|
</DialogActions>
|
|
|
|
|
</form>
|
|
|
|
|
</Dialog>
|
|
|
|
|
)
|
|
|
|
|
}
|