From 98e48eab1534c24b4c6734040270f5e298b75b4b Mon Sep 17 00:00:00 2001 From: pavish Date: Tue, 1 Oct 2024 14:01:50 +0530 Subject: [PATCH] Handle side effects when logged in user is added as a collaborator --- mathesar_ui/src/contexts/DatabaseSettingsRouteContext.ts | 1 + .../settings/collaborators/AddCollaboratorModal.svelte | 7 ++++++- .../database/settings/collaborators/Collaborators.svelte | 1 + 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/mathesar_ui/src/contexts/DatabaseSettingsRouteContext.ts b/mathesar_ui/src/contexts/DatabaseSettingsRouteContext.ts index 6dbac9318f..810e4ed0d0 100644 --- a/mathesar_ui/src/contexts/DatabaseSettingsRouteContext.ts +++ b/mathesar_ui/src/contexts/DatabaseSettingsRouteContext.ts @@ -137,6 +137,7 @@ export class DatabaseSettingsRouteContext { this.collaborators.updateResolvedValue((collaborators) => collaborators.with(newCollaborator.id, newCollaborator), ); + return newCollaborator; } async deleteCollaborator(collaborator: Collaborator) { diff --git a/mathesar_ui/src/pages/database/settings/collaborators/AddCollaboratorModal.svelte b/mathesar_ui/src/pages/database/settings/collaborators/AddCollaboratorModal.svelte index db762e0a97..0be74c4447 100644 --- a/mathesar_ui/src/pages/database/settings/collaborators/AddCollaboratorModal.svelte +++ b/mathesar_ui/src/pages/database/settings/collaborators/AddCollaboratorModal.svelte @@ -28,6 +28,7 @@ export let configuredRolesMap: ImmutableMap; export let usersMap: ImmutableMap; export let collaboratorsMap: ImmutableMap; + export let onAdd: (collaborator: Collaborator) => void; const userId = requiredField(undefined); const configuredRoleId = requiredField(undefined); @@ -41,7 +42,11 @@ async function addCollaborator() { if ($userId && $configuredRoleId) { - await $routeContext.addCollaborator($userId, $configuredRoleId); + const collaborator = await $routeContext.addCollaborator( + $userId, + $configuredRoleId, + ); + onAdd(collaborator); controller.close(); toast.success($_('collaborator_added_successfully')); form.reset(); diff --git a/mathesar_ui/src/pages/database/settings/collaborators/Collaborators.svelte b/mathesar_ui/src/pages/database/settings/collaborators/Collaborators.svelte index dae579b3b0..093f736d53 100644 --- a/mathesar_ui/src/pages/database/settings/collaborators/Collaborators.svelte +++ b/mathesar_ui/src/pages/database/settings/collaborators/Collaborators.svelte @@ -117,6 +117,7 @@ usersMap={$users.resolvedValue} configuredRolesMap={$configuredRoles.resolvedValue} collaboratorsMap={$collaborators.resolvedValue} + onAdd={checkAndHandleSideEffects} /> {/if}