From e79e199a35216dd09d6211304fd08ee51531b1bf Mon Sep 17 00:00:00 2001 From: Kartik-M24 <161120979+Kartik-M24@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:41:53 +1300 Subject: [PATCH] 631 frontend connect the policy to sanity (#773) * Added schemas and util files for each of the policies sub folders * Fixed codestyle issue * Implemented policies using sanity schema and utilised this on the tab content, which is displayed on the bookings page * Formatted file properly * Removed async from file as its not supported * ran yarn to pass precode checks * Removed unwanted changes * Fetched the policies blocks, stored the values and called this in layout to be displayed above the footer * Added title and order to policies schema and util so that it can be sorted by either the title or order * Fixed the bug now the headings match with the content, nothing is out of bounds * Fixed TabContent.story and ran yarn-dev-server * removed line in packag.json server * deleted package-lock.json file * restore yarn.lock to master version * Adjusted layout.tsx to remove type error * Fixed issue in TabsComponent.story.tsx and reset default export on layoout.tsx * Fixed duplicate imports issue * fix errors --------- Co-authored-by: bcho892 --- client/sanity/schema.ts | 2 + .../src/app/bookings/BookingPolicyStorage.tsx | 22 + client/src/app/bookings/layout.tsx | 17 +- client/src/app/bookings/page.tsx | 18 + .../composite/Booking/BookingContext.tsx | 19 + .../BookingsPolicyTabs/TabsContent.story.tsx | 96 +++- .../BookingsPolicyTabs/TabsContent.tsx | 490 ++---------------- .../TabsComponent/TabsComponent.story.tsx | 10 +- .../generic/TabsComponent/TabsComponent.tsx | 23 +- client/src/models/sanity/Policies/Schema.ts | 28 + client/src/models/sanity/Policies/Utils.ts | 9 + 11 files changed, 249 insertions(+), 485 deletions(-) create mode 100644 client/src/app/bookings/BookingPolicyStorage.tsx create mode 100644 client/src/models/sanity/Policies/Schema.ts create mode 100644 client/src/models/sanity/Policies/Utils.ts diff --git a/client/sanity/schema.ts b/client/sanity/schema.ts index 3773d5d3e..0f37f894a 100644 --- a/client/sanity/schema.ts +++ b/client/sanity/schema.ts @@ -5,6 +5,7 @@ import { LodgeInfoSchema } from "@/models/sanity/LodgeInfo/Schema" import { type SchemaTypeDefinition } from "sanity" import { CommitteeMemberSchema } from "@/models/sanity/CommitteeMembers/Schema" import { LifeMemberSchema } from "@/models/sanity/LifeMembers/Schema" +import { PoliciesSchema } from "@/models/sanity/Policies/Schema" export const schema: { types: SchemaTypeDefinition[] } = { types: [ @@ -12,6 +13,7 @@ export const schema: { types: SchemaTypeDefinition[] } = { HomePageSchema, ContactDetailSchema, LodgeInfoSchema, + PoliciesSchema, CommitteeMemberSchema, LifeMemberSchema ] diff --git a/client/src/app/bookings/BookingPolicyStorage.tsx b/client/src/app/bookings/BookingPolicyStorage.tsx new file mode 100644 index 000000000..2d671317c --- /dev/null +++ b/client/src/app/bookings/BookingPolicyStorage.tsx @@ -0,0 +1,22 @@ +"use client" + +import { + BookingContext, + PolicyWithTextBlocks +} from "@/components/composite/Booking/BookingContext" +import { useContext, useEffect } from "react" + +const BookingPolicyStorage = ({ + policies +}: { + policies: PolicyWithTextBlocks[] +}) => { + const { setPolicies } = useContext(BookingContext) + useEffect(() => { + setPolicies?.(policies) + }, [policies, setPolicies]) + + return null +} + +export default BookingPolicyStorage diff --git a/client/src/app/bookings/layout.tsx b/client/src/app/bookings/layout.tsx index 3e5f95bf1..1b0cc2dce 100644 --- a/client/src/app/bookings/layout.tsx +++ b/client/src/app/bookings/layout.tsx @@ -11,10 +11,13 @@ import { Footer } from "@/components/generic/Footer/Footer" import { QueryClientProvider } from "@tanstack/react-query" import queryClient from "@/services/QueryClient" -type IBookingLayout = Readonly<{ children: ReactNode }> +type IBookingLayout = Readonly<{ + children: ReactNode + // policyInfoProps: ReactNode +}> const InnerBookingLayout = ({ children }: IBookingLayout) => { - const { getExistingSession } = useContext(BookingContext) + const { getExistingSession, policies } = useContext(BookingContext) const getExistingSessionCallback = useCallback(() => { getExistingSession?.() @@ -22,6 +25,14 @@ const InnerBookingLayout = ({ children }: IBookingLayout) => { useUserLoggedInCallback(getExistingSessionCallback) + const PoliciesContent = policies + ? policies.slice(0, 3).map((policy) => ({ + order: policy.order || 0, // Ensure order is a number + title: policy.title || "Untitled", // Ensure title is a string + information: policy.information || [] // Make sure information is an array of PortableTextBlocks + })) + : [] + return ( <>
{
- +