Skip to content
This repository has been archived by the owner on Apr 28, 2021. It is now read-only.

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
devton committed May 13, 2020
2 parents 1871e91 + 61ffbf3 commit e1e4644
Show file tree
Hide file tree
Showing 10 changed files with 186 additions and 52 deletions.
22 changes: 18 additions & 4 deletions dist/catarse.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/catarse.js.map

Large diffs are not rendered by default.

82 changes: 82 additions & 0 deletions legacy/spec/components/project-main.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import m from 'mithril';
import mq from 'mithril-query';
import projectMain from '../../src/c/project-main';
import h from '../../src/h';

describe('ProjectMain', () => {

describe('view', () => {

describe('mobile', () => {

let component = null;
let attrs = {
project() {
return {};
},
rewardDetails() {
return [];
},
hasSubscription: () => false,
};

beforeEach(() => {
// activate mobile
spyOnProperty(window.screen, 'width').and.returnValue(500);
window.dispatchEvent(new Event('resize'));

component = mq(m(projectMain, attrs));
});

it('should display rewards suggestions of 10, 25, 50, 100', () => {
component.should.have('#suggestions .fontsize-larger:contains(10)');
component.should.have('#suggestions .fontsize-larger:contains(25)');
component.should.have('#suggestions .fontsize-larger:contains(50)');
component.should.have('#suggestions .fontsize-larger:contains(100)');
});

it('should display rewads list', () => {
attrs.rewardDetails = () => ([
{
id: 100,
minimum_value: 10,
uploaded_image: 'image.png',
description: 'reward description',
}
]);
component = mq(m(projectMain, attrs));

component.should.have(`img[src='${attrs.rewardDetails()[0].uploaded_image}']`);
component.should.have('#rewards');
component.should.contain(`Para R$ ${h.formatNumber(10)}`);
});
});

describe('desktop', () => {
let component = null;
let attrs = {
project() {
return {
budget: 'budget',
};
},
rewardDetails() {
return [];
},
hasSubscription: () => false,
};

beforeEach(() => {
// activate desktop
spyOnProperty(window.screen, 'width').and.returnValue(1024);
window.dispatchEvent(new Event('resize'));

component = mq(m(projectMain, attrs));
});

it('should display about', () => {
component.should.have(`#project-about`);
});
});
});
});
5 changes: 4 additions & 1 deletion legacy/src/c/project-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ const projectMain = {

hash(window.location.hash);


if (_.isEmpty(hash()) || hash() === '#_=_' || hash() === '#preview') {
return tabs[h.mobileScreen() ? '#rewards' : '#about'];
const hasRewards = !_.isEmpty(vnode.attrs.rewardDetails());
const mobileDefault = hasRewards ? '#rewards' : '#contribution_suggestions';
return tabs[h.mobileScreen() ? mobileDefault : '#about'];
}

return tabs[hash()];
Expand Down
24 changes: 16 additions & 8 deletions legacy/src/c/project-rewards.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,22 @@ import projectGoalsBox from './project-goals-box';

const projectRewards = {
view: function({attrs}) {
return m('.w-col.w-col-12', [projectVM.isSubscription(attrs.project) ? attrs.subscriptionData() ? m(

projectGoalsBox,
{ goalDetails: attrs.goalDetails, subscriptionData: attrs.subscriptionData }
) : h.loader() : '', m(projectRewardList, _.extend({}, {
rewardDetails: attrs.rewardDetails,
hasSubscription: attrs.hasSubscription
}, attrs.c_opts))]);
return m('.w-col.w-col-12', [
projectVM.isSubscription(attrs.project) ?
attrs.subscriptionData() ?
m(projectGoalsBox, {
goalDetails: attrs.goalDetails,
subscriptionData: attrs.subscriptionData
})
:
h.loader()
:
'',
m(projectRewardList, _.extend({}, {
rewardDetails: attrs.rewardDetails,
hasSubscription: attrs.hasSubscription
}, attrs.c_opts))
]);
}
};

Expand Down
23 changes: 13 additions & 10 deletions legacy/src/c/project-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,19 @@ const projectTabs = {
}, [
m('.w-container', [
m('.w-row', [
m('.w-col.w-col-8', [!_.isEmpty(rewards()) ?
m(`a[id="rewards-link"][class="w-hidden-main w-hidden-medium dashboard-nav-link mf ${(h.hashMatch('#rewards') || (h.mobileScreen() && h.hashMatch('')) ? 'selected' : '')}"][href="/${project().permalink}#rewards"]`, {
style: 'float: left;',
onclick: h.analytics.event({
cat: 'project_view', act: 'project_rewards_view', project: project() })
}, 'Recompensas') : m(`a[id="rewards-link"][class="w-hidden-main w-hidden-medium dashboard-nav-link mf ${(h.hashMatch('#contribution_suggestions') || (h.mobileScreen() && h.hashMatch('')) ? 'selected' : '')}"][href="/${project().permalink}#contribution_suggestions"]`, {
style: 'float: left;',
onclick: h.analytics.event({
cat: 'project_view', act: 'project_contribsuggestions_view', project: project() })
}, 'Valores Sugeridos'),
m('.w-col.w-col-8', [
!_.isEmpty(rewards()) ?
m(`a[id="rewards-link"][class="w-hidden-main w-hidden-medium dashboard-nav-link mf ${(h.hashMatch('#rewards') || (h.mobileScreen() && h.hashMatch('')) ? 'selected' : '')}"][href="/${project().permalink}#rewards"]`, {
style: 'float: left;',
onclick: h.analytics.event({
cat: 'project_view', act: 'project_rewards_view', project: project() })
}, 'Recompensas')
:
m(`a[id="rewards-link"][class="w-hidden-main w-hidden-medium dashboard-nav-link mf ${(h.hashMatch('#contribution_suggestions') || (h.mobileScreen() && h.hashMatch('')) ? 'selected' : '')}"][href="/${project().permalink}#contribution_suggestions"]`, {
style: 'float: left;',
onclick: h.analytics.event({
cat: 'project_view', act: 'project_contribsuggestions_view', project: project() })
}, 'Valores Sugeridos'),
m(`a[id="about-link"][class="dashboard-nav-link mf ${(h.hashMatch('#about') || (!h.mobileScreen() && h.hashMatch('')) ? 'selected' : '')}"][href="#about"]`, {
style: 'float: left;',
onclick: h.analytics.event({
Expand Down
31 changes: 27 additions & 4 deletions legacy/src/h.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,10 @@ const _dataCache = {},
const user = getUser();
return user == null || user.user_id == null ? null : user.user_id;
},
getUserCommonID = () => {
const user = getUser();
return user && user.common_id
},
userSignedIn = () => !_.isNull(getUserID()),
getBlogPosts = () => {
if (_dataCache.blogPosts) {
Expand Down Expand Up @@ -1113,7 +1117,24 @@ const _dataCache = {},
} catch (e) {
Sentry.captureException(e);
}
};
},
titleCase = (str) => {
// remove leading and trailing spaces
let newString = str ? str.trim() : '';
// remove multiple spaces
newString = newString.replace(/\s{2,}/g, ' ');
// lowercase
newString = newString.toLowerCase();

return newString.split(' ').map(function(word) {
if (['de', 'da', 'do', 'das', 'dos'].includes(word)) {
return word.toLowerCase()
} else {
return word ? word.replace(word[0], word[0].toUpperCase()) : '';
}
}).join(' ');
}


/**
* @param {string} phoneNumberStr
Expand Down Expand Up @@ -1153,7 +1174,7 @@ function ObservableStream(data) {
}

/**
* @param {T} newData
* @param {T} newData
* @return {T}
*/
function set(newData) {
Expand All @@ -1163,7 +1184,7 @@ function ObservableStream(data) {
}

/**
* @param {function(T):void} observeFunction
* @param {function(T):void} observeFunction
*/
function observe(observeFunction) {
observers.push(observeFunction);
Expand Down Expand Up @@ -1201,7 +1222,7 @@ function ObservableRedrawStream(data) {
* @template T
*/
function RedrawStream(data, onUpdate = (param) => {}) {

const _data = prop(data);

/**
Expand Down Expand Up @@ -1293,6 +1314,7 @@ export default {
idVM,
getUser,
getUserID,
getUserCommonID,
getApiHost,
getNewsletterUrl,
getCurrentProject,
Expand Down Expand Up @@ -1357,4 +1379,5 @@ export default {
isDevEnv,
trust,
attachEventsToHistory,
titleCase,
};
4 changes: 2 additions & 2 deletions legacy/src/root/project-edit-integrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ export class ProjectEditIntegrations {
'Informe o seu ID de Acompanhamento e comece a enviar informações dos visitantes de sua página para a sua conta do Google Analytics ',
m('a.alt-link[href="https://suporte.catarse.me/hc/pt-br/articles/360038491812"]', 'Saiba mais')
]),
m('img[src="https://uploads-ssl.webflow.com/57ba58b4846cc19e60acdd5b/5c5cacc4a3136e8188581846_logo_lockup_analytics_icon_horizontal_black_2x.png"][width="146"][alt=""]')
m('img[src="/assets/logo_lockup_analytics_icon_horizontal_black.png"][width="146"][alt=""]')
]),
m('div.w-col.w-col-7',
m('div.w-row', [
Expand All @@ -155,7 +155,7 @@ export class ProjectEditIntegrations {
'Envia informações dos visitantes de sua página para o seu Facebook Pixel ',
m('a.alt-link[href="https://suporte.catarse.me/hc/pt-br/articles/360038491672"]', 'Saiba mais')
]),
m('img[src="https://uploads-ssl.webflow.com/57ba58b4846cc19e60acdd5b/5c5cad962b0f59780182c2b8_xfacebook-pixel-logotyp.png.pagespeed.ic.LYUwNiemhv.png"][width="146"][alt=""]')
m('img[src="/assets/facebook-pixel-logotyp.png"][width="146"][alt=""]')
]),
m('div.w-col.w-col-7', [
m(`input${error() ? '.error' : ''}.text-field.medium.positive.w-input[type="text"][placeholder="123456789123456"][id="fb-pixel-id"]`, {
Expand Down
33 changes: 22 additions & 11 deletions legacy/src/vms/common-payment-vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,14 @@ const updateUser = user => m.request({

const setNewCreditCard = (creditCardFields) => {
const creditCard = new window.PagarMe.creditCard();
creditCard.cardHolderName = titleCase(creditCardFields.name());
creditCard.cardHolderName = h.titleCase(creditCardFields.name());
creditCard.cardExpirationMonth = creditCardFields.expMonth();
creditCard.cardExpirationYear = creditCardFields.expYear();
creditCard.cardNumber = creditCardFields.number();
creditCard.cardCVV = creditCardFields.cvv();
return creditCard;
};

const titleCase = (str) => {
return str.toLowerCase().split(' ').map(function(word) {
if (['de', 'da', 'do', 'das', 'dos'].includes(word)) {
return word.toLowerCase()
} else {
return word.replace(word[0], word[0].toUpperCase());
}
}).join(' ');
}

const userPayload = (customer, address) => ({
id: h.getUser().id,
cpf: customer.ownerDocument(),
Expand Down Expand Up @@ -189,6 +179,26 @@ const processCreditCard = (cardHash, fields) => {
return p;
};

const kondutoExecute = function () {
const customerID = h.getUserCommonID();

if (customerID) {
var period = 300;
var limit = 20 * 1e3;
var nTry = 0;
var intervalID = setInterval(function () {
var clear = limit / period <= ++nTry;
if ((typeof (Konduto) !== "undefined") && (typeof (Konduto.setCustomerID) !== "undefined")) {
window.Konduto.setCustomerID(customerID);
clear = true;
}
if (clear) {
clearInterval(intervalID);
}
}, period);
}
};

const sendCreditCardPayment = (selectedCreditCard, fields, commonData, addVM) => {

if (!fields) {
Expand Down Expand Up @@ -251,6 +261,7 @@ const sendCreditCardPayment = (selectedCreditCard, fields, commonData, addVM) =>
}

const pay = ({ creditCardId }) => {
kondutoExecute()
const p = new Promise((resolve, reject) => {
if (creditCardId) {
_.extend(payload, {
Expand Down
12 changes: 1 addition & 11 deletions legacy/src/vms/payment-vm.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,24 +288,14 @@ const paymentVM = () => {

const setNewCreditCard = () => {
const creditCard = new window.PagarMe.creditCard();
creditCard.cardHolderName = titleCase(creditCardFields.name());
creditCard.cardHolderName = h.titleCase(creditCardFields.name());
creditCard.cardExpirationMonth = creditCardFields.expMonth();
creditCard.cardExpirationYear = creditCardFields.expYear();
creditCard.cardNumber = creditCardFields.number();
creditCard.cardCVV = creditCardFields.cvv();
return creditCard;
};

const titleCase = (str) => {
return str.toLowerCase().split(' ').map(function(word) {
if (['de', 'da', 'do', 'das', 'dos'].includes(word)) {
return word.toLowerCase()
} else {
return word.replace(word[0], word[0].toUpperCase());
}
}).join(' ');
}

const payWithNewCard = (contribution_id, installment) => {
const p = new Promise((resolve, reject) => {
m.request({
Expand Down

0 comments on commit e1e4644

Please sign in to comment.