forked from trent_larson/crowd-funder-for-time-pwa
Fix: notification init + safety checks
This commit is contained in:
@@ -18,7 +18,7 @@
|
|||||||
:to-project-id="toProjectId"
|
:to-project-id="toProjectId"
|
||||||
:giver="giver"
|
:giver="giver"
|
||||||
:receiver="receiver"
|
:receiver="receiver"
|
||||||
:notify="notify"
|
:notify="$notify"
|
||||||
@entity-selected="handleEntitySelected"
|
@entity-selected="handleEntitySelected"
|
||||||
@cancel="cancel"
|
@cancel="cancel"
|
||||||
/>
|
/>
|
||||||
@@ -85,6 +85,16 @@ export default class GiftedDialog extends Vue {
|
|||||||
$notify!: (notification: any, timeout?: number) => void;
|
$notify!: (notification: any, timeout?: number) => void;
|
||||||
notify!: ReturnType<typeof createNotifyHelpers>;
|
notify!: ReturnType<typeof createNotifyHelpers>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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() fromProjectId = "";
|
||||||
@Prop() toProjectId = "";
|
@Prop() toProjectId = "";
|
||||||
@Prop({ default: false }) showProjects = false;
|
@Prop({ default: false }) showProjects = false;
|
||||||
@@ -258,7 +268,7 @@ export default class GiftedDialog extends Vue {
|
|||||||
}
|
}
|
||||||
} catch (err: unknown) {
|
} catch (err: unknown) {
|
||||||
logger.error("Error retrieving settings from database:", err);
|
logger.error("Error retrieving settings from database:", err);
|
||||||
this.notify.error(
|
this.safeNotify.error(
|
||||||
err instanceof Error
|
err instanceof Error
|
||||||
? err.message
|
? err.message
|
||||||
: "There was an error retrieving your settings.",
|
: "There was an error retrieving your settings.",
|
||||||
@@ -307,18 +317,21 @@ export default class GiftedDialog extends Vue {
|
|||||||
|
|
||||||
async confirm() {
|
async confirm() {
|
||||||
if (!this.activeDid) {
|
if (!this.activeDid) {
|
||||||
this.notify.error(
|
this.safeNotify.error(
|
||||||
"You must select an identifier before you can record a give.",
|
"You must select an identifier before you can record a give.",
|
||||||
TIMEOUTS.STANDARD,
|
TIMEOUTS.STANDARD,
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (parseFloat(this.amountInput) < 0) {
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (!this.description && !parseFloat(this.amountInput)) {
|
if (!this.description && !parseFloat(this.amountInput)) {
|
||||||
this.notify.error(
|
this.safeNotify.error(
|
||||||
`You must enter a description or some number of ${
|
`You must enter a description or some number of ${
|
||||||
this.libsUtil.UNIT_LONG[this.unitCode]
|
this.libsUtil.UNIT_LONG[this.unitCode]
|
||||||
}.`,
|
}.`,
|
||||||
@@ -329,7 +342,7 @@ export default class GiftedDialog extends Vue {
|
|||||||
|
|
||||||
// Check for person conflict
|
// Check for person conflict
|
||||||
if (this.hasPersonConflict) {
|
if (this.hasPersonConflict) {
|
||||||
this.notify.error(
|
this.safeNotify.error(
|
||||||
"You cannot select the same person as both giver and recipient.",
|
"You cannot select the same person as both giver and recipient.",
|
||||||
TIMEOUTS.STANDARD,
|
TIMEOUTS.STANDARD,
|
||||||
);
|
);
|
||||||
@@ -337,7 +350,7 @@ export default class GiftedDialog extends Vue {
|
|||||||
}
|
}
|
||||||
|
|
||||||
this.close();
|
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
|
// this is asynchronous, but we don't need to wait for it to complete
|
||||||
await this.recordGive(
|
await this.recordGive(
|
||||||
(this.giver?.did as string) || null,
|
(this.giver?.did as string) || null,
|
||||||
@@ -417,12 +430,12 @@ export default class GiftedDialog extends Vue {
|
|||||||
if (!result.success) {
|
if (!result.success) {
|
||||||
const errorMessage = this.getGiveCreationErrorMessage(result);
|
const errorMessage = this.getGiveCreationErrorMessage(result);
|
||||||
logger.error("Error with give creation result:", result);
|
logger.error("Error with give creation result:", result);
|
||||||
this.notify.error(
|
this.safeNotify.error(
|
||||||
errorMessage || "There was an error creating the give.",
|
errorMessage || "There was an error creating the give.",
|
||||||
TIMEOUTS.MODAL,
|
TIMEOUTS.MODAL,
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
this.notify.success("That gift was recorded.", TIMEOUTS.VERY_LONG);
|
this.safeNotify.success("That gift was recorded.", TIMEOUTS.VERY_LONG);
|
||||||
if (this.callbackOnSuccess) {
|
if (this.callbackOnSuccess) {
|
||||||
this.callbackOnSuccess(amount);
|
this.callbackOnSuccess(amount);
|
||||||
}
|
}
|
||||||
@@ -434,7 +447,7 @@ export default class GiftedDialog extends Vue {
|
|||||||
error.userMessage ||
|
error.userMessage ||
|
||||||
serverMessageForUser(error) ||
|
serverMessageForUser(error) ||
|
||||||
"There was an error recording the give.";
|
"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() {
|
explainData() {
|
||||||
this.notify.info(libsUtil.PRIVACY_MESSAGE, TIMEOUTS.MODAL);
|
this.safeNotify.info(libsUtil.PRIVACY_MESSAGE, TIMEOUTS.MODAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
selectGiver(contact?: Contact) {
|
selectGiver(contact?: Contact) {
|
||||||
@@ -494,7 +507,7 @@ export default class GiftedDialog extends Vue {
|
|||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
logger.error("Error loading projects:", 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() {
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user