import React, { useState } from 'react';
import {
Dialog,
DialogTitle,
DialogContent,
TextField,
DialogActions,
Button,
FormControl,
InputLabel,
Select,
MenuItem,
} from '@material-ui/core';
// styles
import useStyles from './styles';
import {
addTwitterAccountRequest,
getSigningProfilesRequest,
} from '../../squeakclient/requests';
export default function AddTwitterAccountDialog({
open,
handleClose,
reloadAccountsFn,
...props
}) {
const classes = useStyles();
const [twitterHandle, setTwitterHandle] = useState('');
const [profileId, setProfileId] = useState(-1);
const [signingProfiles, setSigningProfiles] = useState([]);
const resetFields = () => {
setTwitterHandle('');
setProfileId(-1);
};
const handleChangeTwitterHandle = (event) => {
setTwitterHandle(event.target.value);
};
const handleChangeProfileId = (event) => {
setProfileId(event.target.value);
};
const handleResponse = (response) => {
reloadAccountsFn();
};
const handleErr = (err) => {
alert(`Error adding twitter account: ${err}`);
};
const addTwitterAccount = (twitterHandle, profileId) => {
addTwitterAccountRequest(twitterHandle, profileId, handleResponse, handleErr);
};
const loadSigningProfiles = () => {
getSigningProfilesRequest(setSigningProfiles);
};
function handleSubmit(event) {
event.preventDefault();
console.log('twitterHandle:', twitterHandle);
console.log('profileId:', profileId);
if (profileId === -1) {
alert('Signing profile must be selected.');
return;
}
if (!twitterHandle) {
alert('twitterHandle cannot be empty.');
return;
}
addTwitterAccount(twitterHandle, profileId);
handleClose();
}
function load(event) {
loadSigningProfiles();
}
function cancel(event) {
event.stopPropagation();
handleClose();
}
function ignore(event) {
event.stopPropagation();
}
function AccountHandleInput() {
return (
);
}
function SelectSigningProfile() {
return (
Signing Profile
);
}
function CancelButton() {
return (
);
}
function AddTwitterAccountButton() {
return (
);
}
return (
);
}