From 8f33dac0a647291c2589512659af9d9f7200266c Mon Sep 17 00:00:00 2001 From: nivedin Date: Thu, 21 Mar 2024 17:55:17 +0530 Subject: [PATCH 1/3] fix: add loading state and switch workspace when current workspace is deleted --- .../src/components/teams/Team.vue | 268 ++++++++++-------- .../src/components/teams/index.vue | 10 +- 2 files changed, 151 insertions(+), 127 deletions(-) diff --git a/packages/hoppscotch-common/src/components/teams/Team.vue b/packages/hoppscotch-common/src/components/teams/Team.vue index 123b63e74e..f8e854a350 100644 --- a/packages/hoppscotch-common/src/components/teams/Team.vue +++ b/packages/hoppscotch-common/src/components/teams/Team.vue @@ -3,134 +3,141 @@ class="flex flex-1 flex-col rounded border border-divider" @contextmenu.prevent="!compact ? options.tippy.show() : null" > -
-
- - -
+
+ + {{ t("state.loading") }}
-
- - - - - - + @@ -161,6 +168,8 @@ import IconMoreVertical from "~icons/lucide/more-vertical" import IconUserX from "~icons/lucide/user-x" import IconUserPlus from "~icons/lucide/user-plus" import IconTrash2 from "~icons/lucide/trash-2" +import { useService } from "dioc/vue" +import { WorkspaceService } from "~/services/workspace.service" const t = useI18n() @@ -173,6 +182,7 @@ const props = defineProps<{ const emit = defineEmits<{ (e: "edit-team"): void (e: "invite-team"): void + (e: "refetch-teams"): void }>() const toast = useToast() @@ -180,7 +190,12 @@ const toast = useToast() const confirmRemove = ref(false) const confirmExit = ref(false) +const loading = ref(false) + +const workspaceService = useService(WorkspaceService) + const deleteTeam = () => { + loading.value = true pipe( backendDeleteTeam(props.teamID), TE.match( @@ -188,9 +203,22 @@ const deleteTeam = () => { // TODO: Better errors ? We know the possible errors now toast.error(`${t("error.something_went_wrong")}`) console.error(err) + loading.value = false }, () => { toast.success(`${t("team.deleted")}`) + loading.value = false + emit("refetch-teams") + + const currentWorkspace = workspaceService.currentWorkspace.value + + // If the current workspace is the deleted team, change the workspace to personal + if ( + currentWorkspace.type === "team" && + currentWorkspace.teamID === props.teamID + ) { + workspaceService.changeWorkspace({ type: "personal" }) + } } ) )() // Tasks (and TEs) are lazy, so call the function returned diff --git a/packages/hoppscotch-common/src/components/teams/index.vue b/packages/hoppscotch-common/src/components/teams/index.vue index 2c3972ec5e..85c7206f9e 100644 --- a/packages/hoppscotch-common/src/components/teams/index.vue +++ b/packages/hoppscotch-common/src/components/teams/index.vue @@ -4,6 +4,7 @@
@@ -16,13 +17,6 @@ :alt="`${t('empty.teams')}`" :text="`${t('empty.teams')}`" > -
@@ -76,6 +71,7 @@ import { useReadonlyStream } from "@composables/stream" import { useColorMode } from "@composables/theming" import { WorkspaceService } from "~/services/workspace.service" import { useService } from "dioc/vue" +import IconPlus from "~icons/lucide/plus" const t = useI18n() From 38b2795eed1d771cebacbb54072864f283dea384 Mon Sep 17 00:00:00 2001 From: nivedin Date: Thu, 21 Mar 2024 19:58:00 +0530 Subject: [PATCH 2/3] refactor: close modal after resolve and remove spinner in team card --- .../src/components/teams/Team.vue | 250 +++++++++--------- 1 file changed, 123 insertions(+), 127 deletions(-) diff --git a/packages/hoppscotch-common/src/components/teams/Team.vue b/packages/hoppscotch-common/src/components/teams/Team.vue index f8e854a350..f07e65e332 100644 --- a/packages/hoppscotch-common/src/components/teams/Team.vue +++ b/packages/hoppscotch-common/src/components/teams/Team.vue @@ -3,137 +3,131 @@ class="flex flex-1 flex-col rounded border border-divider" @contextmenu.prevent="!compact ? options.tippy.show() : null" > -
- - {{ t("state.loading") }} -
- + /> + +
+ + + +
{ const currentWorkspace = workspaceService.currentWorkspace.value - // If the current workspace is the deleted team, change the workspace to personal + // If the current workspace is the deleted workspace, change the workspace to personal if ( currentWorkspace.type === "team" && currentWorkspace.teamID === props.teamID ) { workspaceService.changeWorkspace({ type: "personal" }) } + + confirmRemove.value = false } ) )() // Tasks (and TEs) are lazy, so call the function returned From ebc18d005c0143309c001eab886d451b2f3edcee Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Fri, 22 Mar 2024 17:52:50 +0530 Subject: [PATCH 3/3] chore: close the confirmation modal if the team deletion attempt fails --- packages/hoppscotch-common/src/components/teams/Team.vue | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/hoppscotch-common/src/components/teams/Team.vue b/packages/hoppscotch-common/src/components/teams/Team.vue index f07e65e332..76b51bf4e7 100644 --- a/packages/hoppscotch-common/src/components/teams/Team.vue +++ b/packages/hoppscotch-common/src/components/teams/Team.vue @@ -198,6 +198,7 @@ const deleteTeam = () => { toast.error(`${t("error.something_went_wrong")}`) console.error(err) loading.value = false + confirmRemove.value = false }, () => { toast.success(`${t("team.deleted")}`)