|
11 | 11 | import { page } from '$app/state';
|
12 | 12 | import { toLocaleDateTime } from '$lib/helpers/date';
|
13 | 13 |
|
14 |
| - export let showSelectProject: boolean; |
15 |
| - export let selectedProjects: Array<string> = []; |
| 14 | + const showSelectProject = $props.showSelectProject; |
| 15 | + const selectedProjects = $state([]); |
16 | 16 |
|
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); |
19 | 19 |
|
20 | 20 | onMount(() => {
|
21 | 21 | projects = page.data.projects?.projects || [];
|
22 | 22 | });
|
23 | 23 |
|
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 | + ); |
27 | 27 |
|
28 | 28 | async function updateSelected() {
|
29 | 29 | try {
|
30 | 30 | await sdk.forConsole.billing.updateSelectedProjects(
|
31 | 31 | projects[0].teamId,
|
32 | 32 | selectedProjects
|
33 | 33 | );
|
34 |
| - showSelectProject = false; |
| 34 | + showSelectProject.set(false); |
35 | 35 | invalidate(Dependencies.ORGANIZATION);
|
36 | 36 | addNotification({
|
37 | 37 | type: 'success',
|
|
41 | 41 | error = e.message;
|
42 | 42 | }
|
43 | 43 | }
|
| 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 | + } |
44 | 64 | </script>
|
45 | 65 |
|
46 |
| -<Modal bind:show={showSelectProject} title={'Manage projects'} onSubmit={updateSelected}> |
| 66 | +<Modal bind:show={$showSelectProject} title={'Manage projects'} onSubmit={updateSelected}></Modal> |
47 | 67 | <svelte:fragment slot="description">
|
48 | 68 | Choose which two projects to keep. Projects over the limit will be blocked after this date.
|
49 | 69 | </svelte:fragment>
|
|
53 | 73 | <Table.Root
|
54 | 74 | let:root
|
55 | 75 | allowSelection
|
56 |
| - bind:selectedRows={selectedProjects} |
| 76 | + bind:selectedRows={$selectedProjects} |
57 | 77 | columns={[{ id: 'name' }, { id: 'created' }]}>
|
58 | 78 | <svelte:fragment slot="header" let:root>
|
59 | 79 | <Table.Header.Cell column="name" {root}>Project Name</Table.Header.Cell>
|
|
67 | 87 | </Table.Row.Base>
|
68 | 88 | {/each}
|
69 | 89 | </Table.Root>
|
70 |
| - {#if selectedProjects.length > 2} |
| 90 | + {#if $selectedProjects.length > 2} |
71 | 91 | <div class="u-text-warning u-mb-4">
|
72 | 92 | You can only select two projects. Please deselect others to continue.
|
73 | 93 | </div>
|
74 | 94 | {/if}
|
75 |
| - {#if selectedProjects.length === 2} |
| 95 | + {#if $selectedProjects.length === 2} |
76 | 96 | <Alert.Inline
|
77 | 97 | 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}`}> |
79 | 99 | <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)} |
87 | 101 | will be archived.
|
88 | 102 | </span>
|
89 | 103 | </Alert.Inline>
|
90 | 104 | {/if}
|
91 | 105 | <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)} |
93 | 107 | >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> |
95 | 109 | </svelte:fragment>
|
96 | 110 | </Modal>
|
0 commit comments