mirror of
https://github.com/appwrite/console.git
synced 2026-11-18 20:47:21 +00:00
feat: webhooks table and settings
This commit is contained in:
1 parent
84a6065f7c
commit
b745a6d833
8 files changed
+267
-46
No files matched your search
@@ -1,9 +1,12 @@
|
||||
<script>
|
||||
import { afterNavigate } from '$app/navigation';
|
||||
import { page } from '$app/stores';
|
||||
import { updateLayout } from '$lib/stores/layout';
|
||||
import { onMount } from 'svelte';
|
||||
|
||||
const path = 'settings';
|
||||
const projectId = $page.params.project;
|
||||
let loaded = false;
|
||||
|
||||
onMount(handle);
|
||||
afterNavigate(handle);
|
||||
@@ -17,6 +20,10 @@
|
||||
title: 'Settings',
|
||||
href: 'settings'
|
||||
},
|
||||
copy: {
|
||||
text: 'Project ID',
|
||||
value: projectId
|
||||
},
|
||||
tabs: [
|
||||
{
|
||||
href: path,
|
||||
@@ -33,6 +40,7 @@
|
||||
}
|
||||
]
|
||||
});
|
||||
loaded = true;
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -40,4 +48,6 @@
|
||||
<title>Appwrite - Settings</title>
|
||||
</svelte:head>
|
||||
|
||||
<slot />
|
||||
{#if loaded}
|
||||
<slot />
|
||||
{/if}
|
||||
@@ -4,18 +4,20 @@
|
||||
import { page } from '$app/stores';
|
||||
import { Empty } from '$lib/components';
|
||||
import { Button } from '$lib/elements/forms';
|
||||
import { Pill } from '$lib/elements';
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableRowLink,
|
||||
TableCellHead,
|
||||
TableCellLink,
|
||||
TableCell,
|
||||
TableCellText,
|
||||
TableHeader
|
||||
} from '$lib/elements/table';
|
||||
import { Container } from '$lib/layout';
|
||||
import { sdkForConsole } from '$lib/stores/sdk';
|
||||
import { wizard } from '$lib/stores/wizard';
|
||||
import Create from './createWebhook.svelte';
|
||||
import { webhookList } from './store';
|
||||
|
||||
function openWizard() {
|
||||
wizard.start(Create);
|
||||
@@ -26,7 +28,8 @@
|
||||
});
|
||||
|
||||
const projectId = $page.params.project;
|
||||
const request = sdkForConsole.projects.listWebhooks(projectId);
|
||||
|
||||
$: webhookList.load(projectId);
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
@@ -41,41 +44,43 @@
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{#await request}
|
||||
<div aria-busy="true" />
|
||||
{:then response}
|
||||
{#if response.total}
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableCellHead width={80}>Name</TableCellHead>
|
||||
<TableCellHead>URL</TableCellHead>
|
||||
<TableCellHead width={80}>Events</TableCellHead>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{#each response.webhooks as webhook}
|
||||
<TableCellLink
|
||||
title="Name"
|
||||
href={`${base}/console/project-${projectId}/webhooks/webhook/${webhook.$id}`}>
|
||||
{webhook.name}
|
||||
</TableCellLink>
|
||||
{#if $webhookList.total}
|
||||
<Table>
|
||||
<TableHeader>
|
||||
<TableCellHead>Name</TableCellHead>
|
||||
<TableCellHead>POST URL</TableCellHead>
|
||||
<TableCellHead width={80}>Events</TableCellHead>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{#each $webhookList.webhooks as webhook}
|
||||
<TableRowLink
|
||||
href={`${base}/console/project-${projectId}/settings/webhooks/webhook/${webhook.$id}`}>
|
||||
<TableCell title="Name">
|
||||
<div class="u-flex u-main-space-between">
|
||||
{webhook.name}
|
||||
{#if webhook.security === false}
|
||||
<Pill>SLL/TLS disabled</Pill>
|
||||
{/if}
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCellText title="URL">{webhook.url}</TableCellText>
|
||||
<TableCellText title="Scopes">{webhook.events.length}</TableCellText>
|
||||
{/each}
|
||||
</TableBody>
|
||||
</Table>
|
||||
{:else}
|
||||
<Empty isButton single>
|
||||
<div class="common-section u-text-center">
|
||||
<p class="text">Create your first Webhook to get startedNeed a hand?</p>
|
||||
<p class="text">Check out our documentation.</p>
|
||||
</div>
|
||||
<div class="u-flex u-gap-12 common-section">
|
||||
<Button text href="#/">Documentation</Button>
|
||||
<Button secondary on:click={openWizard}>
|
||||
<span class="text">Create Webhook</span>
|
||||
</Button>
|
||||
</div>
|
||||
</Empty>
|
||||
{/if}
|
||||
{/await}
|
||||
<TableCellText title="Scopes">{webhook.events.length} events</TableCellText>
|
||||
</TableRowLink>
|
||||
{/each}
|
||||
</TableBody>
|
||||
</Table>
|
||||
{:else}
|
||||
<Empty isButton single>
|
||||
<div class="common-section u-text-center">
|
||||
<p class="text">Create your first Webhook to get startedNeed a hand?</p>
|
||||
<p class="text">Check out our documentation.</p>
|
||||
</div>
|
||||
<div class="u-flex u-gap-12 common-section">
|
||||
<Button text href="#/">Documentation</Button>
|
||||
<Button secondary on:click={openWizard}>
|
||||
<span class="text">Create Webhook</span>
|
||||
</Button>
|
||||
</div>
|
||||
</Empty>
|
||||
{/if}
|
||||
</Container>
|
||||
@@ -8,13 +8,13 @@
|
||||
import { wizard } from '$lib/stores/wizard';
|
||||
import type { WizardStepsType } from '$lib/layout/wizard.svelte';
|
||||
import { createWebhook } from './wizard/store';
|
||||
import { sdkForProject } from '$lib/stores/sdk';
|
||||
import { sdkForConsole } from '$lib/stores/sdk';
|
||||
import { page } from '$app/stores';
|
||||
|
||||
const projectId = $page.params.project;
|
||||
const create = async () => {
|
||||
try {
|
||||
await sdkForProject.projects.createWebhook(
|
||||
await sdkForConsole.projects.createWebhook(
|
||||
projectId,
|
||||
$createWebhook.name,
|
||||
$createWebhook.events,
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
import { sdkForConsole } from '$lib/stores/sdk';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import { cachedStore } from '$lib/helpers/cache';
|
||||
|
||||
export const webhookList = cachedStore<
|
||||
Models.WebhookList,
|
||||
{
|
||||
load: (projectId: string) => Promise<void>;
|
||||
}
|
||||
>('webhookList', function ({ set }) {
|
||||
return {
|
||||
load: async (projectId) => {
|
||||
const response = await sdkForConsole.projects.listWebhooks(projectId);
|
||||
set(response);
|
||||
}
|
||||
};
|
||||
});
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
<script lang="ts">
|
||||
import { afterNavigate } from '$app/navigation';
|
||||
import { base } from '$app/paths';
|
||||
import { page } from '$app/stores';
|
||||
import { updateLayout } from '$lib/stores/layout';
|
||||
import { onMount } from 'svelte';
|
||||
import { webhook } from './store';
|
||||
|
||||
const webhookId = $page.params.webhook;
|
||||
const projectId = $page.params.project;
|
||||
|
||||
onMount(handle);
|
||||
afterNavigate(handle);
|
||||
|
||||
async function handle(event = null) {
|
||||
const promise = webhook.load(projectId, webhookId);
|
||||
|
||||
if ($webhook?.$id !== webhookId) {
|
||||
await promise;
|
||||
}
|
||||
|
||||
updateLayout({
|
||||
navigate: event,
|
||||
title: $webhook.name,
|
||||
level: 4,
|
||||
breadcrumbs: {
|
||||
title: $webhook.name,
|
||||
href: `settings/webhook/${webhookId}`
|
||||
},
|
||||
back: `${base}/console/project-${projectId}/settings`,
|
||||
copy: {
|
||||
text: 'Webhook ID',
|
||||
value: webhookId
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
<title>Appwrite - Webhook</title>
|
||||
</svelte:head>
|
||||
|
||||
{#if $webhook}
|
||||
<slot />
|
||||
{/if}
|
||||
+130
-4
@@ -1,10 +1,136 @@
|
||||
<script lang="ts">
|
||||
import { Card } from '$lib/components';
|
||||
import { onMount } from 'svelte';
|
||||
import { CardGrid, Box } from '$lib/components';
|
||||
import { Button, Form, FormList, InputText } from '$lib/elements/forms';
|
||||
import { Container } from '$lib/layout';
|
||||
import { addNotification } from '$lib/stores/notifications';
|
||||
import { sdkForConsole } from '$lib/stores/sdk';
|
||||
import { webhook } from './store';
|
||||
import { page } from '$app/stores';
|
||||
import { toLocaleDateTime } from '$lib/helpers/date';
|
||||
|
||||
const projectId = $page.params.project;
|
||||
let name: string = null;
|
||||
let url: string = null;
|
||||
let events = [];
|
||||
let httpUser: string = null;
|
||||
let httpPass: string = null;
|
||||
let security = false;
|
||||
let showDelete = false;
|
||||
|
||||
onMount(async () => {
|
||||
name ??= $webhook.name;
|
||||
url ??= $webhook.url;
|
||||
events = $webhook.events;
|
||||
httpUser ??= $webhook.httpUser;
|
||||
httpPass ??= $webhook.httpPass;
|
||||
security = $webhook.security;
|
||||
});
|
||||
|
||||
async function updateName() {
|
||||
try {
|
||||
await sdkForConsole.projects.updateWebhook(
|
||||
projectId,
|
||||
$webhook.$id,
|
||||
name,
|
||||
$webhook.events,
|
||||
$webhook.url,
|
||||
$webhook.security
|
||||
);
|
||||
$webhook.name = name;
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: 'Webhook name has been updated'
|
||||
});
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
async function updateUrl() {
|
||||
try {
|
||||
await sdkForConsole.projects.updateWebhook(
|
||||
projectId,
|
||||
$webhook.$id,
|
||||
$webhook.name,
|
||||
$webhook.events,
|
||||
url,
|
||||
$webhook.security
|
||||
);
|
||||
$webhook.url = url;
|
||||
addNotification({
|
||||
type: 'success',
|
||||
message: 'Webhook name has been updated'
|
||||
});
|
||||
} catch (error) {
|
||||
addNotification({
|
||||
type: 'error',
|
||||
message: error.message
|
||||
});
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<Container>
|
||||
<Card>
|
||||
<p>TBD</p>
|
||||
</Card>
|
||||
<Form on:submit={updateName}>
|
||||
<CardGrid>
|
||||
<h6 class="heading-level-7">Update Name</h6>
|
||||
<p>Choose any name that will help you distinguish between Webhooks.</p>
|
||||
<svelte:fragment slot="aside">
|
||||
<FormList>
|
||||
<InputText
|
||||
id="name"
|
||||
label="Name"
|
||||
bind:value={name}
|
||||
required
|
||||
placeholder="Enter name" />
|
||||
</FormList>
|
||||
</svelte:fragment>
|
||||
|
||||
<svelte:fragment slot="actions">
|
||||
<Button disabled={name === $webhook.name} submit>Update</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
</Form>
|
||||
<Form on:submit={updateUrl}>
|
||||
<CardGrid>
|
||||
<h6 class="heading-level-7">Update Url</h6>
|
||||
|
||||
<svelte:fragment slot="aside">
|
||||
<FormList>
|
||||
<InputText
|
||||
id="name"
|
||||
label="Name"
|
||||
bind:value={name}
|
||||
required
|
||||
placeholder="Enter name" />
|
||||
</FormList>
|
||||
</svelte:fragment>
|
||||
|
||||
<svelte:fragment slot="actions">
|
||||
<Button disabled={name === $webhook.name} submit>Update</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
</Form>
|
||||
|
||||
<CardGrid>
|
||||
<div>
|
||||
<h6 class="heading-level-7">Delete Webhook</h6>
|
||||
</div>
|
||||
<p>The webhook will be permanently deleted. This action is irreversible.</p>
|
||||
<svelte:fragment slot="aside">
|
||||
<Box>
|
||||
<svelte:fragment slot="title">
|
||||
<h6 class="u-bold">{$webhook.name}</h6>
|
||||
</svelte:fragment>
|
||||
<p>Last updated: {toLocaleDateTime($webhook.$updatedAt)}</p>
|
||||
</Box>
|
||||
</svelte:fragment>
|
||||
|
||||
<svelte:fragment slot="actions">
|
||||
<Button secondary on:click={() => (showDelete = true)}>Delete</Button>
|
||||
</svelte:fragment>
|
||||
</CardGrid>
|
||||
</Container>
|
||||
@@ -0,0 +1,17 @@
|
||||
import { sdkForConsole } from '$lib/stores/sdk';
|
||||
import type { Models } from '@aw-labs/appwrite-console';
|
||||
import { cachedStore } from '$lib/helpers/cache';
|
||||
|
||||
export const webhook = cachedStore<
|
||||
Models.Webhook,
|
||||
{
|
||||
load: (projectId: string, webhookId: string) => Promise<void>;
|
||||
}
|
||||
>('webhook', function ({ set }) {
|
||||
return {
|
||||
load: async (projectId, webhookId) => {
|
||||
const response = await sdkForConsole.projects.getWebhook(projectId, webhookId);
|
||||
set(response);
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -2,6 +2,7 @@
|
||||
import { InputText, FormList } from '$lib/elements/forms';
|
||||
import { WizardStep } from '$lib/layout';
|
||||
import { createWebhook } from './store';
|
||||
//TODO: Create InputURL component
|
||||
</script>
|
||||
|
||||
<WizardStep>
|
||||
|
||||
Reference in new issue
Block a user