feat: generate landing stub types outside (#33)

This commit is contained in:
RustamRu
2024-11-25 23:37:14 +03:00
parent 409c339b3c
commit 012de3c670
13 changed files with 78 additions and 189 deletions

View File

@@ -9,7 +9,7 @@ import { BenefitsSectionProps } from './types';
import { iconsMap } from './helper';
export const BenefitsSection: FC<BenefitsSectionProps> = ({
data: { heading, description, list },
data: { heading, description, list } = {},
}) => {
const { t } = useTranslation('~', { keyPrefix: 'dry-wash.landing' });

View File

@@ -8,7 +8,7 @@ import { CtaButton, SiteLogo, PageSection } from '../';
import { HeroSectionProps } from './types';
export const HeroSection: FC<HeroSectionProps> = ({
data: { headline, description, video },
data: { headline, description, video } = {},
flexShrink,
}) => {
const { t } = useTranslation('~', { keyPrefix: 'dry-wash.landing' });

View File

@@ -8,7 +8,7 @@ import { ReviewsSlider } from './ReviewsSlider';
import { SocialProofSectionProps } from './types';
export const SocialProofSection: FC<SocialProofSectionProps> = ({
data: { heading },
data: { heading } = {},
}) => {
const { t } = useTranslation('~', { keyPrefix: 'dry-wash.landing' });

View File

@@ -0,0 +1 @@
export * from './stubs';

View File

@@ -0,0 +1 @@
export { default as LandingSuccessStub } from './success';

View File

@@ -0,0 +1,27 @@
// Generated by json-literal-typer
// <-- BEGIN
interface HeroXsection {
description: "hero-section.description";
headline: "hero-section.headline";
video: "demo.mp4";
}
interface Sections {
description?: "benefits-section.description";
heading: "benefits-section.heading" | "social-proof-section.heading";
list?: ("benefits-section.list.0" | "benefits-section.list.1" | "benefits-section.list.2" | "benefits-section.list.3")[];
type: "benefits-section" | "social-proof-section";
}
interface Body {
"hero-section": HeroXsection;
sections: Sections[];
}
interface Root {
body: Body;
success: true;
}
// END -->
export default Root;

View File

@@ -1,9 +1,17 @@
import React, { FC } from 'react';
import { Container, VStack } from '@chakra-ui/react';
import LandingSuccess from '../../../stubs/json/landing/landing-success.json';
import { BenefitsSection, Footer, HeroSection, SocialProofSection } from '../../components/landing';
import {
BenefitsSection,
Footer,
HeroSection,
SocialProofSection,
} from '../../components/landing';
import { LandingThemeProvider } from '../../containers';
import { LandingSuccessStub } from '../../models/landing';
const landingSuccessStub = import(
'../../../stubs/json/landing/success.json'
) as unknown as LandingSuccessStub;
import { isBenefitsSectionData, isSocialProofSectionData } from './types';
@@ -20,11 +28,11 @@ const Page: FC = () => {
>
<VStack w='full' h='full' alignItems='stretch' flexGrow={1}>
<HeroSection
data={LandingSuccess.body['hero-section']}
data={landingSuccessStub['body']['hero-section']}
flexShrink={0}
/>
<VStack as='main' flexGrow={1}>
{LandingSuccess.body.sections.map(({ type, ...data }, i) => {
{landingSuccessStub.body.sections.map(({ type, ...data }, i) => {
if (isBenefitsSectionData(type, data)) {
return <BenefitsSection key={i} data={data} />;
}

View File

@@ -1,8 +1,8 @@
import LandingSuccess from "../../../stubs/json/landing/landing-success.json";
import LandingSuccess from "../../../stubs/json/landing/success.json";
import { BenefitsSectionProps, SocialProofSectionProps } from "../../components/landing";
import { ArrElement } from "../../lib";
type SectionsItemData = ArrElement<LandingSuccess['body']['sections']>;
type SectionsItemData = ArrElement<typeof LandingSuccess['body']['sections']>;
type SectionType = SectionsItemData['type'];
type SectionData = Omit<SectionsItemData, 'type'>;