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

631 frontend connect the policy to sanity #773

Merged
merged 25 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
2e1bd27
Added schemas and util files for each of the policies sub folders
Kartik-M24 Sep 3, 2024
e99902d
Fixed codestyle issue
Kartik-M24 Sep 3, 2024
84f5408
Implemented policies using sanity schema and utilised this on the tab…
Kartik-M24 Sep 11, 2024
586faff
Formatted file properly
Kartik-M24 Sep 11, 2024
d67f27e
Removed async from file as its not supported
Kartik-M24 Sep 11, 2024
dd2051e
Merge branch 'master' into 631-frontend-connect-the-policy-to-sanity
Kartik-M24 Sep 11, 2024
bd00110
ran yarn to pass precode checks
Kartik-M24 Sep 11, 2024
79f3c70
Merge branch '631-frontend-connect-the-policy-to-sanity' of https://g…
Kartik-M24 Sep 11, 2024
5c19532
Removed unwanted changes
Kartik-M24 Sep 12, 2024
22d5c87
Fetched the policies blocks, stored the values and called this in lay…
Kartik-M24 Sep 18, 2024
354c564
Added title and order to policies schema and util so that it can be s…
Kartik-M24 Sep 28, 2024
7f337da
Fixed the bug now the headings match with the content, nothing is out…
Kartik-M24 Sep 28, 2024
72a9d05
Merge branch 'master' into 631-frontend-connect-the-policy-to-sanity
Kartik-M24 Sep 28, 2024
5791b19
Fixed TabContent.story and ran yarn-dev-server
Kartik-M24 Sep 28, 2024
d3cd390
Merge branch 'master' of https://github.com/UoaWDCC/uasc-web into 631…
Kartik-M24 Sep 28, 2024
5e9234f
removed line in packag.json server
Kartik-M24 Sep 28, 2024
15cfb54
deleted package-lock.json file
Kartik-M24 Sep 28, 2024
a4ee539
restore yarn.lock to master version
Kartik-M24 Sep 28, 2024
07b13f3
Merge branch '631-frontend-connect-the-policy-to-sanity' of https://g…
Kartik-M24 Sep 28, 2024
a50e983
Adjusted layout.tsx to remove type error
Kartik-M24 Sep 29, 2024
ad26375
Fixed issue in TabsComponent.story.tsx and reset default export on la…
Kartik-M24 Oct 1, 2024
708f468
Fixed duplicate imports issue
Kartik-M24 Oct 1, 2024
15aec2b
fix errors
choden-dev Oct 2, 2024
22cf881
Merge branch 'master' into 631-frontend-connect-the-policy-to-sanity
Kartik-M24 Oct 2, 2024
a022528
Merge branch 'master' into 631-frontend-connect-the-policy-to-sanity
Kartik-M24 Oct 16, 2024
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
2 changes: 2 additions & 0 deletions client/sanity/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ 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: [
AboutItemSchema,
HomePageSchema,
ContactDetailSchema,
LodgeInfoSchema,
PoliciesSchema,
CommitteeMemberSchema,
LifeMemberSchema
]
Expand Down
16 changes: 16 additions & 0 deletions client/src/app/bookings/BookingPolicyStorage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"use client"

import { BookingContext } from "@/components/composite/Booking/BookingContext"
import { useContext, useEffect } from "react"
import { Policies } from "@/models/sanity/Policies/Utils"

const BookingPolicyStorage = ({ policies }: { policies: Policies[] }) => {
const { setPolicies } = useContext(BookingContext)
useEffect(() => {
setPolicies?.(policies)
}, [policies, setPolicies])

return null
}

export default BookingPolicyStorage
28 changes: 23 additions & 5 deletions client/src/app/bookings/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,30 @@ 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<{
Kartik-M24 marked this conversation as resolved.
Show resolved Hide resolved
children: ReactNode
policyInfoProps: Omit<React.ReactNode, "handbookBookLodgeClick"> & {
children?: React.ReactNode
}
}>

