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

134 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";
import LoadingIndicator from "util/LoadingIndicator.svelte";
import { get_user, put_user } from "lib/PixeldrainAPI.mjs";
2025-03-21 01:11:03 +01:00
// When the always flag is set then the pop-up will also show if the user
// already has an affiliate ID set
export let always = false
2025-03-21 12:57:53 +01:00
let modal: Modal
let loading: boolean
let referral: string
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 () => {
loading = true
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 {
loading = false
}
}
const deny = () => {
localStorage.setItem("affiliate_deny", "1")
modal.hide()
}
</script>
<Modal bind:this={modal} title="Affiliate sponsoring request" width="700px">
<LoadingIndicator bind:loading={loading} />
<section>
<p>
2025-03-21 12:57:53 +01:00
Hi! {referral} wants you to sponsor their pixeldrain account. This
will give them €0.50 every month in pixeldrain prepaid credit. They
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>
Pixeldrain credit cannot be cashed out. So they are not earning
real money with this.
</li>
<li>
This does not cost you any extra money. The commissions paid out
to the creator are paid for by pixeldrain itself.
</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">
<button class="button button_red" on:click={e => deny()}>
Deny
</button>
<button class="button button_highlight" on:click={e => allow()}>
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>