Browse Source

give-detail page: add more-correct parameters from confirm-give page, and allow toggling of project & user-recipient

Trent Larson 5 months ago
parent
commit
b87142d3ed
  1. 2
      src/main.ts
  2. 163
      src/views/ConfirmGiftView.vue
  3. 58
      src/views/GiftedDetails.vue

2
src/main.ts

@ -69,6 +69,7 @@ import {
faRotate, faRotate,
faShareNodes, faShareNodes,
faSpinner, faSpinner,
faSquare,
faSquareCaretDown, faSquareCaretDown,
faSquareCaretUp, faSquareCaretUp,
faSquarePlus, faSquarePlus,
@ -138,6 +139,7 @@ library.add(
faRotate, faRotate,
faShareNodes, faShareNodes,
faSpinner, faSpinner,
faSquare,
faSquareCaretDown, faSquareCaretDown,
faSquareCaretUp, faSquareCaretUp,
faSquarePlus, faSquarePlus,

163
src/views/ConfirmGiftView.vue

@ -27,7 +27,7 @@
</h1> </h1>
</div> </div>
<div v-if="detailsForGive"> <div v-if="giveDetails">
<div class="flex justify-center"> <div class="flex justify-center">
<button <button
class="col-span-1 bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-4 py-2 rounded-md" class="col-span-1 bg-gradient-to-b from-blue-400 to-blue-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-4 py-2 rounded-md"
@ -69,19 +69,19 @@
{{ giverName }} {{ giverName }}
</div> </div>
<div class="ml-6">gave</div> <div class="ml-6">gave</div>
<div v-if="veriClaim.claim?.object"> <div v-if="giveDetails.amount">
<fa icon="hand-holding-dollar" class="fa-fw text-slate-400" /> <fa icon="hand-holding-dollar" class="fa-fw text-slate-400" />
{{ {{
displayAmount( displayAmount(
veriClaim.claim.object.unitCode, giveDetails.unit,
veriClaim.claim.object.amountOfThisGood, giveDetails.amount,
) )
}} }}
</div> </div>
<div> <div v-if="giveDetails.description">
<fa icon="message" class="fa-fw text-slate-400" /> <fa icon="message" class="fa-fw text-slate-400" />
{{ veriClaim.claim?.object ? "and:" : "" }} {{ giveDetails.amount ? "and:" : "" }}
{{ veriClaim.claim?.description }} {{ giveDetails.description }}
</div> </div>
<div class="ml-6">to</div> <div class="ml-6">to</div>
<div> <div>
@ -91,17 +91,17 @@
<div> <div>
<fa icon="calendar" class="fa-fw text-slate-400" /> <fa icon="calendar" class="fa-fw text-slate-400" />
on on
{{ veriClaim.issuedAt?.substring(0, 10) }} {{ giveDetails.issuedAt.substring(0, 10) }}
</div> </div>
<!-- Fullfills Links --> <!-- Fullfills Links -->
<!-- fullfills links for a give --> <!-- fullfills links for a give -->
<div class="mt-2" v-if="detailsForGive?.fulfillsPlanHandleId"> <div class="mt-2" v-if="giveDetails?.fulfillsPlanHandleId">
<router-link <router-link
:to=" :to="
'/project/' + '/project/' +
encodeURIComponent(detailsForGive?.fulfillsPlanHandleId) encodeURIComponent(giveDetails?.fulfillsPlanHandleId)
" "
class="text-blue-500 mt-2 cursor-pointer" class="text-blue-500 mt-2 cursor-pointer"
target="_blank" target="_blank"
@ -113,16 +113,16 @@
<!-- if there's another, it's probably fulfilling an offer, too --> <!-- if there's another, it's probably fulfilling an offer, too -->
<div <div
v-if=" v-if="
detailsForGive?.fulfillsType && giveDetails?.fulfillsType &&
detailsForGive?.fulfillsType !== 'PlanAction' && giveDetails?.fulfillsType !== 'PlanAction' &&
detailsForGive?.fulfillsHandleId giveDetails?.fulfillsHandleId
" "
> >
<!-- router-link to /claim/ only changes URL path --> <!-- router-link to /claim/ only changes URL path -->
<router-link <router-link
:to=" :to="
'/claim/' + '/claim/' +
encodeURIComponent(detailsForGive?.fulfillsHandleId) encodeURIComponent(giveDetails?.fulfillsHandleId)
" "
class="text-blue-500 mt-2 cursor-pointer" class="text-blue-500 mt-2 cursor-pointer"
target="_blank" target="_blank"
@ -130,7 +130,7 @@
This fulfills This fulfills
{{ {{
capitalizeAndInsertSpacesBeforeCapsWithAPrefix( capitalizeAndInsertSpacesBeforeCapsWithAPrefix(
detailsForGive.fulfillsType, giveDetails.fulfillsType,
) )
}} }}
<fa icon="arrow-up-right-from-square" class="fa-fw" /> <fa icon="arrow-up-right-from-square" class="fa-fw" />
@ -254,7 +254,7 @@
<div v-if="confirmerIdList.includes(activeDid)"> <div v-if="confirmerIdList.includes(activeDid)">
You have confirmed this claim. You have confirmed this claim.
</div> </div>
<div v-else-if="veriClaim.issuer == activeDid"> <div v-else-if="giveDetails.agentDid == activeDid">
You cannot confirm this because you issued this claim, so you already You cannot confirm this because you issued this claim, so you already
count as confirming it. count as confirming it.
</div> </div>
@ -428,7 +428,7 @@ export default class ClaimView extends Vue {
confirmerIdList: string[] = []; // list of DIDs that have confirmed this claim excluding the issuer confirmerIdList: string[] = []; // list of DIDs that have confirmed this claim excluding the issuer
confsVisibleErrorMessage = ""; confsVisibleErrorMessage = "";
confsVisibleToIdList: string[] = []; // list of DIDs that can see any confirmer confsVisibleToIdList: string[] = []; // list of DIDs that can see any confirmer
detailsForGive = null; giveDetails = null;
giverName = ""; giverName = "";
issuerName = ""; issuerName = "";
numConfsNotVisible = 0; // number of hidden DIDs in the confirmerIdList, minus the issuer if they aren't visible numConfsNotVisible = 0; // number of hidden DIDs in the confirmerIdList, minus the issuer if they aren't visible
@ -449,7 +449,7 @@ export default class ClaimView extends Vue {
this.confirmerIdList = []; this.confirmerIdList = [];
this.confsVisibleErrorMessage = ""; this.confsVisibleErrorMessage = "";
this.confsVisibleToIdList = []; this.confsVisibleToIdList = [];
this.detailsForGive = null; this.giveDetails = null;
this.numConfsNotVisible = 0; this.numConfsNotVisible = 0;
this.urlForNewGive = ""; this.urlForNewGive = "";
this.veriClaim = serverUtil.BLANK_GENERIC_SERVER_RECORD; this.veriClaim = serverUtil.BLANK_GENERIC_SERVER_RECORD;
@ -603,64 +603,7 @@ export default class ClaimView extends Vue {
this.issuerName = this.didInfo(this.veriClaim.issuer); this.issuerName = this.didInfo(this.veriClaim.issuer);
this.urlForNewGive = "/gifted-details?"; // use give record when possible since it may include edits
if (this.veriClaim.claim.object) {
if (this.veriClaim.claim.object.amountOfThisGood) {
this.urlForNewGive +=
"&amountInput=" +
encodeURIComponent(
String(this.veriClaim.claim.object.amountOfThisGood),
);
}
if (this.veriClaim.claim.object.unitCode) {
this.urlForNewGive +=
"&unitCode=" +
encodeURIComponent(this.veriClaim.claim.object.unitCode as string);
}
}
if (this.veriClaim.claim.description) {
this.urlForNewGive +=
"&description=" +
encodeURIComponent(this.veriClaim.claim.description as string);
}
this.giverName = this.didInfo(
this.veriClaim.claim.agent?.identifier as string,
);
if (this.veriClaim.claim.agent) {
this.urlForNewGive +=
"&giverDid=" +
encodeURIComponent(this.veriClaim.claim.agent.identifier as string) +
"&giverName=" +
encodeURIComponent(this.giverName);
}
this.recipientName = this.didInfo(
this.veriClaim.claim.recipient?.identifier as string,
);
if (this.veriClaim.claim.recipient) {
this.urlForNewGive +=
"&recipientDid=" +
encodeURIComponent(
this.veriClaim.claim.recipient.identifier as string,
) +
"&recipientName=" +
encodeURIComponent(this.recipientName);
}
if (this.veriClaim.claim.image) {
this.urlForNewGive +=
"&image=" + encodeURIComponent(this.veriClaim.claim.image as string);
}
if (this.veriClaim.claim.fulfills) {
this.urlForNewGive += this.fulfillsUrlSnippet(
this.veriClaim.claim.fulfills,
);
if (Array.isArray(this.veriClaim.claim.fulfills)) {
for (const fulfills of this.veriClaim.claim.fulfills) {
console.log("adding fulfills:", fulfills);
this.urlForNewGive += this.fulfillsUrlSnippet(fulfills);
}
}
}
const giveUrl = const giveUrl =
this.apiServer + this.apiServer +
"/api/v2/report/gives?handleId=" + "/api/v2/report/gives?handleId=" +
@ -671,7 +614,7 @@ export default class ClaimView extends Vue {
}); });
// giveResp.data is a Give from https://api.endorser.ch/api-docs/ // giveResp.data is a Give from https://api.endorser.ch/api-docs/
if (giveResp.status === 200) { if (giveResp.status === 200) {
this.detailsForGive = giveResp.data.data[0]; this.giveDetails = giveResp.data.data[0];
} else { } else {
console.error("Error getting detailed give info:", giveResp); console.error("Error getting detailed give info:", giveResp);
this.$notify( this.$notify(
@ -685,6 +628,52 @@ export default class ClaimView extends Vue {
); );
} }
this.urlForNewGive = "/gifted-details?";
if (this.giveDetails.amount) {
this.urlForNewGive +=
"&amountInput=" + encodeURIComponent(String(this.giveDetails.amount));
}
if (this.giveDetails.unit) {
this.urlForNewGive +=
"&unitCode=" + encodeURIComponent(this.giveDetails.unit);
}
if (this.giveDetails.description) {
this.urlForNewGive +=
"&description=" + encodeURIComponent(this.giveDetails.description);
}
this.giverName = this.didInfo(this.giveDetails.agentDid);
if (this.giveDetails.agentDid) {
this.urlForNewGive +=
"&giverDid=" +
encodeURIComponent(this.giveDetails.agentDid) +
"&giverName=" +
encodeURIComponent(this.giverName);
}
this.recipientName = this.didInfo(this.giveDetails.recipientDid);
if (this.giveDetails.recipientDid) {
this.urlForNewGive +=
"&recipientDid=" +
encodeURIComponent(this.giveDetails.recipientDid) +
"&recipientName=" +
encodeURIComponent(this.recipientName);
}
if (this.giveDetails.fullClaim.image) {
this.urlForNewGive +=
"&image=" + encodeURIComponent(this.giveDetails.fullClaim.image);
}
if (
this.giveDetails.type == "Offer" &&
this.giveDetails.fulfillsHandleId
) {
this.urlForNewGive +=
"&offerId=" + encodeURIComponent(this.giveDetails.fulfillsHandleId);
}
if (this.giveDetails.fulfillsPlanHandleId) {
this.urlForNewGive +=
"&projectId=" +
encodeURIComponent(this.giveDetails.fulfillsPlanHandleId);
}
// retrieve the list of confirmers // retrieve the list of confirmers
const confirmUrl = const confirmUrl =
this.apiServer + this.apiServer +
@ -698,7 +687,7 @@ export default class ClaimView extends Vue {
const resultList1 = response.data.result || []; const resultList1 = response.data.result || [];
const resultList2 = R.reject(serverUtil.isHiddenDid, resultList1); const resultList2 = R.reject(serverUtil.isHiddenDid, resultList1);
const resultList3 = R.reject( const resultList3 = R.reject(
(did: string) => did === this.veriClaim.issuer, (did: string) => did === this.giveDetails.agentDid,
resultList2, resultList2,
); );
this.confirmerIdList = resultList3; this.confirmerIdList = resultList3;
@ -729,16 +718,6 @@ export default class ClaimView extends Vue {
} }
} }
fulfillsUrlSnippet(object) {
if (object["@type"] === "PlanAction") {
return "&projectId=" + encodeURIComponent(object.identifier);
} else if (object["@type"] === "OfferAction") {
return "&offerId=" + encodeURIComponent(object.identifier);
} else {
return "";
}
}
confirmConfirmClaim() { confirmConfirmClaim() {
this.$notify( this.$notify(
{ {
@ -785,7 +764,7 @@ export default class ClaimView extends Vue {
title: "Success", title: "Success",
text: "Confirmation submitted.", text: "Confirmation submitted.",
}, },
5000, 3000,
); );
} else { } else {
console.error("Got error submitting the confirmation:", result); console.error("Got error submitting the confirmation:", result);
@ -818,7 +797,7 @@ export default class ClaimView extends Vue {
(this.$refs.customGiveDialog as GiftedDialog).open( (this.$refs.customGiveDialog as GiftedDialog).open(
giver, giver,
undefined, undefined,
this.veriClaim.handleId, this.giveDetails.handleId,
"Offer fulfilled by " + (giver?.name || "someone not named"), "Offer fulfilled by " + (giver?.name || "someone not named"),
); );
} }
@ -860,7 +839,7 @@ export default class ClaimView extends Vue {
}, },
3000, 3000,
); );
} else if (this.veriClaim.issuer == this.activeDid) { } else if (this.giveDetails.agentDid == this.activeDid) {
this.$notify( this.$notify(
{ {
group: "alert", group: "alert",
@ -870,7 +849,7 @@ export default class ClaimView extends Vue {
}, },
3000, 3000,
); );
} else if (serverUtil.containsHiddenDid(this.veriClaim.claim)) { } else if (serverUtil.containsHiddenDid(this.giveDetails.fullClaim)) {
this.$notify( this.$notify(
{ {
group: "alert", group: "alert",

58
src/views/GiftedDetails.vue

@ -76,17 +76,40 @@
</div> </div>
<ImageMethodDialog ref="imageDialog" /> <ImageMethodDialog ref="imageDialog" />
<div v-if="projectId" class="mt-4"> <div class="mt-4">
<input
v-if="!givenToUser"
type="checkbox"
class="h-6 w-6 mr-2"
v-model="givenToProject"
/>
<fa <fa
icon="check" v-else
class="bg-slate-500 text-white h-5 w-5 px-0.5 py-0.5 mr-2 rounded" icon="square"
class="bg-slate-500 text-slate-500 h-5 w-5 px-0.5 py-0.5 mr-2 rounded"
@click="
notifyUser('Cannot be both given to you and also given to a project.')
"
/> />
<label class="text-sm">This is given to {{ projectName }}</label> <label class="text-sm">This was given to {{ projectName }}</label>
</div> </div>
<div v-if="showGivenToUser" class="mt-4"> <div class="mt-4">
<input type="checkbox" class="h-6 w-6 mr-2" v-model="givenToUser" /> <input
<label class="text-sm">Given to you</label> v-if="!givenToProject"
type="checkbox"
class="h-6 w-6 mr-2"
v-model="givenToUser"
/>
<fa
v-else
icon="square"
class="bg-slate-500 text-slate-500 h-5 w-5 px-0.5 py-0.5 mr-2 rounded"
@click="
notifyUser('Cannot be both given to a project and also given to you.')
"
/>
<label class="text-sm">This was given to you</label>
</div> </div>
<div class="mt-4"> <div class="mt-4">
@ -148,6 +171,7 @@ export default class GiftedDetails extends Vue {
amountInput = "0"; amountInput = "0";
description = ""; description = "";
destinationNameAfter = ""; destinationNameAfter = "";
givenToProject = false;
givenToUser = false; givenToUser = false;
giverDid: string | undefined; giverDid: string | undefined;
giverName = ""; giverName = "";
@ -215,7 +239,8 @@ export default class GiftedDetails extends Vue {
this.recipientName = this.recipientName =
this.recipientDid === this.activeDid ? "you" : "someone not named"; this.recipientDid === this.activeDid ? "you" : "someone not named";
} }
this.showGivenToUser = this.givenToProject = !!this.projectId;
this.givenToUser =
!this.projectId && this.recipientDid === this.activeDid; !this.projectId && this.recipientDid === this.activeDid;
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
@ -241,7 +266,7 @@ export default class GiftedDetails extends Vue {
this.axios, this.axios,
this.apiServer, this.apiServer,
); );
// console.log("Got project name from cache", project); console.log("Got project name from cache", project);
this.projectName = project?.name this.projectName = project?.name
? "the project: " + project.name ? "the project: " + project.name
: "a project"; : "a project";
@ -413,6 +438,18 @@ export default class GiftedDetails extends Vue {
await this.recordGive(); await this.recordGive();
} }
notifyUser(message: string) {
this.$notify(
{
group: "alert",
type: "warning",
title: "Error",
text: message,
},
3000,
);
}
/** /**
* *
* @param giverDid may be null * @param giverDid may be null
@ -429,6 +466,7 @@ export default class GiftedDetails extends Vue {
? this.activeDid ? this.activeDid
: undefined : undefined
: this.recipientDid; : this.recipientDid;
const projectId = this.givenToProject ? this.projectId : undefined;
const result = await createAndSubmitGive( const result = await createAndSubmitGive(
this.axios, this.axios,
this.apiServer, this.apiServer,
@ -438,7 +476,7 @@ export default class GiftedDetails extends Vue {
this.description, this.description,
parseFloat(this.amountInput), parseFloat(this.amountInput),
this.unitCode, this.unitCode,
this.projectId, projectId,
this.offerId, this.offerId,
this.isTrade, this.isTrade,
this.imageUrl, this.imageUrl,

Loading…
Cancel
Save