|
1 | 1 | <script lang="ts">
|
2 |
| - import { goto } from '$app/navigation'; |
3 | 2 | import { base } from '$app/paths';
|
4 |
| - import { Submit, trackEvent, trackError } from '$lib/actions/analytics'; |
| 3 | + import { isCloud } from '$lib/system'; |
| 4 | + import { goto } from '$app/navigation'; |
| 5 | + import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; |
5 | 6 | import { BoxAvatar, CardGrid, Heading, Modal } from '$lib/components';
|
6 | 7 | import { Button, FormList, InputText } from '$lib/elements/forms';
|
7 | 8 | import { toLocaleDateTime } from '$lib/helpers/date';
|
8 | 9 | import { addNotification } from '$lib/stores/notifications';
|
9 |
| - import { sdk } from '$lib/stores/sdk'; |
10 |
| - import { isCloud } from '$lib/system'; |
| 10 | + import { getApiEndpoint } from '$lib/stores/sdk'; |
11 | 11 | import { project, projectRegion } from '../store';
|
| 12 | + import { Client as TempClient, Projects as TempProjects } from '@appwrite.io/console'; |
12 | 13 |
|
13 | 14 | let showDelete = false;
|
14 | 15 | let name: string = null;
|
15 | 16 |
|
| 17 | + /** |
| 18 | + * This ensures the underlying client use a region-aware endpoint |
| 19 | + * to correctly route project deletion requests to the appropriate regional pool. |
| 20 | + * |
| 21 | + * The console project itself isn't tied to a region, so its client doesn’t |
| 22 | + * include one. Without this, deletion requests would default to the manager region. |
| 23 | + */ |
| 24 | + const temporaryProjects = (region: string) => { |
| 25 | + const tempClient = new TempClient() |
| 26 | + .setMode('admin') |
| 27 | + .setProject('console') |
| 28 | + .setEndpoint(getApiEndpoint(region)); |
| 29 | +
|
| 30 | + return new TempProjects(tempClient); |
| 31 | + }; |
| 32 | +
|
16 | 33 | const handleDelete = async () => {
|
17 | 34 | try {
|
18 |
| - await sdk.forConsole.projects.delete($project.$id); |
| 35 | + await temporaryProjects($project.region).delete($project.$id); |
19 | 36 | showDelete = false;
|
20 | 37 | addNotification({
|
21 | 38 | type: 'success',
|
|
0 commit comments