Skip to content

Commit

Permalink
v3 - InformationMessage Component + replacement in main/page.tsx (#532)
Browse files Browse the repository at this point in the history
* InformationMessageComponent + replacement in main/page.tsx

* update role attribute in InformationMessage component

* refactor: improve code formatting in InformationMessage component

* Moved links to utils section

* Rename informationMessage to informationSection

* prettier fix
  • Loading branch information
anemne authored Aug 28, 2024
1 parent faf4a79 commit 98c36f4
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 29 deletions.
15 changes: 8 additions & 7 deletions src/app/(main)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import SectionRenderer from "src/utils/renderSection";
import { loadQuery } from "studio/lib/store";
import { Metadata } from "next";
import { fetchSeoData, generateMetadataFromSeo } from "src/utils/seo";
import CustomErrorMessage from "src/blog/components/customErrorMessage/CustomErrorMessage";
import InformationSection from "src/blog/components/informationSection/InformationSection";
import { LinkType } from "studio/lib/payloads/navigation";

export async function generateMetadata(): Promise<Metadata> {
const { data: landingId } = await loadQuery<string>(LANDING_QUERY);
const seo = await fetchSeoData(SEO_PAGE_QUERY, { id: landingId });

return generateMetadataFromSeo(seo);
}

Expand Down Expand Up @@ -43,9 +42,11 @@ const Home = async () => {

if (!landingId) {
return (
<CustomErrorMessage
title="Landing Page Has Not Been Set"
body="It looks like there's no page set as your landing page in the Studio. Head over to the Studio to select a landing page and guide visitors to the right place!"
<InformationSection
title="Welcome! Velkommen! Välkommen!"
body={
"It looks like there's no page set as your landing page in the Studio.\nHead over to the Studio to select a landing page and guide visitors to the right place!"
}
link={navigationManagerLink}
/>
);
Expand All @@ -59,9 +60,9 @@ const Home = async () => {

if (!initialLandingPage.data) {
return (
<CustomErrorMessage
<InformationSection
title="Landing Page is Missing Content"
body={`Your landing page is set, but it looks like there’s no content yet. Visit the Studio to start adding content and make your landing page come to life!`}
body={`Your landing page is set, but it looks like there’s no content yet.\n Visit the Studio to start adding content and make your landing page come to life!`}
link={pagesLink}
/>
);
Expand Down
5 changes: 2 additions & 3 deletions src/blog/Blog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,8 @@ import BlogHero from "./components/hero/BlogHero";
import PostPreview from "src/blog/components/postPreview/PostPreview";
import PostPreviewGrid from "./components/postPreviewGrid/PostPreviewGrid";
import LoadingNews from "./components/loadingNews/LoadingNews";
import CustomErrorMessage, {
homeLink,
} from "./components/customErrorMessage/CustomErrorMessage";
import CustomErrorMessage from "./components/customErrorMessage/CustomErrorMessage";
import { homeLink } from "./components/utils/linkTypes";

interface BlogProps {
blog: BlogPage;
Expand Down
20 changes: 1 addition & 19 deletions src/blog/components/customErrorMessage/CustomErrorMessage.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,9 @@
import Button from "src/components/buttons/Button";
import LinkButton from "src/components/linkButton/LinkButton";
import Text from "src/components/text/Text";
import { ILink, LinkType } from "studio/lib/payloads/navigation";
import { ILink } from "studio/lib/payloads/navigation";
import styles from "./customErrorMessage.module.css";

export const homeLink = {
_key: "return-home",
_type: "link",
linkTitle: "Return to home",
linkType: LinkType.Internal,
internalLink: {
_ref: "/",
},
};

export const studioLink = {
_key: "go-to-studio",
_type: "link",
linkTitle: "Go to studio",
linkType: LinkType.Internal,
internalLink: { _ref: "/studio" },
};

interface CustomErrorMessageProps {
title: string;
body: string;
Expand Down
34 changes: 34 additions & 0 deletions src/blog/components/informationSection/InformationSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import LinkButton from "src/components/linkButton/LinkButton";
import Text from "src/components/text/Text";
import { ILink } from "studio/lib/payloads/navigation";
import styles from "./informationSection.module.css";
import React from "react";

interface InformationSectionProps {
title: string;
body: string;
link?: ILink;
}

const InformationSection = ({ title, body, link }: InformationSectionProps) => {
return (
<section className={styles.wrapper}>
<div className={styles.info}>
<Text type="h1">{title}</Text>
<span>
{body.split("\n").map((line, index) => (
<Text key={index}>
{line}
<br />
</Text>
))}
</span>
<div className={styles.buttonWrapper}>
{link && <LinkButton type="primary" link={link} />}
</div>
</div>
</section>
);
};

export default InformationSection;
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.wrapper {
display: flex;
padding: 5rem 2rem;
align-items: center;
align-self: stretch;
@media (min-width: 640px) {
padding: 5rem 3rem;
justify-content: center;
}

@media (min-width: 1024px) {
padding: 7.5rem;
}
}

.info {
max-width: 88rem;
display: flex;
padding: 3rem;
flex-direction: column;
align-items: flex-start;
gap: 1.5rem;
align-self: stretch;
border-radius: 1rem;
}

.buttonWrapper {
display: flex;
align-items: flex-start;
gap: 1.5rem;
}
19 changes: 19 additions & 0 deletions src/blog/components/utils/linkTypes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { LinkType } from "studio/lib/payloads/navigation";

export const homeLink = {
_key: "return-home",
_type: "link",
linkTitle: "Return to home",
linkType: LinkType.Internal,
internalLink: {
_ref: "/",
},
};

export const studioLink = {
_key: "go-to-studio",
_type: "link",
linkTitle: "Go to studio",
linkType: LinkType.Internal,
internalLink: { _ref: "/studio" },
};

0 comments on commit 98c36f4

Please sign in to comment.