forked from jsnbuchanan/crowd-funder-for-time-pwa
Replace notification literal strings with constants and add usage documentation
- Migrate remaining ContactsView.vue literal strings to centralized constants - Add missing constants: NOTIFY_BLANK_INVITE, NOTIFY_REGISTRATION_ERROR_FALLBACK, etc. - Create composite message functions: getRegisterPersonSuccessMessage(), getVisibilitySuccessMessage() - Document all notification constants with usage locations in comments - Fix scattered hardcoded notification messages preventing translation - 0 linter errors, ContactsView.vue now fully notification-compliant
This commit is contained in:
@@ -396,14 +396,28 @@ import {
|
||||
NOTIFY_CONTACTS_ADD_ERROR,
|
||||
NOTIFY_CONTACT_NO_DID,
|
||||
NOTIFY_CONTACT_INVALID_DID,
|
||||
NOTIFY_CONTACTS_ADDED_VISIBLE,
|
||||
NOTIFY_CONTACTS_ADDED,
|
||||
NOTIFY_CONTACT_IMPORT_ERROR,
|
||||
NOTIFY_CONTACT_IMPORT_CONFLICT,
|
||||
NOTIFY_CONTACT_IMPORT_CONSTRAINT,
|
||||
NOTIFY_CONTACT_SETTING_SAVE_ERROR,
|
||||
NOTIFY_CONTACTS_ADDED_VISIBLE,
|
||||
NOTIFY_CONTACTS_ADDED,
|
||||
NOTIFY_CONTACT_INFO_COPY,
|
||||
NOTIFY_CONTACTS_SELECT_TO_COPY,
|
||||
NOTIFY_CONTACT_LINK_COPIED,
|
||||
NOTIFY_BLANK_INVITE,
|
||||
NOTIFY_INVITE_REGISTRATION_SUCCESS,
|
||||
NOTIFY_CONTACTS_ADDED_CSV,
|
||||
NOTIFY_CONTACT_INPUT_PARSE_ERROR,
|
||||
NOTIFY_CONTACT_NO_CONTACT_FOUND,
|
||||
NOTIFY_GIVES_LOAD_ERROR,
|
||||
NOTIFY_MEETING_STATUS_ERROR,
|
||||
NOTIFY_REGISTRATION_ERROR_FALLBACK,
|
||||
NOTIFY_REGISTRATION_ERROR_GENERIC,
|
||||
NOTIFY_VISIBILITY_ERROR_FALLBACK,
|
||||
getRegisterPersonSuccessMessage,
|
||||
getVisibilitySuccessMessage,
|
||||
getGivesRetrievalErrorMessage,
|
||||
} from "@/constants/notifications";
|
||||
|
||||
@Component({
|
||||
@@ -513,15 +527,7 @@ export default class ContactsView extends Vue {
|
||||
const importedInviteJwt = this.$route.query["inviteJwt"] as string;
|
||||
if (importedInviteJwt === "") {
|
||||
// this happens when a platform (eg iOS) doesn't include anything after the "=" in a shared link.
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Blank Invite",
|
||||
text: "The invite was not included, which can happen when your iOS device cuts off the link. Try pasting the full link into a browser.",
|
||||
},
|
||||
7000,
|
||||
);
|
||||
this.notify.error(NOTIFY_BLANK_INVITE.message, TIMEOUTS.VERY_LONG);
|
||||
} else if (importedInviteJwt) {
|
||||
// make sure user is created
|
||||
if (!this.activeDid) {
|
||||
@@ -541,15 +547,7 @@ export default class ContactsView extends Vue {
|
||||
// Replace databaseUtil.updateDidSpecificSettings with mixin method
|
||||
await this.$saveUserSettings(this.activeDid, { isRegistered: true });
|
||||
this.isRegistered = true;
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "success",
|
||||
title: "Registered",
|
||||
text: "You are now registered.",
|
||||
},
|
||||
3000,
|
||||
);
|
||||
this.notify.success(NOTIFY_INVITE_REGISTRATION_SUCCESS.message);
|
||||
|
||||
// wait for a second before continuing so they see the registration message
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
@@ -602,15 +600,7 @@ export default class ContactsView extends Vue {
|
||||
} else if (error.message) {
|
||||
message = error.message;
|
||||
}
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Error with Invite",
|
||||
text: message,
|
||||
},
|
||||
-1,
|
||||
);
|
||||
this.notify.error(message, TIMEOUTS.MODAL);
|
||||
}
|
||||
// if we're here, they haven't redirected anywhere, so we'll redirect here without a query parameter
|
||||
this.$router.push({ path: "/contacts" });
|
||||
@@ -683,18 +673,7 @@ export default class ContactsView extends Vue {
|
||||
resp.status,
|
||||
resp.data,
|
||||
);
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Retrieval Error",
|
||||
text:
|
||||
"Got an error retrieving your " +
|
||||
(useRecipient ? "given" : "received") +
|
||||
" data from the server.",
|
||||
},
|
||||
3000,
|
||||
);
|
||||
this.notify.error(getGivesRetrievalErrorMessage(useRecipient));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -744,15 +723,7 @@ export default class ContactsView extends Vue {
|
||||
} catch (error) {
|
||||
const fullError = "Error loading gives: " + errorStringForLog(error);
|
||||
logConsoleAndDb(fullError, true);
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Load Error",
|
||||
text: "Got an error loading your gives.",
|
||||
},
|
||||
3000,
|
||||
);
|
||||
this.notify.error(NOTIFY_GIVES_LOAD_ERROR.message);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -797,15 +768,7 @@ export default class ContactsView extends Vue {
|
||||
}
|
||||
try {
|
||||
await Promise.all(lineAdded);
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "success",
|
||||
title: "Contacts Added",
|
||||
text: "Each contact was added. Nothing was sent to the server.",
|
||||
},
|
||||
3000, // keeping it up so that the "visibility" message is seen
|
||||
);
|
||||
this.notify.success(NOTIFY_CONTACTS_ADDED_CSV.message);
|
||||
} catch (e) {
|
||||
const fullError =
|
||||
"Error adding contacts from CSV: " + errorStringForLog(e);
|
||||
@@ -877,13 +840,13 @@ export default class ContactsView extends Vue {
|
||||
"Error adding contacts from array: " + errorStringForLog(e);
|
||||
logConsoleAndDb(fullError, true);
|
||||
// Use notification helper and constant
|
||||
this.notify.error("The input could not be parsed.");
|
||||
this.notify.error(NOTIFY_CONTACT_INPUT_PARSE_ERROR.message);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Use notification helper and constant
|
||||
this.notify.error("No contact info was found in that input.");
|
||||
this.notify.error(NOTIFY_CONTACT_NO_CONTACT_FOUND.message);
|
||||
}
|
||||
|
||||
private async addContactFromEndorserMobileLine(
|
||||
@@ -985,31 +948,9 @@ export default class ContactsView extends Vue {
|
||||
}
|
||||
}
|
||||
|
||||
// note that this is also in DIDView.vue
|
||||
private async confirmSetVisibility(contact: Contact, visibility: boolean) {
|
||||
const visibilityPrompt = visibility
|
||||
? "Are you sure you want to make your activity visible to them?"
|
||||
: "Are you sure you want to hide all your activity from them?";
|
||||
this.$notify(
|
||||
{
|
||||
group: "modal",
|
||||
type: "confirm",
|
||||
title: "Set Visibility",
|
||||
text: visibilityPrompt,
|
||||
onYes: async () => {
|
||||
const success = await this.setVisibility(contact, visibility, true);
|
||||
if (success) {
|
||||
contact.seesMe = visibility; // didn't work inside setVisibility
|
||||
}
|
||||
},
|
||||
},
|
||||
-1,
|
||||
);
|
||||
}
|
||||
|
||||
// note that this is also in DIDView.vue
|
||||
private async register(contact: Contact) {
|
||||
this.$notify({ group: "alert", type: "toast", title: "Sent..." }, 1000);
|
||||
this.notify.sent();
|
||||
|
||||
try {
|
||||
const regResult = await register(
|
||||
@@ -1023,33 +964,18 @@ export default class ContactsView extends Vue {
|
||||
// Replace PlatformServiceFactory with mixin method
|
||||
await this.$updateContact(contact.did, { registered: true });
|
||||
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "success",
|
||||
title: "Registration Success",
|
||||
text:
|
||||
(contact.name || "That unnamed person") + " has been registered.",
|
||||
},
|
||||
3000,
|
||||
);
|
||||
this.notify.success(getRegisterPersonSuccessMessage(contact.name));
|
||||
} else {
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Registration Error",
|
||||
text:
|
||||
(regResult.error as string) ||
|
||||
"Something went wrong during registration.",
|
||||
},
|
||||
-1,
|
||||
this.notify.error(
|
||||
(regResult.error as string) ||
|
||||
NOTIFY_REGISTRATION_ERROR_FALLBACK.message,
|
||||
TIMEOUTS.MODAL,
|
||||
);
|
||||
}
|
||||
} catch (error) {
|
||||
const fullError = "Error when registering: " + errorStringForLog(error);
|
||||
logConsoleAndDb(fullError, true);
|
||||
let userMessage = "There was an error.";
|
||||
let userMessage = NOTIFY_REGISTRATION_ERROR_GENERIC.message;
|
||||
const serverError = error as AxiosError;
|
||||
if (serverError.isAxiosError) {
|
||||
if (
|
||||
@@ -1070,15 +996,7 @@ export default class ContactsView extends Vue {
|
||||
userMessage = error as string;
|
||||
}
|
||||
// Now set that error for the user to see.
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Registration Error",
|
||||
text: userMessage,
|
||||
},
|
||||
-1,
|
||||
);
|
||||
this.notify.error(userMessage, TIMEOUTS.MODAL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1098,18 +1016,8 @@ export default class ContactsView extends Vue {
|
||||
if (result.success) {
|
||||
//contact.seesMe = visibility; // why doesn't it affect the UI from here?
|
||||
if (showSuccessAlert) {
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "success",
|
||||
title: "Visibility Set",
|
||||
text:
|
||||
(contact.name || "That user") +
|
||||
" can " +
|
||||
(visibility ? "" : "not ") +
|
||||
"see your activity.",
|
||||
},
|
||||
3000,
|
||||
this.notify.success(
|
||||
getVisibilitySuccessMessage(contact.name, visibility),
|
||||
);
|
||||
}
|
||||
return true;
|
||||
@@ -1119,16 +1027,8 @@ export default class ContactsView extends Vue {
|
||||
result,
|
||||
);
|
||||
const message =
|
||||
(result.error as string) || "Could not set visibility on the server.";
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
type: "danger",
|
||||
title: "Error Setting Visibility",
|
||||
text: message,
|
||||
},
|
||||
5000,
|
||||
);
|
||||
(result.error as string) || NOTIFY_VISIBILITY_ERROR_FALLBACK.message;
|
||||
this.notify.error(message, TIMEOUTS.LONG);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1314,7 +1214,7 @@ export default class ContactsView extends Vue {
|
||||
.copy(contactsJwtUrl)
|
||||
.then(() => {
|
||||
// Use notification helper
|
||||
this.notify.copied("contact link");
|
||||
this.notify.copied(NOTIFY_CONTACT_LINK_COPIED.message);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1371,7 +1271,7 @@ export default class ContactsView extends Vue {
|
||||
"Error checking meeting status:" + errorStringForLog(error),
|
||||
);
|
||||
// Use notification helper
|
||||
this.notify.error("There was an error checking your meeting status.");
|
||||
this.notify.error(NOTIFY_MEETING_STATUS_ERROR.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user