Files
fnx_web/svelte/src/user_home/AffiliatePrompt.svelte

135 lines
3.4 KiB
Svelte
Raw Normal View History

2025-03-21 12:57:53 +01:00
<script lang="ts">
2025-03-21 01:11:03 +01:00
import { onMount } from "svelte";
import Modal from "util/Modal.svelte";
2026-06-10 23:53:03 +02:00
import { get_user, put_user } from "lib/NovaAPI";
2025-10-13 16:05:50 +02:00
import { loading_finish, loading_start } from "lib/Loading";
2025-03-21 01:11:03 +01:00
2025-10-13 16:05:50 +02:00
let { always = false }: {
// When the always flag is set then the pop-up will also show if the user
// already has an affiliate ID set
always?: boolean;
} = $props();
let modal: Modal = $state()
let referral: string = $state()
2025-03-21 12:57:53 +01:00
let shown = false
export const prompt = async (ref: string) => {
referral = ref
const user = await get_user()
if (referral === null) {
return
} else if (referral === user.affiliate_user_name) {
return // User is already supporting this affiliate ID
} else if (referral === user.username) {
return // This is your own referral link
}
2025-03-21 01:11:03 +01:00
if (!always) {
2025-03-21 12:57:53 +01:00
if (user.subscription.id === "") {
2025-03-21 01:11:03 +01:00
// User does not have an active subscription, setting referral will
// not have effect
return
2025-03-21 12:57:53 +01:00
} else if (user.affiliate_user_name !== "") {
2025-03-21 01:11:03 +01:00
// User is already sponsoring someone
return
} else if (localStorage.getItem("affiliate_deny") === "1") {
// User has dismissed the pop-up in the past
return
}
}
2025-03-21 12:57:53 +01:00
// The prompt can only be shown once per page. This should prevent it from
// showing up every time someone loads a new file.
if (shown === true) {
2025-03-21 01:11:03 +01:00
return
}
2025-03-21 12:57:53 +01:00
shown = true
2025-03-21 01:11:03 +01:00
modal.show()
2025-03-21 12:57:53 +01:00
}
onMount(() => prompt(new URLSearchParams(document.location.search).get("ref")))
2025-03-21 01:11:03 +01:00
const allow = async () => {
2025-10-09 15:48:23 +02:00
loading_start()
2025-03-21 01:11:03 +01:00
try {
2025-03-21 12:57:53 +01:00
await put_user({affiliate_user_name: referral})
2025-03-21 01:11:03 +01:00
// Close the popup
modal.hide()
} catch (err) {
alert(err)
} finally {
2025-10-09 15:48:23 +02:00
loading_finish()
2025-03-21 01:11:03 +01:00
}
}
const deny = () => {
localStorage.setItem("affiliate_deny", "1")
modal.hide()
}
</script>
<Modal bind:this={modal} title="Affiliate sponsoring request" width="700px">
<section>
<p>
2026-06-10 23:53:03 +02:00
Hi! {referral} wants you to sponsor their Nova account. This
will give them €0.50 every month in Nova prepaid credit. They
2025-03-21 12:57:53 +01:00
can use this credit to get a discount on their file storage and
sharing costs. Here is a short summary of what this entails:
2025-03-21 01:11:03 +01:00
</p>
<ul>
<li>
Sponsoring only works while you have an active subscription
plan. When your subscription deactivates the creator will no
longer receive commissions.
</li>
<li>
2026-06-10 23:53:03 +02:00
Nova credit cannot be cashed out. So they are not earning
2025-03-21 01:11:03 +01:00
real money with this.
</li>
<li>
This does not cost you any extra money. The commissions paid out
2026-06-10 23:53:03 +02:00
to the creator are paid for by Nova itself.
2025-03-21 01:11:03 +01:00
</li>
<li>
You can change who you are sponsoring at any time on your <a
href="/user/settings">account settings page</a>.
</li>
<li>
If you want to know more about the affiliate program check out
the <a href="/about#toc_12">Q&A page</a>.
</li>
</ul>
<p>
If you click 'Accept' then the requested affiliate code will be
added to your account and the creator will start earning. If you
choose 'Deny' then we will never show this pop-up again.
</p>
<div class="buttons">
2025-10-13 16:05:50 +02:00
<button class="button button_red" onclick={e => deny()}>
2025-03-21 01:11:03 +01:00
Deny
</button>
2025-10-13 16:05:50 +02:00
<button class="button button_highlight" onclick={e => allow()}>
2025-03-21 01:11:03 +01:00
Accept
</button>
</div>
</section>
</Modal>
<style>
.buttons {
display: flex;
flex-direction: row;
justify-content: space-around;
gap: 10px;
}
.button {
flex: 1 1 auto;
margin: 0;
font-size: 1.2em;
justify-content: center;
}
</style>