|
| 1 | +<script setup lang="ts"> |
| 2 | +/** |
| 3 | + * What's New Overlay |
| 4 | + * |
| 5 | + * Shows once for existing users who upgrade to a new version. |
| 6 | + * Currently highlights the Weekly Celebrations feature (v0.6.0). |
| 7 | + * If user says "Yes", enables both celebrations + encouragement |
| 8 | + * and navigates to settings so they can see the options. |
| 9 | + */ |
| 10 | +
|
| 11 | +const { hasNewVersion, acknowledgeNewVersion } = useOnboarding(); |
| 12 | +const router = useRouter(); |
| 13 | +
|
| 14 | +const isVisible = ref(false); |
| 15 | +const isAuthenticated = ref(false); |
| 16 | +const enabling = ref(false); |
| 17 | +
|
| 18 | +onMounted(async () => { |
| 19 | + try { |
| 20 | + const response = await $fetch<{ user: { id: string } | null }>("/api/auth/session"); |
| 21 | + isAuthenticated.value = !!response.user; |
| 22 | + } catch { |
| 23 | + isAuthenticated.value = false; |
| 24 | + } |
| 25 | +
|
| 26 | + if (isAuthenticated.value && hasNewVersion.value) { |
| 27 | + setTimeout(() => { |
| 28 | + isVisible.value = true; |
| 29 | + }, 800); |
| 30 | + } |
| 31 | +}); |
| 32 | +
|
| 33 | +async function handleEnable() { |
| 34 | + enabling.value = true; |
| 35 | + try { |
| 36 | + await $fetch("/api/weekly-rhythms/settings", { |
| 37 | + method: "PUT", |
| 38 | + body: { |
| 39 | + celebrationEnabled: true, |
| 40 | + encouragementEnabled: true, |
| 41 | + }, |
| 42 | + }); |
| 43 | + } catch { |
| 44 | + // Settings will be off — user can enable manually in settings |
| 45 | + } |
| 46 | + enabling.value = false; |
| 47 | + isVisible.value = false; |
| 48 | + acknowledgeNewVersion(); |
| 49 | + await router.push("/settings"); |
| 50 | +} |
| 51 | +
|
| 52 | +function handleDismiss() { |
| 53 | + isVisible.value = false; |
| 54 | + acknowledgeNewVersion(); |
| 55 | +} |
| 56 | +</script> |
| 57 | + |
| 58 | +<template> |
| 59 | + <Teleport to="body"> |
| 60 | + <Transition |
| 61 | + enter-active-class="transition-all duration-500 ease-out" |
| 62 | + enter-from-class="opacity-0" |
| 63 | + enter-to-class="opacity-100" |
| 64 | + leave-active-class="transition-all duration-300 ease-in" |
| 65 | + leave-from-class="opacity-100" |
| 66 | + leave-to-class="opacity-0" |
| 67 | + > |
| 68 | + <div |
| 69 | + v-if="isVisible" |
| 70 | + class="fixed inset-0 z-[100] flex items-center justify-center p-6" |
| 71 | + > |
| 72 | + <!-- Backdrop --> |
| 73 | + <div |
| 74 | + class="absolute inset-0 bg-gradient-to-b from-tada-900/80 to-stone-900/90 backdrop-blur-sm" |
| 75 | + @click="handleDismiss" |
| 76 | + /> |
| 77 | + |
| 78 | + <!-- Content card --> |
| 79 | + <div |
| 80 | + class="relative bg-white dark:bg-stone-800 rounded-2xl shadow-2xl max-w-sm w-full p-6 text-center" |
| 81 | + > |
| 82 | + <div class="text-4xl mb-4">🎉</div> |
| 83 | + |
| 84 | + <h2 class="text-xl font-bold text-stone-800 dark:text-stone-100 mb-2"> |
| 85 | + New in Ta-Da! |
| 86 | + </h2> |
| 87 | + |
| 88 | + <p class="text-sm text-stone-600 dark:text-stone-300 mb-1"> |
| 89 | + <strong>Weekly Celebrations</strong> — get a stats summary every Monday |
| 90 | + to see how your week went. |
| 91 | + </p> |
| 92 | + <p class="text-sm text-stone-600 dark:text-stone-300 mb-5"> |
| 93 | + Plus a gentle <strong>mid-week encouragement</strong> on Thursdays. |
| 94 | + </p> |
| 95 | + |
| 96 | + <p class="text-sm text-stone-500 dark:text-stone-400 mb-5"> |
| 97 | + Want to turn them on? |
| 98 | + </p> |
| 99 | + |
| 100 | + <div class="flex flex-col gap-2"> |
| 101 | + <button |
| 102 | + class="w-full py-2.5 px-4 rounded-xl bg-tada-600 hover:bg-tada-700 text-white font-medium text-sm transition-colors disabled:opacity-60" |
| 103 | + :disabled="enabling" |
| 104 | + @click="handleEnable" |
| 105 | + > |
| 106 | + {{ enabling ? "Turning on..." : "Yes, turn it on!" }} |
| 107 | + </button> |
| 108 | + <button |
| 109 | + class="w-full py-2 px-4 rounded-xl text-stone-500 dark:text-stone-400 hover:bg-stone-100 dark:hover:bg-stone-700 text-sm transition-colors" |
| 110 | + @click="handleDismiss" |
| 111 | + > |
| 112 | + Maybe later |
| 113 | + </button> |
| 114 | + </div> |
| 115 | + </div> |
| 116 | + </div> |
| 117 | + </Transition> |
| 118 | + </Teleport> |
| 119 | +</template> |
0 commit comments