refactor: Use POST /users to re-invite users (no-changelog) (#7714)

This commit is contained in:
Ricardo Espinoza
2023-11-15 06:40:57 -05:00
committed by GitHub
parent 3460eb5eeb
commit 4020c14d59
5 changed files with 10 additions and 105 deletions

View File

@@ -8,7 +8,6 @@ import {
login,
loginCurrentUser,
logout,
reinvite,
sendForgotPasswordEmail,
setupOwner,
signup,
@@ -328,9 +327,14 @@ export const useUsersStore = defineStore(STORES.USERS, {
this.addUsers(users.map(({ user }) => ({ isPending: true, ...user })));
return users;
},
async reinviteUser(params: { id: string }): Promise<void> {
async reinviteUser(params: { email: string }): Promise<void> {
const rootStore = useRootStore();
await reinvite(rootStore.getRestApiContext, params);
const invitationResponse = await inviteUsers(rootStore.getRestApiContext, [
{ email: params.email },
]);
if (!invitationResponse[0].user.emailSent) {
throw Error(invitationResponse[0].error);
}
},
async getUserInviteLink(params: { id: string }): Promise<{ link: string }> {
const rootStore = useRootStore();

View File

@@ -144,15 +144,14 @@ export default defineComponent({
},
async onReinvite(userId: string) {
const user = this.usersStore.getUserById(userId);
if (user) {
if (user?.email) {
try {
await this.usersStore.reinviteUser({ id: user.id });
await this.usersStore.reinviteUser({ email: user.email });
this.showToast({
type: 'success',
title: this.$locale.baseText('settings.users.inviteResent'),
message: this.$locale.baseText('settings.users.emailSentTo', {
interpolate: { email: user.email || '' },
interpolate: { email: user.email ?? '' },
}),
});
} catch (e) {