squeaknode/frontend/src/components/CreateSigningProfileDialog/CreateSigningProfileDialog.js

120 lines
2.6 KiB
JavaScript
Raw Normal View History

import React, { useState } from 'react';
import {
Dialog,
DialogTitle,
DialogContent,
TextField,
DialogActions,
Button,
} from '@material-ui/core';
import { useHistory } from 'react-router-dom';
// styles
import useStyles from './styles';
import {
createSigningProfileRequest,
} from '../../squeakclient/requests';
Refactor navigation functions (#776) * Refactor navigation functions out of offer detail component * Remove old commentes * Fix go to lightning node from offer detail * Refactor more navigation functions * Refactor goto function out of create contact profile * Refactor goto out of create peer dialog * Refactor goto out of create signing dialog * Refactor goto out of delete squeak dialog * Refactor goto out of import signing profile dialog * Refactor goto out of lightning peer list dialog * Refactor goto out of make squeak dialog * Refactor goto out of open channel dialog * Refactor goto out of pending open channel component * Refactor goto out of pending received payment component * Refactor goto out of send bitcoin dialog * Refactor goto out of sent offer component * Refactor goto out of sent payment component * Refactor goto out of squeak detail component * Refactor goto out of profile detail component * Refactor goto out of squeak thread item component * Refactor goto out of payments page * Refactor goto out of peers page * Refactor goto out of profile page * Refactor goto out of squeak page * Refactor goto out of squeak address page * Refactor goto out of timeline page * Refactor reload out of buy dialog * Refactor reload out of delete peer dialog * Refactor reload out of delete profile dialog * Refactor reload out of delete squeak dialog * Refactor reload out of header * Refactor reload out of squeak detail component * Refactor goto out of timeline avatar component * Refactor reload out of upload image dialog * Refactor reload out of channel page * Refactor reload out of lightning node page * Refactor goto out of profiles page
2021-02-01 02:39:00 -08:00
import {
goToProfilePage,
} from '../../navigation/navigation';
export default function CreateSigningProfileDialog({
open,
handleClose,
...props
}) {
const classes = useStyles();
const history = useHistory();
const [profileName, setProfileName] = useState('');
const resetFields = () => {
setProfileName('');
};
const handleChangeProfileName = (event) => {
setProfileName(event.target.value);
};
const handleResponse = (response) => {
goToProfilePage(history, response.getProfileId());
};
const handleErr = (err) => {
alert(`Error creating signing profile: ${err}`);
};
const createSigningProfile = (profileName) => {
createSigningProfileRequest(profileName, handleResponse, handleErr);
};
function handleSubmit(event) {
event.preventDefault();
console.log('profileName:', profileName);
if (!profileName) {
alert('Profile Name cannot be empty.');
return;
}
createSigningProfile(profileName);
handleClose();
}
function CreateSigningProfileNameInput() {
return (
<TextField
id="standard-textarea"
label="Profile Name"
variant="outlined"
margin="normal"
required
autoFocus
value={profileName}
onChange={handleChangeProfileName}
fullWidth
inputProps={{ maxLength: 64 }}
/>
);
}
function CancelButton() {
return (
<Button
onClick={handleClose}
variant="contained"
color="secondary"
>
Cancel
</Button>
);
}
function CreateSigningProfilButton() {
return (
<Button
type="submit"
variant="contained"
color="primary"
className={classes.button}
>
Create Signing Profile
</Button>
);
}
return (
<Dialog open={open} onEnter={resetFields} onClose={handleClose} aria-labelledby="form-dialog-title">
<DialogTitle id="form-dialog-title">Create Signing Profile</DialogTitle>
<form className={classes.root} onSubmit={handleSubmit} noValidate autoComplete="off">
<DialogContent>
{CreateSigningProfileNameInput()}
</DialogContent>
<DialogActions>
{CancelButton()}
{CreateSigningProfilButton()}
</DialogActions>
</form>
</Dialog>
);
}