Skip to content

Commit

Permalink
refactor: trim whitespace in text user inputs; allow custom IDs for O…
Browse files Browse the repository at this point in the history
…NSPasswordInputs; remove unnecessary user fields
  • Loading branch information
kristian4res committed Nov 4, 2024
1 parent a9d64b0 commit f2791cc
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 17 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
21 changes: 14 additions & 7 deletions src/pages/users/UserProfileEdits/ChangePassword.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,27 @@ export default function ChangePassword(): ReactElement {
const [redirect, setRedirect] = useState<boolean>(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);
Expand Down Expand Up @@ -82,10 +87,12 @@ export default function ChangePassword(): ReactElement {
</ONSPanel>
<form onSubmit={() => changePassword()}>
<ONSPasswordInput label={"New password"}
inputId={"new-password"}
autoFocus={true}
value={password}
onChange={(e) => setPassword(e.target.value)} />
<ONSPasswordInput label={"Confirm password"}
inputId={"confirm-password"}
value={confirmPassword}
onChange={(e) => setConfirmPassword(e.target.value)} />
<ONSButton
Expand Down
8 changes: 2 additions & 6 deletions src/pages/users/UserUpload/NewUser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import React, { ChangeEvent, ReactElement, useEffect, useState } from "react";
import { Navigate } from "react-router-dom";
import { ONSPanel, ONSButton } from "blaise-design-system-react-components";
import { addNewUser, getAllRoles } from "../../../api/http";
import { UserRole } from "blaise-api-node-client";
import { NewUser } from "blaise-api-node-client";
import { UserRole, NewUser } from "blaise-api-node-client";
import FormTextInput from "../../../Components/form/TextInput";
import Form from "../../../Components/form";
import { passwordMatchedValidator, requiredValidator } from "../../../Components/form/FormValidators";
Expand All @@ -27,10 +26,7 @@ function NewUserComponent(): ReactElement {
const newUser: NewUser = {
name: formData.username.trim(),
password: formData.password.trim(),
role: role,
// TODO: Are these needed? These should be set in the server depending on the role
defaultServerPark: "gusty",
serverParks: ["gusty"]
role: role
};
setButtonLoading(true);
const created = await addNewUser(newUser);
Expand Down
21 changes: 18 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4392,6 +4392,20 @@
"@svgr/plugin-svgo" "^5.5.0"
loader-utils "^2.0.0"

"@testing-library/dom@^10.4.0":
version "10.4.0"
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-10.4.0.tgz#82a9d9462f11d240ecadbf406607c6ceeeff43a8"
integrity sha512-pemlzrSESWbdAloYml3bAJMEfNh1Z7EduzqPKprCH5S341frlpYnUEW0H72dLxa6IsYr+mPno20GiSm+h9dEdQ==
dependencies:
"@babel/code-frame" "^7.10.4"
"@babel/runtime" "^7.12.5"
"@types/aria-query" "^5.0.1"
aria-query "5.3.0"
chalk "^4.1.0"
dom-accessibility-api "^0.5.9"
lz-string "^1.5.0"
pretty-format "^27.0.2"

"@testing-library/dom@^8.3.0":
version "8.20.1"
resolved "https://registry.yarnpkg.com/@testing-library/dom/-/dom-8.20.1.tgz#2e52a32e46fc88369eef7eef634ac2a192decd9f"
Expand Down Expand Up @@ -5696,7 +5710,7 @@ [email protected]:
dependencies:
deep-equal "^2.0.5"

aria-query@^5.0.0, aria-query@^5.3.0:
aria-query@5.3.0, aria-query@^5.0.0, aria-query@^5.3.0:
version "5.3.0"
resolved "https://registry.yarnpkg.com/aria-query/-/aria-query-5.3.0.tgz#650c569e41ad90b51b3d7df5e5eed1c7549c103e"
integrity sha512-b0P0sZPKtyu8HkeRAfCq0IfURZK+SuwMjY1UXGBU27wpAiTwQAIlq56IbIO+ytk/JjS1fMR14ee5WBBfKi5J6A==
Expand Down Expand Up @@ -6294,10 +6308,11 @@ bl@^4.0.3, bl@^4.1.0:
regenerator-runtime "^0.14.1"
typescript "~4.2.2"

"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":
version "1.0.0"
resolved "git+https://github.com/ONSdigital/blaise-design-system-react-components#30ea96f77c024cb0cec27e05e5c1c1c10dd4eca0"
resolved "git+https://github.com/ONSdigital/blaise-design-system-react-components#b16f4497287a661daac81cc8a0346fc363ae4e33"
dependencies:
"@testing-library/dom" "^10.4.0"
formik "^2.2.9"
react "^18.2.0"
react-csv "^2.2.2"
Expand Down

0 comments on commit f2791cc

Please sign in to comment.