Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promote from main to preprod #327

Merged
merged 11 commits into from
Feb 8, 2024
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
Loading