From c622a65a8aebc98faa65f4f2f7c88ff94ab86afe Mon Sep 17 00:00:00 2001 From: Christian Andolf Date: Wed, 5 Feb 2025 16:51:45 +0100 Subject: [PATCH 1/3] feat(SW-1543): join scandic friends block is now hidden for logged in users --- server/routers/contentstack/startPage/query.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/server/routers/contentstack/startPage/query.ts b/server/routers/contentstack/startPage/query.ts index 5ce2c5ace..14933cf81 100644 --- a/server/routers/contentstack/startPage/query.ts +++ b/server/routers/contentstack/startPage/query.ts @@ -23,6 +23,7 @@ import { TrackingChannelEnum, type TrackingSDKPageData, } from "@/types/components/tracking" +import { BlocksEnums } from "@/types/enums/blocks" import type { GetStartPageData, GetStartPageRefsSchema, @@ -183,8 +184,21 @@ export const startPageQueryRouter = router({ siteVersion: "new-web", } + const session = await ctx.auth() + return { - startPage: startPage.data.start_page, + startPage: { + ...startPage.data.start_page, + blocks: startPage.data.start_page.blocks?.filter((block) => { + if ( + block.typename === BlocksEnums.block.JoinScandicFriends && + session + ) { + return null + } + return block + }), + }, tracking, } }), From ced8dd5d99a8e770a4e74364103d147387743d01 Mon Sep 17 00:00:00 2001 From: Christian Andolf Date: Thu, 6 Feb 2025 08:49:49 +0100 Subject: [PATCH 2/3] fix: startpage blocks now default to an array --- components/ContentType/StartPage/index.tsx | 2 +- server/routers/contentstack/startPage/output.ts | 4 +++- server/routers/contentstack/startPage/query.ts | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/components/ContentType/StartPage/index.tsx b/components/ContentType/StartPage/index.tsx index 01e174ecd..65769149d 100644 --- a/components/ContentType/StartPage/index.tsx +++ b/components/ContentType/StartPage/index.tsx @@ -45,7 +45,7 @@ export default async function StartPage() { ) : null}
- {(blocks || []).map((block, index) => { + {blocks.map((block, index) => { if (block.typename === BlocksEnums.block.FullWidthCampaign) { return ( val || []), system: systemSchema.merge( z.object({ created_at: z.string(), diff --git a/server/routers/contentstack/startPage/query.ts b/server/routers/contentstack/startPage/query.ts index 14933cf81..20135b6fa 100644 --- a/server/routers/contentstack/startPage/query.ts +++ b/server/routers/contentstack/startPage/query.ts @@ -189,7 +189,7 @@ export const startPageQueryRouter = router({ return { startPage: { ...startPage.data.start_page, - blocks: startPage.data.start_page.blocks?.filter((block) => { + blocks: startPage.data.start_page.blocks.filter((block) => { if ( block.typename === BlocksEnums.block.JoinScandicFriends && session From 69d57b73a2aeb13f9d693221e3bbbdb222e3d200 Mon Sep 17 00:00:00 2001 From: Christian Andolf Date: Thu, 6 Feb 2025 16:22:43 +0100 Subject: [PATCH 3/3] feat(SW-1543): move auth check within component to be suspended --- components/Blocks/JoinScandicFriends/index.tsx | 9 ++++++++- components/Blocks/index.tsx | 8 +++++++- .../ContentType/StartPage/startPage.module.css | 4 ++++ server/routers/contentstack/startPage/query.ts | 16 +--------------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/components/Blocks/JoinScandicFriends/index.tsx b/components/Blocks/JoinScandicFriends/index.tsx index 3f0708bf9..30dc87e7a 100644 --- a/components/Blocks/JoinScandicFriends/index.tsx +++ b/components/Blocks/JoinScandicFriends/index.tsx @@ -1,3 +1,5 @@ +import { getProfileSafely } from "@/lib/trpc/memoizedRequests" + import { SurpriseIcon } from "@/components/Icons" import Image from "@/components/Image" import Button from "@/components/TempDesignSystem/Button" @@ -15,9 +17,14 @@ interface JoinScandicFriendsProps { content: JoinScandicFriends } -export default function JoinScandicFriends({ +export default async function JoinScandicFriends({ content, }: JoinScandicFriendsProps) { + const session = await getProfileSafely() + if (session) { + return null + } + const { show_header, show_usp, usp, primary_button } = content return ( diff --git a/components/Blocks/index.tsx b/components/Blocks/index.tsx index f0a5acf37..35037f803 100644 --- a/components/Blocks/index.tsx +++ b/components/Blocks/index.tsx @@ -1,3 +1,5 @@ +import { Suspense } from "react" + import CardsGrid from "@/components/Blocks/CardsGrid" import CarouselCards from "@/components/Blocks/CarouselCards" import DynamicContent from "@/components/Blocks/DynamicContent" @@ -106,7 +108,11 @@ export default function Blocks({ blocks }: BlocksProps) { case BlocksEnums.block.FullWidthCampaign: return case BlocksEnums.block.JoinScandicFriends: - return + return ( + + + + ) default: return null } diff --git a/components/ContentType/StartPage/startPage.module.css b/components/ContentType/StartPage/startPage.module.css index 3116430fc..d73244aa3 100644 --- a/components/ContentType/StartPage/startPage.module.css +++ b/components/ContentType/StartPage/startPage.module.css @@ -55,6 +55,10 @@ } } +.section:empty { + display: none; +} + .section { margin-left: auto; margin-right: auto; diff --git a/server/routers/contentstack/startPage/query.ts b/server/routers/contentstack/startPage/query.ts index 20135b6fa..5ce2c5ace 100644 --- a/server/routers/contentstack/startPage/query.ts +++ b/server/routers/contentstack/startPage/query.ts @@ -23,7 +23,6 @@ import { TrackingChannelEnum, type TrackingSDKPageData, } from "@/types/components/tracking" -import { BlocksEnums } from "@/types/enums/blocks" import type { GetStartPageData, GetStartPageRefsSchema, @@ -184,21 +183,8 @@ export const startPageQueryRouter = router({ siteVersion: "new-web", } - const session = await ctx.auth() - return { - startPage: { - ...startPage.data.start_page, - blocks: startPage.data.start_page.blocks.filter((block) => { - if ( - block.typename === BlocksEnums.block.JoinScandicFriends && - session - ) { - return null - } - return block - }), - }, + startPage: startPage.data.start_page, tracking, } }),