Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only allow submission of Leaders portion of form if a company is marked as "Leaders Eligible" via label #17

Open
wants to merge 17 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions services/app/app/components/submit-modal/categories.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default Component.extend(ActionMixin, {
email: null,
error: null,

leadershipEnabled: false,
isOpen: false,
isInvalid: computed('name', 'email', function() {
if (!this.name || !this.email) return true;
Expand All @@ -39,9 +40,18 @@ export default Component.extend(ActionMixin, {
const variables = { input: { name, email, hash, type, payload } };

try {
await this.apollo.mutate({ mutation, variables });
if (!this.isDestroyed) this.set('isOpen', false);
this.notify.info('Changes requested. You will recieve an email shortly confirming your request.', { clearDuration: 30000 });
if(this.leadershipEnabled) {
await this.apollo.mutate({ mutation, variables });
if (!this.isDestroyed) this.set('isOpen', false);
this.notify.info('Changes requested. You will recieve an email shortly confirming your request.', { clearDuration: 30000 });
}
else {
if (!this.isDestroyed) this.set('isOpen', false);
const errorString = this.config.contactUrl ?
`<p>Sorry, leadership updates are unavailable for this company. <a href=${this.config.contactUrl} target="_blank" rel="noopener">Click here</a> to contact us if you need help!</p>`
: 'Sorry, leadership updates are unavailable for this company.';
this.notify.error(errorString, { autoClear: false, htmlContent: true });
}
this.onComplete();
} catch (e) {
error(e);
Expand Down
12 changes: 7 additions & 5 deletions services/app/app/controllers/portal/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import { computed } from '@ember/object';

export default Controller.extend({

leadershipEnabled: computed('config.{leadershipEnabled,leadershipCompanyLabel}', 'model.labels.[]', function() {
leadershipEnabled: computed('config.{leadershipEnabled,leadershipCompanyLabel}', 'model.{labels.[]}', function() {
// disable leadership Categories if not enabled
if(!this.config.leadershipEnabled) return false;
// if no company lable configured return the leadershipEnabled setting from the config
if(!this.config.leadershipCompanyLabel) return this.config.leadershipEnabled;
// check that the company label is in the array of labels for this company
return(this.model.labels.includes(this.config.leadershipCompanyLabel));
// if company label is configured return the leadershipEnabled setting from the config
if(this.config.leadershipCompanyLabel) {
// check that the company label is in the array of labels for this company
return this.model.labels.includes(this.config.leadershipCompanyLabel);
}
Shinsina marked this conversation as resolved.
Show resolved Hide resolved
return true;
}),
directoryEnabled: computed('config.{directoryEnabled,directoryCategoryIds}', function () {
return this.config.directoryEnabled && this.config.directoryCategoryIds.length;
Expand Down
11 changes: 11 additions & 0 deletions services/app/app/controllers/portal/leadership.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ export default Controller.extend({
return this.get('categories.length') === 0;
}),

leadershipEnabled: computed('config.{leadershipEnabled,leadershipCompanyLabel}', 'model.contentHash.{labels.[]}', function() {
// disable leadership Categories if not enabled
if(!this.config.leadershipEnabled) return false;
// if company label is configured return the leadershipEnabled setting from the config
if(this.config.leadershipCompanyLabel) {
// check that the company label is in the array of labels for this company
return this.model.contentHash.labels.includes(this.config.leadershipCompanyLabel);
}
return true;
}),

categoryPrefix: computed.reads('config.leadershipCategoryPrefix'),

init() {
Expand Down
1 change: 1 addition & 0 deletions services/app/app/templates/portal/leadership.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@
hash=hash
isOpen=isModalOpen
categories=categories
leadershipEnabled=leadershipEnabled
onComplete=(action "transitionToPortal")
}}