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 - Show Benefits by location #609

Merged
merged 5 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
14 changes: 7 additions & 7 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 BenefitsByLocation from "./components/benefitsByLocation/BenefitsByLocation";

interface CompensationsProps {
compensations: CompensationsPage;
Expand Down Expand Up @@ -64,6 +65,11 @@ const Compensations = ({ compensations, locations }: CompensationsProps) => {
label: companyLocation.companyLocationName,
}));

const benefitsFilteredByLocation =
compensations.benefitsByLocation.find(
(benefit) => benefit.location._ref === selectedLocation,
)?.benefits || [];

return (
<div className={styles.wrapper}>
<Text type="h1">{compensations.basicTitle}</Text>
Expand Down Expand Up @@ -93,13 +99,7 @@ const Compensations = ({ compensations, locations }: CompensationsProps) => {
) : null}
</>
)}
<div className={styles.benefits}>
{compensations.benefitsByLocation.map((benefit) => (
<div key={benefit._key} className={styles.benefitWrapper}>
{/* TODO: display benefits based on locations */}
</div>
))}
</div>
<BenefitsByLocation benefits={benefitsFilteredByLocation} />
</div>
);
};
Expand Down
13 changes: 0 additions & 13 deletions src/compensations/compensations.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,3 @@
padding: 10rem 5rem;
gap: 5rem;
}

.benefits {
display: flex;
flex-direction: column;
gap: 5rem;
max-width: var(--max-content-width-medium);
}

.benefitWrapper {
display: flex;
flex-direction: column;
gap: 1rem;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import Text from "src/components/text/Text";
import { RichText } from "src/components/richText/RichText";
import styles from "./benefitsByLocation.module.css";
import { Benefit } from "studio/lib/payloads/compensations";

interface BenefitsByLocationProps {
benefits: Benefit[];
}

export default function BenefitsByLocation({
benefits,
}: BenefitsByLocationProps) {
return (
<div className={styles.benefits}>
{benefits.map((benefit: Benefit) => (
<div key={benefit._key} className={styles.benefitWrapper}>
<Text type="h2">{benefit.basicTitle}</Text>
<RichText value={benefit.richText} />
</div>
))}
</div>
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.benefits {
display: flex;
flex-direction: column;
gap: 5rem;
max-width: var(--max-content-width-medium);
}

.benefitWrapper {
display: flex;
flex-direction: column;
gap: 1rem;
}
2 changes: 1 addition & 1 deletion studio/lib/payloads/compensations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export interface Benefit {

export interface BenefitsByLocation {
_key: string;
location: string;
location: { _ref: string; _type: string };
anemne marked this conversation as resolved.
Show resolved Hide resolved
benefits: Benefit[];
}

Expand Down
4 changes: 2 additions & 2 deletions studio/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import blog from "./schemas/documents/blog";
import posts from "./schemas/documents/post";
import categories from "./schemas/fields/categories";
import legalDocument from "./schemas/documents/legalDocuments";
import benefit from "./schemas/documents/benefit";
import companyLocation from "./schemas/documents/companyLocation";
import compensations from "./schemas/documents/compensations";
import redirect from "./schemas/documents/redirect";
import benefitsByLocation from "./schemas/objects/compensations/benefitsByLocation";

export const schema: { types: SchemaTypeDefinition[] } = {
types: [
Expand All @@ -31,8 +31,8 @@ export const schema: { types: SchemaTypeDefinition[] } = {
categories,
legalDocument,
compensations,
benefit,
redirect,
benefitsByLocation,
companyLocation,
],
};
52 changes: 0 additions & 52 deletions studio/schemas/documents/benefit.ts

This file was deleted.

62 changes: 55 additions & 7 deletions studio/schemas/objects/compensations/benefitsByLocation.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,36 @@
import { defineField } from "sanity";
import { location, locationID } from "../locations";
import { companyLocationNameID } from "studio/schemas/documents/companyLocation";
import { benefitId } from "studio/schemas/documents/benefit";
import { richText, title } from "studio/schemas/fields/text";
import {
checkForDuplicateLocations,
DocumentWithLocation,
} from "./utils/validation";

const benefitTypeId = "benefitType";

const BENEFIT_TYPE_BASIC_VALUE = "basic";
const BENEFIT_TYPES = [
{ title: "Basic", value: BENEFIT_TYPE_BASIC_VALUE },
{ title: "Bonus", value: "bonus" },
{ title: "Pension", value: "pension" },
{ title: "Salary Growth", value: "salaryGrowth" },
];

const benefitType = defineField({
name: benefitTypeId,
type: "string",
title: "Benefit Type",
description:
"Choose the type of benefit. Some benefit types include visual graphs that will be displayed together with the text.",
options: {
list: BENEFIT_TYPES,
layout: BENEFIT_TYPES.length > 5 ? "dropdown" : "radio",
},
initialValue: BENEFIT_TYPE_BASIC_VALUE,
validation: (Rule) => Rule.required(),
});

export const benefitsByLocation = defineField({
name: "benefitsByLocation",
title: "Benefits by Location",
Expand All @@ -24,21 +48,43 @@ export const benefitsByLocation = defineField({
validation: (Rule) => Rule.required(),
},
defineField({
name: "benefitsGroup",
title: "Benefits Group",
name: "benefits",
title: "Benefits",
description:
"Enter the benefits offered at the location selected above.",
type: "array",
of: [{ type: benefitId }],
of: [
{
name: "benefit",
type: "document",
anemne marked this conversation as resolved.
Show resolved Hide resolved
title: "Benefit",
fields: [benefitType, title, richText],
preview: {
select: {
title: title.name,
type: benefitType.name,
},
prepare({ title, type }) {
const subtitle =
BENEFIT_TYPES.find((o) => o.value === type)?.title ??
"Unknown benefit type";
return {
title,
subtitle,
};
},
},
},
],
}),
],
preview: {
select: {
location: `${locationID}.${companyLocationNameID}`,
benefitsGroup: "benefitsGroup",
benefits: "benefits",
},
prepare({ location, benefitsGroup }) {
const benefitsCount = benefitsGroup ? benefitsGroup.length : 0;
prepare({ location, benefits }) {
const benefitsCount = benefits ? benefits.length : 0;
return {
title: location || "No location selected",
subtitle: `${benefitsCount} benefit${benefitsCount > 1 ? "s" : ""}`,
Expand All @@ -58,3 +104,5 @@ export const benefitsByLocation = defineField({
);
}),
});

export default benefitsByLocation;