-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(messaging): add update subscription perms card to topic's page
- Loading branch information
1 parent
f196bcf
commit 273e277
Showing
3 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/routes/console/project-[project]/messaging/topics/topic-[topic]/updatePermissions.svelte
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<script lang="ts"> | ||
import { invalidate } from '$app/navigation'; | ||
import { page } from '$app/stores'; | ||
import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; | ||
import { CardGrid, Heading } from '$lib/components'; | ||
import { Dependencies } from '$lib/constants'; | ||
import { Button, Form } from '$lib/elements/forms'; | ||
import { addNotification } from '$lib/stores/notifications'; | ||
import { sdk } from '$lib/stores/sdk'; | ||
import { onMount } from 'svelte'; | ||
import { Roles } from '$lib/components/permissions'; | ||
import { symmetricDifference } from '$lib/helpers/array'; | ||
import { topic } from './store'; | ||
const topicId = $page.params.topic; | ||
let arePermsDisabled = true; | ||
let permissions: string[] = []; | ||
onMount(async () => { | ||
permissions = $topic.subscribe || []; | ||
}); | ||
async function updatePermissions() { | ||
try { | ||
await sdk.forProject.messaging.updateTopic(topicId, undefined, permissions); | ||
await invalidate(Dependencies.MESSAGING_TOPIC); | ||
addNotification({ | ||
message: 'Permissions have been updated', | ||
type: 'success' | ||
}); | ||
trackEvent(Submit.MessagingTopicUpdatePermissions); | ||
} catch (error) { | ||
addNotification({ | ||
message: error.message, | ||
type: 'error' | ||
}); | ||
trackError(error, Submit.MessagingTopicUpdatePermissions); | ||
} | ||
} | ||
$: arePermsDisabled = symmetricDifference(permissions, $topic.subscribe).length == 0; | ||
</script> | ||
|
||
<Form onSubmit={updatePermissions}> | ||
<CardGrid> | ||
<Heading tag="h6" size="7" id="permissions">Subscription access</Heading> | ||
<p> | ||
Choose who can subscribe to this topic using the client API. Learn more about <a | ||
href="https://appwrite.io/docs/advanced/platform/permissions" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
class="link"> | ||
Permissions</a | ||
>. | ||
</p> | ||
<svelte:fragment slot="aside"> | ||
<Roles bind:roles={permissions} /> | ||
</svelte:fragment> | ||
|
||
<svelte:fragment slot="actions"> | ||
<Button disabled={arePermsDisabled} submit>Update</Button> | ||
</svelte:fragment> | ||
</CardGrid> | ||
</Form> |