diff --git a/studio/schemas/objects/compensations/benefitsByLocation.ts b/studio/schemas/objects/compensations/benefitsByLocation.ts index b6ba82b85..872508378 100644 --- a/studio/schemas/objects/compensations/benefitsByLocation.ts +++ b/studio/schemas/objects/compensations/benefitsByLocation.ts @@ -2,16 +2,19 @@ import { defineField } from "sanity"; import { location, locationID } from "../locations"; import { companyLocationNameID } from "studio/schemas/documents/companyLocation"; import { benefitId } from "studio/schemas/documents/benefit"; -import { checkForDuplicateLocations, DocumentWithLocation } from "studio/utils/checkForDuplicateLocations"; +import { + checkForDuplicateLocations, + DocumentWithLocation, +} from "studio/utils/checkForDuplicateLocations"; export const benefitsByLocation = defineField({ name: "benefitsByLocation", title: "Benefits by Location", description: - "Enter the benefits offered at each office location. You can only have one location entry, but you can list multiple benefits for each office location.", + "Enter the benefits offered at each office location. You can only have one location entry, but you can list multiple benefits for each office location.", type: "array", of: [ - { + { type: "object", fields: [ { @@ -23,33 +26,35 @@ export const benefitsByLocation = defineField({ defineField({ name: "benefitsGroup", title: "Benefits Group", - description: "Enter the benefits offered at the location selected above.", + description: + "Enter the benefits offered at the location selected above.", type: "array", of: [{ type: benefitId }], }), ], - preview: { - select: { - location: `${locationID}.${companyLocationNameID}`, - benefitsGroup: "benefitsGroup", - }, - prepare({ location, benefitsGroup }) { - const benefitsCount = benefitsGroup ? benefitsGroup.length : 0; - return { - title: location ? `Benefits group for ${location}` : "No location selected", - subtitle: `Number of benefits: ${benefitsCount}`, - }; + preview: { + select: { + location: `${locationID}.${companyLocationNameID}`, + benefitsGroup: "benefitsGroup", + }, + prepare({ location, benefitsGroup }) { + const benefitsCount = benefitsGroup ? benefitsGroup.length : 0; + return { + title: location + ? `Benefits group for ${location}` + : "No location selected", + subtitle: `Number of benefits: ${benefitsCount}`, + }; + }, + }, }, - }, -}, -], -validation: (Rule) => -Rule.custom((benefitsByLocation) => { - return ( - checkForDuplicateLocations( - benefitsByLocation as DocumentWithLocation[] | undefined, - ) || - "Each location should be listed only once in the benefits list." - ); -}), -}); \ No newline at end of file + ], + validation: (Rule) => + Rule.custom((benefitsByLocation) => { + return ( + checkForDuplicateLocations( + benefitsByLocation as DocumentWithLocation[] | undefined, + ) || "Each location should be listed only once in the benefits list." + ); + }), +}); diff --git a/studio/utils/checkForDuplicateLocations.ts b/studio/utils/checkForDuplicateLocations.ts index 425b62812..5369f7d40 100644 --- a/studio/utils/checkForDuplicateLocations.ts +++ b/studio/utils/checkForDuplicateLocations.ts @@ -1,21 +1,20 @@ interface LocationReference { - _ref: string; - _type: string; - title?: string; - } - - export interface DocumentWithLocation { - location: LocationReference; - } + _ref: string; + _type: string; + title?: string; +} +export interface DocumentWithLocation { + location: LocationReference; +} export const checkForDuplicateLocations = ( - documents: DocumentWithLocation[] | undefined, - ): boolean => { - if (!documents) return true; - const locationRefs = documents - .map((entry) => entry.location?._ref) - .filter(Boolean); - const uniqueRefs = new Set(locationRefs); - return uniqueRefs.size === locationRefs.length; - }; \ No newline at end of file + documents: DocumentWithLocation[] | undefined, +): boolean => { + if (!documents) return true; + const locationRefs = documents + .map((entry) => entry.location?._ref) + .filter(Boolean); + const uniqueRefs = new Set(locationRefs); + return uniqueRefs.size === locationRefs.length; +};