Skip to content

Commit

Permalink
feat(Compensations): display yearly bonuses for selected location
Browse files Browse the repository at this point in the history
  • Loading branch information
mathiazom committed Sep 12, 2024
1 parent 6b7aaed commit c99bc74
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/compensations/Compensations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
IOption,
RadioButtonGroup,
} from "src/components/forms/radioButtonGroup/RadioButtonGroup";
import YearlyBonuses from "./components/yearlyBonuses/YearlyBonuses";
import BenefitsByLocation from "./components/benefitsByLocation/BenefitsByLocation";

interface CompensationsProps {
Expand Down Expand Up @@ -70,6 +71,10 @@ const Compensations = ({ compensations, locations }: CompensationsProps) => {
(benefit) => benefit.location._ref === selectedLocation,
)?.benefits || [];

const yearlyBonusesForLocation = compensations.bonusesByLocation.find(
(b) => b.location._ref === selectedLocation,
)?.yearlyBonuses;

return (
<div className={styles.wrapper}>
<Text type="h1">{compensations.basicTitle}</Text>
Expand Down Expand Up @@ -102,6 +107,9 @@ const Compensations = ({ compensations, locations }: CompensationsProps) => {
) : null}
</>
)}
{yearlyBonusesForLocation && (
<YearlyBonuses bonuses={yearlyBonusesForLocation} />
)}
<BenefitsByLocation benefits={benefitsFilteredByLocation} />
</div>
);
Expand Down
43 changes: 43 additions & 0 deletions src/compensations/components/yearlyBonuses/YearlyBonuses.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { BonusPage } from "studio/lib/payloads/compensations";
import Text from "../../../components/text/Text";
import styles from "./yearlyBonuses.module.css";

interface YearlyBonusesProps {
bonuses: BonusPage[];
}

const YearlyBonuses = ({ bonuses }: YearlyBonusesProps) => {
return (
<div className={styles.wrapper}>
<Text type={"h3"}>Historisk bonus</Text>
<table className={styles.table}>
<thead>
<tr>
<th>
<Text>År</Text>
</th>
<th className={styles.bonusHeader}>
<Text>Beløp</Text>
</th>
</tr>
</thead>
<tbody>
{bonuses
.sort((a, b) => b.year - a.year)
.map((bonus) => (
<tr key={bonus._key}>
<th>
<Text type={"small"}>{bonus.year}</Text>
</th>
<td className={styles.bonusCell}>
<Text type={"small"}>{bonus.bonus}</Text>
</td>
</tr>
))}
</tbody>
</table>
</div>
);
};

export default YearlyBonuses;
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.wrapper {
display: flex;
flex-direction: column;
gap: 1rem;
}

.table {
text-align: left;
max-width: 500px;
}

.bonusHeader,
.bonusCell {
text-align: right;
}
10 changes: 9 additions & 1 deletion studio/lib/payloads/compensations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PortableTextBlock } from "src/components/richText/RichText";
import { Slug } from "./global";
import { Reference, Slug } from "./global";

export interface Benefit {
_type: string;
Expand All @@ -21,6 +21,13 @@ export interface SalariesPage {
salaries: string;
}

export interface BonusesByLocationPage {
_type: string;
_key: string;
location: Reference;
yearlyBonuses: BonusPage[];
}

export interface BonusPage {
_type: string;
_key: string;
Expand All @@ -39,6 +46,7 @@ export interface CompensationsPage {
slug: Slug;
pensionPercent?: number;
benefitsByLocation: BenefitsByLocation[];
bonusesByLocation: BonusesByLocationPage[];
showSalaryCalculator: boolean;
}

Expand Down
5 changes: 5 additions & 0 deletions studio/lib/payloads/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,8 @@ export interface Slug {
_type: string;
current: string;
}

export interface Reference {
_type: "reference";
_ref: string;
}

0 comments on commit c99bc74

Please sign in to comment.