Skip to content

Commit 1cd7881

Browse files
committed
[1.5.0] Add Notification component
1 parent 98ad33c commit 1cd7881

File tree

7 files changed

+57
-11
lines changed

7 files changed

+57
-11
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
## 1.5.0
2+
3+
### Add
4+
5+
- `<Notification />` component to show notifications on success/error
6+
17
## 1.4.4
28

39
### Fixed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ See demo at [https://detools.github.io/vue-form](https://detools.github.io/vue-f
7878

7979
## Changelog
8080

81+
- [1.5.0](/CHANGELOG.md#150)
8182
- [1.4.4](/CHANGELOG.md#144)
8283
- [1.4.3](/CHANGELOG.md#143)
8384
- [1.4.2](/CHANGELOG.md#142)

VueForm/Form.vue

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
import { isNil, isBoolean, has, mapValues, noop } from 'lodash'
33
import { Form, Button } from 'element-ui'
44
import FormItem from './ConnectedFormItem'
5+
import Notification from './Notification'
56
import CONSTANTS from './constants'
6-
import isPromise from './utils/is-promise'
77
88
const BUTTONS_POSITION = {
99
START: 'start',
@@ -33,6 +33,8 @@ export default {
3333
default: () => ({}),
3434
},
3535
36+
messages: Object,
37+
3638
handleSubmit: {
3739
type: Function,
3840
default: noop,
@@ -128,14 +130,14 @@ export default {
128130
return this.handleDisabled(this.errors)
129131
}
130132
131-
const response = this.handleSubmit({ ...this.initialValues, ...this.state })
132-
if (isPromise(response)) {
133-
const off = this.manageSubmittingState()
134-
135-
return response.then(off).catch(off)
136-
}
137-
138-
return response
133+
const messages = this.messages || {}
134+
const off = this.manageSubmittingState()
135+
return Promise.resolve(this.handleSubmit({ ...this.initialValues, ...this.state }))
136+
.then(
137+
() => Notification.success(messages.success),
138+
() => Notification.error(messages.error)
139+
)
140+
.then(off)
139141
},
140142
141143
nativeOnReset(event) {

VueForm/Notification.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import Vue from 'vue'
2+
import startCase from 'lodash/startCase'
3+
import { Notification } from 'element-ui'
4+
5+
export default new Vue({
6+
methods: {
7+
renderMessage(message) {
8+
return <div style="text-align: left">{message}</div>
9+
},
10+
11+
getHandler(type, message) {
12+
if (message) {
13+
Notification[type]({ title: startCase(type), message: this.renderMessage(message) })
14+
}
15+
},
16+
17+
success(message) {
18+
return this.getHandler('success', message)
19+
},
20+
21+
warning(message) {
22+
return this.getHandler('warning', message)
23+
},
24+
25+
info(message) {
26+
return this.getHandler('info', message)
27+
},
28+
29+
error(message) {
30+
return this.getHandler('error', message)
31+
},
32+
},
33+
})

VueForm/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import Slider from './ConnectedSlider'
1111
import TimePicker from './ConnectedTimePicker'
1212
import DatePicker from './ConnectedDatePicker'
1313
import FormItem from './ConnectedFormItem'
14+
15+
import Notification from './Notification'
16+
1417
import validations from './validations'
1518

1619
export {
@@ -26,6 +29,7 @@ export {
2629
TimePicker,
2730
DatePicker,
2831
FormItem,
32+
Notification,
2933
validations,
3034
}
3135

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@detools/vue-form",
3-
"version": "1.4.4",
3+
"version": "1.5.0",
44
"description": "Vue Form component on hooks",
55
"main": "VueForm/index.js",
66
"scripts": {

0 commit comments

Comments
 (0)