refactor: remove guest email handling logic from subscription process
This commit is contained in:
parent
1e5b3b77c8
commit
b47a517bd5
@ -530,9 +530,6 @@ export default function SummaryPage() {
|
|||||||
setSubmitError(null)
|
setSubmitError(null)
|
||||||
setSubmitLoading(true)
|
setSubmitLoading(true)
|
||||||
try {
|
try {
|
||||||
const recipientEmail = form.recipientEmail.trim()
|
|
||||||
const recipientName = form.recipientName.trim()
|
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
items: selectedEntries.map(entry => ({
|
items: selectedEntries.map(entry => ({
|
||||||
coffeeId: entry.coffee.id,
|
coffeeId: entry.coffee.id,
|
||||||
@ -572,57 +569,8 @@ export default function SummaryPage() {
|
|||||||
console.info('[SummaryPage] subscribeAbo payload JSON:', JSON.stringify(payload))
|
console.info('[SummaryPage] subscribeAbo payload JSON:', JSON.stringify(payload))
|
||||||
await subscribeAbo(payload)
|
await subscribeAbo(payload)
|
||||||
|
|
||||||
// TEMP: Guest email workaround (ignore contract/PDF for mail)
|
|
||||||
// Open an email draft to the recipient when subscription is for someone else.
|
|
||||||
if (!isForSelf && recipientEmail) {
|
|
||||||
try {
|
|
||||||
// A referral token is required for /register, so we generate a 1-time referral link.
|
|
||||||
const refRes = await createReferralLink({ expiresInDays: 7, maxUses: 1 })
|
|
||||||
const refBody: any = (refRes as any)?.body
|
|
||||||
const refCode =
|
|
||||||
refBody?.data?.code ||
|
|
||||||
refBody?.data?.token ||
|
|
||||||
refBody?.data?.ref ||
|
|
||||||
refBody?.code ||
|
|
||||||
refBody?.token ||
|
|
||||||
refBody?.ref ||
|
|
||||||
''
|
|
||||||
|
|
||||||
const origin = typeof window !== 'undefined' ? window.location.origin : ''
|
|
||||||
const guestLink = refCode
|
|
||||||
? (origin
|
|
||||||
? `${origin}/register?ref=${encodeURIComponent(String(refCode))}&guest=true`
|
|
||||||
: `/register?ref=${encodeURIComponent(String(refCode))}&guest=true`)
|
|
||||||
: ''
|
|
||||||
|
|
||||||
setGuestInviteLink(guestLink)
|
|
||||||
|
|
||||||
if (!guestLink) {
|
|
||||||
console.warn('[SummaryPage] Guest invite: could not generate referral token/link', { refBody })
|
|
||||||
setGuestMailtoHref('')
|
|
||||||
} else {
|
|
||||||
const subject = 'Profit Planet – Guest access for your coffee abonnement'
|
|
||||||
const body =
|
|
||||||
`Hallo${recipientName ? ` ${recipientName}` : ''},\n\n` +
|
|
||||||
`du wurdest eingeladen, um Zugriff auf dein Kaffee-Abonnement zu erhalten.\n\n` +
|
|
||||||
`Bitte registriere dich hier als Gast:\n${guestLink}\n\n` +
|
|
||||||
`Liebe Grüße\nProfit Planet`
|
|
||||||
|
|
||||||
const mailto = `mailto:${recipientEmail}?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(body)}`
|
|
||||||
setGuestMailtoHref(mailto)
|
|
||||||
try {
|
|
||||||
window.location.href = mailto
|
|
||||||
} catch {}
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
console.warn('[SummaryPage] Guest invite: failed to create referral link', e)
|
|
||||||
setGuestMailtoHref('')
|
setGuestMailtoHref('')
|
||||||
setGuestInviteLink('')
|
setGuestInviteLink('')
|
||||||
}
|
|
||||||
} else {
|
|
||||||
setGuestMailtoHref('')
|
|
||||||
setGuestInviteLink('')
|
|
||||||
}
|
|
||||||
|
|
||||||
setShowThanks(true);
|
setShowThanks(true);
|
||||||
try { sessionStorage.removeItem('coffeeSelections'); } catch {}
|
try { sessionStorage.removeItem('coffeeSelections'); } catch {}
|
||||||
@ -979,23 +927,6 @@ export default function SummaryPage() {
|
|||||||
Subscription created.
|
Subscription created.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
{!isForSelf && guestMailtoHref && (
|
|
||||||
<div className="mt-4">
|
|
||||||
<a
|
|
||||||
href={guestMailtoHref}
|
|
||||||
className="inline-flex items-center justify-center rounded-lg bg-[#1C2B4A] text-white px-4 py-2 font-semibold hover:bg-[#1C2B4A]/90"
|
|
||||||
>
|
|
||||||
Open guest email draft again
|
|
||||||
</a>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{!isForSelf && guestInviteLink && (
|
|
||||||
<div className="mt-3 text-xs text-gray-600 break-words">
|
|
||||||
Guest registration link: <a className="underline" href={guestInviteLink} target="_blank" rel="noreferrer">{guestInviteLink}</a>
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div className="mt-6 grid gap-3 sm:grid-cols-2">
|
<div className="mt-6 grid gap-3 sm:grid-cols-2">
|
||||||
<button onClick={() => { setShowThanks(false); backToSelection(); }} className="rounded-lg bg-[#1C2B4A] text-white px-4 py-2 font-semibold hover:bg-[#1C2B4A]/90">
|
<button onClick={() => { setShowThanks(false); backToSelection(); }} className="rounded-lg bg-[#1C2B4A] text-white px-4 py-2 font-semibold hover:bg-[#1C2B4A]/90">
|
||||||
Back to selection
|
Back to selection
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user