Browse Source

add error messages for gives

world-fix
Trent Larson 1 year ago
parent
commit
a8f1e25986
  1. 14
      src/views/HomeView.vue
  2. 26
      src/views/ProjectViewView.vue

14
src/views/HomeView.vue

@ -296,6 +296,12 @@ export default class HomeView extends Vue {
"You must select an identity before you can record a give."; "You must select an identity before you can record a give.";
return; return;
} }
if (!description && !hours) {
this.alertTitle = "Error";
this.alertMessage =
"You must enter a description or some number of hours.";
return;
}
const account = R.find( const account = R.find(
(acc) => acc.did === this.activeDid, (acc) => acc.did === this.activeDid,
this.allAccounts this.allAccounts
@ -319,7 +325,8 @@ export default class HomeView extends Vue {
console.log("Error with give result:", result); console.log("Error with give result:", result);
this.alertTitle = "Error"; this.alertTitle = "Error";
this.alertMessage = this.alertMessage =
result.data?.message || "There was an error recording the give."; result.data?.error?.message ||
"There was an error recording the give.";
} else { } else {
this.alertTitle = "Success"; this.alertTitle = "Success";
this.alertMessage = "That gift was recorded."; this.alertMessage = "That gift was recorded.";
@ -327,10 +334,13 @@ export default class HomeView extends Vue {
} }
}) })
.catch((e) => { .catch((e) => {
// axios throws errors on 400 responses
console.log("Error with give caught:", e); console.log("Error with give caught:", e);
this.alertTitle = "Error"; this.alertTitle = "Error";
this.alertMessage = this.alertMessage =
e.userMessage || "There was an error recording the give."; e.userMessage ||
e.response?.data?.error?.message ||
"There was an error recording the give.";
}); });
} }

26
src/views/ProjectViewView.vue

@ -179,6 +179,18 @@
</ul> </ul>
</div> </div>
--> -->
<!-- This same popup code is in many files. -->
<div v-bind:class="computedAlertClassNames()">
<button
class="close-button bg-slate-200 w-8 leading-loose rounded-full absolute top-2 right-2"
@click="onClickClose()"
>
<fa icon="xmark"></fa>
</button>
<h4 class="font-bold pr-5">{{ alertTitle }}</h4>
<p>{{ alertMessage }}</p>
</div>
</section> </section>
</template> </template>
@ -318,6 +330,12 @@ export default class ProjectViewView extends Vue {
"You must select an identity before you can record a give."; "You must select an identity before you can record a give.";
return; return;
} }
if (!description && !hours) {
this.alertTitle = "Error";
this.alertMessage =
"You must enter a description or some number of hours.";
return;
}
const accounts = await accountsDB.accounts.toArray(); const accounts = await accountsDB.accounts.toArray();
const account = R.find((acc) => acc.did === this.activeDid, accounts); const account = R.find((acc) => acc.did === this.activeDid, accounts);
const identity = JSON.parse(account?.identity || "null"); const identity = JSON.parse(account?.identity || "null");
@ -339,7 +357,8 @@ export default class ProjectViewView extends Vue {
console.log("Error with give result:", result); console.log("Error with give result:", result);
this.alertTitle = "Error"; this.alertTitle = "Error";
this.alertMessage = this.alertMessage =
result.data?.message || "There was an error recording the give."; result.data?.error?.message ||
"There was an error recording the give.";
} else { } else {
this.alertTitle = "Success"; this.alertTitle = "Success";
this.alertMessage = "That gift was recorded."; this.alertMessage = "That gift was recorded.";
@ -347,10 +366,13 @@ export default class ProjectViewView extends Vue {
} }
}) })
.catch((e) => { .catch((e) => {
// axios throws errors on 400 responses
console.log("Error with give caught:", e); console.log("Error with give caught:", e);
this.alertTitle = "Error"; this.alertTitle = "Error";
this.alertMessage = this.alertMessage =
e.userMessage || "There was an error recording the give."; e.userMessage ||
e.response?.data?.error?.message ||
"There was an error recording the give.";
}); });
} }

Loading…
Cancel
Save