-
Notifications
You must be signed in to change notification settings - Fork 6
Port institutional-partnership page JavaScript files to TypeScript (CORE-1249) #2777
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
Changes from all commits
8c0d668
92c486f
59377b0
81cd9ba
f69bb06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately, even the initial conversion came out as delete-and-recreate. :( |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import React from 'react'; | ||
import LoaderPage from '~/components/jsx-helpers/loader-page'; | ||
import LazyLoad from 'react-lazyload'; | ||
import {camelCaseKeys} from '~/helpers/page-data-utils'; | ||
import Banner, {BannerProps} from './sections/banner/banner'; | ||
import OverlappingQuote, { | ||
OverlappingQuoteProps | ||
} from './sections/overlapping-quote/overlapping-quote'; | ||
import About, {AboutProps} from './sections/about/about'; | ||
import Promoting, {PromotingProps} from './sections/promoting/promoting'; | ||
import BigQuote, {BigQuoteProps} from './sections/big-quote/big-quote'; | ||
import Speaking, {SpeakingProps} from './sections/speaking/speaking'; | ||
import Results, {ResultsProps} from './sections/results/results'; | ||
import Participants, { | ||
ParticipantsProps | ||
} from './sections/participants/participants'; | ||
import SmallQuote, {SmallQuoteProps} from './sections/small-quote/small-quote'; | ||
import SignUp, {SignUpProps} from './sections/sign-up/sign-up'; | ||
import './institutional-partnership.scss'; | ||
|
||
type DataObject = Record<string, unknown>; | ||
|
||
type ImageMeta = { | ||
download_url: string; | ||
}; | ||
|
||
type SectionData = { | ||
section_4_background_image: { | ||
meta: ImageMeta; | ||
}; | ||
} & DataObject; | ||
|
||
function unprefixKey( | ||
newObject: DataObject, | ||
oldKey: string, | ||
prefix: string, | ||
data: DataObject | ||
) { | ||
const newKey = oldKey.replace(prefix, ''); | ||
|
||
newObject[newKey] = data[oldKey]; | ||
return newObject; | ||
} | ||
|
||
function sectionData(data: DataObject, sectionNumber: string | number) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This parses out the data for each section, so its output is simply cast to the appropriate props type. We're trusting the CMS to serve the expected format. |
||
const sectionPrefix = `section_${sectionNumber}_`; | ||
|
||
return camelCaseKeys( | ||
Reflect.ownKeys(data) | ||
.filter((k) => String(k).startsWith(sectionPrefix)) | ||
.reduce( | ||
(a, oldKey) => | ||
unprefixKey(a, String(oldKey), sectionPrefix, data), | ||
{} | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we have other CMS data that needs this transformation? I can see this being a reusable helperDo we have other CMS data that needs this transformation? I can see this being a reusable helper There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Somewhat to my surprise, I do not find other pages doing this transformation. |
||
); | ||
} | ||
|
||
function quoteData(data: DataObject) { | ||
return Reflect.ownKeys(data) | ||
.filter((k) => String(k).startsWith('quote')) | ||
.reduce( | ||
(a, oldKey) => unprefixKey(a, String(oldKey), 'quote_', data), | ||
{} | ||
); | ||
} | ||
|
||
function InstitutionalPartnership({data}: {data: SectionData}) { | ||
return ( | ||
<React.Fragment> | ||
<Banner {...(sectionData(data, 1) as BannerProps)} /> | ||
<OverlappingQuote {...(quoteData(data) as OverlappingQuoteProps)} /> | ||
<About {...(sectionData(data, 2) as AboutProps)} /> | ||
<LazyLoad> | ||
<Promoting {...(sectionData(data, 3) as PromotingProps)} /> | ||
<BigQuote | ||
{...{ | ||
backgroundImage: | ||
data.section_4_background_image.meta.download_url, | ||
...(sectionData(data, '4_quote') as Omit< | ||
BigQuoteProps, | ||
'backgroundImage' | ||
>) | ||
}} | ||
/> | ||
</LazyLoad> | ||
<LazyLoad> | ||
<Speaking {...(sectionData(data, 5) as SpeakingProps)} /> | ||
<Results {...(sectionData(data, 6) as ResultsProps)} /> | ||
</LazyLoad> | ||
<LazyLoad> | ||
<Participants | ||
{...(sectionData(data, 7) as ParticipantsProps)} | ||
/> | ||
<SmallQuote | ||
{...(sectionData(data, '8_quote') as SmallQuoteProps)} | ||
/> | ||
</LazyLoad> | ||
<LazyLoad> | ||
<SignUp {...(sectionData(data, 9) as SignUpProps)} /> | ||
</LazyLoad> | ||
</React.Fragment> | ||
); | ||
} | ||
|
||
const slug = 'pages/institutional-partners'; | ||
|
||
export default function PageLoader() { | ||
return ( | ||
<main className="institutional-partnership page"> | ||
<LoaderPage | ||
slug={slug} | ||
Child={InstitutionalPartnership} | ||
doDocumentSetup | ||
noCamelCase | ||
/> | ||
</main> | ||
); | ||
} |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react'; | ||
import RawHTML from '~/components/jsx-helpers/raw-html'; | ||
import useOptimizedImage, { | ||
maxDimIfNarrowerThan | ||
} from '~/helpers/use-optimized-image'; | ||
import './banner.scss'; | ||
|
||
export type BannerProps = { | ||
heading: string; | ||
description: string; | ||
linkText: string; | ||
link: string; | ||
backgroundImage: { | ||
meta: { | ||
downloadUrl: string; | ||
}; | ||
}; | ||
}; | ||
|
||
export default function Banner({ | ||
heading, | ||
description, | ||
linkText, | ||
link, | ||
backgroundImage: { | ||
meta: {downloadUrl: backgroundImage} | ||
} | ||
}: BannerProps) { | ||
const maxDim = maxDimIfNarrowerThan(1920); | ||
const optimizedImage = useOptimizedImage(backgroundImage, maxDim); | ||
|
||
return ( | ||
<section className="banner"> | ||
<div | ||
className="background-image" | ||
style={{backgroundImage: `url(${optimizedImage})`}} | ||
/> | ||
<div className="content-block"> | ||
<h1>{heading}</h1> | ||
<RawHTML html={description} /> | ||
<a className="btn primary" href={link}> | ||
{linkText} | ||
</a> | ||
</div> | ||
</section> | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was something duplicated in several modules, so I made it a utility here.