From b459edee9c30f4f4a7a754d4d4389c1329364476 Mon Sep 17 00:00:00 2001 From: Palak Bhojani Date: Wed, 20 Feb 2019 15:11:49 -0800 Subject: [PATCH] Add notifications for success/failed when creating/deleting/updating buckets --- ui/src/organizations/components/Buckets.tsx | 44 ++++++++++++++++----- ui/src/shared/copy/v2/notifications.ts | 29 +++++++++++++- 2 files changed, 62 insertions(+), 11 deletions(-) diff --git a/ui/src/organizations/components/Buckets.tsx b/ui/src/organizations/components/Buckets.tsx index fea869c6840..d1480933886 100644 --- a/ui/src/organizations/components/Buckets.tsx +++ b/ui/src/organizations/components/Buckets.tsx @@ -44,7 +44,14 @@ interface State { // Decorators import {ErrorHandling} from 'src/shared/decorators/errors' -import {bucketDeleted} from 'src/shared/copy/v2/notifications' +import { + bucketDeleteSuccess, + bucketDeleteFailed, + bucketCreateFailed, + bucketCreateSuccess, + bucketUpdateFailed, + bucketUpdateSuccess, +} from 'src/shared/copy/v2/notifications' @ErrorHandling export default class Buckets extends PureComponent { @@ -106,21 +113,40 @@ export default class Buckets extends PureComponent { } private handleUpdateBucket = async (updatedBucket: PrettyBucket) => { - await client.buckets.update(updatedBucket.id, updatedBucket) - this.props.onChange() + const {onChange, notify} = this.props + try { + await client.buckets.update(updatedBucket.id, updatedBucket) + onChange() + notify(bucketUpdateSuccess(updatedBucket.name)) + } catch (e) { + console.error(e) + notify(bucketUpdateFailed(updatedBucket.name)) + } } private handleDeleteBucket = async (deletedBucket: PrettyBucket) => { const {onChange, notify} = this.props - await client.buckets.delete(deletedBucket.id) - onChange() - notify(bucketDeleted(deletedBucket.name)) + try { + await client.buckets.delete(deletedBucket.id) + onChange() + notify(bucketDeleteSuccess(deletedBucket.name)) + } catch (e) { + console.error(e) + bucketDeleteFailed(deletedBucket.name) + } } private handleCreateBucket = async (bucket: Bucket): Promise => { - await client.buckets.create(bucket) - this.props.onChange() - this.handleCloseModal() + const {onChange, notify} = this.props + try { + await client.buckets.create(bucket) + onChange() + this.handleCloseModal() + notify(bucketCreateSuccess()) + } catch (e) { + console.error(e) + notify(bucketCreateFailed()) + } } private handleOpenModal = (): void => { diff --git a/ui/src/shared/copy/v2/notifications.ts b/ui/src/shared/copy/v2/notifications.ts index cee3895afa1..b795166b6ee 100644 --- a/ui/src/shared/copy/v2/notifications.ts +++ b/ui/src/shared/copy/v2/notifications.ts @@ -120,9 +120,34 @@ export const labelUpdateFailed = (): Notification => ({ message: 'Failed to update label', }) -export const bucketDeleted = (bucketName: string): Notification => ({ +export const bucketDeleteSuccess = (bucketName: string): Notification => ({ ...defaultSuccessNotification, - message: `Bucket ${bucketName} was successfully deleted`, + message: `Bucket "${bucketName}" was successfully deleted`, +}) + +export const bucketDeleteFailed = (bucketName: string): Notification => ({ + ...defaultErrorNotification, + message: `Failed to delete bucket: "${bucketName}"`, +}) + +export const bucketCreateSuccess = (): Notification => ({ + ...defaultSuccessNotification, + message: 'Bucket was successfully created', +}) + +export const bucketCreateFailed = (): Notification => ({ + ...defaultErrorNotification, + message: 'Failed to create bucket', +}) + +export const bucketUpdateSuccess = (bucketName: string): Notification => ({ + ...defaultSuccessNotification, + message: `Bucket "${bucketName}" was successfully updated`, +}) + +export const bucketUpdateFailed = (bucketName: string): Notification => ({ + ...defaultErrorNotification, + message: `Failed to update bucket: "${bucketName}"`, }) export const scraperDeleteSuccess = (scraperName: string): Notification => ({