fix: invalidate org to update the nav breadcrumb when creating/deleting projects.

This commit is contained in:
Darshan
2025-06-21 12:12:16 +05:30
parent b1df97a4c3
commit 400e083318
3 changed files with 28 additions and 26 deletions
@@ -44,11 +44,11 @@
message: e.message
});
} finally {
isLoading = false;
if (organization) {
loadAvailableRegions(organization?.$id).then();
await goto(`${base}/organization-${organization.$id}`);
}
isLoading = false;
}
}
</script>
@@ -1,8 +1,7 @@
<script lang="ts">
import { sdk } from '$lib/stores/sdk';
import { onDestroy } from 'svelte';
import { addNotification } from '$lib/stores/notifications';
import { goto } from '$app/navigation';
import { goto, invalidate } from '$app/navigation';
import { page } from '$app/state';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { ID, type Models, Region as ConsoleRegion, Region } from '@appwrite.io/console';
@@ -10,6 +9,7 @@
import CreateProject from '$lib/layout/createProject.svelte';
import { Modal } from '$lib/components';
import { Button } from '$lib/elements/forms';
import { Dependencies } from '$lib/constants';
export let showCreateProjectCloud: boolean;
export let regions: Array<Models.ConsoleRegion> = [];
@@ -22,30 +22,26 @@
let showSubmissionLoader = false;
const teamId = page.params.organization;
function onFinish() {
addNotification({ type: 'success', message: `${name} has been created` });
trackEvent(Submit.ProjectCreate, { customId: !!id, teamId, region: region });
}
async function create() {
let project: Models.Project;
showSubmissionLoader = true;
try {
// TODO: fix typing once SDK is updated
const project = await sdk.forConsole.projects.create(
id ?? ID.unique(),
name,
teamId,
region
);
project = await sdk.forConsole.projects.create(id ?? ID.unique(), name, teamId, region);
onFinish();
await goto(`${base}/project-${project.region}-${project.$id}`);
trackEvent(Submit.ProjectCreate, { customId: !!id, teamId, region: region });
} catch (e) {
error = e.message;
trackError(e, Submit.ProjectCreate);
} finally {
showSubmissionLoader = false;
if (project) {
// reload projects for nav breadcrumb!
await invalidate(Dependencies.ORGANIZATION);
}
}
}
@@ -1,5 +1,5 @@
<script lang="ts">
import { goto } from '$app/navigation';
import { goto, invalidate } from '$app/navigation';
import { base } from '$app/paths';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { BoxAvatar, Confirm, CardGrid } from '$lib/components';
@@ -10,24 +10,30 @@
import { isCloud } from '$lib/system';
import { project, projectRegion } from '../store';
import { organization } from '$lib/stores/organization';
import { Dependencies } from '$lib/constants';
let error: string;
let showDelete = false;
let name: string = null;
async function finishAndRedirect() {
showDelete = false;
trackEvent(Submit.ProjectDelete);
addNotification({ type: 'success', message: `${$project.name} has been deleted` });
await goto(`${base}/organization-${$organization.$id}`, {
replaceState: true
});
// reload projects for nav breadcrumb!
await invalidate(Dependencies.ORGANIZATION);
}
const handleDelete = async () => {
try {
// send the project to correct region pool for deletion!
await sdk.forConsoleIn($project.region).projects.delete($project.$id);
showDelete = false;
addNotification({
type: 'success',
message: `${$project.name} has been deleted`
});
trackEvent(Submit.ProjectDelete);
await goto(`${base}/organization-${$organization.$id}`, {
replaceState: true
});
await finishAndRedirect();
} catch (e) {
error = e.message;
trackError(e, Submit.ProjectDelete);