referrals: add "use expiry" option
adds an option when enabling referrals to use the duration of the source invited (i.e., months, days, hours) for the referral invite. If enabled, the user won't be able to make a new referral link after it expires. For referrals enabled for new users via a profile, the clock starts ticking as soon as the account is created.
This commit is contained in:
@@ -783,6 +783,7 @@ export class accountsList {
|
||||
private _userSelect = document.getElementById("modify-user-users") as HTMLSelectElement;
|
||||
private _referralsProfileSelect = document.getElementById("enable-referrals-user-profiles") as HTMLSelectElement;
|
||||
private _referralsInviteSelect = document.getElementById("enable-referrals-user-invites") as HTMLSelectElement;
|
||||
private _referralsExpiry = document.getElementById("enable-referrals-user-expiry") as HTMLInputElement;
|
||||
private _searchBox = document.getElementById("accounts-search") as HTMLInputElement;
|
||||
private _search: Search;
|
||||
|
||||
@@ -1578,7 +1579,7 @@ export class accountsList {
|
||||
send["from"] = "invite";
|
||||
send["id"] = this._referralsInviteSelect.value;
|
||||
}
|
||||
_post("/users/referral/" + send["from"] + "/" + (send["id"] ? send["id"] : send["profile"]), send, (req: XMLHttpRequest) => {
|
||||
_post("/users/referral/" + send["from"] + "/" + (send["id"] ? send["id"] : send["profile"]) + "/" + (this._referralsExpiry.checked ? "with-expiry" : "none"), send, (req: XMLHttpRequest) => {
|
||||
if (req.readyState == 4) {
|
||||
toggleLoader(button);
|
||||
if (req.status == 400) {
|
||||
@@ -1593,6 +1594,7 @@ export class accountsList {
|
||||
};
|
||||
this._enableReferralsProfile.checked = true;
|
||||
this._enableReferralsInvite.checked = false;
|
||||
this._referralsExpiry.checked = false;
|
||||
window.modals.enableReferralsUser.show();
|
||||
}
|
||||
|
||||
|
||||
@@ -225,6 +225,7 @@ export class ProfileEditor {
|
||||
|
||||
enableReferrals = (name: string) => {
|
||||
const referralsInviteSelect = document.getElementById("enable-referrals-profile-invites") as HTMLSelectElement;
|
||||
const referralsExpiry = document.getElementById("enable-referrals-profile-expiry") as HTMLInputElement;
|
||||
_get("/invites", null, (req: XMLHttpRequest) => {
|
||||
if (req.readyState != 4 || req.status != 200) return;
|
||||
|
||||
@@ -257,7 +258,7 @@ export class ProfileEditor {
|
||||
"invite": referralsInviteSelect.value
|
||||
};
|
||||
|
||||
_post("/profiles/referral/" + send["profile"] + "/" + send["invite"], send, (req: XMLHttpRequest) => {
|
||||
_post("/profiles/referral/" + send["profile"] + "/" + send["invite"] + "/" + (referralsExpiry.checked ? "with-expiry" : "none"), send, (req: XMLHttpRequest) => {
|
||||
if (req.readyState == 4) {
|
||||
toggleLoader(button);
|
||||
if (req.status == 400) {
|
||||
@@ -270,6 +271,7 @@ export class ProfileEditor {
|
||||
}
|
||||
});
|
||||
};
|
||||
referralsExpiry.checked = false;
|
||||
window.modals.profiles.close();
|
||||
window.modals.enableReferralsProfile.show();
|
||||
};
|
||||
|
||||
+15
@@ -116,6 +116,7 @@ interface MyReferral {
|
||||
remaining_uses: number;
|
||||
no_limit: boolean;
|
||||
expiry: number;
|
||||
use_expiry: boolean;
|
||||
}
|
||||
|
||||
interface ContactDTO {
|
||||
@@ -252,6 +253,7 @@ class ReferralCard {
|
||||
private _url: string;
|
||||
private _expiry: Date;
|
||||
private _expiryUnix: number;
|
||||
private _useExpiry: boolean;
|
||||
private _remainingUses: number;
|
||||
private _noLimit: boolean;
|
||||
|
||||
@@ -259,6 +261,7 @@ class ReferralCard {
|
||||
private _infoArea: HTMLDivElement;
|
||||
private _remainingUsesEl: HTMLSpanElement;
|
||||
private _expiryEl: HTMLSpanElement;
|
||||
private _descriptionEl: HTMLSpanElement;
|
||||
|
||||
get code(): string { return this._code; }
|
||||
set code(c: string) {
|
||||
@@ -294,11 +297,22 @@ class ReferralCard {
|
||||
this._expiry = new Date(expiryUnix * 1000);
|
||||
this._expiryEl.textContent = toDateString(this._expiry);
|
||||
}
|
||||
|
||||
get use_expiry(): boolean { return this._useExpiry; }
|
||||
set use_expiry(v: boolean) {
|
||||
this._useExpiry = v;
|
||||
if (v) {
|
||||
this._descriptionEl.textContent = window.lang.strings("referralsWithExpiryDescription");
|
||||
} else {
|
||||
this._descriptionEl.textContent = window.lang.strings("referralsDescription");
|
||||
}
|
||||
}
|
||||
|
||||
constructor(card: HTMLElement) {
|
||||
this._card = card;
|
||||
this._button = this._card.querySelector(".user-referrals-button") as HTMLButtonElement;
|
||||
this._infoArea = this._card.querySelector(".user-referrals-info") as HTMLDivElement;
|
||||
this._descriptionEl = this._card.querySelector(".user-referrals-description") as HTMLSpanElement;
|
||||
|
||||
this._infoArea.innerHTML = `
|
||||
<div class="row my-3">
|
||||
@@ -344,6 +358,7 @@ class ReferralCard {
|
||||
this.no_limit = referral.no_limit;
|
||||
this.expiry = referral.expiry;
|
||||
this._card.classList.remove("unfocused");
|
||||
this.use_expiry = referral.use_expiry;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user