|
@@ -1,15 +1,19 @@
|
|
|
<script lang="ts">
|
|
|
- import { getContext, createEventDispatcher } from 'svelte';
|
|
|
-
|
|
|
+ import { getContext, createEventDispatcher, onMount } from 'svelte';
|
|
|
import { createNewChannel } from '$lib/apis/channels';
|
|
|
|
|
|
import Modal from '$lib/components/common/Modal.svelte';
|
|
|
import AccessControl from '$lib/components/workspace/common/AccessControl.svelte';
|
|
|
+ import DeleteConfirmDialog from '$lib/components/common/ConfirmDialog.svelte';
|
|
|
+
|
|
|
import { toast } from 'svelte-sonner';
|
|
|
const i18n = getContext('i18n');
|
|
|
|
|
|
export let show = false;
|
|
|
- export let onChange: Function = () => {};
|
|
|
+ export let onSubmit: Function = () => {};
|
|
|
+
|
|
|
+ export let channel = null;
|
|
|
+ export let edit = false;
|
|
|
|
|
|
let name = '';
|
|
|
let accessControl = null;
|
|
@@ -22,25 +26,41 @@
|
|
|
|
|
|
const submitHandler = async () => {
|
|
|
loading = true;
|
|
|
- const res = await createNewChannel(localStorage.token, {
|
|
|
+ await onSubmit({
|
|
|
name: name.replace(/\s/g, '-'),
|
|
|
access_control: accessControl
|
|
|
- }).catch((error) => {
|
|
|
- toast.error(error);
|
|
|
- return null;
|
|
|
});
|
|
|
-
|
|
|
- onChange();
|
|
|
show = false;
|
|
|
-
|
|
|
loading = false;
|
|
|
};
|
|
|
+
|
|
|
+ const init = () => {
|
|
|
+ name = channel.name;
|
|
|
+ accessControl = channel.access_control;
|
|
|
+ };
|
|
|
+
|
|
|
+ $: if (channel) {
|
|
|
+ init();
|
|
|
+ }
|
|
|
+
|
|
|
+ let showDeleteConfirmDialog = false;
|
|
|
+
|
|
|
+ const deleteHandler = async () => {
|
|
|
+ showDeleteConfirmDialog = false;
|
|
|
+ show = false;
|
|
|
+ };
|
|
|
</script>
|
|
|
|
|
|
<Modal size="sm" bind:show>
|
|
|
<div>
|
|
|
<div class=" flex justify-between dark:text-gray-300 px-5 pt-4 pb-1">
|
|
|
- <div class=" text-lg font-medium self-center">{$i18n.t('Create Channel')}</div>
|
|
|
+ <div class=" text-lg font-medium self-center">
|
|
|
+ {#if edit}
|
|
|
+ {$i18n.t('Edit Channel')}
|
|
|
+ {:else}
|
|
|
+ {$i18n.t('Create Channel')}
|
|
|
+ {/if}
|
|
|
+ </div>
|
|
|
<button
|
|
|
class="self-center"
|
|
|
on:click={() => {
|
|
@@ -93,6 +113,18 @@
|
|
|
</div>
|
|
|
|
|
|
<div class="flex justify-end pt-3 text-sm font-medium gap-1.5">
|
|
|
+ {#if edit}
|
|
|
+ <button
|
|
|
+ class="px-3.5 py-1.5 text-sm font-medium dark:bg-black dark:hover:bg-black/90 dark:text-white bg-white text-black hover:bg-gray-100 transition rounded-full flex flex-row space-x-1 items-center"
|
|
|
+ type="button"
|
|
|
+ on:click={() => {
|
|
|
+ showDeleteConfirmDialog = true;
|
|
|
+ }}
|
|
|
+ >
|
|
|
+ {$i18n.t('Delete')}
|
|
|
+ </button>
|
|
|
+ {/if}
|
|
|
+
|
|
|
<button
|
|
|
class="px-3.5 py-1.5 text-sm font-medium bg-black hover:bg-gray-950 text-white dark:bg-white dark:text-black dark:hover:bg-gray-100 transition rounded-full flex flex-row space-x-1 items-center {loading
|
|
|
? ' cursor-not-allowed'
|
|
@@ -100,7 +132,11 @@
|
|
|
type="submit"
|
|
|
disabled={loading}
|
|
|
>
|
|
|
- {$i18n.t('Create')}
|
|
|
+ {#if edit}
|
|
|
+ {$i18n.t('Update')}
|
|
|
+ {:else}
|
|
|
+ {$i18n.t('Create')}
|
|
|
+ {/if}
|
|
|
|
|
|
{#if loading}
|
|
|
<div class="ml-2 self-center">
|
|
@@ -136,3 +172,12 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
</Modal>
|
|
|
+
|
|
|
+<DeleteConfirmDialog
|
|
|
+ bind:show={showDeleteConfirmDialog}
|
|
|
+ message={$i18n.t('Are you sure you want to delete this channel?')}
|
|
|
+ confirmLabel={$i18n.t('Delete')}
|
|
|
+ on:confirm={() => {
|
|
|
+ deleteHandler();
|
|
|
+ }}
|
|
|
+/>
|