Skip to content

Commit

Permalink
feat(preview): throw TypeError if internationalizedArrayString fails …
Browse files Browse the repository at this point in the history
…type guard
  • Loading branch information
mathiazom committed Oct 10, 2024
1 parent 3533b53 commit 037c352
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 16 deletions.
10 changes: 6 additions & 4 deletions studio/schemas/documents/compensations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,13 @@ const compensations = defineType({
title: title.name,
},
prepare({ title }) {
const translatedTitle = isInternationalizedString(title)
? firstTranslation(title)
: null;
if (!isInternationalizedString(title)) {
throw new TypeError(
`Expected 'title' to be InternationalizedString, was ${typeof title}`,
);
}
return {
title: translatedTitle ?? undefined,
title: firstTranslation(title) ?? undefined,
};
},
},
Expand Down
10 changes: 6 additions & 4 deletions studio/schemas/fields/callToActionFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ const callToActionField = defineField({
title: "linkTitle",
},
prepare({ title }) {
const translatedTitle = isInternationalizedString(title)
? firstTranslation(title)
: null;
if (!isInternationalizedString(title)) {
throw new TypeError(
`Expected 'title' to be InternationalizedString, was ${typeof title}`,
);
}
return {
title: translatedTitle ?? undefined,
title: firstTranslation(title) ?? undefined,
subtitle: "Call to Action",
};
},
Expand Down
10 changes: 6 additions & 4 deletions studio/schemas/objects/compensations/benefitsByLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,16 @@ export const benefitsByLocation = defineField({
type: benefitType.name,
},
prepare({ title, type }) {
const translatedTitle = isInternationalizedString(title)
? firstTranslation(title)
: null;
if (!isInternationalizedString(title)) {
throw new TypeError(
`Expected 'title' to be InternationalizedString, was ${typeof title}`,
);
}
const subtitle =
BENEFIT_TYPES.find((o) => o.value === type)?.title ??
"Unknown benefit type";
return {
title: translatedTitle ?? undefined,
title: firstTranslation(title) ?? undefined,
subtitle,
};
},
Expand Down
10 changes: 6 additions & 4 deletions studio/schemas/objects/link.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,13 @@ export const link = defineField({
type: "linkType",
},
prepare({ title, type }) {
const translatedTitle = isInternationalizedString(title)
? firstTranslation(title)
: null;
if (!isInternationalizedString(title)) {
throw new TypeError(
`Expected 'title' to be InternationalizedString, was ${typeof title}`,
);
}
return {
title: translatedTitle ?? undefined,
title: firstTranslation(title) ?? undefined,
subtitle: type ? type.charAt(0).toUpperCase() + type.slice(1) : "",
};
},
Expand Down

0 comments on commit 037c352

Please sign in to comment.