From f2791cc8029a18ad28ec22559b1b12b8aafe9cea Mon Sep 17 00:00:00 2001 From: kristian4res <57638182+kristian4res@users.noreply.github.com> Date: Mon, 4 Nov 2024 09:53:18 +0000 Subject: [PATCH] refactor: trim whitespace in text user inputs; allow custom IDs for ONSPasswordInputs; remove unnecessary user fields --- package.json | 2 +- .../users/UserProfileEdits/ChangePassword.tsx | 21 ++++++++++++------- src/pages/users/UserUpload/NewUser.tsx | 8 ++----- yarn.lock | 21 ++++++++++++++++--- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/package.json b/package.json index 76add15..5278df3 100644 --- a/package.json +++ b/package.json @@ -34,7 +34,7 @@ "@testing-library/user-event": "^13.5.0", "axios": "^1.7.4", "blaise-api-node-client": "git+https://github.com/ONSdigital/blaise-api-node-client", - "blaise-design-system-react-components": "git+https://github.com/ONSdigital/blaise-design-system-react-components#0.14.0", + "blaise-design-system-react-components": "git+https://github.com/ONSdigital/blaise-design-system-react-components#BLAIS5-4254", "blaise-login-react": "git+https://github.com/ONSdigital/blaise-login-react#1.1.1", "dotenv": "^10.0.0", "ejs": "^3.1.10", diff --git a/src/pages/users/UserProfileEdits/ChangePassword.tsx b/src/pages/users/UserProfileEdits/ChangePassword.tsx index d56ba4e..f38daf2 100644 --- a/src/pages/users/UserProfileEdits/ChangePassword.tsx +++ b/src/pages/users/UserProfileEdits/ChangePassword.tsx @@ -18,22 +18,27 @@ export default function ChangePassword(): ReactElement { const [redirect, setRedirect] = useState(false); const changePassword = () => { - if (password === "") { + const sanitisedPassword = password.trim(); + const sanitisedConfirmPassword = confirmPassword.trim(); + + if (sanitisedPassword === "" || sanitisedConfirmPassword === "") { setMessage("Passwords cannot be blank"); return; } - if (password !== confirmPassword) { + if (sanitisedPassword !== sanitisedConfirmPassword) { setMessage("Passwords do not match"); return; } setButtonLoading(true); const authManager = new AuthManager(); - fetch("/api/change-password/" + viewedUsername, { - "headers": Object.assign({}, { - "password": password - }, authManager.authHeader()) - }) + + fetch("/api/change-password/" + viewedUsername, + { + "headers": Object.assign({}, { + "password": sanitisedPassword + }, authManager.authHeader()) + }) .then((r: Response) => { if (r.status === 204) { setButtonLoading(false); @@ -82,10 +87,12 @@ export default function ChangePassword(): ReactElement {
changePassword()}> setPassword(e.target.value)} /> setConfirmPassword(e.target.value)} />