Skip to content

Commit 5c41897

Browse files
authored
Merge pull request #1909 from fedspendingtransparency/FDG-10777
FDG 10777 Add External Link Banner to Social Share Clicks
2 parents 584ff45 + 0ff5761 commit 5c41897

File tree

8 files changed

+116
-31
lines changed

8 files changed

+116
-31
lines changed

src/components/modal/redirect-modal/redirect-modal.module.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,12 @@
7272
width: 1.25rem;
7373
color: $content-section-background;
7474
}
75+
76+
@media screen and (max-width: $breakpoint-sm - 1) {
77+
.redirectBody {
78+
padding: 1rem;
79+
}
80+
.titleText {
81+
font-size: $font-size-28;
82+
}
83+
}

src/components/social-share/social-share-dropdown/social-share-dropdown.spec.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React from 'react';
22
import { render, screen, act } from '@testing-library/react';
33
import userEvent from '@testing-library/user-event';
44
import SocialShareDropdown from './social-share-dropdown';
5+
import { RecoilRoot } from 'recoil';
56

67
const testCopy = {
78
title: 'test',
@@ -42,11 +43,14 @@ describe('exchange rates banner', () => {
4243
});
4344

4445
it('closes the dropdown when a social button is clicked', () => {
45-
render(<SocialShareDropdown copy={testCopy} pageName="" />);
46-
const shareBtn = screen.getByRole('button', { name: 'Share' });
47-
46+
const { getByRole } = render(
47+
<RecoilRoot>
48+
<SocialShareDropdown copy={testCopy} pageName="" />
49+
</RecoilRoot>
50+
);
51+
const shareBtn = getByRole('button', { name: 'Share' });
4852
userEvent.click(shareBtn);
49-
const facebookBtn = screen.getByRole('button', { name: 'facebook' });
53+
const facebookBtn = getByRole('button', { name: 'facebook' });
5054
userEvent.click(facebookBtn);
5155

5256
act(() => {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export const socialUrls = {
2+
facebook: `https://www.facebook.com/sharer/sharer.php?u=`,
3+
twitter: `https://twitter.com/intent/tweet?url=`,
4+
reddit: `http://www.reddit.com/submit?url=`,
5+
linkedin: `https://www.linkedin.com/shareArticle?mini=true&url=`,
6+
};
7+
8+
export const getLinkedInParams = (site, url, title) => {
9+
return socialUrls[site] + encodeURIComponent(url) + '&title=' + encodeURIComponent(title);
10+
};
11+
12+
export const getFacebookParams = (site, url) => {
13+
return socialUrls[site] + encodeURIComponent(url);
14+
};
15+
16+
export const getTwitterParams = (site, url, title) => {
17+
return socialUrls[site] + encodeURIComponent(url) + '&title=' + encodeURIComponent(title);
18+
};
19+
20+
export const getRedditParams = (site, url, title) => {
21+
return socialUrls[site] + encodeURIComponent(url) + '&title=' + encodeURIComponent(title);
22+
};

src/components/social-share/social-share.module.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,14 @@
5959
}
6060
}
6161

62+
.customShareButton {
63+
background: none;
64+
border: none;
65+
padding: 0;
66+
margin-top: 0.75rem;
67+
cursor: pointer;
68+
}
69+
6270
@media screen and (max-width: $breakpoint-lg - 1) {
6371
.horizontalShareButtonContainer {
6472
margin-right: 1.5rem;

src/components/social-share/social-share.spec.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { render } from '@testing-library/react';
33
import { SocialShareComponent } from './social-share';
44
import { breakpointLg, breakpointSm } from '../../../../variables.module.scss';
55
import Analytics from '../../utils/analytics/analytics';
6+
import { RecoilRoot } from 'recoil';
67

78
jest.mock('./variables.module.scss', content => ({
89
...content,
@@ -79,7 +80,11 @@ describe('Social Share component', () => {
7980
it('calls the appropriate analytics for Explainer pages event when buttons are clicked on', () => {
8081
const spy = jest.spyOn(Analytics, 'event');
8182
window.open = jest.fn();
82-
const { getByRole } = render(<SocialShareComponent copy={testCopy} pageName={'Debt'} width={breakpointSm} explainer />);
83+
const { getByRole } = render(
84+
<RecoilRoot>
85+
<SocialShareComponent copy={testCopy} pageName={'Debt'} width={breakpointSm} explainer />
86+
</RecoilRoot>
87+
);
8388

8489
const facebookButton = getByRole('button', { name: 'facebook' });
8590
const twitterButton = getByRole('button', { name: 'twitter' });
@@ -131,7 +136,11 @@ describe('Social Share component', () => {
131136
it('calls the appropriate XR Converter analytics event when buttons are clicked on', () => {
132137
const spy = jest.spyOn(Analytics, 'event');
133138
window.open = jest.fn();
134-
const { getByRole } = render(<SocialShareComponent copy={testCopy} pageName={'Exchange Rates Converter'} width={breakpointSm} />);
139+
const { getByRole } = render(
140+
<RecoilRoot>
141+
<SocialShareComponent copy={testCopy} pageName={'Exchange Rates Converter'} width={breakpointSm} />
142+
</RecoilRoot>
143+
);
135144

136145
const facebookButton = getByRole('button', { name: 'facebook' });
137146
const twitterButton = getByRole('button', { name: 'twitter' });

src/components/social-share/social-share.tsx

Lines changed: 54 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from 'react';
1+
import React, { SyntheticEvent } from 'react';
22
import {
33
socialShareContent,
44
shareButton,
@@ -9,20 +9,21 @@ import {
99
listShareButton,
1010
listSocialShareContent,
1111
headerText,
12+
customShareButton,
1213
} from './social-share.module.scss';
1314
import { withWindowSize } from 'react-fns';
1415
import { pxToNumber } from '../../helpers/styles-helper/styles-helper';
1516
import { breakpointLg } from '../../variables.module.scss';
16-
import { FacebookShareButton, TwitterShareButton, LinkedinShareButton, RedditShareButton, EmailShareButton } from 'react-share';
17-
import globalConstants from '../../helpers/constants';
1817
import Analytics from '../../utils/analytics/analytics';
1918
import ShareButtonContent from './share-button-content/share-button-content';
2019
import { FunctionComponent } from 'react';
2120
import { ISocialShareComponent } from '../../models/ISocialShareComponent';
2221
import SocialMetaData from './social-metadata/social-metadata';
2322
import Heading from '../heading/heading';
24-
25-
const baseUrl = globalConstants.BASE_SITE_URL;
23+
import { redirectModalState } from '../../components/modal/redirect-modal/redirect-modal-helper';
24+
import { useSetRecoilState } from 'recoil';
25+
import { getLinkedInParams, getFacebookParams, getTwitterParams, getRedditParams } from './social-share-helper';
26+
import { EmailShareButton } from 'react-share';
2627

2728
const analyticsClickHandler = (page: string, social: string, explainer: boolean) => {
2829
let gaCategory: string;
@@ -53,6 +54,7 @@ export const SocialShareComponent: FunctionComponent<ISocialShareComponent> = ({
5354
explainer,
5455
}) => {
5556
const { title, description, body, emailSubject, emailBody, url, image } = copy;
57+
const setModal = useSetRecoilState(redirectModalState);
5658

5759
let contentStyle = socialShareContent;
5860
let containerStyle = shareButtonContainer;
@@ -75,42 +77,73 @@ export const SocialShareComponent: FunctionComponent<ISocialShareComponent> = ({
7577
}
7678
};
7779

80+
const openModal = (e: SyntheticEvent, url: string) => {
81+
e.preventDefault();
82+
setModal({
83+
open: true,
84+
url,
85+
after: () => {
86+
window.open(url, '_blank', 'noreferrer, noopener, width=650,height=600');
87+
},
88+
});
89+
};
90+
7891
return (
7992
<>
8093
<SocialMetaData image={image} title={title} description={description} url={url} />
81-
<div className={`${contentStyle} socialShareContent`}>
94+
<div className={`${contentStyle} socialShareContent facebook`}>
8295
{displayStyle === 'responsive' && width >= pxToNumber(breakpointLg) && (
8396
<Heading headingLevel={headerLevel} className={headerText}>
8497
Share this page
8598
</Heading>
8699
)}
87100
<div className={containerStyle}>
88-
<FacebookShareButton className={`${buttonStyle} facebookShare`} url={url} quote={body} beforeOnClick={() => handleClick('Facebook')}>
101+
<button
102+
className={`${buttonStyle} ${customShareButton} facebookShare`}
103+
aria-label={'facebook'}
104+
onClick={e => {
105+
handleClick('Facebook');
106+
openModal(e, getFacebookParams('facebook', url));
107+
}}
108+
>
89109
<ShareButtonContent name="facebook" width={width} displayStyle={displayStyle} />
90-
</FacebookShareButton>
110+
</button>
91111
</div>
92112
<div className={containerStyle}>
93-
<TwitterShareButton className={`${buttonStyle} twitterShare`} url={url} title={body} beforeOnClick={() => handleClick('Twitter')}>
113+
<button
114+
className={`${buttonStyle} ${customShareButton} twitterShare`}
115+
aria-label={'twitter'}
116+
onClick={e => {
117+
handleClick('Twitter');
118+
openModal(e, getTwitterParams('twitter', url, title));
119+
}}
120+
>
94121
<ShareButtonContent name="twitter" width={width} displayStyle={displayStyle} />
95-
</TwitterShareButton>
122+
</button>
96123
</div>
97124
<div className={containerStyle}>
98-
<LinkedinShareButton
99-
className={`${buttonStyle} linkedInShare`}
100-
url={url}
101-
title={title}
102-
summary={body}
103-
source={baseUrl}
104-
windowHeight={650}
105-
beforeOnClick={() => handleClick('LinkedIn')}
125+
<button
126+
className={`${buttonStyle} ${customShareButton} linkedInShare`}
127+
aria-label={'linkedin'}
128+
onClick={e => {
129+
handleClick('LinkedIn');
130+
openModal(e, getLinkedInParams('linkedin', url, title));
131+
}}
106132
>
107133
<ShareButtonContent name="linkedin" width={width} displayStyle={displayStyle} />
108-
</LinkedinShareButton>
134+
</button>
109135
</div>
110136
<div className={containerStyle}>
111-
<RedditShareButton className={`${buttonStyle} redditShare`} url={url} title={title} beforeOnClick={() => handleClick('Reddit')}>
137+
<button
138+
className={`${buttonStyle} ${customShareButton} redditShare`}
139+
aria-label={'reddit'}
140+
onClick={e => {
141+
handleClick('Reddit');
142+
openModal(e, getRedditParams('reddit', url, title));
143+
}}
144+
>
112145
<ShareButtonContent name="reddit" width={width} displayStyle={displayStyle} />
113-
</RedditShareButton>
146+
</button>
114147
</div>
115148
<div className={containerStyle}>
116149
<EmailShareButton

src/layouts/insight/insight.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ describe('Insights Template', () => {
108108
value: 400,
109109
});
110110

111-
const { findByRole, queryByRole, getByTestId } = render(<InsightPageLayout pageContext={mockPageContext} />, {
111+
const { findByRole, queryByRole, findByTestId, getByTestId } = render(<InsightPageLayout pageContext={mockPageContext} />, {
112112
wrapper,
113113
});
114114

src/pages/americas-finance-guide/americas-finance-guide.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React from 'react';
22
import { render } from '@testing-library/react';
33
import AmericasFinanceGuide from './index';
44
import { useStaticQuery } from 'gatsby';
5-
import { RecoilRoot } from "recoil";
5+
import { RecoilRoot } from 'recoil';
66

77
Object.defineProperty(window, 'innerWidth', { writable: true, configurable: true, value: 1200 });
88

@@ -40,15 +40,15 @@ describe('Americas Finance Guide', () => {
4040
});
4141

4242
it('renders the top container', async () => {
43-
const { getByTestId } = render(<AmericasFinanceGuide width={100} />, {wrapper: RecoilRoot});
43+
const { getByTestId } = render(<AmericasFinanceGuide width={100} />, { wrapper: RecoilRoot });
4444

4545
expect(getByTestId('topContainer')).toBeInTheDocument();
4646
expect(getByTestId('quoteContainer')).toBeInTheDocument();
4747
expect(getByTestId('bottomContainer')).toBeInTheDocument();
4848
});
4949

5050
it('renders the Social Share', () => {
51-
const { getByRole } = render(<AmericasFinanceGuide width={100} />, {wrapper: RecoilRoot});
51+
const { getByRole } = render(<AmericasFinanceGuide width={100} />, { wrapper: RecoilRoot });
5252

5353
const facebook = getByRole('button', { name: 'facebook' });
5454
const twitter = getByRole('button', { name: 'twitter' });

0 commit comments

Comments
 (0)