mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
fix: login flow, files and more
This commit is contained in:
1 parent
96a85388f1
commit
7cefd845eb
6 files changed
+67
-29
No files matched your search
@@ -38,7 +38,8 @@ export const load: LayoutLoad = async ({ depends, url }) => {
|
||||
];
|
||||
|
||||
if (!acceptedRoutes.some((n) => url.pathname.startsWith(n))) {
|
||||
throw redirect(303, '/login');
|
||||
const redirectUrl = `${url.search}&redirect=${url.pathname}`;
|
||||
throw redirect(303, `/login${redirectUrl}`);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -14,7 +14,6 @@
|
||||
|
||||
async function handleDelete() {
|
||||
try {
|
||||
console.log(selectedAddress);
|
||||
await sdk.forConsole.billing.deleteAddress(selectedAddress.$id);
|
||||
await invalidate(Dependencies.PAYMENT_METHODS);
|
||||
showDelete = false;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { page } from '$app/stores';
|
||||
import type { AggregationList } from '$lib/sdk/billing';
|
||||
import { derived } from 'svelte/store';
|
||||
|
||||
export const aggregationList = derived(
|
||||
page,
|
||||
($page) => $page.data.aggregationList as string | null
|
||||
($page) => $page.data.aggregationList as AggregationList | null
|
||||
);
|
||||
@@ -57,6 +57,10 @@
|
||||
|
||||
const projectId = $page.params.project;
|
||||
const bucketId = $page.params.bucket;
|
||||
const totalStorage = data.aggregationList.aggregations.reduce((acc, curr) => {
|
||||
acc += curr.usageStorage;
|
||||
return acc;
|
||||
}, 0);
|
||||
const getPreview = (fileId: string) =>
|
||||
sdk.forProject.storage.getFilePreview(bucketId, fileId, 32, 32).toString() + '&mode=admin';
|
||||
|
||||
@@ -85,12 +89,15 @@
|
||||
trackError(error, Submit.FileDelete);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: fetch the total storage used
|
||||
</script>
|
||||
|
||||
<Container>
|
||||
<ContainerHeader title="Files" serviceId="storage" isFlex={false} total={10}>
|
||||
<ContainerHeader
|
||||
title="Files"
|
||||
serviceId="storage"
|
||||
isFlex={false}
|
||||
total={totalStorage}
|
||||
buttonDisabled={$readOnly.storage}>
|
||||
<svelte:fragment slot="alert" let:tier let:upgradeMethod>
|
||||
<Alert type="warning">
|
||||
<span class="text">
|
||||
@@ -101,21 +108,23 @@
|
||||
</span>
|
||||
</Alert>
|
||||
</svelte:fragment>
|
||||
<SearchQuery search={data.search} placeholder="Search by filename">
|
||||
<div
|
||||
use:tooltip={{
|
||||
content: `Upgrade to add more files`,
|
||||
disabled: data.files.total < getServiceLimit('storage')
|
||||
}}>
|
||||
<Button
|
||||
on:click={() => ($showCreate = true)}
|
||||
event="create_file"
|
||||
disabled={data.files.total >= getServiceLimit('storage') || $readOnly.storage}>
|
||||
<span class="icon-plus" aria-hidden="true" />
|
||||
<span class="text">Create file</span>
|
||||
</Button>
|
||||
</div>
|
||||
</SearchQuery>
|
||||
<svelte:fragment let:isButtonDisabled>
|
||||
<SearchQuery search={data.search} placeholder="Search by filename">
|
||||
<div
|
||||
use:tooltip={{
|
||||
content: `Upgrade to add more files`,
|
||||
disabled: !isButtonDisabled
|
||||
}}>
|
||||
<Button
|
||||
on:click={() => ($showCreate = true)}
|
||||
event="create_file"
|
||||
disabled={isButtonDisabled}>
|
||||
<span class="icon-plus" aria-hidden="true" />
|
||||
<span class="text">Create file</span>
|
||||
</Button>
|
||||
</div>
|
||||
</SearchQuery>
|
||||
</svelte:fragment>
|
||||
<svelte:fragment slot="tooltip" let:limit let:tier let:upgradeMethod>
|
||||
<p class="text">
|
||||
You are limited to {limit} of storage on the {tier} plan.
|
||||
|
||||
@@ -3,6 +3,10 @@ import { sdk } from '$lib/stores/sdk';
|
||||
import { getLimit, getPage, getSearch, pageToOffset } from '$lib/helpers/load';
|
||||
import { Dependencies, PAGE_LIMIT } from '$lib/constants';
|
||||
import type { PageLoad } from './$types';
|
||||
import { isCloud } from '$lib/system';
|
||||
import type { AggregationList } from '$lib/sdk/billing';
|
||||
import { organization } from '$lib/stores/organization';
|
||||
import { get } from 'svelte/store';
|
||||
|
||||
export const load: PageLoad = async ({ params, depends, url, route }) => {
|
||||
depends(Dependencies.FILES);
|
||||
@@ -10,6 +14,10 @@ export const load: PageLoad = async ({ params, depends, url, route }) => {
|
||||
const search = getSearch(url);
|
||||
const limit = getLimit(url, route, PAGE_LIMIT);
|
||||
const offset = pageToOffset(page, limit);
|
||||
let aggregationList: AggregationList = null;
|
||||
if (isCloud && get(organization)) {
|
||||
aggregationList = await sdk.forConsole.billing.listUsage(get(organization)?.$id);
|
||||
}
|
||||
|
||||
return {
|
||||
offset,
|
||||
@@ -19,6 +27,7 @@ export const load: PageLoad = async ({ params, depends, url, route }) => {
|
||||
params.bucket,
|
||||
[Query.limit(limit), Query.offset(offset), Query.orderDesc('')],
|
||||
search
|
||||
)
|
||||
),
|
||||
aggregationList
|
||||
};
|
||||
};
|
||||
@@ -15,6 +15,7 @@
|
||||
import { Dependencies } from '$lib/constants';
|
||||
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
|
||||
import { isCloud } from '$lib/system';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
let mail: string, pass: string, disabled: boolean;
|
||||
|
||||
@@ -28,7 +29,17 @@
|
||||
message: 'Successfully logged in.'
|
||||
});
|
||||
trackEvent(Submit.AccountCreate);
|
||||
await goto(`${base}/console`);
|
||||
if ($page.url.searchParams) {
|
||||
const redirect = $page.url.searchParams.get('redirect');
|
||||
$page.url.searchParams.delete('redirect');
|
||||
if (redirect) {
|
||||
await goto(`${base}${redirect}${$page.url.search}`);
|
||||
} else {
|
||||
await goto(`${base}/console${$page.url.search ?? ''}`);
|
||||
}
|
||||
} else {
|
||||
await goto(`${base}/console`);
|
||||
}
|
||||
} catch (error) {
|
||||
disabled = false;
|
||||
addNotification({
|
||||
@@ -40,12 +51,20 @@
|
||||
}
|
||||
|
||||
function onGithubLogin() {
|
||||
sdk.forConsole.account.createOAuth2Session(
|
||||
'github',
|
||||
window.location.origin,
|
||||
window.location.origin,
|
||||
['read:user', 'user:email']
|
||||
);
|
||||
let url = window.location.origin;
|
||||
if ($page.url.searchParams) {
|
||||
const redirect = $page.url.searchParams.get('redirect');
|
||||
$page.url.searchParams.delete('redirect');
|
||||
if (redirect) {
|
||||
url = `${base}${redirect}${$page.url.search}`;
|
||||
} else {
|
||||
url = `${base}/console${$page.url.search ?? ''}`;
|
||||
}
|
||||
}
|
||||
sdk.forConsole.account.createOAuth2Session('github', url, window.location.origin, [
|
||||
'read:user',
|
||||
'user:email'
|
||||
]);
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
Reference in new issue
Block a user