Skip to content

Commit

Permalink
v3 - yearly bonuses per location (#613)
Browse files Browse the repository at this point in the history
* feat(bonusesByLocation): replace average bonus with yearly bonuses

* feat(bonusesByLocation): reword titles and descriptions
  • Loading branch information
mathiazom authored Sep 12, 2024
1 parent 5a73832 commit 9080f21
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 17 deletions.
7 changes: 7 additions & 0 deletions studio/lib/payloads/compensations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
75 changes: 59 additions & 16 deletions studio/schemas/objects/compensations/bonusesByLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};
},
},
Expand Down
2 changes: 1 addition & 1 deletion studio/schemas/objects/compensations/salariesByLocation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 9080f21

Please sign in to comment.