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

fix: Disallow publish event without tickets #4674

Merged
merged 4 commits into from
Jul 31, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
30 changes: 22 additions & 8 deletions app/controllers/events/view.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import Controller from '@ember/controller';
import { isEmpty } from '@ember/utils';
import { action } from '@ember/object';
import { action, computed } from '@ember/object';

export default class extends Controller {
@computed('model.state', 'model.tickets', 'model.locationName')
get isEventPublishable() {
return !(this.model.state === 'draft' && (isEmpty(this.model.tickets) || isEmpty(this.model.locationName)));
}

@action
openConfirmModal() {
this.set('isPublishUnpublishModalOpen', true);
Expand All @@ -11,15 +16,24 @@ export default class extends Controller {
@action
togglePublishState() {
this.set('isPublishUnpublishModalOpen', false);
if (isEmpty(this.model.locationName)) {
this.notify.error(this.l10n.t('Your event must have a location before it can be published.'),
{
id: 'event_location'
});
return;
const { state } = this.model;
if (state === 'draft') {
if (isEmpty(this.model.tickets)) {
this.notify.error(this.l10n.t('Your event must have tickets before it can be published.'),
{
id: 'event_tickets'
});
return;
}
if (isEmpty(this.model.locationName)) {
this.notify.error(this.l10n.t('Your event must have a location before it can be published.'),
{
id: 'event_location'
});
return;
}
}
this.set('isLoading', true);
const { state } = this.model;
this.set('model.state', state === 'draft' ? 'published' : 'draft');
this.model.save()
.then(() => {
Expand Down
30 changes: 22 additions & 8 deletions app/templates/components/modals/publish-unpublish-modal.hbs
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<i class="black close icon"></i>
<div class="header">
{{t 'Are you sure?'}}
{{#if (or (eq this.state 'published') this.isEventPublishable)}}
{{t 'Are you sure?'}}
{{else}}
{{t 'Incomplete event details'}}
{{/if}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have used tabs instead of spaces. Please use spaces

</div>
<div class="content">
{{#if (eq this.state 'published')}}
<p>{{t 'This will unpublish your event. It will not be accessible to the public on the Internet anymore if you continue. The data of the event will still be available on your dashboard, but tickets, call for speakers or any other features will no longer be available online. Do you want to unpublish your event now?'}}</p>
{{else}}
<p>{{t 'This will publish the event and the event will be visible on the Internet. Please confirm you want to publish your event.'}}</p>
{{#if this.isEventPublishable}}
<p>{{t 'This will publish the event and the event will be visible on the Internet. Please confirm you want to publish your event.'}}</p>
{{else}}
<p>{{t 'You need to add more details such as location and tickets to your event in order to publish it.'}}</p>
{{/if}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have used tabs instead of spaces. Please use spaces

{{/if}}
</div>
<div class="actions">
Expand All @@ -18,11 +26,17 @@
{{t 'Cancel'}}
</button>
{{else}}
<button type="button" class="ui green button" {{action this.togglePublishState}}>
{{t 'Yes'}}
</button>
<button type="button" class="ui button" {{action 'toggleView'}}>
{{t 'Cancel, Do Not Publish it Now'}}
</button>
{{#if this.isEventPublishable}}
<button type="button" class="ui green button" {{action this.togglePublishState}}>
{{t 'Yes'}}
</button>
<button type="button" class="ui button" {{action 'toggleView'}}>
{{t 'Cancel, Do Not Publish it Now'}}
</button>
{{else}}
<button type="button" class="ui button" {{action 'toggleView'}}>
{{t 'Okay'}}
</button>
{{/if}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have used tabs instead of spaces. Please use spaces

{{/if}}
</div>
6 changes: 3 additions & 3 deletions app/templates/events/view.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<i class="unhide icon"></i>
</a>
<button
class="ui button {{if (eq this.model.state 'published') 'orange' 'green'}}"
class="ui button {{if (eq this.model.state 'published') 'orange'}} {{if this.isEventPublishable 'green'}}"
{{action 'openConfirmModal'}}
data-tooltip="{{if (eq this.model.state 'published') 'Unpublish' 'Publish'}}"
data-position="top left"
Expand All @@ -49,7 +49,7 @@
{{/if}}
</a>

<button class="ui button labeled icon small {{if (eq this.model.state 'published') 'orange' 'green'}}" {{action 'openConfirmModal'}}>
<button class="ui button labeled icon small {{if (eq this.model.state 'published') 'orange'}} {{if this.isEventPublishable 'green'}}" {{action 'openConfirmModal'}}>
{{#if (eq this.model.state 'published')}}
<i class="ban icon"></i>
{{t 'Unpublish'}}
Expand Down Expand Up @@ -105,4 +105,4 @@
{{!-- the edit page will be rendered without any of the above tabs --}}
{{outlet}}
{{/if}}
<Modals::PublishUnpublishModal @isOpen={{this.isPublishUnpublishModalOpen}} @state={{this.model.state}} @togglePublishState={{action 'togglePublishState'}} />
<Modals::PublishUnpublishModal @isOpen={{this.isPublishUnpublishModalOpen}} @state={{this.model.state}} @isEventPublishable={{this.isEventPublishable}} @togglePublishState={{action 'togglePublishState'}} />