) => async ( dispatch: Dispatch<Actions | RouterAction | PublishNotificationAction> ) => { let createdOrg: Organization try { createdOrg = await client.organizations.create(org) await client.templates.create({ ...defaultTemplates.systemTemplate(), orgID: createdOrg.id, }) await client.templates.create({ ...defaultTemplates.gettingStartedWithFluxTemplate(), orgID: createdOrg.id, }) dispatch(notify(orgCreateSuccess())) dispatch(addOrg(createdOrg)) dispatch(push(`/orgs/${createdOrg.id}`)) await client.buckets.create({ ...bucket, organizationID: createdOrg.id, }) dispatch(notify(bucketCreateSuccess())) } catch (e) { console.error(e) if (!createdOrg) { dispatch(notify(orgCreateFailed())) } dispatch(notify(bucketCreateFailed())) } }
) => async (dispatch: Dispatch<Action>) => { try { const bucket = await client.buckets.update(updatedBucket.id, updatedBucket) dispatch(editBucket(bucket)) dispatch(notify(bucketRenameSuccess(updatedBucket.name))) } catch (e) { console.error(e) dispatch(notify(bucketRenameFailed(originalName))) } }
export const deleteBucket = (id: string, name: string) => async ( dispatch: Dispatch<Action> ) => { try { await client.buckets.delete(id) dispatch(removeBucket(id)) } catch (e) { console.error(e) dispatch(notify(bucketDeleteFailed(name))) } }
export const updateBucket = (updatedBucket: Bucket) => async ( dispatch: Dispatch<Action> ) => { try { const bucket = await client.buckets.update(updatedBucket.id, updatedBucket) dispatch(editBucket(bucket)) } catch (e) { console.error(e) dispatch(notify(bucketUpdateFailed(updatedBucket.name))) } }
export const getBuckets = () => async ( dispatch: Dispatch<Action>, getState: () => AppState ) => { try { dispatch(setBuckets(RemoteDataState.Loading)) const { orgs: {org}, } = getState() const buckets = await client.buckets.getAll(org.id) dispatch(setBuckets(RemoteDataState.Done, buckets)) } catch (e) { console.error(e) dispatch(setBuckets(RemoteDataState.Error)) dispatch(notify(getBucketsFailed())) } }
export const createBucket = (bucket: Bucket) => async ( dispatch: Dispatch<Action>, getState: () => AppState ) => { try { const { orgs: {org}, } = getState() const createdBucket = await client.buckets.create({ ...bucket, organizationID: org.id, }) dispatch(addBucket(createdBucket)) } catch (e) { console.error(e) dispatch(notify(bucketCreateFailed())) throw e } }
export const createBucket = (bucket: Bucket) => async ( dispatch: Dispatch<Action>, getState: () => AppState ) => { try { const { orgs: {org}, } = getState() const createdBucket = await client.buckets.create({ ...bucket, orgID: org.id, }) dispatch(addBucket(createdBucket)) dispatch(checkBucketLimits()) } catch (error) { console.error(error) const message = getErrorMessage(error) dispatch(notify(bucketCreateFailed(message))) } }