squeaknode/frontend/src/components/CreateContactProfileDialog/CreateContactProfileDialog.js
Jonathan Zernik 5198467889
Use new squeak protocol with schnorr and pubkey as identifier (#1870)
* Got all tests in core dir passing

* Got all tests in db dir passing

* Got tests for admin dir passing

* Got all unit tests passing

* Added migration for squeak table and profile table using new pubkey

* Re-start db migrations with new data-v2.db file

* Fix column type for profile public key

* Got all itests passing

* Log the public key in hex in create contact profile handle fn

* Rename rpc methods to use pubkey instead of address

* Got frontend mostly working with new profile pubkey

* Update frontend to use pubkey instead of address

* Change size of squeak profile detail item

* Update create contact profile dialog to use pubkey

* Update twitter account item to use pubkey

* Include label for pubkey in profile detail item

* Decrease size of profile detail item

* Update frontend build

* Improve logging of requests in handler
2021-12-20 09:28:38 -08:00

147 lines
3.3 KiB
JavaScript

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 {
createContactProfileRequest,
} from '../../squeakclient/requests';
import {
goToProfilePage,
} from '../../navigation/navigation';
export default function CreateContactProfileDialog({
open,
handleClose,
initialPubkey = '',
...props
}) {
const classes = useStyles();
const history = useHistory();
const [profileName, setProfileName] = useState('');
const [pubkey, setPubkey] = useState(initialPubkey);
const resetFields = () => {
setProfileName('');
setPubkey(initialPubkey);
};
const handleChangeProfileName = (event) => {
setProfileName(event.target.value);
};
const handleChangePubkey = (event) => {
setPubkey(event.target.value);
};
const handleResponse = (response) => {
goToProfilePage(history, response.getProfileId());
};
const handleErr = (err) => {
alert(`Error creating contact profile: ${err}`);
};
const createContactProfile = (profileName, squeakPubkey) => {
createContactProfileRequest(profileName, squeakPubkey, handleResponse, handleErr);
};
function handleSubmit(event) {
event.preventDefault();
console.log('profileName:', profileName);
console.log('pubkey:', pubkey);
if (!profileName) {
alert('Profile Name cannot be empty.');
return;
}
if (!pubkey) {
alert('Pubkey Name cannot be empty.');
return;
}
createContactProfile(profileName, pubkey);
handleClose();
}
function CreateContactProfileNameInput() {
return (
<TextField
id="standard-textarea"
label="Profile Name"
variant="outlined"
required
autoFocus
value={profileName}
onChange={handleChangeProfileName}
fullWidth
margin="normal"
inputProps={{ maxLength: 64 }}
/>
);
}
function CreateContactPubkeyInput() {
return (
<TextField
required
id="standard-textarea"
label="Pubkey"
variant="outlined"
margin="normal"
value={pubkey}
onChange={handleChangePubkey}
inputProps={{ maxLength: 66 }}
/>
);
}
function CancelButton() {
return (
<Button
onClick={handleClose}
variant="contained"
color="secondary"
>
Cancel
</Button>
);
}
function CreateContactProfilButton() {
return (
<Button
type="submit"
variant="contained"
color="primary"
className={classes.button}
>
Create Contact Profile
</Button>
);
}
return (
<Dialog open={open} onEnter={resetFields} 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>
{CreateContactProfileNameInput()}
{CreateContactPubkeyInput()}
</DialogContent>
<DialogActions>
{CancelButton()}
{CreateContactProfilButton()}
</DialogActions>
</form>
</Dialog>
);
}