From 8cb1d81d7173339701dfbf403ad10d0e5cb4949d Mon Sep 17 00:00:00 2001 From: Susmitha Girumala Date: Tue, 23 Jun 2020 15:15:47 -0400 Subject: [PATCH] Add user creation view --- ui/core/app/components/form/user/index.hbs | 49 +++++++++++++++++++ ui/core/app/routes/orgs/org/users/new.js | 46 +++++++++++++++++ ui/core/app/templates/orgs/org/users/new.hbs | 18 ++++++- ui/core/app/templates/orgs/org/users/user.hbs | 2 +- ui/core/translations/en-us.yaml | 5 ++ 5 files changed, 118 insertions(+), 2 deletions(-) create mode 100644 ui/core/app/components/form/user/index.hbs diff --git a/ui/core/app/components/form/user/index.hbs b/ui/core/app/components/form/user/index.hbs new file mode 100644 index 000000000..9db695baa --- /dev/null +++ b/ui/core/app/components/form/user/index.hbs @@ -0,0 +1,49 @@ + + + + {{#if @model.errors.name}} + + {{#each @model.errors.name as |error|}} + {{error.message}} + {{/each}} + + {{/if}} + + + + {{#if @model.errors.description}} + + {{#each @model.errors.description as |error|}} + {{error.message}} + {{/each}} + + {{/if}} + + + + + diff --git a/ui/core/app/routes/orgs/org/users/new.js b/ui/core/app/routes/orgs/org/users/new.js index 5df3b6cb8..a740f6caf 100644 --- a/ui/core/app/routes/orgs/org/users/new.js +++ b/ui/core/app/routes/orgs/org/users/new.js @@ -1,4 +1,50 @@ import Route from '@ember/routing/route'; +import { inject as service } from '@ember/service'; +import { action } from '@ember/object'; export default class OrgsOrgUsersNewRoute extends Route { + // =services + + @service intl; + @service notify; + + // =methods + + /** + * Returns a new unsaved user. + * @return {Promise{UserModel}} + */ + model() { + return this.store.createRecord('user'); + } + + // =actions + + /** + * Rollback changes on user to destroy unsaved instance + * and redirect to users index. + * @param {UserModel} user + */ + @action + cancel(user) { + user.rollbackAttributes(); + this.transitionTo('orgs.org.users'); + } + + /** + * Handle saving a user. + * @param {UserModel} user + * @param {Event} e + */ + @action + async save(user) { + try { + await user.save(); + this.transitionTo('orgs.org.users.user', user); + this.notify.success(this.intl.t('notify.user.create-success')); + } catch (error) { + // TODO: replace with translated strings + this.notify.error(error.message, { closeAfter: null }); + } + } } diff --git a/ui/core/app/templates/orgs/org/users/new.hbs b/ui/core/app/templates/orgs/org/users/new.hbs index e2147cab0..4ae7ef85c 100644 --- a/ui/core/app/templates/orgs/org/users/new.hbs +++ b/ui/core/app/templates/orgs/org/users/new.hbs @@ -1 +1,17 @@ -{{outlet}} \ No newline at end of file + + + + + + +

{{t "titles.new"}}

+
+ + + + +
diff --git a/ui/core/app/templates/orgs/org/users/user.hbs b/ui/core/app/templates/orgs/org/users/user.hbs index e2147cab0..c24cd6895 100644 --- a/ui/core/app/templates/orgs/org/users/user.hbs +++ b/ui/core/app/templates/orgs/org/users/user.hbs @@ -1 +1 @@ -{{outlet}} \ No newline at end of file +{{outlet}} diff --git a/ui/core/translations/en-us.yaml b/ui/core/translations/en-us.yaml index 9b925155f..e2b3c8f9b 100644 --- a/ui/core/translations/en-us.yaml +++ b/ui/core/translations/en-us.yaml @@ -48,6 +48,11 @@ errors: notfound-error: We could not find the requested resource. You can ask your administrator or try again later. server-error: We ran into a problem and could not continue. You can ask your administrator or try again later. unknown-error: Please contact your administrator or try again later. +notify: + save-success: Save succeeded. + user: + create-success: User created succesfully. + delete-success: Deleted user successfully. dev: default-org: Default Org menu-item: Menu item