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
apolloClient, .overwriteRequestTeams(
JSON.stringify(requestUpdated), apolloClient,
requestUpdated.name, JSON.stringify(requestUpdated),
picked.value.requestID requestUpdated.name,
) 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,21 +300,30 @@ 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")
const req = await teamUtils.saveRequestAsTeams( try {
apolloClient, const req = await teamUtils.saveRequestAsTeams(
JSON.stringify(requestUpdated), apolloClient,
requestUpdated.name, JSON.stringify(requestUpdated),
collectionsType.value.selectedTeam.id, requestUpdated.name,
picked.value.folderID collectionsType.value.selectedTeam.id,
) picked.value.folderID
)
if (req && req.id) { if (req && req.id) {
setRESTSaveContext({ setRESTSaveContext({
originLocation: "team-collection", originLocation: "team-collection",
requestID: req.id, requestID: req.id,
teamID: collectionsType.value.selectedTeam.id, teamID: collectionsType.value.selectedTeam.id,
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))
@@ -306,21 +332,30 @@ 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")
const req = await teamUtils.saveRequestAsTeams( try {
apolloClient, const req = await teamUtils.saveRequestAsTeams(
JSON.stringify(requestUpdated), apolloClient,
requestUpdated.name, JSON.stringify(requestUpdated),
collectionsType.value.selectedTeam.id, requestUpdated.name,
picked.value.collectionID collectionsType.value.selectedTeam.id,
) picked.value.collectionID
)
if (req && req.id) { if (req && req.id) {
setRESTSaveContext({ setRESTSaveContext({
originLocation: "team-collection", originLocation: "team-collection",
requestID: req.id, requestID: req.id,
teamID: collectionsType.value.selectedTeam.id, teamID: collectionsType.value.selectedTeam.id,
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 ?
@@ -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
) )
.then(() => {
$toast.success(`${t("request.saved")}`, {
icon: "playlist_add_check",
})
})
.catch(() => {
$toast.error(t("profile.no_permission").toString(), {
icon: "error_outline",
})
})
} catch (error) { } catch (error) {
showSaveRequestModal.value = true 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", () => { defineActionHandler("request.send-cancel", () => {