const InnerBookingLayout = ({ children }: IBookingLayout) => {
const { getExistingSession } = useContext(BookingContext)
const { getExistingSession, policies } = useContext(BookingContext)

const getExistingSessionCallback = useCallback(() => {
getExistingSession?.()
}, [getExistingSession])

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 (
<>
<div
Expand All @@ -36,18 +49,23 @@ const InnerBookingLayout = ({ children }: IBookingLayout) => {
</div>
</div>
<span className="relative z-[11]">
<PolicyTabs />
<PolicyTabs policiesArray={PoliciesContent} />
</span>
<Footer />
</>
)
}

export default function BookingLayout({ children }: IBookingLayout) {
export default function BookingLayout({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the problem is this default export shouldn't be changed because we are using BookingPolicyStorage now

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to undo all changes to this, have a look at the check builds workflow

children,
policyInfoProps
}: IBookingLayout) {
return (
<QueryClientProvider client={queryClient}>
<BookingContextProvider>
<InnerBookingLayout>{children}</InnerBookingLayout>
<InnerBookingLayout policyInfoProps={policyInfoProps}>
{children}
</InnerBookingLayout>
</BookingContextProvider>
</QueryClientProvider>
)
Expand Down
9 changes: 9 additions & 0 deletions client/src/app/bookings/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import {
LodgeInformation
} from "@/models/sanity/LodgeInfo/Utils"
import { PortableText } from "@portabletext/react"
import { Policies, POLICIES_GROQ_QUERY } from "@/models/sanity/Policies/Utils"
import BookingPolicyStorage from "./BookingPolicyStorage"

const BookingPage = async () => {
const lodgeInfo = await sanityQuery<LodgeInformation[]>(
Expand Down Expand Up @@ -34,6 +36,12 @@ const BookingPage = async () => {
: ""
) || []

const fetchedPolicies = await sanityQuery<Policies[]>(POLICIES_GROQ_QUERY)

/** We assume there will be only one based on the way {@link Policies } is set up in sanity */
// If list isn't empty, assign all policies to the variable
const policies = fetchedPolicies.length > 0 ? fetchedPolicies : []

return (
<>
<BookingInformationAndCreation
Expand All @@ -43,6 +51,7 @@ const BookingPage = async () => {
imageSrcs: processedImages
}}
/>
<BookingPolicyStorage policies={policies} />
</>
)
}
Expand Down
15 changes: 15 additions & 0 deletions client/src/components/composite/Booking/BookingContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { BOOKING_AVAILABLITY_KEY } from "@/services/Booking/BookingQueries"
import { useBookingPaymentClientSecretMutation } from "@/services/Payment/PaymentMutations"
import queryClient from "@/services/QueryClient"
import { useEditSelfMutation } from "@/services/User/UserMutations"
import { Policies } from "@/models/sanity/Policies/Utils"
import { useRouter } from "next/navigation"

interface IBookingContext {
Expand Down Expand Up @@ -43,6 +44,16 @@ interface IBookingContext {
* Parsed message describing problems arising from a network call
*/
errorMessage?: string

/**
* Booking Policy Items fetched from Sanity
*/
policies?: Policies[]

/**
* Setter function for the booking policies
*/
setPolicies?: (newPolicies: Policies[]) => void
}

/**
Expand All @@ -63,6 +74,8 @@ export const BookingContextProvider = ({
error
} = useBookingPaymentClientSecretMutation()

const [policies, setPolicies] = useState<Policies[]>([])

const [allergies, setAllergies] = useState<string>("")

const { mutateAsync: updateAllergies } = useEditSelfMutation()
Expand Down Expand Up @@ -108,6 +121,8 @@ export const BookingContextProvider = ({
isPending,
setAllergies,
forceRefreshBookings,
policies,
setPolicies,
errorMessage:
error?.name === "UnavailableBookingError" ? error?.message : undefined
}}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
import type { Meta } from "@storybook/react"
import {
BehaviourPolicyContent,
BookingPolicyContent,
PolicyTabs
} from "./TabsContent"
import { PolicyTabs } from "./TabsContent"

const meta: Meta = {
component: PolicyTabs
Expand All @@ -13,15 +9,3 @@ export default meta
export const DefaultPolicyTabs = () => {
return <PolicyTabs />
}

export const BookingPolicyStory = () => {
return <BookingPolicyContent />
}

export const CancellationPolicyStory = () => {
return <CancellationPolicyStory />
}

export const BehaviourPolicyStory = () => {
return <BehaviourPolicyContent />
}
Loading
Loading