diff --git a/src/components/GiftedDialog.vue b/src/components/GiftedDialog.vue index ba4e2f63..5e5e4bed 100644 --- a/src/components/GiftedDialog.vue +++ b/src/components/GiftedDialog.vue @@ -18,7 +18,7 @@ :to-project-id="toProjectId" :giver="giver" :receiver="receiver" - :notify="notify" + :notify="$notify" @entity-selected="handleEntitySelected" @cancel="cancel" /> @@ -85,6 +85,16 @@ export default class GiftedDialog extends Vue { $notify!: (notification: any, timeout?: number) => void; notify!: ReturnType; + /** + * Safe notification method that ensures notify helpers are available + */ + get safeNotify() { + if (!this.notify && this.$notify) { + this.notify = createNotifyHelpers(this.$notify); + } + return this.notify; + } + @Prop() fromProjectId = ""; @Prop() toProjectId = ""; @Prop({ default: false }) showProjects = false; @@ -258,7 +268,7 @@ export default class GiftedDialog extends Vue { } } catch (err: unknown) { logger.error("Error retrieving settings from database:", err); - this.notify.error( + this.safeNotify.error( err instanceof Error ? err.message : "There was an error retrieving your settings.", @@ -307,18 +317,21 @@ export default class GiftedDialog extends Vue { async confirm() { if (!this.activeDid) { - this.notify.error( + this.safeNotify.error( "You must select an identifier before you can record a give.", TIMEOUTS.STANDARD, ); return; } if (parseFloat(this.amountInput) < 0) { - this.notify.error("You may not send a negative number.", TIMEOUTS.SHORT); + this.safeNotify.error( + "You may not send a negative number.", + TIMEOUTS.SHORT, + ); return; } if (!this.description && !parseFloat(this.amountInput)) { - this.notify.error( + this.safeNotify.error( `You must enter a description or some number of ${ this.libsUtil.UNIT_LONG[this.unitCode] }.`, @@ -329,7 +342,7 @@ export default class GiftedDialog extends Vue { // Check for person conflict if (this.hasPersonConflict) { - this.notify.error( + this.safeNotify.error( "You cannot select the same person as both giver and recipient.", TIMEOUTS.STANDARD, ); @@ -337,7 +350,7 @@ export default class GiftedDialog extends Vue { } this.close(); - this.notify.toast("Recording the give...", undefined, TIMEOUTS.BRIEF); + this.safeNotify.toast("Recording the give...", undefined, TIMEOUTS.BRIEF); // this is asynchronous, but we don't need to wait for it to complete await this.recordGive( (this.giver?.did as string) || null, @@ -417,12 +430,12 @@ export default class GiftedDialog extends Vue { if (!result.success) { const errorMessage = this.getGiveCreationErrorMessage(result); logger.error("Error with give creation result:", result); - this.notify.error( + this.safeNotify.error( errorMessage || "There was an error creating the give.", TIMEOUTS.MODAL, ); } else { - this.notify.success("That gift was recorded.", TIMEOUTS.VERY_LONG); + this.safeNotify.success("That gift was recorded.", TIMEOUTS.VERY_LONG); if (this.callbackOnSuccess) { this.callbackOnSuccess(amount); } @@ -434,7 +447,7 @@ export default class GiftedDialog extends Vue { error.userMessage || serverMessageForUser(error) || "There was an error recording the give."; - this.notify.error(errorMessage, TIMEOUTS.MODAL); + this.safeNotify.error(errorMessage, TIMEOUTS.MODAL); } } @@ -454,7 +467,7 @@ export default class GiftedDialog extends Vue { } explainData() { - this.notify.info(libsUtil.PRIVACY_MESSAGE, TIMEOUTS.MODAL); + this.safeNotify.info(libsUtil.PRIVACY_MESSAGE, TIMEOUTS.MODAL); } selectGiver(contact?: Contact) { @@ -494,7 +507,7 @@ export default class GiftedDialog extends Vue { } } catch (error) { logger.error("Error loading projects:", error); - this.notify.error("Failed to load projects", TIMEOUTS.STANDARD); + this.safeNotify.error("Failed to load projects", TIMEOUTS.STANDARD); } } @@ -647,7 +660,17 @@ export default class GiftedDialog extends Vue { } created() { - this.notify = createNotifyHelpers(this.$notify); + // Initialize notify helpers when component is created + if (this.$notify) { + this.notify = createNotifyHelpers(this.$notify); + } + } + + mounted() { + // Ensure notify helpers are initialized if not already done + if (!this.notify && this.$notify) { + this.notify = createNotifyHelpers(this.$notify); + } } }