diff --git a/ui/src/shared/copy/notifications.ts b/ui/src/shared/copy/notifications.ts index eb700c0aa..fd923af61 100644 --- a/ui/src/shared/copy/notifications.ts +++ b/ui/src/shared/copy/notifications.ts @@ -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', diff --git a/ui/src/sources/components/DashboardStep.tsx b/ui/src/sources/components/DashboardStep.tsx index f414b2306..ab45885d7 100644 --- a/ui/src/sources/components/DashboardStep.tsx +++ b/ui/src/sources/components/DashboardStep.tsx @@ -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 { public next = async (): Promise => { 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 { 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} } }