fix: when organizer adds people, they automatically register them as well

This commit is contained in:
2025-11-03 20:21:34 -07:00
parent 73806e78bc
commit 7e861e2fca
8 changed files with 127 additions and 67 deletions

View File

@@ -134,8 +134,9 @@ import { Vue, Component, Prop } from "vue-facing-decorator";
import { PlatformServiceMixin } from "@/utils/PlatformServiceMixin";
import { SOMEONE_UNNAMED } from "@/constants/entities";
import { MemberData } from "@/interfaces";
import { setVisibilityUtil, getHeaders } from "@/libs/endorserServer";
import { setVisibilityUtil, getHeaders, register } from "@/libs/endorserServer";
import { createNotifyHelpers } from "@/utils/notify";
import { Contact } from "@/db/tables/contacts";
@Component({
mixins: [PlatformServiceMixin],
@@ -253,33 +254,37 @@ export default class BulkMembersDialog extends Vue {
async handleMainAction() {
if (this.dialogType === "admit") {
await this.admitWithVisibility();
await this.organizerAdmitAndAddWithVisibility();
} else {
await this.addContactWithVisibility();
await this.memberAddContactWithVisibility();
}
}
async admitWithVisibility() {
async organizerAdmitAndAddWithVisibility() {
try {
const selectedMembers = this.membersData.filter((member) =>
const selectedMembers: MemberData[] = this.membersData.filter((member) =>
this.selectedMembers.includes(member.did),
);
const notSelectedMembers = this.membersData.filter(
const notSelectedMembers: MemberData[] = this.membersData.filter(
(member) => !this.selectedMembers.includes(member.did),
);
let admittedCount = 0;
let contactAddedCount = 0;
let errors = 0;
for (const member of selectedMembers) {
try {
// First, admit the member
await this.admitMember(member);
// Register them
await this.registerMember(member);
admittedCount++;
// If they're not a contact yet, add them as a contact
if (!member.isContact) {
await this.addAsContact(member);
await this.addAsContact(member, true);
contactAddedCount++;
}
@@ -289,19 +294,33 @@ export default class BulkMembersDialog extends Vue {
// eslint-disable-next-line no-console
console.error(`Error processing member ${member.did}:`, error);
// Continue with other members even if one fails
errors++;
}
}
// Show success notification
this.$notify(
{
group: "alert",
type: "success",
title: "Members Admitted Successfully",
text: `${admittedCount} member${admittedCount === 1 ? "" : "s"} admitted${contactAddedCount === 0 ? "" : admittedCount === contactAddedCount ? " and" : `, ${contactAddedCount}`}${contactAddedCount === 0 ? "" : ` added as contact${contactAddedCount === 1 ? "" : "s"}`}.`,
},
10000,
);
if (admittedCount > 0) {
this.$notify(
{
group: "alert",
type: "success",
title: "Members Admitted Successfully",
text: `${admittedCount} member${admittedCount === 1 ? "" : "s"} admitted and registered${contactAddedCount === 0 ? "" : admittedCount === contactAddedCount ? " and" : `, ${contactAddedCount}`}${contactAddedCount === 0 ? "" : ` added as contact${contactAddedCount === 1 ? "" : "s"}`}.`,
},
10000,
);
}
if (errors > 0) {
this.$notify(
{
group: "alert",
type: "danger",
title: "Error",
text: "Failed to fully admit some members. Work with them individually below.",
},
5000,
);
}
this.close(notSelectedMembers.map((member) => member.did));
} catch (error) {
@@ -312,19 +331,19 @@ export default class BulkMembersDialog extends Vue {
group: "alert",
type: "danger",
title: "Error",
text: "Failed to admit some members. Please try again.",
text: "Some errors occurred. Work with members individually below.",
},
5000,
);
}
}
async addContactWithVisibility() {
async memberAddContactWithVisibility() {
try {
const selectedMembers = this.membersData.filter((member) =>
const selectedMembers: MemberData[] = this.membersData.filter((member) =>
this.selectedMembers.includes(member.did),
);
const notSelectedMembers = this.membersData.filter(
const notSelectedMembers: MemberData[] = this.membersData.filter(
(member) => !this.selectedMembers.includes(member.did),
);
@@ -334,7 +353,7 @@ export default class BulkMembersDialog extends Vue {
try {
// If they're not a contact yet, add them as a contact first
if (!member.isContact) {
await this.addAsContact(member);
await this.addAsContact(member, undefined);
contactsAddedCount++;
}
@@ -367,7 +386,7 @@ export default class BulkMembersDialog extends Vue {
group: "alert",
type: "danger",
title: "Error",
text: "Failed to add some members as contacts. Please try again.",
text: "Some errors occurred. Work with members individually below.",
},
5000,
);
@@ -393,11 +412,39 @@ export default class BulkMembersDialog extends Vue {
}
}
async addAsContact(member: { did: string; name: string }) {
async registerMember(member: MemberData) {
try {
const newContact = {
const contact: Contact = { did: member.did };
const result = await register(
this.activeDid,
this.apiServer,
this.axios,
contact,
);
if (result.success) {
if (result.embeddedRecordError) {
throw new Error(result.embeddedRecordError);
}
await this.$updateContact(member.did, { registered: true });
} else {
throw result;
}
} catch (err) {
// eslint-disable-next-line no-console
console.error("Error registering member:", err);
throw err;
}
}
async addAsContact(
member: { did: string; name: string },
isRegistered?: boolean,
) {
try {
const newContact: Contact = {
did: member.did,
name: member.name,
registered: isRegistered,
};
await this.$insertContact(newContact);