diff --git a/apps/next/src/app/about/page.tsx b/apps/next/src/app/about/page.tsx index d1eaecde..69fb7aa9 100644 --- a/apps/next/src/app/about/page.tsx +++ b/apps/next/src/app/about/page.tsx @@ -17,6 +17,7 @@ export default function About() { return (
An Image of UCI's signage. { + if (!sessionStorage.getItem(ACCOUNT_DELETED_KEY)) return; + sessionStorage.removeItem(ACCOUNT_DELETED_KEY); + showSnackbar("Your account has been deleted.", "success"); + }, [showSnackbar]); return ( diff --git a/apps/next/src/app/nutrition/page.tsx b/apps/next/src/app/nutrition/page.tsx index aa6c0e91..b0c03627 100644 --- a/apps/next/src/app/nutrition/page.tsx +++ b/apps/next/src/app/nutrition/page.tsx @@ -1,7 +1,7 @@ "use client"; import type { RouterOutputs } from "@api/index"; -import { Box, Typography } from "@mui/material"; +import { Box, CircularProgress, Typography } from "@mui/material"; import { useRouter } from "next/navigation"; import posthog from "posthog-js"; import { useEffect, useMemo, useState } from "react"; @@ -335,7 +335,18 @@ export default function MealTracker() { const isMobile = useMediaQuery("(max-width: 768px)"); - if (isLoading) return
Loading meals...
; + if (isLoading) + return ( +
+ +
+ ); if (error) return
Error loading meals
; return ( diff --git a/apps/next/src/components/ui/card/food-card.tsx b/apps/next/src/components/ui/card/food-card.tsx index d57bc852..0082d8bc 100644 --- a/apps/next/src/components/ui/card/food-card.tsx +++ b/apps/next/src/components/ui/card/food-card.tsx @@ -212,20 +212,19 @@ const FoodCardContent = React.forwardRef( : "No description available."}
- {/* Nudges the heart up so it looks visually centered */} -
- -
+
+ +
diff --git a/apps/next/src/components/ui/delete-account-content.tsx b/apps/next/src/components/ui/delete-account-content.tsx new file mode 100644 index 00000000..ff38d850 --- /dev/null +++ b/apps/next/src/components/ui/delete-account-content.tsx @@ -0,0 +1,169 @@ +"use client"; + +import DeleteIcon from "@mui/icons-material/DeleteOutline"; +import { Button } from "@mui/material"; +import posthog from "posthog-js"; +import { useEffect, useState } from "react"; +import { getSignInUrl } from "@/lib/auth-actions"; +import { SESSION_FRESH_AGE } from "@/lib/auth-constants"; +import { Provider } from "@/lib/auth-types"; +import { authClient, signOut, useSession } from "@/utils/auth-client"; + +// Added to the return URL so the dialog reopens at the confirm step after signing in again. +export const DELETE_ACCOUNT_CONFIRM_PARAM = "deleteAccount"; + +export const ACCOUNT_DELETED_KEY = "accountDeleted"; + +type DeleteAccountContentProps = { + onClose: () => void; +}; + +export default function DeleteAccountContent({ + onClose, +}: DeleteAccountContentProps) { + const { data: session } = useSession(); + const [confirmRequested, setConfirmRequested] = useState(false); + const [isWorking, setIsWorking] = useState(false); + const [error, setError] = useState(null); + + useEffect(() => { + const url = new URL(window.location.href); + if (!url.searchParams.has(DELETE_ACCOUNT_CONFIRM_PARAM)) return; + url.searchParams.delete(DELETE_ACCOUNT_CONFIRM_PARAM); + window.history.replaceState(null, "", url); + setConfirmRequested(true); + }, []); + + const handleSignInAgain = async () => { + setError(null); + setIsWorking(true); + try { + const { data: accounts } = await authClient.listAccounts(); + const provider = accounts?.[0]?.accountId.startsWith("apple_") + ? Provider.Apple + : Provider.Google; + const returnUrl = new URL(window.location.href); + returnUrl.searchParams.set(DELETE_ACCOUNT_CONFIRM_PARAM, "confirm"); + window.location.href = await getSignInUrl(provider, { + returnUrl: returnUrl.pathname + returnUrl.search, + authorizationUrlParams: { prompt: "consent" }, + }); + } catch (signInError) { + console.error("Error signing in again", signInError); + posthog.captureException(signInError); + setError("Couldn't start sign-in. Please try again."); + setIsWorking(false); + } + }; + + const handleDelete = async () => { + setError(null); + setIsWorking(true); + const { error: deleteError } = await authClient.deleteUser(); + if (deleteError) { + console.error("Error deleting account", deleteError); + setError("Couldn't delete your account. Please try again."); + setIsWorking(false); + return; + } + + sessionStorage.setItem(ACCOUNT_DELETED_KEY, "1"); + await signOut(); + }; + + // Only offer deletion right after signing in again from this dialog. + const isConfirmStep = + confirmRequested && + !!session && + Date.now() - new Date(session.session.createdAt).getTime() < + SESSION_FRESH_AGE * 1000; + + const sectionHeading = + "font-poppins text-[24px] font-bold leading-[36px] text-[var(--primary-accent-hex)] dark:text-[var(--primary-accent-light)]"; + const sectionDescription = + "font-poppins text-[14px] font-normal leading-[21px] text-[var(--text-muted-soft)] dark:text-white"; + const buttonBase = + "font-poppins text-[14px] font-medium leading-[26px] tracking-[0.46px] !flex !items-center !justify-center !rounded-[8px] !h-[49px] !w-full !min-w-0 md:!w-auto md:!min-w-[81.4px] md:!px-4"; + + return ( +
+
+
+ +
+
+

+ Delete your account +

+

+ This can't be undone +

+
+
+ +
+

+ {isConfirmStep ? "Are you sure?" : "Delete Account"} +

+

+ This permanently deletes the PeterPlate account for{" "} + {session?.user.email}, + including your ratings, favorites, logged meals, and preferences. +

+ {!isConfirmStep && ( +

+ To continue, sign in again to confirm it's you. +

+ )} + {error && ( +

+ {error} +

+ )} +
+ +
+ + {isConfirmStep ? ( + + ) : ( + + )} +
+
+ ); +} diff --git a/apps/next/src/components/ui/restaurant/restaurant-controls.tsx b/apps/next/src/components/ui/restaurant/restaurant-controls.tsx index f5b7e74e..938608ec 100644 --- a/apps/next/src/components/ui/restaurant/restaurant-controls.tsx +++ b/apps/next/src/components/ui/restaurant/restaurant-controls.tsx @@ -56,7 +56,7 @@ export function RestaurantControls({ // Sticky while scrolling
{/* Desktop title & status. Its large grow factor soaks up spare space diff --git a/apps/next/src/components/ui/restaurant/restaurant-page.tsx b/apps/next/src/components/ui/restaurant/restaurant-page.tsx index 26fd117c..3fe00ca6 100644 --- a/apps/next/src/components/ui/restaurant/restaurant-page.tsx +++ b/apps/next/src/components/ui/restaurant/restaurant-page.tsx @@ -67,7 +67,7 @@ export function RestaurantPage({ {/* Hero image & mobile header */} -
+
{hero.alt} void; onEditPreferencesClick: () => void; + onDeleteAccountClick: () => void; } export default function SidebarContent({ onClose, onEditPreferencesClick, + onDeleteAccountClick, }: ProfileMenuContentProps): React.JSX.Element | null { const { data: session } = useSession(); const user = session?.user; @@ -232,6 +235,23 @@ export default function SidebarContent({ > About PeterPlate + + {user && ( + + )}
diff --git a/apps/next/src/components/ui/toolbar.tsx b/apps/next/src/components/ui/toolbar.tsx index e6a40281..4bba6533 100644 --- a/apps/next/src/components/ui/toolbar.tsx +++ b/apps/next/src/components/ui/toolbar.tsx @@ -22,6 +22,7 @@ import { Snackbar, Tooltip, Typography, + useScrollTrigger, } from "@mui/material"; import Image from "next/image"; import Link from "next/link"; @@ -30,8 +31,12 @@ import { useTheme } from "next-themes"; import type { MouseEvent } from "react"; import { useEffect, useState } from "react"; import { type TourId, useTourStore } from "@/context/useTourStore"; +import { useHeroFade } from "@/hooks/useHeroFade"; import { useMediaQuery } from "@/hooks/useMediaQuery"; import { useSession } from "@/utils/auth-client"; +import DeleteAccountContent, { + DELETE_ACCOUNT_CONFIRM_PARAM, +} from "./delete-account-content"; import EditPreferencesContent from "./edit-preferences-content"; import { WelcomeView } from "./onboarding"; import SidebarContent from "./sidebar/sidebar-content"; @@ -134,7 +139,8 @@ const MOBILE_TOOLBAR_ELEMENTS: ToolbarElement[] = [ }, ]; -// Routes on which the toolbar should remain transparent +// Routes on which the toolbar stays fixed: clear over the hero image, then +// solid once the image has scrolled under it const TRANSPARENT_PAGES = ["/about", "/brandywine", "/anteatery"]; function ToolbarDropdown({ @@ -212,7 +218,9 @@ function ToolbarDropdown({ export function DesktopToolbar(): React.JSX.Element { const { resolvedTheme } = useTheme(); const pathname = usePathname(); - const isTransparent = TRANSPARENT_PAGES.includes(pathname); + const isTransparentPage = TRANSPARENT_PAGES.includes(pathname); + const heroFade = useHeroFade(isTransparentPage); + const isTransparent = isTransparentPage && heroFade < 0.5; const isDesktop = useMediaQuery("(min-width: 768px)"); const [profileAnchor, setProfileAnchor] = useState(null); @@ -222,6 +230,7 @@ export function DesktopToolbar(): React.JSX.Element { const [editPreferencesSnackbarOpen, setEditPreferencesSnackbarOpen] = useState(false); const [editPreferencesExpanded, setEditPreferencesExpanded] = useState(false); + const [deleteAccountOpen, setDeleteAccountOpen] = useState(false); const handleProfileOpen = (event: MouseEvent) => { setProfileAnchor(event.currentTarget); @@ -241,25 +250,53 @@ export function DesktopToolbar(): React.JSX.Element { setEditPreferencesOpen(false); setEditPreferencesSnackbarOpen(true); }; + const handleDeleteAccountOpen = () => { + setDeleteAccountOpen(true); + }; + const handleDeleteAccountClose = () => { + setDeleteAccountOpen(false); + }; const { data: session, isPending } = useSession(); const user = session?.user; const start = useTourStore((state) => state.start); const tour = TOURS_BY_PATH[pathname]; + // Reopens at the confirm step after signing in again. + useEffect(() => { + const params = new URLSearchParams(window.location.search); + if (params.has(DELETE_ACCOUNT_CONFIRM_PARAM)) setDeleteAccountOpen(true); + }, []); + return ( <> + {/* Fades from the gradient to solid as the hero scrolls under it */} + {isTransparentPage && ( + <> +
+
+ + )}
@@ -278,6 +315,7 @@ export function DesktopToolbar(): React.JSX.Element { isTransparent && resolvedTheme === "light" ? "white" : "primary.main", + transition: "color 300ms", }} > PeterPlate @@ -411,6 +449,7 @@ export function DesktopToolbar(): React.JSX.Element { @@ -474,6 +513,18 @@ export function DesktopToolbar(): React.JSX.Element { )} + + + + (null); const profileOpen = Boolean(profileAnchor); const [welcomeOpen, setWelcomeOpen] = useState(false); @@ -502,6 +559,7 @@ function MobileToolbar(): React.JSX.Element { useState(false); const [_editPreferencesExpanded, setEditPreferencesExpanded] = useState(false); + const [deleteAccountOpen, setDeleteAccountOpen] = useState(false); const start = useTourStore((state) => state.start); const tour = TOURS_BY_PATH[pathname]; @@ -509,6 +567,12 @@ function MobileToolbar(): React.JSX.Element { setIsMounted(true); }, []); + // Reopens at the confirm step after signing in again. + useEffect(() => { + const params = new URLSearchParams(window.location.search); + if (params.has(DELETE_ACCOUNT_CONFIRM_PARAM)) setDeleteAccountOpen(true); + }, []); + const handleProfileOpen = (event: React.MouseEvent) => { setProfileAnchor(event.currentTarget); }; @@ -532,6 +596,15 @@ function MobileToolbar(): React.JSX.Element { setEditPreferencesSnackbarOpen(true); }; + const handleDeleteAccountOpen = () => { + setProfileAnchor(null); + setDeleteAccountOpen(true); + }; + + const handleDeleteAccountClose = () => { + setDeleteAccountOpen(false); + }; + const diningHref = pathname === "/brandywine" ? "/anteatery" @@ -558,17 +631,24 @@ function MobileToolbar(): React.JSX.Element { {/* Sticky top header bar */}
+ {/* Fades to solid as the hero scrolls under it */} + {isTransparentPage && ( +
+ )} + {/* Hidden until the bar is solid, so the hall name on the hero image + never shows through behind it */} {greeting} @@ -621,11 +701,11 @@ function MobileToolbar(): React.JSX.Element { > @@ -718,6 +798,7 @@ function MobileToolbar(): React.JSX.Element { @@ -752,6 +833,20 @@ function MobileToolbar(): React.JSX.Element { /> + + + + { + if (!enabled) return; + + const update = () => { + const heroBottom = + document.getElementById("hero")?.getBoundingClientRect().bottom ?? 0; + setFade(Math.min(Math.max((128 - heroBottom) / 64, 0), 1)); + }; + + update(); + window.addEventListener("scroll", update, { passive: true }); + return () => window.removeEventListener("scroll", update); + }, [enabled]); + + return fade; +} diff --git a/apps/next/src/lib/auth-constants.ts b/apps/next/src/lib/auth-constants.ts index 346df8bb..9eba1daa 100644 --- a/apps/next/src/lib/auth-constants.ts +++ b/apps/next/src/lib/auth-constants.ts @@ -1 +1,4 @@ export const AUTH_PROVIDER_ID = "icssc"; + +/** Seconds since sign-in during which a session can delete its account. */ +export const SESSION_FRESH_AGE = 5 * 60; diff --git a/apps/next/src/lib/auth.ts b/apps/next/src/lib/auth.ts index 825f7c09..469f75de 100644 --- a/apps/next/src/lib/auth.ts +++ b/apps/next/src/lib/auth.ts @@ -7,7 +7,7 @@ import { betterAuth } from "better-auth/minimal"; import { nextCookies } from "better-auth/next-js"; import { genericOAuth } from "better-auth/plugins"; -import { AUTH_PROVIDER_ID } from "@/lib/auth-constants"; +import { AUTH_PROVIDER_ID, SESSION_FRESH_AGE } from "@/lib/auth-constants"; import type { AuthAdditionalData } from "@/lib/auth-types"; import { getSafeAuthRedirectPath } from "@/lib/auth-utils"; @@ -41,8 +41,15 @@ export const auth = betterAuth({ enabled: true, maxAge: 5 * 60, }, + // Account deletion requires a sign-in this recent. + freshAge: SESSION_FRESH_AGE, }, user: { + deleteUser: { + enabled: true, + // TODO: When auth.icssc.club adds account deletion, call it from a + // beforeDelete hook to revoke Sign in with Apple tokens and end ICSSC sessions. + }, additionalFields: { hasOnboarded: { type: "boolean", diff --git a/apps/next/src/utils/funcs.ts b/apps/next/src/utils/funcs.ts index bebce6aa..98b9808d 100644 --- a/apps/next/src/utils/funcs.ts +++ b/apps/next/src/utils/funcs.ts @@ -527,18 +527,21 @@ export function getEventType(title: string): string { } /** - * Scrolls to a station section while leaving room for the sticky restaurant controls. + * Scrolls to a station section while leaving room for the toolbar and sticky + * restaurant controls. */ export function scrollToStation(stationId: string) { const section = document.getElementById(stationId); if (!section) return; - const controlsHeight = - document.getElementById("restaurant-controls")?.offsetHeight ?? 0; + const controls = document.getElementById("restaurant-controls"); + const controlsBottom = controls + ? Number.parseFloat(getComputedStyle(controls).top) + controls.offsetHeight + : 0; window.scrollTo({ top: section.getBoundingClientRect().top + window.scrollY - - controlsHeight - + controlsBottom - 16, behavior: "smooth", });