feat(member): account/profile polish + tier upgrade flow

- Timezone: curated USelectMenu dropdown (app/config/timezones.js), preserves unknown saved values
- Profile save now uses useToast() for success/error; remove inline save banner
- Nav onboarding dot nudged down 1px for optical alignment with lowercase text
- Onboarding: skip a suggestion with POST /api/onboarding/track {skip}; member.onboarding.skipped map; does not affect graduation
- CirclePicker takes :saved-value so 'Current' badge stays until save completes
- PrivacyToggle is binary (USwitch labeled Private); member schema enum reduced to ['members','private']; zod coerces legacy 'public'
- New /member/payment-setup page: HelcimPay $0 verify + update-contribution, wired from account.vue via requiresPaymentSetup redirect
- Helcim portal: NUXT_PUBLIC_HELCIM_PORTAL_URL env + account.vue 'Manage billing in Helcim' link
- Migration script: scripts/migrate-privacy-public-to-members.js
This commit is contained in:
Jennie Robinson Faber 2026-04-14 20:35:37 +01:00
parent 08fc3884da
commit 7292b11c0b
18 changed files with 604 additions and 122 deletions

View file

@ -68,6 +68,15 @@
}}</span>
</div>
</div>
<a
v-if="helcimPortalUrl && memberData.helcimCustomerId"
:href="helcimPortalUrl"
target="_blank"
rel="noopener"
class="billing-link"
>
Manage billing in Helcim &rarr;
</a>
</PageSection>
<PageSection divider="top">
@ -178,6 +187,7 @@
<CirclePicker
v-model="selectedCircle"
:saved-value="memberData.circle"
:circles="circleOptions"
/>
<button
@ -204,6 +214,7 @@ definePageMeta({
const { memberData, checkMemberStatus } = useAuth();
const { openLoginModal } = useLoginModal();
const toast = useToast();
const helcimPortalUrl = useRuntimeConfig().public.helcimPortalUrl || '';
const selectedTier = ref(0);
const selectedCircle = ref("");
@ -276,13 +287,22 @@ const handleUpdateTier = async () => {
body: { contributionTier: String(selectedTier.value) },
});
await checkMemberStatus();
toast.add({ title: "Contribution updated", color: "green" });
toast.add({ title: "Contribution updated", color: "success" });
} catch (err) {
// Paid upgrade without a saved card route to payment setup instead of erroring.
if (err.data?.data?.requiresPaymentSetup) {
await navigateTo(
`/member/payment-setup?tier=${selectedTier.value}&circle=${
selectedCircle.value || memberData.value?.circle || 'community'
}`,
);
return;
}
selectedTier.value = Number(memberData.value?.contributionTier || 0);
toast.add({
title: "Update failed",
description: err.data?.statusMessage || "Please try again.",
color: "red",
color: "error",
});
} finally {
isUpdating.value = false;
@ -297,13 +317,13 @@ const handleUpdateCircle = async () => {
body: { circle: selectedCircle.value },
});
await checkMemberStatus();
toast.add({ title: "Circle updated", color: "green" });
toast.add({ title: "Circle updated", color: "success" });
} catch (err) {
selectedCircle.value = memberData.value?.circle || "community";
toast.add({
title: "Update failed",
description: err.data?.statusMessage || "Please try again.",
color: "red",
color: "error",
});
} finally {
isUpdating.value = false;
@ -326,12 +346,12 @@ const handleUpdateEmail = async () => {
});
await checkMemberStatus();
cancelEmailEdit();
toast.add({ title: "Email updated", color: "green" });
toast.add({ title: "Email updated", color: "success" });
} catch (err) {
toast.add({
title: "Update failed",
description: err.data?.statusMessage || "Please try again.",
color: "red",
color: "error",
});
} finally {
isUpdatingEmail.value = false;
@ -359,13 +379,13 @@ const confirmCancelMembership = async () => {
color: "neutral",
});
} else {
toast.add({ title: "Membership cancelled", color: "orange" });
toast.add({ title: "Membership cancelled", color: "warning" });
}
} catch (err) {
toast.add({
title: "Cancellation failed",
description: err.data?.statusMessage || "Please try again.",
color: "red",
color: "error",
});
} finally {
isCancelling.value = false;
@ -528,4 +548,16 @@ const confirmCancelMembership = async () => {
text-align: center;
}
.billing-link {
display: inline-block;
margin-top: 10px;
font-size: 12px;
color: var(--candle);
text-decoration: none;
}
.billing-link:hover {
text-decoration: underline;
}
</style>

View file

@ -0,0 +1,189 @@
<template>
<PageShell>
<ClientOnly>
<PageHeader
title="Set Up Payment"
:subtitle="targetTier ? `Upgrading to $${targetTier}/month` : 'Payment setup'"
/>
<ColumnsLayout cols="1">
<PageSection>
<div v-if="step === 'loading'" class="status-block">
<p>Preparing payment setup</p>
</div>
<div v-else-if="step === 'error'" class="status-block">
<div class="error-box">{{ errorMessage }}</div>
<div class="button-row">
<button class="btn" @click="initialize">Try again</button>
<NuxtLink to="/member/account" class="btn">Back to account</NuxtLink>
</div>
</div>
<div v-else-if="step === 'ready'" class="status-block">
<p>
To upgrade to <strong>${{ targetTier }}/month</strong>, we need a
payment method on file. Click below to open the secure payment
form we'll verify your card with a $0 authorization and then
activate your new tier.
</p>
<div v-if="errorMessage" class="error-box">{{ errorMessage }}</div>
<div class="button-row">
<button
class="btn btn-primary"
:disabled="isProcessing"
@click="openModal"
>
{{ isProcessing ? 'Processing…' : 'Enter payment details' }}
</button>
<NuxtLink to="/member/account" class="btn">Cancel</NuxtLink>
</div>
</div>
<div v-else-if="step === 'success'" class="status-block">
<p>Payment setup complete. Redirecting to your account</p>
</div>
</PageSection>
</ColumnsLayout>
</ClientOnly>
</PageShell>
</template>
<script setup>
definePageMeta({ middleware: 'auth' });
const route = useRoute();
const router = useRouter();
const toast = useToast();
const { memberData, checkMemberStatus } = useAuth();
const { initializeHelcimPay, verifyPayment, cleanup: cleanupHelcim } = useHelcimPay();
const VALID_TIERS = ['5', '15', '30', '50'];
const VALID_CIRCLES = ['community', 'founder', 'practitioner'];
const targetTier = computed(() => {
const t = String(route.query.tier || '');
return VALID_TIERS.includes(t) ? t : null;
});
const targetCircle = computed(() => {
const c = String(route.query.circle || '');
return VALID_CIRCLES.includes(c) ? c : null;
});
const step = ref('loading'); // loading | ready | success | error
const errorMessage = ref('');
const isProcessing = ref(false);
const customerId = ref('');
const customerCode = ref('');
const initialize = async () => {
errorMessage.value = '';
step.value = 'loading';
if (!targetTier.value) {
errorMessage.value = 'Missing or invalid target tier.';
step.value = 'error';
return;
}
try {
const customer = await $fetch('/api/helcim/get-or-create-customer', {
method: 'POST',
});
customerId.value = customer.customerId;
customerCode.value = customer.customerCode;
await initializeHelcimPay(customerId.value, customerCode.value, 0);
step.value = 'ready';
} catch (err) {
console.error('Payment setup init failed:', err);
errorMessage.value =
err.data?.statusMessage || err.message || 'Failed to initialize payment.';
step.value = 'error';
}
};
const openModal = async () => {
if (isProcessing.value) return;
isProcessing.value = true;
errorMessage.value = '';
try {
const result = await verifyPayment();
if (!result?.success) throw new Error('Payment was not completed.');
await $fetch('/api/helcim/verify-payment', {
method: 'POST',
body: {
cardToken: result.cardToken,
customerId: customerId.value,
},
});
// Update circle first if it changed update-contribution only touches tier.
if (targetCircle.value && targetCircle.value !== memberData.value?.circle) {
await $fetch('/api/members/update-circle', {
method: 'POST',
body: { circle: targetCircle.value },
});
}
await $fetch('/api/members/update-contribution', {
method: 'POST',
body: { contributionTier: targetTier.value },
});
await checkMemberStatus();
step.value = 'success';
toast.add({ title: 'Payment method saved', color: 'success' });
setTimeout(() => router.push('/member/account'), 1500);
} catch (err) {
console.error('Payment setup error:', err);
errorMessage.value =
err.data?.statusMessage || err.message || 'Payment setup failed.';
// Re-initialize Helcim session so the user can try again.
cleanupHelcim();
await initialize();
} finally {
isProcessing.value = false;
}
};
onMounted(() => {
initialize();
});
onBeforeUnmount(() => {
cleanupHelcim();
});
useHead({ title: 'Set Up Payment - Ghost Guild' });
</script>
<style scoped>
.status-block {
padding: 12px 0;
font-size: 13px;
line-height: 1.6;
color: var(--text);
}
.status-block p {
margin-bottom: 16px;
}
.error-box {
padding: 12px 14px;
border: 1px dashed var(--ember);
color: var(--ember);
font-size: 12px;
margin-bottom: 16px;
}
.button-row {
display: flex;
gap: 10px;
align-items: center;
flex-wrap: wrap;
}
</style>

View file

@ -65,10 +65,14 @@
</div>
<div class="field">
<label>Timezone</label>
<input
<USelectMenu
v-model="formData.timeZone"
type="text"
placeholder="e.g., America/Toronto"
:items="timezoneItems"
value-key="value"
searchable
searchable-placeholder="Search timezones..."
placeholder="Select a timezone"
class="timezone-select"
/>
<PrivacyToggle v-model="formData.timeZonePrivacy" />
</div>
@ -242,12 +246,6 @@
<button type="button" class="btn" @click="resetForm">
Reset Changes
</button>
<span v-if="saveSuccess" class="save-msg save-msg-ok"
>Profile updated.</span
>
<span v-if="saveError" class="save-msg save-msg-err">{{
saveError
}}</span>
</div>
</template>
@ -264,6 +262,7 @@
<script setup>
import { MEMBER_STATUSES } from "~/composables/useMemberStatus";
import { TIMEZONE_OPTIONS } from "~/config/timezones";
definePageMeta({
middleware: 'auth',
@ -283,6 +282,16 @@ const availableGhosts = [
{ value: "wtf", label: "WTF", image: "/ghosties/Ghost-WTF.png" },
];
// Include the saved timezone as a custom option if it's not in the curated list.
const timezoneItems = computed(() => {
const saved = formData.timeZone;
const list = [...TIMEZONE_OPTIONS];
if (saved && !list.some((t) => t.value === saved)) {
list.unshift({ label: saved, value: saved });
}
return list;
});
const notificationToggles = [
{ key: "events", label: "Event reminders", sub: "Get notified about upcoming events" },
{ key: "updates", label: "Community updates", sub: "New posts from members you follow" },
@ -328,10 +337,7 @@ const formData = reactive({
const loading = ref(false);
const saving = ref(false);
const saveSuccess = ref(false);
const saveError = ref(null);
const initialData = ref(null);
let saveSuccessTimer = null;
const memberId = computed(() => memberData.value?._id || memberData.value?.id);
@ -376,8 +382,6 @@ const loadProfile = () => {
const handleSubmit = async () => {
saving.value = true;
saveSuccess.value = false;
saveError.value = null;
try {
await $fetch("/api/members/profile", {
@ -385,20 +389,17 @@ const handleSubmit = async () => {
body: { ...formData },
});
saveSuccess.value = true;
await checkMemberStatus();
loadProfile();
if (saveSuccessTimer) clearTimeout(saveSuccessTimer);
saveSuccessTimer = setTimeout(() => {
saveSuccess.value = false;
saveSuccessTimer = null;
}, 3000);
toast.add({ title: "Profile updated", color: "success" });
} catch (error) {
console.error("Profile save error:", error);
saveError.value =
error.data?.message || "Failed to save profile. Please try again.";
toast.add({
title: "Update failed",
description: error.data?.statusMessage || error.data?.message || "Please try again.",
color: "error",
});
} finally {
saving.value = false;
}
@ -406,8 +407,6 @@ const handleSubmit = async () => {
const resetForm = () => {
loadProfile();
saveSuccess.value = false;
saveError.value = null;
};
onMounted(async () => {
@ -452,10 +451,6 @@ const handleDeletePost = async (post) => {
}
};
onBeforeUnmount(() => {
if (saveSuccessTimer) clearTimeout(saveSuccessTimer);
});
useHead({
title: "Edit Profile - Ghost Guild",
});
@ -708,17 +703,9 @@ useHead({
gap: 12px;
}
.save-msg {
font-size: 11px;
margin-left: auto;
}
.save-msg-ok {
color: var(--green);
}
.save-msg-err {
color: var(--ember);
/* ---- TIMEZONE SELECT ---- */
.timezone-select {
width: 100%;
}
/* ---- RESPONSIVE ---- */