Update to svelte 5
This commit is contained in:
@@ -1,43 +1,23 @@
|
||||
<script>
|
||||
<script lang="ts">
|
||||
import Euro from "util/Euro.svelte"
|
||||
import SuccessMessage from "util/SuccessMessage.svelte";
|
||||
import PatreonActivationResult from "./PatreonActivationResult.svelte";
|
||||
import { loading_finish, loading_start } from "lib/Loading";
|
||||
import { user } from "lib/UserStore";
|
||||
import { put_user } from "lib/PixeldrainAPI";
|
||||
|
||||
let subscription = window.user.subscription.id
|
||||
let subscription_type = window.user.subscription.type
|
||||
let success_message
|
||||
let subscription = $state($user.subscription.id)
|
||||
let subscription_type = $state($user.subscription.type)
|
||||
let success_message: SuccessMessage = $state()
|
||||
|
||||
const update = async (plan) => {
|
||||
const update = async (plan: string) => {
|
||||
const form = new FormData()
|
||||
form.append("subscription", plan)
|
||||
|
||||
loading_start()
|
||||
try {
|
||||
{
|
||||
const resp = await fetch(
|
||||
window.api_endpoint+"/user",
|
||||
{ method: "PUT", body: form },
|
||||
)
|
||||
if(resp.status >= 400) {
|
||||
let json = await resp.json()
|
||||
throw json.message
|
||||
}
|
||||
|
||||
success_message.set(true, "Subscription updated")
|
||||
}
|
||||
|
||||
{
|
||||
const resp = await fetch(window.api_endpoint+"/user")
|
||||
if(resp.status >= 400) {
|
||||
let json = await resp.json()
|
||||
throw json.message
|
||||
}
|
||||
|
||||
window.user = await resp.json()
|
||||
subscription = window.user.subscription.id
|
||||
subscription_type = window.user.subscription.type
|
||||
}
|
||||
await put_user({subscription: plan})
|
||||
success_message.set(true, "Subscription updated")
|
||||
} catch (err) {
|
||||
success_message.set(false, "Failed to update subscription: "+err)
|
||||
} finally {
|
||||
@@ -101,9 +81,9 @@ const update = async (plan) => {
|
||||
<p>
|
||||
The Prepaid subscription is charged daily based on usage. When you reach
|
||||
negative balance the subscription will automatically end. You need at
|
||||
least <Euro amount="1e6"/> account credit to activate prepaid. Your
|
||||
least <Euro amount={1e6}/> account credit to activate prepaid. Your
|
||||
current credit amount is <Euro
|
||||
amount={window.user.balance_micro_eur}/>. You can deposit credit on the
|
||||
amount={$user.balance_micro_eur}/>. You can deposit credit on the
|
||||
<a href="/user/prepaid/deposit">credit deposit page</a>.
|
||||
</p>
|
||||
|
||||
@@ -152,7 +132,7 @@ const update = async (plan) => {
|
||||
{#if subscription === "prepaid"}
|
||||
Currently active
|
||||
{:else}
|
||||
<button on:click={() => update("prepaid")}>
|
||||
<button onclick={() => update("prepaid")}>
|
||||
<i class="icon">attach_money</i>
|
||||
Activate
|
||||
</button>
|
||||
|
Reference in New Issue
Block a user