refac
This commit is contained in:
1 parent
f7406ff576
commit
3c7f9aa6a4
27 files changed
+789
-253
No files matched your search
@@ -23,7 +23,7 @@
|
||||
export let onSubmit: Function = () => {};
|
||||
export let onUpdate: Function = () => {};
|
||||
|
||||
export let channel = null;
|
||||
export let channel: any = null;
|
||||
export let edit = false;
|
||||
|
||||
let channelTypes = ['group', 'dm'];
|
||||
@@ -31,7 +31,7 @@
|
||||
let name = '';
|
||||
|
||||
let isPrivate = null;
|
||||
let accessControl = {};
|
||||
let accessGrants = [];
|
||||
|
||||
let groupIds = [];
|
||||
let userIds = [];
|
||||
@@ -65,8 +65,8 @@
|
||||
await onSubmit({
|
||||
type: type,
|
||||
name: name.replace(/\s/g, '-'),
|
||||
is_private: type === 'group' ? isPrivate : null,
|
||||
access_control: type === '' ? accessControl : {},
|
||||
is_private: type === 'group' ? (isPrivate ?? true) : null,
|
||||
access_grants: type === '' ? accessGrants : [],
|
||||
group_ids: groupIds,
|
||||
user_ids: userIds
|
||||
});
|
||||
@@ -85,8 +85,12 @@
|
||||
|
||||
if (channel) {
|
||||
name = channel?.name ?? '';
|
||||
isPrivate = channel?.is_private ?? null;
|
||||
accessControl = channel.access_control;
|
||||
if (type === 'group') {
|
||||
isPrivate = typeof channel?.is_private === 'boolean' ? channel.is_private : true;
|
||||
} else {
|
||||
isPrivate = null;
|
||||
}
|
||||
accessGrants = channel?.access_grants ?? [];
|
||||
userIds = channel?.user_ids ?? [];
|
||||
}
|
||||
};
|
||||
@@ -102,8 +106,14 @@
|
||||
|
||||
const deleteHandler = async () => {
|
||||
showDeleteConfirmDialog = false;
|
||||
if (!channel?.id) {
|
||||
show = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await deleteChannelById(localStorage.token, channel.id).catch((error) => {
|
||||
const channelId = channel.id;
|
||||
|
||||
const res = await deleteChannelById(localStorage.token, channelId).catch((error) => {
|
||||
toast.error(error.message);
|
||||
});
|
||||
|
||||
@@ -111,7 +121,7 @@
|
||||
toast.success($i18n.t('Channel deleted successfully'));
|
||||
onUpdate();
|
||||
|
||||
if ($page.url.pathname === `/channels/${channel.id}`) {
|
||||
if ($page.url.pathname === `/channels/${channelId}`) {
|
||||
goto('/');
|
||||
}
|
||||
}
|
||||
@@ -122,7 +132,7 @@
|
||||
const resetHandler = () => {
|
||||
type = '';
|
||||
name = '';
|
||||
accessControl = {};
|
||||
accessGrants = [];
|
||||
userIds = [];
|
||||
loading = false;
|
||||
};
|
||||
@@ -226,11 +236,11 @@
|
||||
{#if type !== 'dm'}
|
||||
<div class="-mx-2 mb-1 mt-2.5 px-2">
|
||||
{#if type === ''}
|
||||
<AccessControl bind:accessControl accessRoles={['read', 'write']} />
|
||||
<AccessControl bind:accessGrants accessRoles={['read', 'write']} />
|
||||
{:else if type === 'group'}
|
||||
<Visibility
|
||||
state={isPrivate ? 'private' : 'public'}
|
||||
onChange={(value) => {
|
||||
onChange={(value: string) => {
|
||||
if (value === 'private') {
|
||||
isPrivate = true;
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user