Skip to content

Commit

Permalink
feat: HoursCard uses hours entity field
Browse files Browse the repository at this point in the history
Uses an entityField for hours

Also changed any -> HoursType
  • Loading branch information
jwartofsky-yext committed Nov 11, 2024
1 parent 966065e commit 8735c2a
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 36 deletions.
57 changes: 24 additions & 33 deletions src/components/puck/HoursCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,30 @@ import { DayOfWeekNames, HoursTable, HoursType } from "@yext/pages-components";
import { Section, sectionVariants } from "./atoms/section.js";
import "@yext/pages-components/style.css";
import { VariantProps } from "class-variance-authority";
import { EntityField, useDocument } from "../../index.js";
import {
EntityField,
resolveYextEntityField,
useDocument,
YextEntityField,
YextEntityFieldSelector,
} from "../../index.js";

export type HoursCardProps = {
hours: YextEntityField<HoursType>;
startOfWeek: keyof DayOfWeekNames | "today";
collapseDays: boolean;
showAdditionalHoursText: boolean;
alignment: "items-start" | "items-center";
padding: VariantProps<typeof sectionVariants>["padding"];
};

type Interval = {
start: any;
end: any;
};

type HolidayHours = {
date: string;
openIntervals?: Interval[];
isClosed?: boolean;
isRegularHours?: boolean;
};

type DayHour = {
openIntervals?: Interval[];
isClosed?: boolean;
};

type Hours = {
monday?: DayHour;
tuesday?: DayHour;
wednesday?: DayHour;
thursday?: DayHour;
friday?: DayHour;
saturday?: DayHour;
sunday?: DayHour;
holidayHours?: HolidayHours[];
reopenDate?: string;
};

const hoursCardFields: Fields<HoursCardProps> = {
hours: YextEntityFieldSelector({
label: "Hours",
filter: {
types: ["type.hours"],
},
}),
startOfWeek: {
label: "Start of the week",
type: "radio",
Expand Down Expand Up @@ -95,14 +79,17 @@ const hoursCardFields: Fields<HoursCardProps> = {
};

const HoursCard = ({
hours: hoursField,
startOfWeek,
collapseDays,
showAdditionalHoursText,
alignment,
padding,
}: HoursCardProps) => {
const { hours, additionalHoursText } = useDocument() as {
hours: Hours;
const document = useDocument();
const hours = resolveYextEntityField(document, hoursField);

const { additionalHoursText } = document as {
additionalHoursText: string;
};

Expand All @@ -115,7 +102,7 @@ const HoursCard = ({
{hours && (
<EntityField displayName="Hours" fieldId="hours">
<HoursTable
hours={hours as HoursType}
hours={hours}
startOfWeek={startOfWeek}
collapseDays={collapseDays}
/>
Expand All @@ -134,6 +121,10 @@ const HoursCard = ({
export const HoursCardComponent: ComponentConfig<HoursCardProps> = {
fields: hoursCardFields,
defaultProps: {
hours: {
field: "hours",
constantValue: {},
},
startOfWeek: "today",
collapseDays: false,
showAdditionalHoursText: true,
Expand Down
6 changes: 3 additions & 3 deletions src/components/puck/HoursStatus.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as React from "react";
import { ComponentConfig, Fields } from "@measured/puck";
import { HoursStatus } from "@yext/pages-components";
import { HoursStatus, HoursType } from "@yext/pages-components";
import {
yextCn,
useDocument,
Expand All @@ -11,7 +11,7 @@ import {
} from "../../index.js";

export interface HoursStatusProps {
hours: YextEntityField<any>;
hours: YextEntityField<HoursType>;
className?: string;
showCurrentStatus?: boolean;
timeFormat?: "12h" | "24h";
Expand Down Expand Up @@ -97,7 +97,7 @@ export const HoursStatusComponent: ComponentConfig<HoursStatusProps> = {
defaultProps: {
hours: {
field: "hours",
constantValue: "",
constantValue: {},
},
className: "",
showCurrentStatus: true,
Expand Down

0 comments on commit 8735c2a

Please sign in to comment.