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,13 @@
import Script from "next/script"
import { env } from "@/env/server"
export default function AdobeSDKScript() {
return env.ADOBE_SDK_SCRIPT_SRC ? (
<Script
data-cookieconsent="statistics"
src={env.ADOBE_SDK_SCRIPT_SRC}
async
/>
) : null
}

View File

@@ -0,0 +1,18 @@
import Script from "next/script"
import { env } from "@/env/server"
export default function GTMScript() {
return env.ENABLE_GTMSCRIPT ? (
<Script
id="gtm-script-tag"
data-cookieconsent="statistics"
dangerouslySetInnerHTML={{
__html: `
(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= 'https://analytics.scandichotels.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','adobeDataLayer','GTM-KNJCW67W');
`,
}}
async
/>
) : null
}

View File

@@ -0,0 +1,41 @@
"use client"
import { usePathname, useSearchParams } from "next/navigation"
import { startTransition, useEffect, useRef } from "react"
import useRouterTransitionStore from "@/stores/router-transition"
import useTrackingStore from "@/stores/tracking"
import { trackPageViewStart } from "@/utils/tracking"
export default function RouterTracking() {
const pathName = usePathname()
const searchParams = useSearchParams()
const { setInitialPageLoadTime } = useTrackingStore()
const { startRouterTransition } = useRouterTransitionStore()
// We need this check to differentiate hard vs soft navigations
// This is not because of StrictMode
const hasRunInitial = useRef<boolean>(false)
const previousPathname = useRef<string | null>(null)
useEffect(() => {
if (!hasRunInitial.current) {
hasRunInitial.current = true
previousPathname.current = pathName // Set initial path to compare later
return
}
if (previousPathname.current !== pathName) {
setInitialPageLoadTime(Date.now())
trackPageViewStart()
startTransition(() => {
startRouterTransition()
})
}
previousPathname.current = pathName // Update for next render
}, [pathName, searchParams, setInitialPageLoadTime, startRouterTransition])
return null
}

View File

@@ -0,0 +1,158 @@
"use client"
import { usePathname } from "next/navigation"
import {
startTransition,
useEffect,
useOptimistic,
useRef,
useState,
} from "react"
import useRouterTransitionStore from "@/stores/router-transition"
import useTrackingStore from "@/stores/tracking"
import { useSessionId } from "@/hooks/useSessionId"
import { createSDKPageObject, trackPageView } from "@/utils/tracking"
import type { TrackingSDKProps } from "@/types/components/tracking"
enum TransitionStatusEnum {
NotRun = "NotRun",
Running = "Running",
Done = "Done",
}
type TransitionStatus = keyof typeof TransitionStatusEnum
export default function RouterTransition({
pageData,
userData,
hotelInfo,
paymentInfo,
}: TrackingSDKProps) {
const [loading, setLoading] = useOptimistic(false)
const [status, setStatus] = useState<TransitionStatus>(
TransitionStatusEnum.NotRun
)
const { getPageLoadTime, hasRun, setHasRun } = useTrackingStore()
const sessionId = useSessionId()
const pathName = usePathname()
const { isTransitioning, stopRouterTransition } = useRouterTransitionStore()
const previousPathname = useRef<string | null>(null)
// We need this check to differentiate hard vs soft navigations
// This is not because of StrictMode
const hasRunInitial = useRef<boolean>(false)
useEffect(() => {
if (!hasRun && !hasRunInitial.current) {
const handleLoad = () => {
const perfObserver = new PerformanceObserver((observedEntries) => {
const entry = observedEntries.getEntriesByType("navigation")[0]
if (entry) {
const trackingData = {
...pageData,
sessionId,
pathName,
pageLoadTime: entry.duration / 1000,
}
const pageObject = createSDKPageObject(trackingData)
trackPageView({
event: "pageView",
pageInfo: pageObject,
userInfo: userData,
hotelInfo: hotelInfo,
paymentInfo,
})
perfObserver.disconnect()
}
})
perfObserver.observe({
type: "navigation",
buffered: true,
})
}
// If the page is already loaded, execute immediately
if (document.readyState === "complete") {
handleLoad()
} else {
// Otherwise wait for the load event
window.addEventListener("load", handleLoad)
return () => window.removeEventListener("load", handleLoad)
}
hasRunInitial.current = true
setHasRun()
}
}, [
pathName,
hasRun,
setHasRun,
hotelInfo,
userData,
pageData,
sessionId,
paymentInfo,
])
useEffect(() => {
if (isTransitioning && status === TransitionStatusEnum.NotRun) {
startTransition(() => {
setStatus(TransitionStatusEnum.Running)
setLoading(true)
})
} else if (
!loading &&
isTransitioning &&
status === TransitionStatusEnum.Running
) {
setStatus(TransitionStatusEnum.Done)
stopRouterTransition()
} else if (
!loading &&
!isTransitioning &&
status === TransitionStatusEnum.Done
) {
if (hasRun && !hasRunInitial.current) {
const pageLoadTime = getPageLoadTime()
const trackingData = {
...pageData,
sessionId,
pathName,
pageLoadTime: pageLoadTime,
}
const pageObject = createSDKPageObject(trackingData)
if (previousPathname.current !== pathName) {
trackPageView({
event: "pageView",
pageInfo: pageObject,
userInfo: userData,
hotelInfo: hotelInfo,
paymentInfo,
})
}
previousPathname.current = pathName // Update for next render
}
}
}, [
isTransitioning,
loading,
status,
setLoading,
stopRouterTransition,
pageData,
pathName,
userData,
hotelInfo,
getPageLoadTime,
hasRun,
sessionId,
paymentInfo,
])
return null
}

View File

@@ -0,0 +1,34 @@
import { getUserTracking } from "@/lib/trpc/memoizedRequests"
import RouterTransition from "@/components/TrackingSDK/RouterTransition"
import type {
TrackingSDKHotelInfo,
TrackingSDKPageData,
TrackingSDKPaymentInfo,
} from "@/types/components/tracking"
export const preloadUserTracking = () => {
void getUserTracking()
}
export default async function TrackingSDK({
pageData,
hotelInfo,
paymentInfo,
}: {
pageData: TrackingSDKPageData
hotelInfo?: TrackingSDKHotelInfo
paymentInfo?: TrackingSDKPaymentInfo
}) {
const userTrackingData = await getUserTracking()
return (
<RouterTransition
pageData={pageData}
userData={userTrackingData}
hotelInfo={hotelInfo}
paymentInfo={paymentInfo}
/>
)
}