Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3 - yearly bonuses per location #613

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 location. Each location should have a unique entry with the yearly bonuses given to employees.",
mathiazom marked this conversation as resolved.
Show resolved Hide resolved
type: "array",
of: [
defineField({
name: "bonusData",
title: "Bonus Information",
title: "Location Bonuses",
mathiazom marked this conversation as resolved.
Show resolved Hide resolved
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 bonuses given to employees.",
mathiazom marked this conversation as resolved.
Show resolved Hide resolved
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 bonuses data. Each location must be unique.",
mathiazom marked this conversation as resolved.
Show resolved Hide resolved
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