feat: display registration success response

This commit is contained in:
Tobias Mahnke 2021-04-20 17:19:29 +02:00
parent 947412b0a2
commit 5d4b0ed783

View file

@ -9,12 +9,16 @@ import type { RootState } from '../store';
const RegistrationPage = connect((state: RootState) => ({ loggedIn: Boolean(state.login) }))(function RegistrationPage({ const RegistrationPage = connect((state: RootState) => ({ loggedIn: Boolean(state.login) }))(function RegistrationPage({
loggedIn, loggedIn,
}) { }) {
const [message, setMessage] = React.useState();
const onSubmit = React.useCallback(async ({ username, email, password }) => { const onSubmit = React.useCallback(async ({ username, email, password }) => {
const response = await api.post(`/accounts/register`, { const response = await api.post(`/accounts/register`, {
body: { username, email, password, confirmPassword: password }, body: { username, email, password, confirmPassword: password },
}); });
console.log('response', response); if (response && response.message) {
setMessage(response.message);
}
}, []); }, []);
return loggedIn ? ( return loggedIn ? (
@ -22,7 +26,7 @@ const RegistrationPage = connect((state: RootState) => ({ loggedIn: Boolean(stat
) : ( ) : (
<Page small> <Page small>
<h2>Register</h2> <h2>Register</h2>
<RegistrationForm onSubmit={onSubmit} /> {message ? message : <RegistrationForm onSubmit={onSubmit} />}
</Page> </Page>
); );
}); });