-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Show iframe for Amazon listing (#2495)
* Use Amazon iframe and snippet for order print copy Fix language selector, too separate useAmazonIframe * Fix tests * Explain commented-out test
- Loading branch information
1 parent
eb188ef
commit 5f1aa0d
Showing
14 changed files
with
174 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import cmsFetch from '~/helpers/cms-fetch'; | ||
import {camelCaseKeys} from '~/helpers/page-data-utils'; | ||
|
||
export default cmsFetch('snippets/amazonbookblurb') | ||
.then((r) => r[0]) | ||
.then(camelCaseKeys) | ||
.then((r) => r?.amazonBookBlurb ?? '** no Amazon blurb snippet**') as Promise<string>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/app/pages/details/common/get-this-title-files/order-print-copy/use-amazon-iframe.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import React from 'react'; | ||
import useDetailsContext from '../../../context'; | ||
import useAmazonAssociatesLink from '../amazon-associates-link'; | ||
import {IntlShape, useIntl} from 'react-intl'; | ||
import {faUser} from '@fortawesome/free-solid-svg-icons/faUser'; | ||
|
||
export default function useAmazonIframe(slug: string) { | ||
const {amazonIframe} = useDetailsContext(); | ||
const amazonDataLink = useAmazonAssociatesLink(slug); | ||
const {formatMessage} = useIntl(); | ||
|
||
const iframeCode = React.useMemo( | ||
() => amazonIframe?.length > 0 ? (` | ||
${amazonIframe} | ||
<div> | ||
${amazonDataLink.disclosure || 'disclosure: we make money from Amazon sales'} | ||
</div> | ||
`) : null, | ||
[amazonIframe, amazonDataLink.disclosure] | ||
); | ||
|
||
return iframeCode ?? amazonButton(amazonDataLink, formatMessage); | ||
} | ||
|
||
function amazonButton( | ||
amazonDataLink: ReturnType<typeof useAmazonAssociatesLink>, | ||
formatMessage: IntlShape['formatMessage'] | ||
) { | ||
const individual = formatMessage({ | ||
id: 'printcopy.individual', | ||
defaultMessage: 'Individual' | ||
}); | ||
const disclosure = formatMessage({ | ||
id: 'printcopy.disclosure', | ||
defaultMessage: '***' | ||
}); | ||
const button1Text = formatMessage({ | ||
id: 'printcopy.button1', | ||
defaultMessage: 'Order a personal copy' | ||
}); | ||
|
||
return ({ | ||
headerText: individual, | ||
headerIcon: faUser, | ||
disclosure: | ||
disclosure === '***' | ||
? amazonDataLink.disclosure | ||
: disclosure, | ||
buttonText: button1Text, | ||
buttonUrl: amazonDataLink.url | ||
}); | ||
} |
Oops, something went wrong.