+
Latest Activity
@@ -110,7 +114,7 @@ import GiftedDialog from "@/components/GiftedDialog.vue";
import { db, accountsDB } from "@/db";
import { MASTER_SETTINGS_KEY } from "@/db/tables/settings";
import { accessToken } from "@/libs/crypto";
-import { didInfo } from "@/libs/endorserServer";
+import { createAndSubmitGive, didInfo } from "@/libs/endorserServer";
import { Account } from "@/db/tables/accounts";
import { Contact } from "@/db/tables/contacts";
@@ -185,10 +189,12 @@ export default class HomeView extends Vue {
(acc) => acc.did === this.activeDid,
this.allAccounts
);
- console.log("about to parse from", this.activeDid, account?.identity);
+ //console.log("about to parse from", this.activeDid, account?.identity);
const identity = JSON.parse(account?.identity || "undefined");
const token = await accessToken(identity);
headers["Authorization"] = "Bearer " + token;
+ } else {
+ // it's OK without auth... we just won't get any identifiers
}
return fetch(this.apiServer + "/api/v2/report/gives?" + beforeQuery, {
method: "GET",
@@ -240,22 +246,66 @@ export default class HomeView extends Vue {
return unitCode === "HUR" ? (single ? "hour" : "hours") : unitCode;
}
- recordGive(contact) {
- console.log("recordGive", contact);
- }
-
openDialog(contact) {
this.$refs.customDialog.open(contact);
}
handleDialogResult(result) {
if (result.action === "confirm") {
return new Promise((resolve) => {
- console.log("Dialog confirmed: ", result.description);
+ this.recordGive(result.contact, result.description, result.hours);
resolve();
});
} else {
- // action was "cancel"
+ // action was "cancel" so do nothing
+ }
+ }
+
+ /**
+ *
+ * @param contact may be null
+ * @param description may be an empty string
+ * @param hours may be 0
+ */
+ recordGive(contact, description, hours) {
+ if (this.activeDid == null) {
+ this.alertTitle = "Error";
+ this.alertMessage =
+ "You must select an identity before you can record a give.";
+ return;
}
+ const account = R.find(
+ (acc) => acc.did === this.activeDid,
+ this.allAccounts
+ );
+ //console.log("about to parse from", this.activeDid, account?.identity);
+ const identity = JSON.parse(account?.identity || "undefined");
+ createAndSubmitGive(
+ this.axios,
+ this.apiServer,
+ identity,
+ contact?.did,
+ this.activeDid,
+ description,
+ hours
+ )
+ .then((result) => {
+ if (result.status != 201 || result.data?.error) {
+ console.log("Error with give result:", result);
+ this.alertTitle = "Error";
+ this.alertMessage =
+ result.data?.message || "There was an error recording the give.";
+ } else {
+ this.alertTitle = "Success";
+ this.alertMessage = "That gift was recorded.";
+ //this.updateAllFeed(); // full update is overkill but we should show something
+ }
+ })
+ .catch((e) => {
+ console.log("Error with give caught:", e);
+ this.alertTitle = "Error";
+ this.alertMessage =
+ e.userMessage || "There was an error recording the give.";
+ });
}
// This same popup code is in many files.