Bug(UI): Signup onclick loading (#541)

* bug(UI): on click loader is added

* bug(UI): on click loader is added
This commit is contained in:
pal-sig 2021-12-24 11:42:25 +05:30 committed by GitHub
parent d825fc2f30
commit 7f5b0c15c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,13 +20,11 @@ import {
const Signup = ({ loggedIn }: SignupProps): JSX.Element => { const Signup = ({ loggedIn }: SignupProps): JSX.Element => {
const [notificationsInstance, Element] = notification.useNotification(); const [notificationsInstance, Element] = notification.useNotification();
const [state, setState] = useState({ submitted: false }); const [loading, setLoading] = useState(false);
const [formState, setFormState] = useState({ const [formState, setFormState] = useState({
firstName: { value: '' }, firstName: { value: '' },
companyName: { value: '' },
email: { value: '' }, email: { value: '' },
password: { value: '', valid: true },
emailOptIn: { value: true },
}); });
const updateForm = ( const updateForm = (
@ -50,7 +48,7 @@ const Signup = ({ loggedIn }: SignupProps): JSX.Element => {
(async (): Promise<void> => { (async (): Promise<void> => {
try { try {
e.preventDefault(); e.preventDefault();
setState((state) => ({ ...state, submitted: true })); setLoading(true);
const payload = { const payload = {
first_name: formState.firstName, first_name: formState.firstName,
email: formState.email, email: formState.email,
@ -69,10 +67,12 @@ const Signup = ({ loggedIn }: SignupProps): JSX.Element => {
message: 'Something went wrong', message: 'Something went wrong',
}); });
} }
setLoading(false);
} catch (error) { } catch (error) {
notificationsInstance.error({ notificationsInstance.error({
message: 'Something went wrong', message: 'Something went wrong',
}); });
setLoading(false);
} }
})(); })();
}; };
@ -121,7 +121,8 @@ const Signup = ({ loggedIn }: SignupProps): JSX.Element => {
type="primary" type="primary"
htmlType="submit" htmlType="submit"
data-attr="signup" data-attr="signup"
disabled={state.submitted && !formState.password} loading={loading}
disabled={loading || !formState.email.value}
> >
Get Started Get Started
</Button> </Button>