diff --git a/studio/lib/payloads/compensations.ts b/studio/lib/payloads/compensations.ts index 63abc1a1a..ddec7437e 100644 --- a/studio/lib/payloads/compensations.ts +++ b/studio/lib/payloads/compensations.ts @@ -21,6 +21,13 @@ export interface SalariesPage { salaries: string; } +export interface BonusPage { + _type: string; + _key: string; + year: number; + bonus: number; +} + export interface CompensationsPage { _createdAt: string; _id: string; diff --git a/studio/schemas/objects/compensations/bonusesByLocation.ts b/studio/schemas/objects/compensations/bonusesByLocation.ts index 7e2a443e5..d71c64847 100644 --- a/studio/schemas/objects/compensations/bonusesByLocation.ts +++ b/studio/schemas/objects/compensations/bonusesByLocation.ts @@ -5,48 +5,91 @@ import { DocumentWithLocation, checkForDuplicateLocations, } from "./utils/validation"; +import { BonusPage } from "../../../lib/payloads/compensations"; export const bonusesByLocation = defineField({ name: "bonusesByLocation", - title: "Bonus by Location", + title: "Bonuses by Location", description: - "Enter the average bonus amount for each company location. Each location can have only one bonus entry, but you can assign the same bonus amount to multiple locations.", + "Yearly bonus data specific to a particular company location. Each location should have a unique entry with the yearly bonuses given to their employees.", type: "array", of: [ defineField({ name: "bonusData", - title: "Bonus Information", + title: "Bonus by location", description: - "Details of the bonus amount specific to a particular location. Each location should have a unique entry with the average bonus calculated for that site.", + "Details of the bonus amount specific to a particular location. Each location should have a unique entry with the yearly bonus given to employees.", type: "object", fields: [ { ...location, description: - "Select the company location for which you are entering the average bonus information. Each location must be unique.", + "Select the company location for which you are entering the yearly bonus data. Each location must be unique.", validation: (Rule) => Rule.required(), }, defineField({ - name: "averageBonus", - title: "Average Bonus", + name: "yearlyBonuses", + title: "Yearly Bonuses", description: - "Enter the average bonus amount for this location. Ensure the amount is positive and reflective of the compensation package for this location.", - type: "number", - validation: (Rule) => - Rule.required() - .min(0) - .error("Please enter a positive bonus amount."), + "Bonus data reflecting the bonus given to employees for a given year.", + type: "array", + of: [ + { + type: "object", + fields: [ + defineField({ + name: "year", + title: "Year", + description: + "The calendar year for which this bonus was given", + type: "number", + validation: (Rule) => Rule.required(), + }), + defineField({ + name: "bonus", + title: "Bonus", + description: + "Enter the bonus amount for this year. Ensure the amount is positive and reflective of the compensation package for this location.", + type: "number", + validation: (Rule) => + Rule.required() + .min(0) + .error("Please enter a positive bonus amount."), + }), + ], + preview: { + select: { + title: "year", + subtitle: "bonus", + }, + }, + }, + ], }), ], preview: { select: { - averageBonus: "averageBonus", location: `${locationID}.${companyLocationNameID}`, + yearlyBonuses: `yearlyBonuses`, }, - prepare({ averageBonus, location }) { + prepare({ location, yearlyBonuses }) { + const latestBonus = + yearlyBonuses && yearlyBonuses.length > 0 + ? yearlyBonuses.reduce( + (latestBonus: BonusPage, bonus: BonusPage) => { + if (bonus.year > latestBonus.year) { + return bonus; + } + return latestBonus; + }, + yearlyBonuses[0], + ) + : undefined; return { title: location || "No location selected", - subtitle: averageBonus || "N/A", + subtitle: latestBonus + ? `Latest bonus (${latestBonus.year}): ${latestBonus.bonus}` + : "N/A", }; }, }, diff --git a/studio/schemas/objects/compensations/salariesByLocation.ts b/studio/schemas/objects/compensations/salariesByLocation.ts index 70665b70d..134bbd55c 100644 --- a/studio/schemas/objects/compensations/salariesByLocation.ts +++ b/studio/schemas/objects/compensations/salariesByLocation.ts @@ -42,7 +42,7 @@ export const salariesByLocation = defineField({ description: "The calendar year for which these salaries were in effect", type: "number", - validation: (Rule) => Rule.required().min(2018), + validation: (Rule) => Rule.required(), }), defineField({ name: "salaries",