forked from trent_larson/crowd-funder-for-time-pwa
feat: adjust to the new endpoints for editable plan records
This commit is contained in:
@@ -17,6 +17,10 @@
|
||||
<!-- Project Details -->
|
||||
<!-- Image - (see design model) Empty -->
|
||||
|
||||
<div>
|
||||
{{ errorMessage }}
|
||||
</div>
|
||||
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Project Name"
|
||||
@@ -67,10 +71,9 @@ import { useAppStore } from "@/store/app";
|
||||
export default class NewEditProjectView extends Vue {
|
||||
projectName = "";
|
||||
description = "";
|
||||
projectId =
|
||||
localStorage.getItem("projectId") === null
|
||||
? ""
|
||||
: localStorage.getItem("projectId");
|
||||
errorMessage = "";
|
||||
|
||||
projectId = localStorage.getItem("projectId") || "";
|
||||
|
||||
async created() {
|
||||
if (this.projectId === "") {
|
||||
@@ -90,7 +93,8 @@ export default class NewEditProjectView extends Vue {
|
||||
|
||||
async LoadProject(identity: IIdentifier) {
|
||||
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER;
|
||||
const url = endorserApiServer + "/api/claim/" + this.projectId;
|
||||
const url =
|
||||
endorserApiServer + "/api/plan/" + encodeURIComponent(this.projectId);
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
@@ -111,12 +115,10 @@ export default class NewEditProjectView extends Vue {
|
||||
}
|
||||
|
||||
private async SaveProject(identity: IIdentifier) {
|
||||
const address = identity.did;
|
||||
// Make a claim
|
||||
const vcClaim = {
|
||||
"@context": "https://schema.org",
|
||||
"@type": "PlanAction",
|
||||
identifier: address,
|
||||
name: this.projectName,
|
||||
description: this.description,
|
||||
};
|
||||
@@ -149,7 +151,7 @@ export default class NewEditProjectView extends Vue {
|
||||
|
||||
const payload = JSON.stringify({ jwtEncoded: vcJwt });
|
||||
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER;
|
||||
const url = endorserApiServer + "/api/claim";
|
||||
const url = endorserApiServer + "/api/v2/claim";
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
@@ -158,21 +160,37 @@ export default class NewEditProjectView extends Vue {
|
||||
|
||||
try {
|
||||
const resp = await this.axios.post(url, payload, { headers });
|
||||
useAppStore().setProjectId(resp.data);
|
||||
setTimeout(
|
||||
function (that: Vue) {
|
||||
console.log("THAT:", localStorage.getItem("projectId"));
|
||||
const route = {
|
||||
name: "project",
|
||||
};
|
||||
console.log(route);
|
||||
that.$router.push(route);
|
||||
},
|
||||
2000,
|
||||
this
|
||||
);
|
||||
} catch (error) {
|
||||
console.log(error);
|
||||
console.log("Got resp data:", resp.data);
|
||||
if (resp.data?.success?.fullIri) {
|
||||
this.errorMessage = "";
|
||||
useAppStore().setProjectId(resp.data.success.fullIri);
|
||||
setTimeout(
|
||||
function (that: Vue) {
|
||||
console.log("THAT:", localStorage.getItem("projectId"));
|
||||
const route = {
|
||||
name: "project",
|
||||
};
|
||||
console.log(route);
|
||||
that.$router.push(route);
|
||||
},
|
||||
2000,
|
||||
this
|
||||
);
|
||||
}
|
||||
} catch (error: any) {
|
||||
let userMessage = "There was an error. See logs for more info.";
|
||||
const serverError = error.response?.data?.error;
|
||||
if (serverError) {
|
||||
if (serverError.message) {
|
||||
userMessage = serverError.message; // This is info for the user.
|
||||
} else {
|
||||
console.log("Server gave an error:", serverError);
|
||||
}
|
||||
} else {
|
||||
console.log("Here's the full error trying to save the claim:", error);
|
||||
}
|
||||
// Now set that error for the user to see.
|
||||
this.errorMessage = userMessage;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,10 +157,7 @@ export default class ProjectViewView extends Vue {
|
||||
truncatedDesc = "";
|
||||
truncateLength = 40;
|
||||
timeSince = "";
|
||||
projectId =
|
||||
localStorage.getItem("projectId") === null
|
||||
? ""
|
||||
: localStorage.getItem("projectId");
|
||||
projectId = localStorage.getItem("projectId") || "";
|
||||
|
||||
onEditClick() {
|
||||
localStorage.setItem("projectId", this.projectId as string);
|
||||
@@ -181,7 +178,8 @@ export default class ProjectViewView extends Vue {
|
||||
|
||||
async LoadProject(identity: IIdentifier) {
|
||||
const endorserApiServer = AppString.DEFAULT_ENDORSER_API_SERVER;
|
||||
const url = endorserApiServer + "/api/claim/" + this.projectId;
|
||||
const url =
|
||||
endorserApiServer + "/api/plan/" + encodeURIComponent(this.projectId);
|
||||
const token = await accessToken(identity);
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
@@ -192,13 +190,12 @@ export default class ProjectViewView extends Vue {
|
||||
const resp = await this.axios.get(url, { headers });
|
||||
console.log(resp.status, resp.data);
|
||||
if (resp.status === 200) {
|
||||
const claim = resp.data.claim;
|
||||
const issuedAt = resp.data.issuedAt;
|
||||
const eventDate = new Date(issuedAt);
|
||||
const startTime = resp.data.startTime;
|
||||
const eventDate = new Date(startTime);
|
||||
const now = moment.now();
|
||||
this.timeSince = moment.utc(now).to(eventDate);
|
||||
this.name = claim.name;
|
||||
this.description = claim.description;
|
||||
this.name = resp.data.name;
|
||||
this.description = resp.data.description;
|
||||
this.truncatedDesc = this.description.slice(0, this.truncateLength);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -96,13 +96,14 @@ export default class ProjectsView extends Vue {
|
||||
const resp = await this.axios.get(url, { headers });
|
||||
if (resp.status === 200) {
|
||||
const claims = resp.data;
|
||||
console.log("All claims:", claims);
|
||||
for (let i = 0; i < claims.length; i++) {
|
||||
console.log(claims[i]);
|
||||
const claim = claims[i].claim;
|
||||
const data = {
|
||||
id: claims[i].id,
|
||||
name: claim.name,
|
||||
description: claim.description,
|
||||
identifier: claim.identifier,
|
||||
};
|
||||
this.projects.push(data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user