Browse Source

add an invite-delete function

master
Trent Larson 2 months ago
parent
commit
fd6a43d3b5
  1. 95
      src/views/InviteOneView.vue

95
src/views/InviteOneView.vue

@ -60,6 +60,13 @@
<td class="py-2 text-center"> <td class="py-2 text-center">
{{ getTruncatedRedeemedBy(invite.redeemedBy) }} {{ getTruncatedRedeemedBy(invite.redeemedBy) }}
</td> </td>
<td>
<fa
icon="trash-can"
class="text-red-600 text-xl ml-2 mr-2 cursor-pointer"
@click="deleteInvite(invite.inviteIdentifier)"
/>
</td>
</tr> </tr>
</tbody> </tbody>
</table> </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() { async createInvite() {
const inviteIdentifier = const inviteIdentifier =
Math.random().toString(36).substring(2) + Math.random().toString(36).substring(2) +
@ -191,31 +219,56 @@ export default class InviteOneView extends Vue {
}); });
// eslint-disable-next-line @typescript-eslint/no-explicit-any // eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (error: any) { } catch (error: any) {
console.error("Error creating invite:", error); this.lookForErrorAndNotify(
let message = "Got an error creating your invite."; error,
if ( "Error Creating Invite",
error.response && "Got an error creating your invite.",
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: "Error Creating Invite",
text: message,
},
5000,
); );
} }
}, },
); );
} }
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: "success",
title: "Deleted",
text: "Invite deleted.",
},
3000,
);
} catch (e) {
this.lookForErrorAndNotify(
e,
"Error Deleting Invite",
"Got an error deleting your invite.",
);
}
},
},
-1,
);
}
} }
</script> </script>

Loading…
Cancel
Save