From dc99131831f44d938ed51ad3df952b3d3e5e39a9 Mon Sep 17 00:00:00 2001 From: Chad Kruse <314653+chadokruse@users.noreply.github.com> Date: Wed, 15 Jan 2025 12:51:51 -0600 Subject: [PATCH] Ability to quickly toggle Surprise Me feature --- apps/legacy/src/hooks.server.ts | 16 +++++++++++++++- apps/legacy/src/lib/components/Profile.svelte | 16 ++++++++++++++-- .../routes/profiles/v0/[ein]/+layout.server.ts | 5 +++++ .../src/routes/profiles/v0/[ein]/+page.svelte | 4 ++-- 4 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 apps/legacy/src/routes/profiles/v0/[ein]/+layout.server.ts diff --git a/apps/legacy/src/hooks.server.ts b/apps/legacy/src/hooks.server.ts index 6eba49b..2f74904 100644 --- a/apps/legacy/src/hooks.server.ts +++ b/apps/legacy/src/hooks.server.ts @@ -1,4 +1,4 @@ -import type { HandleServerError } from '@sveltejs/kit'; +import { redirect, type HandleServerError } from '@sveltejs/kit'; type Redirects = { [key: string]: string }; @@ -14,6 +14,20 @@ export async function handle({ event, resolve }) { return Response.redirect(new URL(legacySitemapRedirects[path], event.url.origin), 301); } + // Handle Surprise Me feature + const accessToken = event.url.searchParams.get('access'); + + if (accessToken === 'welcome-friend') { + event.cookies.set('surprise-me-access', 'granted', { + path: '/', + maxAge: 60 * 60 * 24 * 30, // 30 days + }); + + // Redirect to the same page without the query param + const redirectTo = event.url.pathname; + redirect(302, redirectTo); + } + return resolve(event); } diff --git a/apps/legacy/src/lib/components/Profile.svelte b/apps/legacy/src/lib/components/Profile.svelte index d1d0807..71be70c 100644 --- a/apps/legacy/src/lib/components/Profile.svelte +++ b/apps/legacy/src/lib/components/Profile.svelte @@ -13,9 +13,10 @@ import { upperFirstLetter } from '@repo/shared/functions/formatters/names'; interface Props { profile: GrantmakersExtractedDataObj; + hasSurpriseMeAccess: boolean; } - let { profile }: Props = $props(); + let { profile, hasSurpriseMeAccess }: Props = $props(); // Mimic Jekyll const site = { @@ -137,8 +138,19 @@ {/if}