Browse Source

add an invite-delete function

master
Trent Larson 1 month ago
parent
commit
fd6a43d3b5
  1. 83
      src/views/InviteOneView.vue

83
src/views/InviteOneView.vue

@ -60,6 +60,13 @@
<td class="py-2 text-center">
{{ getTruncatedRedeemedBy(invite.redeemedBy) }}
</td>
<td>
<fa
icon="trash-can"
class="text-red-600 text-xl ml-2 mr-2 cursor-pointer"
@click="deleteInvite(invite.inviteIdentifier)"
/>
</td>
</tr>
</tbody>
</table>
@ -153,6 +160,27 @@ export default class InviteOneView extends Vue {
);
}
lookForErrorAndNotify(error, title, defaultMessage) {
console.error(title, "-", error);
let message = defaultMessage;
if (error.response && error.response.data && error.response.data.error) {
if (error.response.data.error.message) {
message = error.response.data.error.message;
} else {
message = error.response.data.error;
}
}
this.$notify(
{
group: "alert",
type: "danger",
title: title,
text: message,
},
5000,
);
}
async createInvite() {
const inviteIdentifier =
Math.random().toString(36).substring(2) +
@ -191,30 +219,55 @@ export default class InviteOneView extends Vue {
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) {
console.error("Error creating invite:", error);
let message = "Got an error creating your invite.";
if (
error.response &&
error.response.data &&
error.response.data.error
) {
if (error.response.data.error.message) {
message = error.response.data.error.message;
} else {
message = error.response.data.error;
this.lookForErrorAndNotify(
error,
"Error Creating Invite",
"Got an error creating your invite.",
);
}
},
);
}
deleteInvite(inviteId: string) {
this.$notify(
{
group: "modal",
type: "confirm",
title: "Delete Invite?",
text: "Are you sure you want to erase this invite? (There is no undo.)",
onYes: async () => {
const headers = await getHeaders(this.activeDid);
try {
const result = await axios.delete(
this.apiServer + "/api/userUtil/invite/" + inviteId,
{ headers },
);
if (result.status !== 204) {
throw result.data;
}
this.invites = this.invites.filter(
(invite) => invite.inviteIdentifier !== inviteId,
);
this.$notify(
{
group: "alert",
type: "danger",
title: "Error Creating Invite",
text: message,
type: "success",
title: "Deleted",
text: "Invite deleted.",
},
5000,
3000,
);
} catch (e) {
this.lookForErrorAndNotify(
e,
"Error Deleting Invite",
"Got an error deleting your invite.",
);
}
},
},
-1,
);
}
}

Loading…
Cancel
Save