diff --git a/src/Project/Sugcon2024/Sugcon/src/components/Basic Components/Hero.tsx b/src/Project/Sugcon2024/Sugcon/src/components/Basic Components/Hero.tsx index 0e9c4020..354e67ed 100644 --- a/src/Project/Sugcon2024/Sugcon/src/components/Basic Components/Hero.tsx +++ b/src/Project/Sugcon2024/Sugcon/src/components/Basic Components/Hero.tsx @@ -1,7 +1,15 @@ import React from 'react'; import { Box, Heading, Text, Image, Flex, useBreakpointValue } from '@chakra-ui/react'; -import { Field, ImageField, LinkField } from '@sitecore-jss/sitecore-jss-nextjs'; + +import { + TextField, + ImageField, + LinkField, + Text as JssText, +} from '@sitecore-jss/sitecore-jss-nextjs'; + import { ButtonLink } from '../../basics/ButtonLink'; + import { isSitecoreLinkFieldPopulated, isSitecoreTextFieldPopulated, @@ -10,13 +18,13 @@ import { // Define the type of props that Hero will accept interface Fields { /** Title of the event banner */ - Headline: Field; + Headline: TextField; /** Date of the event */ - EventDate: Field; + EventDate: TextField; /** Description of the event */ - Text: Field; + Text: TextField; /** Link to trigger when the button is clicked */ CallToAction: LinkField; @@ -51,16 +59,16 @@ export const HeroHomepage = (props: HeroProps): JSX.Element => { > - {props.fields.Headline?.value} + {isSitecoreTextFieldPopulated(props.fields.EventDate) && ( - {props.fields.EventDate?.value} + )} {isSitecoreTextFieldPopulated(props.fields.Text) && ( - {props.fields.Text?.value} + )} {isSitecoreLinkFieldPopulated(props.fields.CallToAction) && ( @@ -103,11 +111,11 @@ export const HeroEvent = (props: HeroProps): JSX.Element => { > - {props.fields.Headline?.value} + {isSitecoreTextFieldPopulated(props.fields.Text) && ( - {props.fields.Text?.value} + )} @@ -154,11 +162,11 @@ export const HeroJustificationLetter = (props: HeroProps): JSX.Element => { alignItems="flex-start" > - {props.fields.Headline?.value} + {isSitecoreTextFieldPopulated(props.fields.Text) && ( - {props.fields.Text?.value} + )} {isSitecoreLinkFieldPopulated(props.fields.CallToAction) && ( diff --git a/src/Project/Sugcon2024/Sugcon/src/lib/utils/sitecoreUtils.ts b/src/Project/Sugcon2024/Sugcon/src/lib/utils/sitecoreUtils.ts index 59e0345b..70fe3bf3 100644 --- a/src/Project/Sugcon2024/Sugcon/src/lib/utils/sitecoreUtils.ts +++ b/src/Project/Sugcon2024/Sugcon/src/lib/utils/sitecoreUtils.ts @@ -1,3 +1,5 @@ +import { TextField } from '@sitecore-jss/sitecore-jss-nextjs'; + interface SitecoreLinkField { value?: { href?: string; @@ -6,10 +8,6 @@ interface SitecoreLinkField { }; } -interface SitecoreTextField { - value?: string; -} - interface SitecoreImageField { value?: { src?: string; @@ -20,7 +18,7 @@ export function isSitecoreLinkFieldPopulated(field?: SitecoreLinkField): boolean return Boolean(field?.value?.href && (field?.value?.text || field?.value?.anchor)); } -export function isSitecoreTextFieldPopulated(field: SitecoreTextField): boolean { +export function isSitecoreTextFieldPopulated(field: TextField): boolean { return Boolean(field?.value); } diff --git a/src/Project/Sugcon2024/Sugcon/src/stories/components/Basic Components/HomepageHero.stories.ts b/src/Project/Sugcon2024/Sugcon/src/stories/components/Basic Components/HomepageHero.stories.tsx similarity index 79% rename from src/Project/Sugcon2024/Sugcon/src/stories/components/Basic Components/HomepageHero.stories.ts rename to src/Project/Sugcon2024/Sugcon/src/stories/components/Basic Components/HomepageHero.stories.tsx index d6c41313..66225617 100644 --- a/src/Project/Sugcon2024/Sugcon/src/stories/components/Basic Components/HomepageHero.stories.ts +++ b/src/Project/Sugcon2024/Sugcon/src/stories/components/Basic Components/HomepageHero.stories.tsx @@ -1,5 +1,7 @@ import { Meta, StoryObj } from '@storybook/react'; import { HeroHomepage } from '../../../components/Basic Components/Hero'; +import { SitecoreContext } from '@sitecore-jss/sitecore-jss-react'; + const meta = { title: 'Components/Hero', component: HeroHomepage, @@ -7,6 +9,14 @@ const meta = { layout: 'centered', }, tags: ['autodocs'], + decorators: [ + (Story) => ( + // Assuming you might need to provide a mock context value + null}> + + + ), + ], argTypes: {}, } satisfies Meta; export default meta; diff --git a/src/Project/Sugcon2024/Sugcon/src/stories/components/Basic Components/JustificationLetterHero.stories.ts b/src/Project/Sugcon2024/Sugcon/src/stories/components/Basic Components/JustificationLetterHero.stories.tsx similarity index 84% rename from src/Project/Sugcon2024/Sugcon/src/stories/components/Basic Components/JustificationLetterHero.stories.ts rename to src/Project/Sugcon2024/Sugcon/src/stories/components/Basic Components/JustificationLetterHero.stories.tsx index 9257c748..e2d2a817 100644 --- a/src/Project/Sugcon2024/Sugcon/src/stories/components/Basic Components/JustificationLetterHero.stories.ts +++ b/src/Project/Sugcon2024/Sugcon/src/stories/components/Basic Components/JustificationLetterHero.stories.tsx @@ -1,5 +1,7 @@ import { Meta, StoryObj } from '@storybook/react'; import { HeroJustificationLetter } from '../../../components/Basic Components/Hero'; +import { SitecoreContext } from '@sitecore-jss/sitecore-jss-react'; + const meta = { title: 'Components/Hero', component: HeroJustificationLetter, @@ -7,6 +9,13 @@ const meta = { layout: 'centered', }, tags: ['autodocs'], + decorators: [ + (Story) => ( + null}> + + + ), + ], argTypes: {}, } satisfies Meta; export default meta;