Skip to content

Commit

Permalink
perf(proposals): update project proposal approval buttons to use ofetch
Browse files Browse the repository at this point in the history
  • Loading branch information
brucetony committed Sep 9, 2024
1 parent 5aedb47 commit f46f9cc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 30 deletions.
19 changes: 12 additions & 7 deletions components/projects/ApproveRejectButtons.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<script setup lang="ts">
import { approveRejectProjectProposal } from "~/composables/useAPIFetch";
import { useToastService } from "~/composables/connectionErrorToast";
const props = defineProps({
Expand All @@ -13,14 +12,20 @@ const emit = defineEmits(["updatedRow"]);
async function onSubmitProjectApproval(isApproved: boolean) {
loading.value = true;
const { data: response, status } = await approveRejectProjectProposal(
isApproved,
props.projectId!,
);
if (status.value === "success") {
const formData = new FormData();
formData.append("approval_status", isApproved ? "approved" : "rejected");
const approvalResp = await useNuxtApp()
.$hubApi(`/project-nodes/${props.projectId}`, {
method: "POST",
body: formData,
})
.catch(() => null);
if (approvalResp) {
showSuccessfulSubmission(isApproved);
// Send data to parent component
emit("updatedRow", response.value);
emit("updatedRow", approvalResp);
} else {
showFailedSubmission();
}
Expand Down
23 changes: 0 additions & 23 deletions composables/useAPIFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,6 @@ export function useAPIFetch<T>(
}

// Hub endpoints
export function approveRejectProjectProposal(
approved: boolean,
project_id: string,
) {
const formData = new FormData();
formData.append("approval_status", approved ? "approved" : "rejected");

return useAPIFetch(`/project-nodes/${project_id}`, {
method: "POST",
body: formData,
});
}

export function getProposals(opts?) {
return useAPIFetch<{ data: ListProjectNodes }>("/project-nodes", {
...opts,
Expand Down Expand Up @@ -84,16 +71,6 @@ export function getAnalysisNodes(opts?) {
);
}

export function updateAnalysis(analysis_id: string, updates) {
// const formData = new FormData();
// formData.append("approval_status", approved ? "approved" : "rejected");

return useAPIFetch(`/analyses/${analysis_id}`, {
method: "POST",
body: updates,
});
}

// Kong endpoints
export function getDataStores(includeProject: boolean, opts?) {
// return nuxtApp.$hubApi("/kong/datastore", {
Expand Down

0 comments on commit f46f9cc

Please sign in to comment.