diff --git a/packages/hoppscotch-app/components/collections/SaveRequest.vue b/packages/hoppscotch-app/components/collections/SaveRequest.vue index d7370e5f7..c412503c6 100644 --- a/packages/hoppscotch-app/components/collections/SaveRequest.vue +++ b/packages/hoppscotch-app/components/collections/SaveRequest.vue @@ -231,6 +231,8 @@ const saveRequestAs = async () => { folderPath: picked.value.folderPath, requestIndex: picked.value.requestIndex, }) + + requestSaved() } else if (picked.value.pickedType === "my-folder") { if (!isHoppRESTRequest(requestUpdated)) throw new Error("requestUpdated is not a REST Request") @@ -245,6 +247,8 @@ const saveRequestAs = async () => { folderPath: picked.value.folderPath, requestIndex: insertionIndex, }) + + requestSaved() } else if (picked.value.pickedType === "my-collection") { if (!isHoppRESTRequest(requestUpdated)) throw new Error("requestUpdated is not a REST Request") @@ -253,11 +257,14 @@ const saveRequestAs = async () => { `${picked.value.collectionIndex}`, requestUpdated ) + setRESTSaveContext({ originLocation: "user-collection", folderPath: `${picked.value.collectionIndex}`, requestIndex: insertionIndex, }) + + requestSaved() } else if (picked.value.pickedType === "teams-request") { if (!isHoppRESTRequest(requestUpdated)) throw new Error("requestUpdated is not a REST Request") @@ -265,12 +272,22 @@ const saveRequestAs = async () => { if (collectionsType.value.type !== "team-collections") throw new Error("Collections Type mismatch") - teamUtils.overwriteRequestTeams( - apolloClient, - JSON.stringify(requestUpdated), - requestUpdated.name, - picked.value.requestID - ) + teamUtils + .overwriteRequestTeams( + apolloClient, + JSON.stringify(requestUpdated), + requestUpdated.name, + picked.value.requestID + ) + .then(() => { + requestSaved() + }) + .catch((error) => { + $toast.error(t("profile.no_permission").toString(), { + icon: "error_outline", + }) + throw new Error(error) + }) setRESTSaveContext({ originLocation: "team-collection", @@ -283,21 +300,30 @@ const saveRequestAs = async () => { if (collectionsType.value.type !== "team-collections") throw new Error("Collections Type mismatch") - const req = await teamUtils.saveRequestAsTeams( - apolloClient, - JSON.stringify(requestUpdated), - requestUpdated.name, - collectionsType.value.selectedTeam.id, - picked.value.folderID - ) + try { + const req = await teamUtils.saveRequestAsTeams( + apolloClient, + JSON.stringify(requestUpdated), + requestUpdated.name, + collectionsType.value.selectedTeam.id, + picked.value.folderID + ) - if (req && req.id) { - setRESTSaveContext({ - originLocation: "team-collection", - requestID: req.id, - teamID: collectionsType.value.selectedTeam.id, - collectionID: picked.value.folderID, + if (req && req.id) { + setRESTSaveContext({ + originLocation: "team-collection", + requestID: req.id, + teamID: collectionsType.value.selectedTeam.id, + collectionID: picked.value.folderID, + }) + } + + requestSaved() + } catch (error) { + $toast.error(t("profile.no_permission").toString(), { + icon: "error_outline", }) + console.error(error) } } else if (picked.value.pickedType === "teams-collection") { if (!isHoppRESTRequest(requestUpdated)) @@ -306,21 +332,30 @@ const saveRequestAs = async () => { if (collectionsType.value.type !== "team-collections") throw new Error("Collections Type mismatch") - const req = await teamUtils.saveRequestAsTeams( - apolloClient, - JSON.stringify(requestUpdated), - requestUpdated.name, - collectionsType.value.selectedTeam.id, - picked.value.collectionID - ) + try { + const req = await teamUtils.saveRequestAsTeams( + apolloClient, + JSON.stringify(requestUpdated), + requestUpdated.name, + collectionsType.value.selectedTeam.id, + picked.value.collectionID + ) - if (req && req.id) { - setRESTSaveContext({ - originLocation: "team-collection", - requestID: req.id, - teamID: collectionsType.value.selectedTeam.id, - collectionID: picked.value.collectionID, + if (req && req.id) { + setRESTSaveContext({ + originLocation: "team-collection", + requestID: req.id, + teamID: collectionsType.value.selectedTeam.id, + collectionID: picked.value.collectionID, + }) + } + + requestSaved() + } catch (error) { + $toast.error(t("profile.no_permission").toString(), { + icon: "error_outline", }) + console.error(error) } } else if (picked.value.pickedType === "gql-my-request") { // TODO: Check for GQL request ? @@ -329,19 +364,28 @@ const saveRequestAs = async () => { picked.value.requestIndex, requestUpdated as HoppGQLRequest ) + + requestSaved() } else if (picked.value.pickedType === "gql-my-folder") { // TODO: Check for GQL request ? saveGraphqlRequestAs( picked.value.folderPath, requestUpdated as HoppGQLRequest ) + + requestSaved() } else if (picked.value.pickedType === "gql-my-collection") { // TODO: Check for GQL request ? saveGraphqlRequestAs( `${picked.value.collectionIndex}`, requestUpdated as HoppGQLRequest ) + + requestSaved() } +} + +const requestSaved = () => { $toast.success(`${t("request.added")}`, { icon: "post_add", }) diff --git a/packages/hoppscotch-app/components/http/Request.vue b/packages/hoppscotch-app/components/http/Request.vue index 042903fde..f13e2e854 100644 --- a/packages/hoppscotch-app/components/http/Request.vue +++ b/packages/hoppscotch-app/components/http/Request.vue @@ -382,6 +382,9 @@ const saveRequest = () => { if (saveCtx.originLocation === "user-collection") { editRESTRequest(saveCtx.folderPath, saveCtx.requestIndex, getRESTRequest()) + $toast.success(`${t("request.saved")}`, { + icon: "playlist_add_check", + }) } else if (saveCtx.originLocation === "team-collection") { const req = getRESTRequest() @@ -393,14 +396,24 @@ const saveRequest = () => { req.name, saveCtx.requestID ) + .then(() => { + $toast.success(`${t("request.saved")}`, { + icon: "playlist_add_check", + }) + }) + .catch(() => { + $toast.error(t("profile.no_permission").toString(), { + icon: "error_outline", + }) + }) } catch (error) { showSaveRequestModal.value = true - return + $toast.error(t("error.something_went_wrong").toString(), { + icon: "error_outline", + }) + console.error(error) } } - $toast.success(`${t("request.saved")}`, { - icon: "playlist_add_check", - }) } defineActionHandler("request.send-cancel", () => {