Skip to content

Commit

Permalink
Merge pull request #495 from varianter/feature/v3-expand-benefit-schema
Browse files Browse the repository at this point in the history
v3 - benefit type field
  • Loading branch information
mathiazom authored Aug 21, 2024
2 parents a1bb514 + fef485b commit f10c3f2
Showing 1 changed file with 35 additions and 10 deletions.
45 changes: 35 additions & 10 deletions studio/schemas/documents/benefit.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,52 @@
import { defineType } from 'sanity';
import { richText, title } from '../fields/text';
import { defineField, defineType } from "sanity";
import { richText, title } from "../fields/text";

export const benefitId = "benefit";
export const benefitTypeId = "benefitType";

const BENEFIT_TYPE_BASIC_VALUE = "basic";
const BENEFIT_TYPES = [
{ title: "Basic", value: BENEFIT_TYPE_BASIC_VALUE },
{ title: "Gadgets", value: "gadgets" },
{ title: "Bonus", value: "bonus" },
{ title: "Pension", value: "pension" },
{ title: "Salary Growth", value: "salaryGrowth" },
];

const benefitType = defineField({
name: benefitTypeId,
type: "string",
title: "Benefit Type",
description:
"Choose the type of benefit. Some benefit types include visual graphs that will be displayed together with the text.",
options: {
list: BENEFIT_TYPES,
layout: BENEFIT_TYPES.length > 5 ? "dropdown" : "radio",
},
initialValue: BENEFIT_TYPE_BASIC_VALUE,
validation: (Rule) => Rule.required(),
});

const benefit = defineType({
name: benefitId,
type: "document",
title: "Benefit",
fields: [
title,
richText
],
fields: [benefitType, title, richText],
preview: {
select: {
title: title.name,
type: benefitType.name,
},
prepare({ title }) {
prepare({ title, type }) {
const subtitle =
BENEFIT_TYPES.find((o) => o.value === type)?.title ??
"Unknown benefit type";
return {
title,
subtitle: "Benefit",
subtitle,
};
},
},
})
});

export default benefit;
export default benefit;

0 comments on commit f10c3f2

Please sign in to comment.