Skip to content

Commit

Permalink
Merge pull request #326 from ONSdigital/BLAIS5-3814
Browse files Browse the repository at this point in the history
Promote from BLAIS5-3814 to main
  • Loading branch information
elthorne authored Feb 7, 2024
2 parents fd337e9 + c680da1 commit eb60842
Show file tree
Hide file tree
Showing 9 changed files with 2,861 additions and 90 deletions.
Empty file added .yarnrc
Empty file.
2 changes: 1 addition & 1 deletion src/pages/users/BulkUserUpload/BulkUserUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function BulkUserUpload(): ReactElement {
case Pages.Upload:
return <SelectFile setUsersToUpload={setUsersToUpload} movePageForward={MovePageToSummary} />;
case Pages.ToUploadSummary:
return <UsersToUploadSummary statusDescriptionList={usersToUpload} uploadUsers={UploadUsers} />;
return <UsersToUploadSummary usersToImport={usersToUpload} uploadUsers={UploadUsers} />;
case Pages.InProgress:
return <UsersUploadInProgress />;
case Pages.UploadedSummary:
Expand Down
59 changes: 4 additions & 55 deletions src/pages/users/BulkUserUpload/SelectFile.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import React, {ReactElement, useEffect, useState} from "react";
import React, {ReactElement, useState} from "react";
import {Collapsible, ONSButton} from "blaise-design-system-react-components";
import CSVReader from "react-csv-reader";
import {ImportUser} from "../../../../Interfaces";
import {UserRole} from "blaise-api-node-client";
import {getAllRoles} from "../../../utilities/http";

interface Props {
setUsersToUpload: (users: ImportUser[]) => void;
Expand All @@ -14,61 +12,12 @@ function SelectFile({setUsersToUpload, movePageForward}: Props): ReactElement {

const [buttonLoading, setButtonLoading] = useState<boolean>(false);
const [uploadData, setUploadData] = useState<ImportUser[]>([]);
const [roles, setRoles] = useState<UserRole[]>([]);

useEffect(() => {
getRolesList().then(() => {return;});
}, []);

async function getRolesList() {
setRoles([]);

const [success, roleList] = await getAllRoles();
if (!success) {
return;
}
setRoles(roleList);
}

function validateUser(user: ImportUser) {
user.valid = true;
user.warnings = [];

if (user.name === undefined || user.name === null) {
user.valid = false;
user.warnings.push("Invalid name");
}

if (user.password === undefined || user.password === null) {
user.valid = false;
user.warnings.push("Invalid password");
}

if (user.role === undefined || user.role === null) {
user.warnings.push("Invalid role");
user.valid = false;
} else {
const isValidRole = roles.some(function (el) {
return el.name === user.role;
});

if (!isValidRole) {
user.warnings.push("Not a valid role");
user.valid = false;
}
}
}

function validateUpload() {
function uploadUsers() {
setButtonLoading(true);

uploadData.map((row) => {
validateUser(row);
});

setUsersToUpload(uploadData);
setButtonLoading(false);

setUsersToUpload(uploadData);
movePageForward();
}

Expand All @@ -94,7 +43,7 @@ function SelectFile({setUsersToUpload, movePageForward}: Props): ReactElement {
/>

<br />
<ONSButton label={"Upload"} primary={true} onClick={() => validateUpload()} loading={buttonLoading} />
<ONSButton label={"Upload"} primary={true} onClick={() => uploadUsers()} loading={buttonLoading} />

<Collapsible title="What format should the bulk upload file be?">
<>
Expand Down
Loading

0 comments on commit eb60842

Please sign in to comment.