feat: better prompts on actions for team members without admin role

This commit is contained in:
liyasthomas
2021-11-11 21:43:45 +05:30
parent 25878b9bb1
commit 1f637edd36
2 changed files with 93 additions and 36 deletions

View File

@@ -231,6 +231,8 @@ const saveRequestAs = async () => {
folderPath: picked.value.folderPath, folderPath: picked.value.folderPath,
requestIndex: picked.value.requestIndex, requestIndex: picked.value.requestIndex,
}) })
requestSaved()
} else if (picked.value.pickedType === "my-folder") { } else if (picked.value.pickedType === "my-folder") {
if (!isHoppRESTRequest(requestUpdated)) if (!isHoppRESTRequest(requestUpdated))
throw new Error("requestUpdated is not a REST Request") throw new Error("requestUpdated is not a REST Request")
@@ -245,6 +247,8 @@ const saveRequestAs = async () => {
folderPath: picked.value.folderPath, folderPath: picked.value.folderPath,
requestIndex: insertionIndex, requestIndex: insertionIndex,
}) })
requestSaved()
} else if (picked.value.pickedType === "my-collection") { } else if (picked.value.pickedType === "my-collection") {
if (!isHoppRESTRequest(requestUpdated)) if (!isHoppRESTRequest(requestUpdated))
throw new Error("requestUpdated is not a REST Request") throw new Error("requestUpdated is not a REST Request")
@@ -253,11 +257,14 @@ const saveRequestAs = async () => {
`${picked.value.collectionIndex}`, `${picked.value.collectionIndex}`,
requestUpdated requestUpdated
) )
setRESTSaveContext({ setRESTSaveContext({
originLocation: "user-collection", originLocation: "user-collection",
folderPath: `${picked.value.collectionIndex}`, folderPath: `${picked.value.collectionIndex}`,
requestIndex: insertionIndex, requestIndex: insertionIndex,
}) })
requestSaved()
} else if (picked.value.pickedType === "teams-request") { } else if (picked.value.pickedType === "teams-request") {
if (!isHoppRESTRequest(requestUpdated)) if (!isHoppRESTRequest(requestUpdated))
throw new Error("requestUpdated is not a REST Request") throw new Error("requestUpdated is not a REST Request")
@@ -265,12 +272,22 @@ const saveRequestAs = async () => {
if (collectionsType.value.type !== "team-collections") if (collectionsType.value.type !== "team-collections")
throw new Error("Collections Type mismatch") throw new Error("Collections Type mismatch")
teamUtils.overwriteRequestTeams( teamUtils
.overwriteRequestTeams(
apolloClient, apolloClient,
JSON.stringify(requestUpdated), JSON.stringify(requestUpdated),
requestUpdated.name, requestUpdated.name,
picked.value.requestID picked.value.requestID
) )
.then(() => {
requestSaved()
})
.catch((error) => {
$toast.error(t("profile.no_permission").toString(), {
icon: "error_outline",
})
throw new Error(error)
})
setRESTSaveContext({ setRESTSaveContext({
originLocation: "team-collection", originLocation: "team-collection",
@@ -283,6 +300,7 @@ const saveRequestAs = async () => {
if (collectionsType.value.type !== "team-collections") if (collectionsType.value.type !== "team-collections")
throw new Error("Collections Type mismatch") throw new Error("Collections Type mismatch")
try {
const req = await teamUtils.saveRequestAsTeams( const req = await teamUtils.saveRequestAsTeams(
apolloClient, apolloClient,
JSON.stringify(requestUpdated), JSON.stringify(requestUpdated),
@@ -299,6 +317,14 @@ const saveRequestAs = async () => {
collectionID: picked.value.folderID, 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") { } else if (picked.value.pickedType === "teams-collection") {
if (!isHoppRESTRequest(requestUpdated)) if (!isHoppRESTRequest(requestUpdated))
throw new Error("requestUpdated is not a REST Request") throw new Error("requestUpdated is not a REST Request")
@@ -306,6 +332,7 @@ const saveRequestAs = async () => {
if (collectionsType.value.type !== "team-collections") if (collectionsType.value.type !== "team-collections")
throw new Error("Collections Type mismatch") throw new Error("Collections Type mismatch")
try {
const req = await teamUtils.saveRequestAsTeams( const req = await teamUtils.saveRequestAsTeams(
apolloClient, apolloClient,
JSON.stringify(requestUpdated), JSON.stringify(requestUpdated),
@@ -322,6 +349,14 @@ const saveRequestAs = async () => {
collectionID: picked.value.collectionID, 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") { } else if (picked.value.pickedType === "gql-my-request") {
// TODO: Check for GQL request ? // TODO: Check for GQL request ?
editGraphqlRequest( editGraphqlRequest(
@@ -329,19 +364,28 @@ const saveRequestAs = async () => {
picked.value.requestIndex, picked.value.requestIndex,
requestUpdated as HoppGQLRequest requestUpdated as HoppGQLRequest
) )
requestSaved()
} else if (picked.value.pickedType === "gql-my-folder") { } else if (picked.value.pickedType === "gql-my-folder") {
// TODO: Check for GQL request ? // TODO: Check for GQL request ?
saveGraphqlRequestAs( saveGraphqlRequestAs(
picked.value.folderPath, picked.value.folderPath,
requestUpdated as HoppGQLRequest requestUpdated as HoppGQLRequest
) )
requestSaved()
} else if (picked.value.pickedType === "gql-my-collection") { } else if (picked.value.pickedType === "gql-my-collection") {
// TODO: Check for GQL request ? // TODO: Check for GQL request ?
saveGraphqlRequestAs( saveGraphqlRequestAs(
`${picked.value.collectionIndex}`, `${picked.value.collectionIndex}`,
requestUpdated as HoppGQLRequest requestUpdated as HoppGQLRequest
) )
requestSaved()
} }
}
const requestSaved = () => {
$toast.success(`${t("request.added")}`, { $toast.success(`${t("request.added")}`, {
icon: "post_add", icon: "post_add",
}) })

View File

@@ -382,6 +382,9 @@ const saveRequest = () => {
if (saveCtx.originLocation === "user-collection") { if (saveCtx.originLocation === "user-collection") {
editRESTRequest(saveCtx.folderPath, saveCtx.requestIndex, getRESTRequest()) editRESTRequest(saveCtx.folderPath, saveCtx.requestIndex, getRESTRequest())
$toast.success(`${t("request.saved")}`, {
icon: "playlist_add_check",
})
} else if (saveCtx.originLocation === "team-collection") { } else if (saveCtx.originLocation === "team-collection") {
const req = getRESTRequest() const req = getRESTRequest()
@@ -393,14 +396,24 @@ const saveRequest = () => {
req.name, req.name,
saveCtx.requestID saveCtx.requestID
) )
} catch (error) { .then(() => {
showSaveRequestModal.value = true
return
}
}
$toast.success(`${t("request.saved")}`, { $toast.success(`${t("request.saved")}`, {
icon: "playlist_add_check", icon: "playlist_add_check",
}) })
})
.catch(() => {
$toast.error(t("profile.no_permission").toString(), {
icon: "error_outline",
})
})
} catch (error) {
showSaveRequestModal.value = true
$toast.error(t("error.something_went_wrong").toString(), {
icon: "error_outline",
})
console.error(error)
}
}
} }
defineActionHandler("request.send-cancel", () => { defineActionHandler("request.send-cancel", () => {