Skip to content

Commit

Permalink
feat: read notes
Browse files Browse the repository at this point in the history
- total sub count added to the top panel on the general stats of the scripters dashboard
- missing stripe information added and is only visible to people that are missing information
- per script subs is partially added on the backend but not visible yet. Due to limitations only total subs per script will be shown instead of separate weekly/monthly/yearly
  • Loading branch information
Torwent committed Jan 10, 2024
1 parent c8d2f35 commit 5374454
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 104 deletions.
14 changes: 3 additions & 11 deletions src/routes/dashboard/Table.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
export let schema: BundleArraySchema | NewBundleSchema | ScriptArraySchema | NewScriptArraySchema
export let data: SuperValidated<typeof schema>
export let headers: string[]
export let subscriptions: number[] | undefined = undefined
export let subscriptions: number | undefined = undefined
export let action: string
const { form, errors, enhance, allErrors } = superForm(data, {
Expand Down Expand Up @@ -60,11 +60,7 @@
/>
</TableCell>

{#if subscriptions}
<TableCell>
{#each subscriptions as sub, i}{#if i > 0}&nbsp;/&nbsp;{/if}{sub}{/each}
</TableCell>
{/if}
{#if subscriptions !== undefined}<TableCell>{subscriptions}</TableCell>{/if}

<TableCell padding={0}>
<button
Expand Down Expand Up @@ -102,11 +98,7 @@
/>
</TableCell>

{#if subscriptions}
<TableCell>
{#each subscriptions as sub, i}{#if i > 0}&nbsp;/&nbsp;{/if}{sub}{/each}
</TableCell>
{/if}
{#if subscriptions !== undefined}<TableCell>{subscriptions}</TableCell>{/if}

<TableCell padding={0}>
<button
Expand Down
135 changes: 72 additions & 63 deletions src/routes/dashboard/[slug]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@
$: if (payoutContainer && stripeConnectInstance)
payoutContainer.appendChild(stripeConnectInstance.create("payouts"))
let totalSubs = 0
data.subscriptions.subscriptions.forEach((sub) => (totalSubs += sub.count ?? 0))
onMount(async () => {
if (browser && document) {
const connectJS = await import("@stripe/connect-js")
Expand Down Expand Up @@ -190,12 +194,6 @@
Create stripe connected account
</button>
</form>
{:else}
<form method="POST" action="?/updateStripe" class="my-32 grid place-items-center">
<h3>Stripe Account</h3>

<button class="btn variant-filled-secondary">Update stripe connected account</button>
</form>
{/if}

<h3 class="justify-center text-center my-12">General stats</h3>
Expand All @@ -208,9 +206,7 @@
"Premium scripts",
"Monthly downloads",
"Premium monthly downloads",
"Weekly subscribers",
"Monthly subscribers",
"Yearly subscribers"
"Subscribers"
]}
/>
<tr class="table-row">
Expand All @@ -220,9 +216,7 @@
<TableCell>
{stats.month_premium_user_downloads} / {stats.month_premium_downloads}
</TableCell>
<TableCell>0</TableCell>
<TableCell>0</TableCell>
<TableCell>0</TableCell>
<TableCell>{totalSubs}</TableCell>
</tr>
<tbody />
</table>
Expand Down Expand Up @@ -255,43 +249,69 @@
<!-- Tab Panels --->
<svelte:fragment slot="panel">
{#if tabSet === 0}
<form
method="POST"
action="?/displayName"
class="my-32 place-items-center flex"
use:dbaEnhance
>
<div class="my-4">
<label for="dba">Invoice display name:</label>
<input class="input" name="dba" id="dba" bind:value={$dbaForm.dba} />
{#if $dbaErrors && $dbaErrors.dba}
<div
class="max-h-24 bg-surface-700 rounded-md overflow-y-scroll overflow-x-hidden text-error-500"
>
{$dbaErrors.dba}
</div>
{/if}
{#if $dbaAllErrors}
<div
class="max-h-24 bg-surface-700 rounded-md overflow-y-scroll overflow-x-hidden text-error-500"
>
{#each $dbaAllErrors as error, i}
{#if i === 0}
Errors:
{/if}
<small class="mx-8 text-error-500 flex rounded-md">
Error path: {error.path}
{#each error.messages as messages}
{messages}
{/each}
</small>
{/each}
</div>
{/if}
</div>
<button class="btn variant-filled-secondary mt-6 mx-4 h-10">Update</button>
</form>
<div class="flex justify-around">
<form
method="POST"
action="?/displayName"
class="my-32 place-items-center flex"
use:dbaEnhance
>
<div class="my-4">
<label for="dba">Invoice display name:</label>
<input class="input" name="dba" id="dba" bind:value={$dbaForm.dba} />
{#if $dbaErrors && $dbaErrors.dba}
<div
class="max-h-24 bg-surface-700 rounded-md overflow-y-scroll overflow-x-hidden text-error-500"
>
{$dbaErrors.dba}
</div>
{/if}
{#if $dbaAllErrors}
<div
class="max-h-24 bg-surface-700 rounded-md overflow-y-scroll overflow-x-hidden text-error-500"
>
{#each $dbaAllErrors as error, i}
{#if i === 0}
Errors:
{/if}
<small class="mx-8 text-error-500 flex rounded-md">
Error path: {error.path}
{#each error.messages as messages}
{messages}
{/each}
</small>
{/each}
</div>
{/if}
</div>
<button class="btn variant-filled-secondary mt-6 mx-4 h-10">Update</button>
</form>

<form method="POST" action="?/updateStripe" class="my-32 block place-items-center">
<div class="my-4 grid">
<span>Account information</span>
<button class="btn variant-filled-secondary h-10 mt-0">
Update stripe connected account
</button>
</div>
</form>
</div>

{#if data.stripeAccount?.requirements?.currently_due && data.stripeAccount?.requirements?.currently_due.length > 0}
<div class="mb-24">
<span class="my-2">Missing account information:</span>

<div class="my-2 text-error-500 grid bg-surface-700">
{#each data.stripeAccount?.requirements?.currently_due as requirement}
<small class="w-full mx-auto">{requirement}</small>
{/each}
</div>
<small>
This can be updated on the "Update stripe connected account" button. Ask Torwent
for help if needed.
</small>
</div>
{/if}
<h5 class="text-center my-4">Payments</h5>
<div class="my-8" bind:this={paymentContainer} />
<h5 class="text-center my-4">Payouts</h5>
Expand All @@ -301,14 +321,8 @@
id="bundleEdit"
schema={bundleArraySchema}
data={data.bundlesForm}
headers={[
"Title",
"Price (Week/Month/Year)",
"Subscribers (Week/Month/Year)",
"Scripts",
"Action"
]}
subscriptions={[0, 5, 10]}
headers={["Title", "Price (Week/Month/Year)", "Subscribers", "Scripts", "Action"]}
subscriptions={0}
action={"bundleEdit&product"}
/>

Expand All @@ -324,13 +338,8 @@
id="scriptEdit"
schema={scriptArraySchema}
data={data.scriptsForm}
headers={[
"Title",
"Price (Week/Month/Year)",
"Subscribers (Week/Month/Year)",
"Action"
]}
subscriptions={[0, 5, 10]}
headers={["Title", "Price (Week/Month/Year)", "Subscribers", "Action"]}
subscriptions={0}
action={"scriptEdit&product"}
/>

Expand Down
46 changes: 16 additions & 30 deletions src/routes/dashboard/[slug]/+page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,39 +92,17 @@ export const load = async ({ parent, data, depends, url, params: { slug } }) =>
)
}

const result: {
id: string
user_id: string
name: string
username: string
bundle: string | null
script: string | null
active: boolean
subs: {
id: string
price: string
cancel: boolean
}[]
subCount: number
}[] = []

for (let i = 0; i < data.length; i++) {
const product = data[i]
const subs = await getSubscriptions(product.id)
result.push({
return data.map((product) => {
return {
id: product.id,
user_id: product.user_id,
name: product.name,
username: product.bundles?.username ?? product.scripts?.protected.username ?? "",
bundle: product.bundle,
script: product.script,
active: product.active,
subs: subs.data,
subCount: subs.count ?? 0
})
}

return result
active: product.active
}
})
}

async function getStats() {
Expand Down Expand Up @@ -213,7 +191,12 @@ export const load = async ({ parent, data, depends, url, params: { slug } }) =>
bundlesForm.data.bundles = []
scriptsForm.data.scripts = []

products.forEach((product) => {
const subscriptionsPromises = []

for (let index = 0; index < products.length; index++) {
const product = products[index]
subscriptionsPromises.push(getSubscriptions(product.id))

const productPrices = [...prices].reduce<Prices[]>((acc, price, i) => {
if (acc.length > 2) return acc
if (price.product === product.id) {
Expand Down Expand Up @@ -282,7 +265,7 @@ export const load = async ({ parent, data, depends, url, params: { slug } }) =>
tmpScripts.splice(i, 1)
}
}
})
}

newScriptForm.data.scripts = tmpScripts.map((script) => {
return {
Expand All @@ -307,6 +290,8 @@ export const load = async ({ parent, data, depends, url, params: { slug } }) =>
active: script.active
}
})

return { subscriptions: await Promise.all(subscriptionsPromises) }
}

const promises = await Promise.all([
Expand Down Expand Up @@ -342,6 +327,7 @@ export const load = async ({ parent, data, depends, url, params: { slug } }) =>
newScriptForm,
profile,
scripter,
stats: promises[1]
stats: promises[1],
subscriptions: promises[2]
}
}

0 comments on commit 5374454

Please sign in to comment.