diff --git a/src/components/AppNavbar.vue b/src/components/AppNavbar.vue index 9f8028a..9a71287 100644 --- a/src/components/AppNavbar.vue +++ b/src/components/AppNavbar.vue @@ -217,55 +217,25 @@ function onNavItemBtnClick(event) { case "FILES": store.filesTag = navItemCandidate; break; - case "DISCOVER": + case "DISCOVER": { type = route.params.type; fileId = route.params.fileId; isCheckPage = route.name.includes("Check"); - - switch (navItemCandidate) { - case "MAP": - if (isCheckPage) { - router.push({ - name: "CheckMap", - params: { type: type, fileId: fileId }, - }); - } else { - router.push({ - name: "Map", - params: { type: type, fileId: fileId }, - }); - } - break; - case "CONFORMANCE": - if (isCheckPage) { - // Beware of Swal popup, it might disturb which is the current active page - router.push({ - name: "CheckConformance", - params: { type: type, fileId: fileId }, - }); - } else { - // Beware of Swal popup, it might disturb which is the current active page - router.push({ - name: "Conformance", - params: { type: type, fileId: fileId }, - }); - } - break; - case "PERFORMANCE": - if (isCheckPage) { - router.push({ - name: "CheckPerformance", - params: { type: type, fileId: fileId }, - }); - } else { - router.push({ - name: "Performance", - params: { type: type, fileId: fileId }, - }); - } - break; + const discoverRoutes = { + MAP: "Map", + CONFORMANCE: "Conformance", + PERFORMANCE: "Performance", + }; + const baseName = discoverRoutes[navItemCandidate]; + if (baseName) { + const routeName = isCheckPage ? `Check${baseName}` : baseName; + router.push({ + name: routeName, + params: { type: type, fileId: fileId }, + }); } break; + } case "COMPARE": switch (navItemCandidate) { case "MAP": diff --git a/src/views/AccountManagement/ModalAccountEditCreate.vue b/src/views/AccountManagement/ModalAccountEditCreate.vue index cb254df..0dce0c9 100644 --- a/src/views/AccountManagement/ModalAccountEditCreate.vue +++ b/src/views/AccountManagement/ModalAccountEditCreate.vue @@ -310,55 +310,54 @@ const onInputDoubleClick = () => { isEditable.value = true; }; -const onConfirmBtnClick = async () => { - // rule for minimum length - validatePwdLength(); - if (!isPwdLengthValid.value) { - return; - } +/** Handles account creation in the confirm flow. */ +async function handleCreateNew() { + await checkAccountIsUnique(); + if (!isAccountUnique.value) return; + await acctMgmtStore.createNewAccount({ + username: inputUserAccount.value, + password: inputPwd.value === undefined ? "" : inputPwd.value, + name: inputName.value, + is_admin: isSetAsAdminChecked.value, + is_active: isSetActivedChecked.value, + }); + toast.success(i18next.t("AcctMgmt.MsgAccountAdded")); + modalStore.closeModal(); + acctMgmtStore.setShouldUpdateList(true); + await router.push("/account-admin"); +} + +/** Handles account editing in the confirm flow. */ +async function handleEditAccount() { + await checkAccountIsUnique(); + if (!isAccountUnique.value) return; + // Note that the old username and new username can be different + const editDetail = { + newUsername: inputUserAccount.value, + name: inputName.value === undefined ? "" : inputName.value, + is_active: true, + }; + if (isResetPwdSectionShow.value) { + editDetail.password = inputPwd.value; + } + await acctMgmtStore.editAccount( + currentViewingUser.value.username, + editDetail, + ); + toast.success(i18next.t("AcctMgmt.MsgAccountEdited")); + isEditable.value = false; +} + +const onConfirmBtnClick = async () => { + validatePwdLength(); + if (!isPwdLengthValid.value) return; - // rule for account uniqueness switch (whichCurrentModal.value) { case MODAL_CREATE_NEW: - await checkAccountIsUnique(); - if (!isAccountUnique.value) { - return; - } - await acctMgmtStore.createNewAccount({ - username: inputUserAccount.value, - password: inputPwd.value === undefined ? "" : inputPwd.value, - name: inputName.value, - is_admin: isSetAsAdminChecked.value, - is_active: isSetActivedChecked.value, - }); - toast.success(i18next.t("AcctMgmt.MsgAccountAdded")); - modalStore.closeModal(); - acctMgmtStore.setShouldUpdateList(true); - await router.push("/account-admin"); + await handleCreateNew(); break; case MODAL_ACCT_EDIT: - await checkAccountIsUnique(); - if (!isAccountUnique.value) { - return; - } - // Note that the old username and new username can be different - // Distinguish between cases with and without a password - if (isResetPwdSectionShow.value) { - await acctMgmtStore.editAccount(currentViewingUser.value.username, { - newUsername: inputUserAccount.value, - password: inputPwd.value, - name: inputName.value === undefined ? "" : inputName.value, - is_active: true, - }); - } else { - await acctMgmtStore.editAccount(currentViewingUser.value.username, { - newUsername: inputUserAccount.value, - name: inputName.value === undefined ? "" : inputName.value, - is_active: true, - }); - } - toast.success(i18next.t("AcctMgmt.MsgAccountEdited")); - isEditable.value = false; + await handleEditAccount(); break; default: break;