refactor: 💡 authenticate route and forms to be type agnostic

This commit is contained in:
Randall Morey committed 2021-01-06 13:46:22 -05:00
1 parent 2af8d7efb8
commit 8e3551ddae
5 files changed
+76 -38

No files matched your search

@@ -0,0 +1,7 @@
{{#if @model.type}}
{{component (concat "form/authenticate/" @model.type)
submit=@submit
cancel=false
disabled=@disabled
}}
{{/if}}
@@ -0,0 +1,28 @@
<Rose::Form
class="full-width"
@onSubmit={{fn this.submit @submit (hash
identification=this.identification
password=this.password
)}}
@cancel={{false}}
@disabled={{@disabled}}
as |form|
>
<form.input
@name="identification"
@type="text"
@value={{this.identification}}
@label={{t "form.login_name.label"}} />
<form.input
@name="password"
@type="password"
@value={{this.password}}
@label={{t "form.password.label"}} />
<form.actions
@submitText={{t "actions.authenticate"}}
@showCancel={{false}} />
</Rose::Form>
@@ -0,0 +1,37 @@
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { run } from '@ember/runloop';
export default class FormAuthenticatePasswordComponent extends Component {
// =properties
/**
* New password property
* @type {string}
*/
@tracked password;
// =methods
/**
* Unsets the password field.
*/
resetPassword() {
this.password = null;
}
// =actions
/**
* Submit credentials, but reset the password first in case of failure.
* Callback with no arguments otherwise.
* @param {function} fn
* @param {object} creds
*/
@action
submit(fn, creds) {
run(() => this.resetPassword());
run(() => fn(creds));
}
}