Skip to content

Commit

Permalink
lolololol
Browse files Browse the repository at this point in the history
  • Loading branch information
apaleslimghost committed Nov 6, 2018
1 parent 7766961 commit ac21318
Show file tree
Hide file tree
Showing 11 changed files with 109 additions and 35 deletions.
8 changes: 4 additions & 4 deletions components/x-gift-article/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"name": "@financial-times/x-gift-article",
"version": "0.0.0",
"description": "This module provides gift article form",
"main": "dist/GiftArticleWrapper.cjs.js",
"browser": "dist/GiftArticleWrapper.es5.js",
"module": "dist/GiftArticleWrapper.esm.js",
"main": "dist/GiftArticle.cjs.js",
"browser": "dist/GiftArticle.es5.js",
"module": "dist/GiftArticle.esm.js",
"style": "dist/GiftArticle.css",
"scripts": {
"prepare": "npm run build",
Expand All @@ -18,7 +18,7 @@
"license": "ISC",
"dependencies": {
"@financial-times/x-engine": "file:../../packages/x-engine",
"@financial-times/x-interaction": "0.0.4",
"@financial-times/x-interaction": "0.0.5",
"classnames": "^2.2.6"
},
"devDependencies": {
Expand Down
8 changes: 4 additions & 4 deletions components/x-gift-article/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ Component provided by this module expects a map of [gift article properties](#pr

```jsx
import React from 'react';
import { GiftArticleWrapper } from '@financial-times/x-gift-article';
import { GiftArticle } from '@financial-times/x-gift-article';

// A == B == C
const a = GiftArticleWrapper(props);
const b = <GiftArticleWrapper {...props} />;
const c = React.createElement(GiftArticleWrapper, props);
const a = GiftArticle(props);
const b = <GiftArticle {...props} />;
const c = React.createElement(GiftArticle, props);
```

Your app should dispatch a custom event (`xDash.giftArticle.activate`) to activate the gift article form when your app actually displays the form.
Expand Down
8 changes: 4 additions & 4 deletions components/x-gift-article/src/Buttons.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { h } from '@financial-times/x-engine';
import { shareType } from './lib/constants';
import { ShareType } from './lib/constants';
import styles from './GiftArticle.css';

const ButtonsClassName = styles.buttons;
Expand Down Expand Up @@ -31,7 +31,7 @@ export default ({
shareByNativeShare
}) => {

if (isGiftUrlCreated || shareType === shareType.nonGift) {
if (isGiftUrlCreated || shareType === ShareType.nonGift) {

if (showNativeShareButton) {
return (
Expand All @@ -47,12 +47,12 @@ export default ({
<button
className={ ButtonWithGapClassNames }
type="button"
onClick={ shareType === shareType.gift ? copyGiftUrl : copyNonGiftUrl }
onClick={ shareType === ShareType.gift ? copyGiftUrl : copyNonGiftUrl }
>
Copy link
</button>
}
<a className={ ButtonClassNames } href={ mailtoUrl } target="_blank" rel="noopener noreferrer" onClick={ shareType === shareType.gift ? emailGiftUrl : emailNonGiftUrl }>Email link</a>
<a className={ ButtonClassNames } href={ mailtoUrl } target="_blank" rel="noopener noreferrer" onClick={ shareType === ShareType.gift ? emailGiftUrl : emailNonGiftUrl }>Email link</a>
</div>
);
}
Expand Down
22 changes: 13 additions & 9 deletions components/x-gift-article/src/GiftArticle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,26 +22,30 @@ const withGiftFormActions = withActions(

return {
showGiftUrlSection() {
return updaters.showGiftUrlSection();
return updaters.showGiftUrlSection;
},

async showNonGiftUrlSection() {
if (!updaters.isNonGiftUrlShortened) {
const { url, isShortened } = await api.getShorterUrl(updaters.urls.nonGift);
showNonGiftUrlSection() {
return async (state) => {
if (!state.isNonGiftUrlShortened) {
const { url, isShortened } = await api.getShorterUrl(state.urls.nonGift);

if (isShortened) {
updaters.setShortenedNonGiftUrl(url);
return updaters.setShortenedNonGiftUrl(url)(state);
}
}
}

return updaters.showNonGiftUrlSection();
return updaters.showNonGiftUrlSection(state);
}
},

async createGiftUrl() {
const { redemptionUrl, redemptionLimit } = await api.getGiftUrl(articleId);
const { redemptionUrl, redemptionLimit } = await api.getGiftUrl(props.articleId);

if (redemptionUrl) {
const { url, isShortened } = await api.getShorterUrl(redemptionUrl);
tracking.createGiftLink(url, redemptionUrl);

return updaters.setGiftUrl(url, redemptionLimit, isShortened);
} else {
// TODO do something
Expand Down Expand Up @@ -81,7 +85,7 @@ const withGiftFormActions = withActions(
},

async activate() {
if (isFreeArticle) {
if (props.isFreeArticle) {
const { url, isShortened } = await api.getShorterUrl(updaters.urls.nonGift);

if (isShortened) {
Expand Down
6 changes: 3 additions & 3 deletions components/x-gift-article/src/Message.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { h } from '@financial-times/x-engine';
import { shareType } from './lib/constants';
import { ShareType } from './lib/constants';
import styles from './GiftArticle.css';

const messageClassName = styles.message;
Expand All @@ -15,7 +15,7 @@ export default ({ shareType, isGiftUrlCreated, isFreeArticle, giftCredits, month
);
}

if (shareType === shareType.gift) {
if (shareType === ShareType.gift) {
if (giftCredits === 0) {
return (
<div className={ messageClassName }>
Expand All @@ -40,7 +40,7 @@ export default ({ shareType, isGiftUrlCreated, isFreeArticle, giftCredits, month
);
}

if (shareType === shareType.nonGift) {
if (shareType === ShareType.nonGift) {
return (
<div className={ messageClassName }>
This link can only be read by existing subscribers
Expand Down
6 changes: 3 additions & 3 deletions components/x-gift-article/src/RadioButtonsSection.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { h } from '@financial-times/x-engine';
import { shareType } from './lib/constants';
import { ShareType } from './lib/constants';
import styles from './GiftArticle.css';

const boldTextClassName = styles.bold;
Expand All @@ -18,7 +18,7 @@ export default ({ shareType, showGiftUrlSection, showNonGiftUrlSection }) => (
value="giftLink"
className="o-forms__radio"
id="giftLink"
checked={ shareType === shareType.gift }
checked={ shareType === ShareType.gift }
onChange={ showGiftUrlSection }
/>

Expand All @@ -32,7 +32,7 @@ export default ({ shareType, showGiftUrlSection, showNonGiftUrlSection }) => (
value="nonGiftLink"
className="o-forms__radio"
id="nonGiftLink"
checked={ shareType === shareType.nonGift }
checked={ shareType === ShareType.nonGift }
onChange={ showNonGiftUrlSection }/>

<label htmlFor="nonGiftLink" className="o-forms__label">
Expand Down
4 changes: 2 additions & 2 deletions components/x-gift-article/src/Url.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { h } from '@financial-times/x-engine';
import { shareType.gift } from './lib/constants';
import { ShareType } from './lib/constants';
import styles from './GiftArticle.css';

const urlClassNames = [
Expand All @@ -14,7 +14,7 @@ export default ({ shareType, isGiftUrlCreated, url, urlType }) => {
name={ urlType }
value={ url }
className={ urlClassNames }
disabled={ shareType === shareType.gift && !isGiftUrlCreated }
disabled={ shareType === ShareType.gift && !isGiftUrlCreated }
readOnly
/>
);
Expand Down
4 changes: 2 additions & 2 deletions components/x-gift-article/src/UrlSection.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { h } from '@financial-times/x-engine';
import { shareType.gift } from './lib/constants';
import { ShareType } from './lib/constants';
import Url from './Url';
import Message from './Message';
import Buttons from './Buttons';
Expand Down Expand Up @@ -31,7 +31,7 @@ export default ({
shareByNativeShare
}) => {

const hideUrlShareElements = ( giftCredits === 0 && shareType === shareType.gift );
const hideUrlShareElements = ( giftCredits === 0 && shareType === ShareType.gift );
const showUrlShareElements = !hideUrlShareElements;

return (
Expand Down
4 changes: 2 additions & 2 deletions components/x-gift-article/src/lib/constants.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
export const shareType = {
export const ShareType = {
gift: 'gift',
nonGift: 'nonGift'
};

export const urlType = {
export const UrlType = {
dummy: 'example-gift-link',
gift: 'gift-link',
nonGift: 'non-gift-link'
Expand Down
70 changes: 70 additions & 0 deletions components/x-gift-article/src/lib/updaters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { createMailtoUrl } from './share-link-actions';
import { ShareType, UrlType } from './constants';

const monthNames = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];

export const showGiftUrlSection = (props) => ({
shareType: ShareType.gift,
url: props.urls.gift || props.urls.dummy,
urlType: props.urls.gift ? UrlType.gift : UrlType.dummy,
mailtoUrl: props.mailtoUrls.gift,
showCopyConfirmation: false
});

export const showNonGiftUrlSection = (props) => ({
shareType: ShareType.nonGift,
url: props.urls.nonGift,
urlType: UrlType.nonGift,
mailtoUrl: props.mailtoUrls.nonGift,
showCopyConfirmation: false
});

export const setGiftUrl = (url, redemptionLimit, isShortened) => {
const mailtoUrl = createMailtoUrl(this.articleTitle, url);

return props => ({
url,
mailtoUrl,
redemptionLimit,
isGiftUrlCreated: true,
isGiftUrlShortened: isShortened,
urlType: UrlType.gift,

urls: Object.assign(props.urls, {
gift: url,
}),

mailtoUrls: Object.assign(props.mailtoUrls, {
gift: mailtoUrl,
})
});
};

export const setAllowance = (giftCredits, monthlyAllowance, nextRenewalDate) => {
const date = new Date(nextRenewalDate);
const nextRenewalDateText = `${ monthNames[date.getMonth()] } ${ date.getDate() }`;

return {
giftCredits,
monthlyAllowance,
nextRenewalDateText
};
};

export const setShortenedNonGiftUrl = (shortenedUrl) => props => {
const mailtoUrl = createMailtoUrl(props.articleTitle, shortenedUrl);

return {
url: shortenedUrl,
mailtoUrl: mailtoUrl,
isNonGiftUrlShortened: true,

urls: Object.assign(props.urls, {
gift: shortenedUrl,
}),

mailtoUrls: Object.assign(props.mailtoUrls, {
gift: mailtoUrl,
})
};
};
4 changes: 2 additions & 2 deletions components/x-gift-article/stories/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const { GiftArticleWrapper } = require('../');
const { GiftArticle } = require('../');

exports.component = GiftArticleWrapper;
exports.component = GiftArticle;

exports.package = require('../package.json');

Expand Down

0 comments on commit ac21318

Please sign in to comment.