add invite-one-accept screen dedicated to accepting invitations

This commit is contained in:
2024-12-13 13:27:22 -07:00
parent b657dc343a
commit 156950c7f0
11 changed files with 222 additions and 66 deletions

View File

@@ -99,7 +99,7 @@
{{ invite.notes }}
</td>
<td class="text-center">
{{ invite.expiresAt.substring(0, 10) }}
{{ invite.redeemedAt ? "" : invite.expiresAt.substring(0, 10) }}
</td>
<td class="text-center">
{{ invite.redeemedAt?.substring(0, 10) }}
@@ -137,8 +137,9 @@ import ContactNameDialog from "@/components/ContactNameDialog.vue";
import QuickNav from "@/components/QuickNav.vue";
import TopMessage from "@/components/TopMessage.vue";
import InviteDialog from "@/components/InviteDialog.vue";
import { APP_SERVER, NotificationIface } from "@/constants/app";
import { db, retrieveSettingsForActiveAccount } from "@/db";
import { APP_SERVER, AppString, NotificationIface } from "@/constants/app";
import { db, retrieveSettingsForActiveAccount } from "@/db/index";
import { Contact } from "@/db/tables/contacts";
import { createInviteJwt, getHeaders } from "@/libs/endorserServer";
interface Invite {
@@ -159,7 +160,7 @@ export default class InviteOneView extends Vue {
invites: Invite[] = [];
activeDid: string = "";
apiServer: string = "";
contactsRedeemed = {};
contactsRedeemed: { [key: string]: Contact } = {};
isRegistered: boolean = false;
showAppleWarning = false;
@@ -178,12 +179,12 @@ export default class InviteOneView extends Vue {
);
this.invites = response.data.data;
const baseContacts = await db.contacts.toArray();
const baseContacts: Contact[] = await db.contacts.toArray();
for (const invite of this.invites) {
const contact = baseContacts.find(
(contact) => contact.did === invite.redeemedBy,
);
if (contact) {
if (contact && invite.redeemedBy) {
this.contactsRedeemed[invite.redeemedBy] = contact;
}
}
@@ -209,14 +210,16 @@ export default class InviteOneView extends Vue {
getTruncatedRedeemedBy(redeemedBy: string | null): string {
if (!redeemedBy) return "";
if (this.contactsRedeemed[redeemedBy]) {
return this.contactsRedeemed[redeemedBy].name;
return (
this.contactsRedeemed[redeemedBy].name || AppString.NO_CONTACT_NAME
);
}
if (redeemedBy.length <= 19) return redeemedBy;
return `${redeemedBy.slice(0, 13)}...${redeemedBy.slice(-3)}`;
}
inviteLink(jwt: string): string {
return APP_SERVER + "/contacts?inviteJwt=" + jwt;
return APP_SERVER + "/invite-one-accept/" + jwt;
}
copyInviteAndNotify(inviteId: string, jwt: string) {
@@ -251,7 +254,8 @@ export default class InviteOneView extends Vue {
);
}
lookForErrorAndNotify(error, title: string, defaultMessage: string) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
lookForErrorAndNotify(error: any, title: string, defaultMessage: string) {
console.error(title, "-", error);
let message = defaultMessage;
if (error.response && error.response.data && error.response.data.error) {
@@ -301,14 +305,15 @@ export default class InviteOneView extends Vue {
{ inviteJwt: inviteJwt, notes: notes },
{ headers },
);
this.invites.push({
const newInvite = {
inviteIdentifier: inviteIdentifier,
expiresAt: expiresAt,
jwt: inviteJwt,
notes: notes,
redeemedAt: null,
redeemedBy: null,
});
};
this.invites = [newInvite, ...this.invites];
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
this.lookForErrorAndNotify(
@@ -321,7 +326,7 @@ export default class InviteOneView extends Vue {
);
}
addNewContact(did) {
addNewContact(did: string) {
(this.$refs.contactNameDialog as ContactNameDialog).open(
"To Whom Did You Send The Invite?",
"Their name will be added to your contact list.",