Skip to content

feat: implement dropdown for social media in other-details step #4924

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

Merged
merged 2 commits into from
Sep 2, 2020
Merged
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
29 changes: 1 addition & 28 deletions app/components/forms/wizard/other-details-step.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import Component from '@ember/component';
import { computed } from '@ember/object';
import moment from 'moment';
import { merge, orderBy, find } from 'lodash-es';
import { orderBy, find } from 'lodash-es';
import { licenses } from 'open-event-frontend/utils/dictionary/licenses';
import { timezones } from 'open-event-frontend/utils/dictionary/date-time';
import FormMixin from 'open-event-frontend/mixins/form';
Expand All @@ -23,38 +23,13 @@ export default Component.extend(FormMixin, EventWizardMixin, {
return orderBy(licenses, 'name');
}),


socialLinks: computed('data.event.socialLinks.@each.isDeleted', function() {
return this.data.event.socialLinks.filterBy('isDeleted', false);
}),

isUserUnverified: computed('authManager.currentUser.isVerified', function() {
return !this.authManager.currentUser.isVerified;
}),
/**
* returns the validation rules for the social links.
*/
socialLinksValidationRules: computed('socialLinks', function() {
let validationRules = {};
for (let i = 0; i < this.socialLinks.length; i++) {
validationRules = merge(validationRules, {
[this.socialLinks.get(i).identifier]: {
identifier : this.socialLinks.get(i).identifier,
optional : true,
rules : [
{
type : 'regExp',
value : protocolLessValidUrlPattern,
prompt : this.l10n.t('Please enter a valid url')
}
]
}
});
}

return validationRules;
}),


showDraftButton: computed('data.event.state', function() {
return this.data.event.state !== 'published';
Expand Down Expand Up @@ -126,8 +101,6 @@ export default Component.extend(FormMixin, EventWizardMixin, {
}
}
};
// Merging the predetermined rules with the rules for social links.
validationRules.fields = merge(validationRules.fields, this.socialLinksValidationRules);
return validationRules;
},

Expand Down
20 changes: 20 additions & 0 deletions app/components/widgets/forms/link-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,26 @@ export default class LinkInput extends Component {
});
}

@observes('linkName')
linkNameObserver() {
const link = this.linkName;
const socialPlatforms = ['twitter', 'facebook', 'instagram', 'linkedin', 'youtube'];

if (socialPlatforms.includes(link)) {
this.set('segmentedLink', {
protocol : `https://${link}.com/`,
address : ''
});
}

if (link === 'website') {
this.set('segmentedLink', {
protocol : 'https://',
address : ''
});
}
}

didInsertElement() {
super.didInsertElement(...arguments);
if (this.segmentedLink) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Widgets::Forms::LinkInput
@hasLinkName={{true}}
@fixedName={{true}}
@linkName={{t "External event URL"}}
@linkName={{t "Website"}}
@inputId="external_event_url"
@segmentedLink={{this.data.event.segmentedExternalEventUrl}}
@isChild={{unless this.data.event.socialLinks true}}
Expand Down
38 changes: 28 additions & 10 deletions app/templates/components/widgets/forms/link-input.hbs
Original file line number Diff line number Diff line change
@@ -1,18 +1,36 @@
{{#if this.hasLinkName}}
<div class="three wide field">
<Input @type="text" @value={{this.linkName}} @disabled={{this.fixedName}} />
<div class="ui labeled input">
{{#if this.fixedName}}
<Input @type="text" @value={{this.linkName}} @disabled={{this.fixedName}} />
{{else}}
<UiDropdown @class='selection' @selected={{this.linkName}} @onChange={{action (mut this.linkName)}}>
<div class="default text">Select</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value='website' >Website</div>
<div class="item" data-value="twitter">Twitter</div>
<div class="item" data-value="facebook">Facebook</div>
<div class="item" data-value="linkedin">Linkedin</div>
<div class="item" data-value="instagram">Instagram</div>
<div class="item" data-value="youtube">Youtube</div>
</div>
</UiDropdown>
{{/if}}
</div>
</div>
<div class="six wide field">
<div class="ui labeled {{if this.isChild 'action'}} input">
<UiDropdown @class="label" @selected={{this.protocol}} @onChange={{action (mut this.protocol)}}>
<div class="text">https://</div>
<i class="dropdown icon"></i>
<div class="menu">
<div class="item" data-value="http">http://</div>
<div class="item" data-value="https">https://</div>
<div class="ui labeled {{if this.isChild 'action'}} input">
<div class="ui labeled input">
<div class="ui label">
{{#if this.isChild}}
{{this.protocol}}
{{else}}
https://
{{/if}}
</div>
<Input @type="text" @value={{this.address}} @name={{name}} @id={{this.inputId}} />
</div>
</UiDropdown>
<Input @type="text" @value={{this.address}} @name={{name}} @id={{this.inputId}} />
{{#if this.isChild}}
<div class="ui icon buttons">
{{#if this.canRemoveItem}}
Expand Down
9 changes: 5 additions & 4 deletions app/utils/computed-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,18 @@ export const computedSegmentedLink = function(property) {
const splitted = this.get(property) ? this.get(property).split('://') : [];
if (!splitted || splitted.length === 0 || (splitted.length === 1 && splitted[0].includes('http'))) {
return {
protocol : 'https',
protocol : 'https://',
address : ''
};
}
const socialUrl = splitted[1].split('/');
return {
protocol : splitted[0],
address : splitted[1]
protocol : `${splitted[0]}://${socialUrl[0]}/`,
address : socialUrl[1]
};
},
set(key, value) {
const finalLink = values(value).join('://');
const finalLink = values(value).join('');
if (finalLink && isValidUrl(finalLink.trim())) {
this.set(property, finalLink.trim());
} else {
Expand Down