/
contact-no-mson.js
64 lines (55 loc) · 1.62 KB
/
contact-no-mson.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import Form from 'mson/lib/form';
import { TextField, EmailField, ButtonField } from 'mson/lib/fields';
import compiler from 'mson/lib/compiler';
import globals from 'mson/lib/globals';
// Note: you can also use the following instead of the import above
// const Form = compiler.getCompiledComponent('Form');
class ContactNoMSON extends Form {
_create(props) {
super._create(props);
this.set({
fields: [
new TextField({
name: 'firstName',
label: 'First Name',
required: true,
block: false
}),
new TextField({ name: 'lastName', label: 'Last Name', required: true }),
new EmailField({ name: 'email', label: 'Email' }),
new ButtonField({
name: 'import',
label: 'Import',
icon: 'ImportContacts'
}),
new ButtonField({
name: 'submit',
label: 'Submit',
type: 'submit',
icon: 'Save'
}),
new ButtonField({ name: 'cancel', label: 'Cancel', icon: 'Cancel' })
]
});
this.on('import', () => {
this.setValues({
firstName: 'Prince',
lastName: 'Nelson',
email: 'prince@example.com'
});
});
this.on('submit', () => {
// TODO: do something like contact an API
const values = this.getValues();
console.log('submitting', values);
globals.displaySnackbar(
`Submitted ${values.firstName} ${values.lastName}`
);
});
this.on('cancel', () => {
// Redirect home
globals.redirect('/');
});
}
}
compiler.registerComponent('app.ContactNoMSON', ContactNoMSON);