diff --git a/src/components/specific/subscriptions/space-creator/SpaceCreator.vue b/src/components/specific/subscriptions/space-creator/SpaceCreator.vue index 264847ee2..908a61250 100644 --- a/src/components/specific/subscriptions/space-creator/SpaceCreator.vue +++ b/src/components/specific/subscriptions/space-creator/SpaceCreator.vue @@ -116,7 +116,7 @@ export default { newSpaceLoading.value = true; // TODO: Try to fix/improve - // Here we set both `organizationId` and `organization.id` + // Here we set both `organization_id` and `organization.id` // because they are both used elsewhere in the code. // Setting only one of the two would break in some cases. // More specifically: @@ -144,10 +144,10 @@ export default { // References newSpace, newSpaceLoading, - openBillingAccountModal, orga, spaceNameInput, // Methods + openBillingAccountModal, submit, updateOrga }; diff --git a/src/components/specific/users/invitation-form/InvitationForm.vue b/src/components/specific/users/invitation-form/InvitationForm.vue index 57236b3c1..f8b79a92a 100644 --- a/src/components/specific/users/invitation-form/InvitationForm.vue +++ b/src/components/specific/users/invitation-form/InvitationForm.vue @@ -7,17 +7,13 @@ class="invitation-form__input__email" :placeholder="$t('InvitationForm.emailInputPlaceholder')" v-model="email" - :error="hasError" - :errorMessage=" - userAlreadyExist - ? $t('InvitationForm.userAlreadyExistInputErrorMessage') - : $t('InvitationForm.emailInputErrorMessage') - " + :error="errorMessage !== ''" + :errorMessage="errorMessage" @keyup.enter.stop="submit" margin="0px" /> - + {{ $t("t.cancel") }} import { onMounted, ref, watch } from "vue"; import { useI18n } from "vue-i18n"; -import { useAppNotification } from "../../app/app-notification/app-notification.js"; import { PROJECT_ROLE } from "../../../../config/projects.js"; -import { useProjects } from "../../../../state/projects.js"; -import { useSpaces } from "../../../../state/spaces.js"; import { debounce } from "../../../../utils/async.js"; +import { parseEmails } from "../../../../utils/users.js"; const roleList = [ { id: "admin", value: PROJECT_ROLE.ADMIN }, @@ -60,34 +54,26 @@ const roleList = [ export default { props: { - space: { - type: Object, - default: null, + roleSelector: { + type: Boolean, + default: false, }, - project: { - type: Object, - default: null, - }, - users: { - type: Array, - default: () => [], - }, - currentTab: { + error: { type: String, - default: "admins", - }, + default: "" + } }, - emits: ["close", "success"], + emits: ["cancel", "submit"], setup(props, { emit }) { const { locale, t } = useI18n(); - const { pushNotification } = useAppNotification(); - const { sendSpaceInvitation, updateSpaceUser, spaceUsers } = useSpaces(); - const { sendProjectInvitation } = useProjects(); + + const emailInput = ref(null); + const email = ref(""); const roleOptions = ref([]); const role = ref(null); watch( - [() => props.space, () => props.project, () => locale.value], + locale, () => { let availableRoles = roleList; @@ -101,76 +87,38 @@ export default { { immediate: true } ); - const emailInput = ref(null); - const email = ref(""); - const hasError = ref(false); - const userAlreadyExist = ref(false); + const errorMessage = ref(""); + watch( + () => props.error, + msg => { + errorMessage.value = msg; + }, + { immediate: true } + ); const reset = () => { email.value = ""; - hasError.value = false; + errorMessage.value = ""; }; const submit = debounce(async () => { - let currentUser; - if (email.value) { - if (props.users.map((user) => user.email).includes(email.value)) { - emailInput.value.focus(); - hasError.value = true; - userAlreadyExist.value = true; - } else { - userAlreadyExist.value = false; - if (props.project) { - await sendProjectInvitation(props.project, { - email: email.value, - role: role.value.value, - }); - } else if (props.space) { - currentUser = spaceUsers.value.find((user) => user.email === email.value); - if (currentUser) { - await updateSpaceUser(props.space, { - ...currentUser, - cloud_role: 100, - }); - } else { - if (props.currentTab === "users") { - await sendSpaceInvitation(props.space, { - email: email.value, - in_all_projects: true, - project_role: 50, - role: 50, - }); - } else { - await sendSpaceInvitation(props.space, { - email: email.value, - }); - } - } - } - pushNotification( - { - type: "success", - title: t("t.success"), - message: t( - currentUser - ? "InvitationForm.successUsertoAdmin" - : "InvitationForm.successNotifText" - ), - }, - 2500 - ); - reset(); - emit("success"); - } - } else { + errorMessage.value = ""; + + if (!email.value) { emailInput.value.focus(); - hasError.value = true; + errorMessage.value = t("InvitationForm.emailInputErrorMessage"); + return; } + + const emails = parseEmails(email.value); + + emit("submit", { emails, role: role.value.value }); + reset(); }, 500); - const close = () => { + const cancel = () => { + emit("cancel"); reset(); - emit("close"); }; onMounted(() => { @@ -181,12 +129,11 @@ export default { // References email, emailInput, - hasError, - userAlreadyExist, + errorMessage, role, roleOptions, // Methods - close, + cancel, submit, }; }, diff --git a/src/components/specific/users/invitation-form/ProjectInvitationForm.vue b/src/components/specific/users/invitation-form/ProjectInvitationForm.vue new file mode 100644 index 000000000..7b743399c --- /dev/null +++ b/src/components/specific/users/invitation-form/ProjectInvitationForm.vue @@ -0,0 +1,58 @@ + + + diff --git a/src/components/specific/users/invitation-form/SpaceInvitationForm.vue b/src/components/specific/users/invitation-form/SpaceInvitationForm.vue new file mode 100644 index 000000000..f28f8f958 --- /dev/null +++ b/src/components/specific/users/invitation-form/SpaceInvitationForm.vue @@ -0,0 +1,70 @@ + + + diff --git a/src/components/specific/users/project-users-manager/ProjectUsersManager.vue b/src/components/specific/users/project-users-manager/ProjectUsersManager.vue index d90884de7..19aa5805b 100644 --- a/src/components/specific/users/project-users-manager/ProjectUsersManager.vue +++ b/src/components/specific/users/project-users-manager/ProjectUsersManager.vue @@ -33,7 +33,7 @@ clear /> - -