-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from samvera/113-contentful-service-providers
Wire up Service Providers data to Contentful CMS
- Loading branch information
Showing
16 changed files
with
780 additions
and
121 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,8 @@ | ||
import { documentToReactComponents } from "@contentful/rich-text-react-renderer"; | ||
|
||
const RichTextContent = ({ content }) => { | ||
if (!content) return null; | ||
return <>{documentToReactComponents(content)}</>; | ||
}; | ||
|
||
export default RichTextContent; |
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,23 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
import { documentToReactComponents } from "@contentful/rich-text-react-renderer"; | ||
import { richTextFromMarkdown } from "@contentful/rich-text-from-markdown"; | ||
|
||
const RichTextFromMarkdown = ({ content }) => { | ||
const [richText, setRichText] = useState(null); | ||
|
||
useEffect(() => { | ||
if (!content) return; | ||
|
||
async function fn() { | ||
const response = await richTextFromMarkdown(content); | ||
|
||
setRichText(response); | ||
} | ||
fn(); | ||
}, [content]); | ||
|
||
return richText ? <>{documentToReactComponents(richText)}</> : null; | ||
}; | ||
|
||
export default RichTextFromMarkdown; |
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,97 @@ | ||
import Breadcrumbs from "../Breadcrumbs"; | ||
import Layout from "../layout/Layout"; | ||
import Main from "../layout/Main"; | ||
import MarkdownContent from "../MarkdownContent"; | ||
import React from "react"; | ||
import RichTextContent from "components/RichTextContent"; | ||
import getContentful from "lib/get-contentful"; | ||
|
||
export default function ExamplesAndDemos({ config, content, frontmatter }) { | ||
const contentful = getContentful(); | ||
const [entries, setEntries] = React.useState([]); | ||
|
||
React.useEffect(() => { | ||
async function fetchEntries() { | ||
const entries = await contentful.getEntries({ | ||
content_type: "examplesAndDemos", | ||
}); | ||
|
||
if (!entries.items) { | ||
return console.error("Error getting entries."); | ||
} | ||
setEntries(entries.items); | ||
} | ||
|
||
fetchEntries(); | ||
}, [contentful]); | ||
|
||
function classNames(...classes) { | ||
return classes.filter(Boolean).join(" "); | ||
} | ||
|
||
return ( | ||
<Layout title={`${frontmatter.title} - ${config.parentDirLabel} - Samvera`}> | ||
<Main> | ||
<Breadcrumbs | ||
items={[ | ||
{ | ||
href: "/", | ||
label: config.parentDirLabel, | ||
}, | ||
{ | ||
label: frontmatter.title, | ||
}, | ||
]} | ||
/> | ||
|
||
<h1>{frontmatter.title}</h1> | ||
|
||
<MarkdownContent content={content} /> | ||
|
||
<div className="mb-10 overflow-hidden bg-gray-200 divide-y divide-gray-200 rounded-lg shadow sm:grid sm:grid-cols-2 sm:gap-px sm:divide-y-0"> | ||
{entries.map((entry, actionIdx) => ( | ||
<div | ||
key={entry.fields.title} | ||
className={classNames( | ||
actionIdx === 0 | ||
? "rounded-tl-lg rounded-tr-lg sm:rounded-tr-none" | ||
: "", | ||
actionIdx === 1 ? "sm:rounded-tr-lg" : "", | ||
actionIdx === entries.length - 2 ? "sm:rounded-bl-lg" : "", | ||
actionIdx === entries.length - 1 | ||
? "rounded-bl-lg rounded-br-lg sm:rounded-bl-none" | ||
: "", | ||
"group relative bg-white p-6 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-500" | ||
)} | ||
> | ||
<div className="mt-8"> | ||
<h3 className="text-base font-semibold leading-6 text-gray-900"> | ||
<a href={entry.fields.url} className="focus:outline-none"> | ||
{/* Extend touch target to entire panel */} | ||
<span className="absolute inset-0" aria-hidden="true" /> | ||
{entry.fields.title} | ||
</a> | ||
</h3> | ||
<p className="mt-2 text-sm text-gray-500"> | ||
<RichTextContent content={entry.fields.description} /> | ||
</p> | ||
</div> | ||
<span | ||
className="absolute text-gray-300 pointer-events-none right-6 top-6 group-hover:text-gray-400" | ||
aria-hidden="true" | ||
> | ||
<svg | ||
className="w-6 h-6" | ||
fill="currentColor" | ||
viewBox="0 0 24 24" | ||
> | ||
<path d="M20 4h1a1 1 0 00-1-1v1zm-1 12a1 1 0 102 0h-2zM8 3a1 1 0 000 2V3zM3.293 19.293a1 1 0 101.414 1.414l-1.414-1.414zM19 4v12h2V4h-2zm1-1H8v2h12V3zm-.707.293l-16 16 1.414 1.414 16-16-1.414-1.414z" /> | ||
</svg> | ||
</span> | ||
</div> | ||
))} | ||
</div> | ||
</Main> | ||
</Layout> | ||
); | ||
} |
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,114 @@ | ||
import { useEffect, useState } from "react"; | ||
|
||
import Breadcrumbs from "components/Breadcrumbs"; | ||
import Layout from "../layout/Layout"; | ||
import Main from "components/layout/Main"; | ||
import MarkdownContent from "components/MarkdownContent"; | ||
import RichTextContent from "components/RichTextContent"; | ||
import getContentful from "lib/get-contentful"; | ||
|
||
function classNames(...classes) { | ||
return classes.filter(Boolean).join(" "); | ||
} | ||
|
||
export default function ServiceProviders({ config, content, frontmatter }) { | ||
const contentful = getContentful(); | ||
const [entries, setEntries] = useState([]); | ||
|
||
useEffect(() => { | ||
async function fetchEntries() { | ||
const entries = await contentful.getEntries({ | ||
content_type: "serviceProviderProfile", | ||
}); | ||
console.log("entries", entries); | ||
|
||
if (!entries.items) { | ||
return console.error("Error getting entries."); | ||
} | ||
setEntries(entries.items); | ||
} | ||
|
||
fetchEntries(); | ||
}, [contentful]); | ||
|
||
return ( | ||
<Layout title={`${frontmatter.title} - ${config.parentDirLabel} - Samvera`}> | ||
<Breadcrumbs | ||
items={[ | ||
{ | ||
href: "/", | ||
label: config.parentDirLabel, | ||
}, | ||
{ | ||
label: frontmatter.title, | ||
}, | ||
]} | ||
/> | ||
|
||
<h1>{frontmatter.title}</h1> | ||
|
||
<MarkdownContent content={content} /> | ||
<Main> | ||
<div className="my-10 overflow-hidden bg-gray-200 divide-y divide-gray-200 rounded-lg shadow sm:grid sm:grid-cols-2 sm:gap-px sm:divide-y-0"> | ||
{entries.map( | ||
( | ||
{ fields: { descriptionRich, email, logo, name, url } }, | ||
actionIdx | ||
) => ( | ||
<div | ||
key={name} | ||
className={classNames( | ||
actionIdx === 0 | ||
? "rounded-tl-lg rounded-tr-lg sm:rounded-tr-none" | ||
: "", | ||
actionIdx === 1 ? "sm:rounded-tr-lg" : "", | ||
actionIdx === entries?.length - 2 ? "sm:rounded-bl-lg" : "", | ||
actionIdx === entries?.length - 1 | ||
? "rounded-bl-lg rounded-br-lg sm:rounded-bl-none" | ||
: "", | ||
"group relative bg-white p-6 focus-within:ring-2 focus-within:ring-inset focus-within:ring-indigo-500" | ||
)} | ||
> | ||
<div> | ||
<img | ||
src={logo?.fields?.file?.url} | ||
alt={logo?.fields?.title || ""} | ||
/> | ||
</div> | ||
<div className="mt-8 space-y-4"> | ||
<h3 className="text-base font-semibold leading-6 "> | ||
<a | ||
href={url} | ||
className="inline-block text-gray-900 focus:outline-none hover:text-gray-900" | ||
> | ||
<span className="" aria-hidden="true" /> | ||
{name} | ||
</a> | ||
</h3> | ||
<a href={`mailto:${email}`} className="text-base leading-6 "> | ||
{email} | ||
</a> | ||
<p className="text-gray-500 "> | ||
<RichTextContent content={descriptionRich} /> | ||
</p> | ||
</div> | ||
<a | ||
href={url} | ||
className="absolute text-gray-300 right-6 top-6 group-hover:text-gray-400" | ||
> | ||
<svg | ||
className="w-6 h-6" | ||
fill="currentColor" | ||
viewBox="0 0 24 24" | ||
> | ||
<path d="M20 4h1a1 1 0 00-1-1v1zm-1 12a1 1 0 102 0h-2zM8 3a1 1 0 000 2V3zM3.293 19.293a1 1 0 101.414 1.414l-1.414-1.414zM19 4v12h2V4h-2zm1-1H8v2h12V3zm-.707.293l-16 16 1.414 1.414 16-16-1.414-1.414z" /> | ||
</svg> | ||
</a> | ||
</div> | ||
) | ||
)} | ||
</div> | ||
</Main> | ||
</Layout> | ||
); | ||
} |
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,16 @@ | ||
import { createClient } from "contentful"; | ||
|
||
let client; | ||
|
||
function getContentful() { | ||
if (!client) { | ||
client = createClient({ | ||
space: process.env.NEXT_PUBLIC_CONTENTFUL_SPACE_ID, | ||
accessToken: process.env.NEXT_PUBLIC_CONTENTFUL_ACCESS_TOKEN, | ||
}); | ||
} | ||
|
||
return client; | ||
} | ||
|
||
export default getContentful; |
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
Oops, something went wrong.