Skip to content

Commit 400e083

Browse files
committed
fix: invalidate org to update the nav breadcrumb when creating/deleting projects.
1 parent b1df97a commit 400e083

File tree

3 files changed

+28
-26
lines changed

3 files changed

+28
-26
lines changed

src/routes/(console)/onboarding/create-organization/+page.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@
4444
message: e.message
4545
});
4646
} finally {
47-
isLoading = false;
4847
if (organization) {
4948
loadAvailableRegions(organization?.$id).then();
5049
await goto(`${base}/organization-${organization.$id}`);
5150
}
51+
isLoading = false;
5252
}
5353
}
5454
</script>

src/routes/(console)/organization-[organization]/createProjectCloud.svelte

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<script lang="ts">
22
import { sdk } from '$lib/stores/sdk';
33
import { onDestroy } from 'svelte';
4-
import { addNotification } from '$lib/stores/notifications';
5-
import { goto } from '$app/navigation';
4+
import { goto, invalidate } from '$app/navigation';
65
import { page } from '$app/state';
76
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
87
import { ID, type Models, Region as ConsoleRegion, Region } from '@appwrite.io/console';
98
import { base } from '$app/paths';
109
import CreateProject from '$lib/layout/createProject.svelte';
1110
import { Modal } from '$lib/components';
1211
import { Button } from '$lib/elements/forms';
12+
import { Dependencies } from '$lib/constants';
1313
1414
export let showCreateProjectCloud: boolean;
1515
export let regions: Array<Models.ConsoleRegion> = [];
@@ -22,30 +22,26 @@
2222
let showSubmissionLoader = false;
2323
const teamId = page.params.organization;
2424
25-
function onFinish() {
26-
addNotification({ type: 'success', message: `${name} has been created` });
27-
trackEvent(Submit.ProjectCreate, { customId: !!id, teamId, region: region });
28-
}
29-
3025
async function create() {
26+
let project: Models.Project;
27+
3128
showSubmissionLoader = true;
3229
3330
try {
34-
// TODO: fix typing once SDK is updated
35-
const project = await sdk.forConsole.projects.create(
36-
id ?? ID.unique(),
37-
name,
38-
teamId,
39-
region
40-
);
31+
project = await sdk.forConsole.projects.create(id ?? ID.unique(), name, teamId, region);
4132
42-
onFinish();
4333
await goto(`${base}/project-${project.region}-${project.$id}`);
34+
trackEvent(Submit.ProjectCreate, { customId: !!id, teamId, region: region });
4435
} catch (e) {
4536
error = e.message;
4637
trackError(e, Submit.ProjectCreate);
4738
} finally {
4839
showSubmissionLoader = false;
40+
41+
if (project) {
42+
// reload projects for nav breadcrumb!
43+
await invalidate(Dependencies.ORGANIZATION);
44+
}
4945
}
5046
}
5147

src/routes/(console)/project-[region]-[project]/settings/deleteProject.svelte

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import { goto } from '$app/navigation';
2+
import { goto, invalidate } from '$app/navigation';
33
import { base } from '$app/paths';
44
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
55
import { BoxAvatar, Confirm, CardGrid } from '$lib/components';
@@ -10,24 +10,30 @@
1010
import { isCloud } from '$lib/system';
1111
import { project, projectRegion } from '../store';
1212
import { organization } from '$lib/stores/organization';
13+
import { Dependencies } from '$lib/constants';
1314
1415
let error: string;
1516
let showDelete = false;
1617
let name: string = null;
1718
19+
async function finishAndRedirect() {
20+
showDelete = false;
21+
22+
trackEvent(Submit.ProjectDelete);
23+
addNotification({ type: 'success', message: `${$project.name} has been deleted` });
24+
await goto(`${base}/organization-${$organization.$id}`, {
25+
replaceState: true
26+
});
27+
28+
// reload projects for nav breadcrumb!
29+
await invalidate(Dependencies.ORGANIZATION);
30+
}
31+
1832
const handleDelete = async () => {
1933
try {
2034
// send the project to correct region pool for deletion!
2135
await sdk.forConsoleIn($project.region).projects.delete($project.$id);
22-
showDelete = false;
23-
addNotification({
24-
type: 'success',
25-
message: `${$project.name} has been deleted`
26-
});
27-
trackEvent(Submit.ProjectDelete);
28-
await goto(`${base}/organization-${$organization.$id}`, {
29-
replaceState: true
30-
});
36+
await finishAndRedirect();
3137
} catch (e) {
3238
error = e.message;
3339
trackError(e, Submit.ProjectDelete);

0 commit comments

Comments
 (0)