Skip to content
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

V3 customer case block results #857

Merged
merged 10 commits into from
Nov 5, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { CustomerCaseSection as CustomerCaseSectionObject } from "studioShared/l

import ImageSection from "./image/ImageSection";
import QuoteBlock from "./quote/QuoteBlock";
import ResultsBlock from "./results/ResultsBlock";
import RichTextSection from "./richText/RichTextSection";
import SplitSection from "./splitSection/SplitSection";

Expand All @@ -19,5 +20,7 @@ export function CustomerCaseSection({
return <QuoteBlock section={section} />;
case "imageBlock":
return <ImageSection section={section} />;
case "resultsBlock":
return <ResultsBlock section={section} />;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import Text from "src/components/text/Text";
import { ResultsBlock as ResultsBlockObject } from "studioShared/lib/interfaces/resultsBlock";

import styles from "./resultsBlock.module.css";

export interface ResultsBlockProps {
section: ResultsBlockObject;
}

export default function ResultsBlock({ section }: ResultsBlockProps) {
return (
section.resultsBlockTitle && (
<div className={styles.wrapper}>
<div className={styles.resultblock}>
<Text type="h4" className={styles.blocktitle}>
{section.resultsBlockTitle}
</Text>
<div className={styles.resultrow}>
{section.resultsList?.map((result) => (
<div className={styles.results} key={result._key}>
<Text type="h2" className={styles.mainresult}>
{result.result}
</Text>
<Text type="labelRegular">{result.description}</Text>
</div>
))}
</div>
</div>
</div>
)
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
.wrapper {
display: flex;
flex-direction: column;
align-items: center;
}

.resultblock {
display: flex;
flex-direction: column;
align-items: flex-start;
gap: 2.25rem;
max-width: 960px;
width: 100%;
}

.blocktitle {
font-size: 1.5rem;
font-style: normal;
font-weight: 500;
line-height: 120%;
}

.resultrow {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: flex-start;
align-self: stretch;
text-wrap: wrap;

@media (max-width: 1024px) {
flex-direction: column;
align-items: center;
}
}

.results {
display: flex;
flex-direction: column;
gap: 1.5rem;
max-width: 20%;
align-items: center;

@media (max-width: 1024px) {
max-width: 100%;
}
}

.mainresult {
color: var(--blue-dark);
font-size: 3rem;
font-style: normal;
font-weight: 600;
line-height: 120%;
}
11 changes: 1 addition & 10 deletions src/components/text/text.module.css
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
.desktopLink,
.h1,
.h2,
.h3,
.h4,
.h5,
.h6,
.bodyXl {
color: var(--primary-black);
:where(.desktopLink, .h1, .h2, .h3, .h4, .h5, .h6, .bodyXl) {
font-family: var(--font-britti-sans);
}

Expand All @@ -24,7 +16,6 @@
.bodyNormal,
.bodyBig,
.list {
color: var(--primary-black);
font-family: var(--font-britti-sans);
line-height: 140%;
}
Expand Down
3 changes: 3 additions & 0 deletions src/styles/global.css
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ html {

--focus-color: #8b0f40;

--blue-dark: #0014cd;

/* TODO: upgrade color-scheme with correct colors */
--secondary-red: #f0503f;

Expand All @@ -47,6 +49,7 @@ body {
width: 100vw;
background-color: var(--primary-bg);
font-family: var(--font-britti-sans);
color: var(--primary-black);
}

h1,
Expand Down
6 changes: 5 additions & 1 deletion studioShared/lib/interfaces/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IImage } from "studio/lib/interfaces/media";

import { ImageBlock } from "./imageBlock";
import { QuoteBlock } from "./quoteBlock";
import { ResultsBlock } from "./resultsBlock";
import { RichTextBlock } from "./richTextBlock";
import { SplitSection } from "./splitSection";

Expand Down Expand Up @@ -30,7 +31,10 @@ export interface CustomerCaseBase {

export type BaseCustomerCaseSection = RichTextBlock | ImageBlock | QuoteBlock;

export type CustomerCaseSection = BaseCustomerCaseSection | SplitSection;
export type CustomerCaseSection =
| BaseCustomerCaseSection
| SplitSection
| ResultsBlock;

export interface CustomerCase extends CustomerCaseBase {
projectInfo: CustomerCaseProjectInfo;
Expand Down
12 changes: 12 additions & 0 deletions studioShared/lib/interfaces/resultsBlock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
interface ResultsListItem {
result: string;
description: string;
_key: string;
}

export interface ResultsBlock {
_key: string;
_type: "resultsBlock";
resultsBlockTitle?: string;
resultsList?: ResultsListItem[];
}
8 changes: 8 additions & 0 deletions studioShared/lib/queries/customerCases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,14 @@ export const CUSTOMER_CASE_QUERY = groq`
${BASE_SECTIONS_FRAGMENT}
}
},
_type == "resultsBlock" => {
"resultsBlockTitle": ${translatedFieldFragment("resultsBlockTitle")},
"resultsList": resultsList[] {
_key,
result,
"description": ${translatedFieldFragment("description")},
}
},
${BASE_SECTIONS_FRAGMENT}
},
"featuredCases": featuredCases[] -> {
Expand Down
7 changes: 6 additions & 1 deletion studioShared/schemas/documents/customerCase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@ import { titleSlug } from "studio/schemas/schemaTypes/slug";
import { buildDraftId, buildPublishedId } from "studio/utils/documentUtils";
import { firstTranslation } from "studio/utils/i18n";
import { customerCaseProjectInfo } from "studioShared/schemas/fields/customerCaseProjectInfo";
import resultsBlock from "studioShared/schemas/objects/resultsBlock";
import { baseCustomerCaseSections } from "studioShared/schemas/objects/sections";
import splitSection from "studioShared/schemas/objects/splitSection";

export const customerCaseID = "customerCase";

export const customerCaseSections = [...baseCustomerCaseSections, splitSection];
export const customerCaseSections = [
...baseCustomerCaseSections,
splitSection,
resultsBlock,
];

const customerCase = defineType({
name: customerCaseID,
Expand Down
88 changes: 88 additions & 0 deletions studioShared/schemas/objects/resultsBlock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
import { defineField } from "sanity";

import { isInternationalizedString } from "studio/lib/interfaces/global";
import { firstTranslation } from "studio/utils/i18n";

const resultsBlock = defineField({
name: "resultsBlock",
type: "object",
title: "Results Block",
description: "This block can be used to add some results from the project.",
fields: [
{
name: "resultsBlockTitle",
title: "Results Block Title",
description:
"Please provide a title for the result block, for example: 'These are the results from the project'",
type: "internationalizedArrayString",
},
{
name: "resultsList",
title: "List of results",
description: "Add up to five results to be included in this list",
type: "array",
validation: (rule) =>
rule.max(5).error("You can add a maximum of five results"),
of: [
{
type: "object",
title: "Result List Item",
name: "resultlistitem",
fields: [
{
name: "result",
type: "string",
title: "Result",
description: "Add result, for example '+ 72%'",
},
{
name: "description",
type: "internationalizedArrayString",
title: "Description of the result, for example 'Satisfied users'",
},
],
preview: {
select: {
item: "description",
subtitle: "result",
},
prepare({ item, subtitle }) {
if (item !== undefined && !isInternationalizedString(item)) {
throw new TypeError(
`Expected 'title' to be InternationalizedString, was ${typeof item}`,
);
}
return {
title:
item !== undefined
? (firstTranslation(item) ?? undefined)
: undefined,
subtitle: subtitle,
};
},
},
},
],
},
],
preview: {
select: {
title: "resultsBlockTitle",
},
prepare({ title }) {
if (title !== undefined && !isInternationalizedString(title)) {
throw new TypeError(
`Expected 'title' to be InternationalizedString, was ${typeof title}`,
);
}
return {
title:
title !== undefined
? (firstTranslation(title) ?? undefined)
: undefined,
};
},
},
});

export default resultsBlock;