Skip to content

Commit 3a46d36

Browse files
committed
use svelte5 syntax
1 parent c307071 commit 3a46d36

File tree

3 files changed

+54
-35
lines changed

3 files changed

+54
-35
lines changed

src/lib/components/billing/alerts/projectsLimit.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
upgradeURL
1010
} from '$lib/stores/billing';
1111
import { currentPlan } from '$lib/stores/organization';
12-
import SelectProjectCloud from '$lib/components/billing/alerts/selectProjectCloud.svelte';
13-
let showSelectProject = false;
12+
import SelectProjectCloud from './selectProjectCloud.svelte';
13+
let showSelectProject = $state(false);
1414
</script>
1515

1616
<SelectProjectCloud bind:showSelectProject />

src/lib/components/billing/alerts/selectProjectCloud.svelte

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,27 @@
1111
import { page } from '$app/state';
1212
import { toLocaleDateTime } from '$lib/helpers/date';
1313
14-
export let showSelectProject: boolean;
15-
export let selectedProjects: Array<string> = [];
14+
const showSelectProject = $props.showSelectProject;
15+
const selectedProjects = $state([]);
1616
17-
let projects: Array<Models.Project> = [];
18-
let error: string | null = null;
17+
let projects = $state<Array<Models.Project>>([]);
18+
let error = $state<string | null>(null);
1919
2020
onMount(() => {
2121
projects = page.data.projects?.projects || [];
2222
});
2323
24-
let projectsToArchive: Array<Models.Project> = [];
25-
26-
$: projectsToArchive = projects.filter((project) => !selectedProjects.includes(project.$id));
24+
let projectsToArchive = $derived(
25+
projects.filter((project) => !selectedProjects.includes(project.$id))
26+
);
2727
2828
async function updateSelected() {
2929
try {
3030
await sdk.forConsole.billing.updateSelectedProjects(
3131
projects[0].teamId,
3232
selectedProjects
3333
);
34-
showSelectProject = false;
34+
showSelectProject.set(false);
3535
invalidate(Dependencies.ORGANIZATION);
3636
addNotification({
3737
type: 'success',
@@ -41,9 +41,29 @@
4141
error = e.message;
4242
}
4343
}
44+
45+
function formatProjectsToArchive(projects: Array<Models.Project>) {
46+
let result = '';
47+
48+
projectsToArchive.forEach((project, index) => {
49+
const text = `${index === 0 ? '' : ' '}<b>${project.name}</b> `;
50+
result += text;
51+
52+
if (index < projectsToArchive.length - 1) {
53+
if (index == projectsToArchive.length - 2) {
54+
result += 'and ';
55+
}
56+
if (index < projectsToArchive.length - 2) {
57+
result += ', ';
58+
}
59+
}
60+
});
61+
62+
return result;
63+
}
4464
</script>
4565

46-
<Modal bind:show={showSelectProject} title={'Manage projects'} onSubmit={updateSelected}>
66+
<Modal bind:show={$showSelectProject} title={'Manage projects'} onSubmit={updateSelected}></Modal>
4767
<svelte:fragment slot="description">
4868
Choose which two projects to keep. Projects over the limit will be blocked after this date.
4969
</svelte:fragment>
@@ -53,7 +73,7 @@
5373
<Table.Root
5474
let:root
5575
allowSelection
56-
bind:selectedRows={selectedProjects}
76+
bind:selectedRows={$selectedProjects}
5777
columns={[{ id: 'name' }, { id: 'created' }]}>
5878
<svelte:fragment slot="header" let:root>
5979
<Table.Header.Cell column="name" {root}>Project Name</Table.Header.Cell>
@@ -67,30 +87,24 @@
6787
</Table.Row.Base>
6888
{/each}
6989
</Table.Root>
70-
{#if selectedProjects.length > 2}
90+
{#if $selectedProjects.length > 2}
7191
<div class="u-text-warning u-mb-4">
7292
You can only select two projects. Please deselect others to continue.
7393
</div>
7494
{/if}
75-
{#if selectedProjects.length === 2}
95+
{#if $selectedProjects.length === 2}
7696
<Alert.Inline
7797
status="warning"
78-
title={`${projects.length - selectedProjects.length} projects will be archived on ${billingProjectsLimitDate}`}>
98+
title={`${projects.length - $selectedProjects.length} projects will be archived on ${billingProjectsLimitDate}`}>
7999
<span>
80-
{#each projectsToArchive as project, index}
81-
{@const text = `${index === 0 ? '' : ' '}<b>${project.name}</b> `}
82-
{@html text}{#if index < projectsToArchive.length - 1}{#if index == projectsToArchive.length - 2}
83-
and
84-
{/if}{#if index < projectsToArchive.length - 2},
85-
{/if}{/if}
86-
{/each}
100+
{@html formatProjectsToArchive(projectsToArchive)}
87101
will be archived.
88102
</span>
89103
</Alert.Inline>
90104
{/if}
91105
<svelte:fragment slot="footer">
92-
<Button.Button size="s" variant="secondary" on:click={() => (showSelectProject = false)}
106+
<Button.Button size="s" variant="secondary" on:click={() => ($showSelectProject = false)}
93107
>Cancel</Button.Button>
94-
<Button.Button size="s" disabled={selectedProjects.length !== 2}>Save</Button.Button>
108+
<Button.Button size="s" disabled={$selectedProjects.length !== 2}>Save</Button.Button>
95109
</svelte:fragment>
96110
</Modal>

src/lib/layout/createProject.svelte

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,17 @@
1111
import type { Models } from '@appwrite.io/console';
1212
import { filterRegions } from '$lib/helpers/regions';
1313
14-
export let projectName: string;
15-
export let id: string;
16-
export let regions: Array<Models.ConsoleRegion> = [];
17-
export let region: string;
18-
export let showTitle = true;
19-
export let projects: number = undefined;
14+
let projectName = $state('');
15+
let id = $state('');
16+
let regions = $state<Array<Models.ConsoleRegion>>([]);
17+
let region = $state('');
18+
let showTitle = $state(true);
19+
let projects = $state<number | undefined>(undefined);
2020
21-
let showCustomId = false;
22-
$: projectsLimited = $currentPlan.projects > 0 && projects && projects >= $currentPlan?.projects;
21+
let showCustomId = $state(false);
22+
let projectsLimited = $derived(
23+
$currentPlan.projects > 0 && projects && projects >= $currentPlan?.projects
24+
);
2325
</script>
2426

2527
<svelte:head>
@@ -28,13 +30,16 @@
2830
{/each}
2931
</svelte:head>
3032

31-
<form on:submit|preventDefault>
33+
<form
34+
onsubmit={(e) => {
35+
e.preventDefault();
36+
}}>
3237
<Layout.Stack direction="column" gap="xxl">
3338
{#if showTitle}
3439
<Typography.Title size="l">Create your project</Typography.Title>
3540
{/if}
3641
{#if projectsLimited}
37-
<Alert.Inline status="warning" title="Youve reached your limit of 2 projects">
42+
<Alert.Inline status="warning" title="You've reached your limit of 2 projects">
3843
Extra projects are available on paid plans for an additional fee
3944
<svelte:fragment slot="actions">
4045
<Button
@@ -80,6 +85,6 @@
8085
{/if}
8186
</Layout.Stack>
8287
</Layout.Stack>
83-
<slot name="submit"></slot>
88+
{@render globalThis.$slots.submit?.()}
8489
</Layout.Stack>
8590
</form>

0 commit comments

Comments
 (0)