Merged in monorepo-step-1 (pull request #1080)

Migrate to a monorepo setup - step 1

* Move web to subfolder /apps/scandic-web

* Yarn + transitive deps

- Move to yarn
- design-system package removed for now since yarn doesn't
support the parameter for token (ie project currently broken)
- Add missing transitive dependencies as Yarn otherwise
prevents these imports
- VS Code doesn't pick up TS path aliases unless you open
/apps/scandic-web instead of root (will be fixed with monorepo)

* Pin framer-motion to temporarily fix typing issue

https://github.com/adobe/react-spectrum/issues/7494

* Pin zod to avoid typ error

There seems to have been a breaking change in the types
returned by zod where error is now returned as undefined
instead of missing in the type. We should just handle this
but to avoid merge conflicts just pin the dependency for
now.

* Pin react-intl version

Pin version of react-intl to avoid tiny type issue where formatMessage
does not accept a generic any more. This will be fixed in a future
commit, but to avoid merge conflicts just pin for now.

* Pin typescript version

Temporarily pin version as newer versions as stricter and results in
a type error. Will be fixed in future commit after merge.

* Setup workspaces

* Add design-system as a monorepo package

* Remove unused env var DESIGN_SYSTEM_ACCESS_TOKEN

* Fix husky for monorepo setup

* Update netlify.toml

* Add lint script to root package.json

* Add stub readme

* Fix react-intl formatMessage types

* Test netlify.toml in root

* Remove root toml

* Update netlify.toml publish path

* Remove package-lock.json

* Update build for branch/preview builds


Approved-by: Linus Flood
This commit is contained in:
Anton Gunnarsson
2025-02-26 10:36:17 +00:00
committed by Linus Flood
parent 667cab6fb6
commit 80100e7631
2731 changed files with 30986 additions and 23708 deletions

View File

@@ -0,0 +1,23 @@
"use client"
import { useEffect, useState } from "react"
import { PaymentMethodEnum } from "@/constants/booking"
export function useAvailablePaymentOptions(
otherPaymentOptions: PaymentMethodEnum[]
) {
const [availablePaymentOptions, setAvailablePaymentOptions] = useState(
otherPaymentOptions.filter(
(option) => option !== PaymentMethodEnum.applePay
)
)
useEffect(() => {
if (window.ApplePaySession) {
setAvailablePaymentOptions(otherPaymentOptions)
}
}, [otherPaymentOptions, setAvailablePaymentOptions])
return availablePaymentOptions
}

View File

@@ -0,0 +1,52 @@
"use client"
import { useRef } from "react"
import { trpc } from "@/lib/trpc/client"
import type { BookingStatusEnum } from "@/constants/booking"
export function useHandleBookingStatus({
confirmationNumber,
expectedStatus,
maxRetries,
retryInterval,
enabled,
}: {
confirmationNumber: string | null
expectedStatus: BookingStatusEnum
maxRetries: number
retryInterval: number
enabled: boolean
}) {
const retries = useRef(0)
const query = trpc.booking.status.useQuery(
{ confirmationNumber: confirmationNumber ?? "" },
{
enabled,
refetchInterval: (query) => {
retries.current = query.state.dataUpdateCount
if (query.state.error || query.state.dataUpdateCount >= maxRetries) {
return false
}
if (query.state.data?.reservationStatus === expectedStatus) {
return false
}
return retryInterval
},
refetchIntervalInBackground: true,
refetchOnWindowFocus: false,
refetchOnMount: false,
retry: false,
}
)
return {
...query,
isTimeout: retries.current >= maxRetries,
}
}

View File

@@ -0,0 +1,65 @@
"use client"
import { usePathname, useRouter, useSearchParams } from "next/navigation"
import { useCallback, useEffect } from "react"
import { useIntl } from "react-intl"
import { PaymentErrorCodeEnum } from "@/constants/booking"
import { useEnterDetailsStore } from "@/stores/enter-details"
import { toast } from "@/components/TempDesignSystem/Toasts"
export function usePaymentFailedToast() {
const updateSearchParams = useEnterDetailsStore(
(state) => state.actions.updateSeachParamString
)
const intl = useIntl()
const searchParams = useSearchParams()
const pathname = usePathname()
const router = useRouter()
const getErrorMessage = useCallback(
(errorCode: PaymentErrorCodeEnum) => {
switch (errorCode) {
case PaymentErrorCodeEnum.Cancelled:
return intl.formatMessage({
id: "You have now cancelled your payment.",
})
default:
return intl.formatMessage({
id: "We had an issue processing your booking. Please try again. No charges have been made.",
})
}
},
[intl]
)
const errorCodeString = searchParams.get("errorCode")
const errorCode = Number(errorCodeString) as PaymentErrorCodeEnum
const errorMessage = getErrorMessage(errorCode)
useEffect(() => {
if (!errorCode) return
// setTimeout is needed to show toasts on page load: https://sonner.emilkowal.ski/toast#render-toast-on-page-load
setTimeout(() => {
const toastType =
errorCode === PaymentErrorCodeEnum.Cancelled ? "warning" : "error"
toast[toastType](errorMessage)
})
const queryParams = new URLSearchParams(searchParams.toString())
queryParams.delete("errorCode")
updateSearchParams(queryParams.toString())
router.push(`${pathname}?${queryParams.toString()}`)
}, [
searchParams,
pathname,
errorCode,
errorMessage,
router,
updateSearchParams,
])
}

View File

@@ -0,0 +1,62 @@
import { useCallback, useEffect } from "react"
import { useMediaQuery } from "usehooks-ts"
import type { StepEnum } from "@/types/enums/step"
export default function useScrollToActiveSection(
step: StepEnum,
steps: StepEnum[],
isActive: boolean
) {
const isMobile = useMediaQuery("(max-width: 768px)")
const handleScroll = useCallback(() => {
if (!isMobile) {
return
}
const currentElement = document.querySelector<HTMLElement>(
`[data-step="${step}"]`
)
const prevOpenElement =
document.querySelector<HTMLElement>(`[data-open="true"]`)
const currentStepIndex = steps.indexOf(step)
const prevStep = prevOpenElement
? (Number(prevOpenElement?.dataset.step) as StepEnum)
: null
const prevStepIndex = prevStep ? steps.indexOf(prevStep) : null
if (currentElement) {
const BOOKING_WIDGET_OFFSET = 71
const prevElementContent = prevOpenElement?.querySelector("header + div")
let collapsedSpace = 0
if (
prevElementContent &&
prevStepIndex &&
prevStepIndex < currentStepIndex
) {
collapsedSpace = prevElementContent.clientHeight
}
const currentElementTop =
currentElement.getBoundingClientRect().top + window.scrollY
const scrollTarget = Math.round(
currentElementTop - BOOKING_WIDGET_OFFSET - collapsedSpace
)
window.scrollTo({
top: scrollTarget,
behavior: "smooth",
})
}
}, [step, steps, isMobile])
useEffect(() => {
if (!isActive) return
handleScroll()
}, [isActive, handleScroll])
}