Add dashboard step next notifications

pull/4314/head
Deniz Kusefoglu 2018-08-27 12:02:18 -07:00
parent 7fa26dc97f
commit 21668a6dbe
2 changed files with 25 additions and 1 deletions

View File

@ -468,6 +468,18 @@ export const notifyDashboardDeleted = (name: string): Notification => ({
message: `Dashboard ${name} deleted successfully.`,
})
export const notifyDashboardCreated = (count: number): Notification => ({
...defaultSuccessNotification,
icon: 'dash-h',
message: `Selected dashboard${count > 1 ? 's' : ''} have been created.`,
})
export const notifyDashboardCreationFailed = (count: number): Notification => ({
...defaultErrorNotification,
icon: 'dash-h',
message: `Could not create selected dashboard${count > 1 ? 's' : ''}.`,
})
export const notifyDashboardExported = (name: string): Notification => ({
...defaultSuccessNotification,
icon: 'dash-h',

View File

@ -21,6 +21,12 @@ import SearchBar from 'src/hosts/components/SearchBar'
// Actions
import {notify as notifyAction} from 'src/shared/actions/notifications'
// Constants
import {
notifyDashboardCreated,
notifyDashboardCreationFailed,
} from 'src/shared/copy/notifications'
// Types
import {Protoboard} from 'src/types'
import {NextReturn} from 'src/types/wizard'
@ -32,6 +38,7 @@ interface State {
}
interface Props {
notify: typeof notifyAction
dashboardsCreated: Protoboard[]
}
@ -57,7 +64,7 @@ class DashboardStep extends Component<Props, State> {
public next = async (): Promise<NextReturn> => {
const {selected, protoboards} = this.state
const {dashboardsCreated} = this.props
const {dashboardsCreated, notify} = this.props
const selectedProtoboards = protoboards.filter(p => selected[p.id])
@ -68,13 +75,18 @@ class DashboardStep extends Component<Props, State> {
return d.id === p.id
})
)
const countNew = newSelectedProtoboards.length
try {
newSelectedProtoboards.forEach(p => {
createDashboardFromProtoboard(p)
})
if (countNew > 0) {
notify(notifyDashboardCreated(countNew))
}
return {error: false, payload: selectedProtoboards}
} catch (err) {
notify(notifyDashboardCreationFailed(countNew))
return {error: true, payload: null}
}
}