-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(UI): Import CSV-license file PAGE
Signed-off-by: dushimsam <[email protected]>
- Loading branch information
dushimsam
committed
Sep 6, 2022
1 parent
cf11dae
commit ff7491e
Showing
9 changed files
with
238 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,149 @@ | ||
/* | ||
Copyright (C) 2022 Samuel Dushimimana ([email protected]) | ||
SPDX-License-Identifier: GPL-2.0 | ||
This program is free software; you can redistribute it and/or | ||
modify it under the terms of the GNU General Public License | ||
version 2 as published by the Free Software Foundation. | ||
This program is distributed in the hope that it will be useful, | ||
but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
GNU General Public License for more details. | ||
You should have received a copy of the GNU General Public License along | ||
with this program; if not, write to the Free Software Foundation, Inc., | ||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
import React, { useState } from "react"; | ||
|
||
// Title | ||
import Title from "components/Title"; | ||
import { initialImportCsvLicense, initialMessage } from "constants/constants"; | ||
import { Alert, Button, InputContainer, Spinner } from "components/Widgets"; | ||
import { importLicenseCsv } from "services/licenses"; | ||
|
||
const ImportLicense = () => { | ||
// Data required for importing the csv file | ||
const [uploadFileData, setUploadFileData] = useState(initialImportCsvLicense); | ||
// State Variables for handling Error Boundaries | ||
const [loading, setLoading] = useState(false); | ||
const [showMessage, setShowMessage] = useState(false); | ||
const [message, setMessage] = useState(initialMessage); | ||
|
||
const handleChange = (e) => { | ||
if (e.target.type === "fileInput") { | ||
setUploadFileData({ | ||
...uploadFileData, | ||
[e.target.name]: e.target.files[0], | ||
}); | ||
} else { | ||
setUploadFileData({ | ||
...uploadFileData, | ||
[e.target.name]: e.target.value, | ||
}); | ||
} | ||
}; | ||
|
||
const handleSubmit = async (e) => { | ||
e.preventDefault(); | ||
try { | ||
setLoading(true); | ||
const { data } = await importLicenseCsv(uploadFileData); | ||
setMessage({ | ||
type: "success", | ||
text: data.message, | ||
}); | ||
setUploadFileData(initialImportCsvLicense); | ||
} catch (error) { | ||
setMessage({ | ||
type: "danger", | ||
text: error.message, | ||
}); | ||
} finally { | ||
setLoading(false); | ||
setShowMessage(true); | ||
} | ||
}; | ||
return ( | ||
<> | ||
<Title title="Admin Obligation CSV Import" /> | ||
<div className="main-container my-3"> | ||
<div className="row"> | ||
<div className="col-lg-8 col-md-12 col-sm-12 col-12"> | ||
{showMessage && ( | ||
<Alert | ||
type={message.type} | ||
setShow={setShowMessage} | ||
message={message.text} | ||
/> | ||
)} | ||
<h1 className="font-size-main-heading"> | ||
Admin Obligation CSV Import | ||
</h1> | ||
</div> | ||
<div className="col-lg-8 col-md-12 col-sm-12 col-12"> | ||
<p> | ||
This option permits uploading a CSV file from your computer to | ||
Your FOSSology server has imposed a maximum upload file size of | ||
700Mbytes. | ||
</p> | ||
</div> | ||
<div className="col-lg-8 col-md-12 col-sm-12 col-12"> | ||
<span>Select the CSV-file to upload:</span> | ||
<InputContainer | ||
type="file" | ||
name="fileInput" | ||
id="upload-file-input" | ||
onChange={(e) => handleChange(e)} | ||
/> | ||
</div> | ||
<div className="col-lg-8 col-md-12 col-sm-12 col-12"> | ||
<div> | ||
<InputContainer | ||
type="text" | ||
name="name" | ||
id="delimiter" | ||
onChange={handleChange} | ||
value={uploadFileData.delimiter} | ||
> | ||
Delimiter: | ||
</InputContainer> | ||
</div> | ||
|
||
<div> | ||
<InputContainer | ||
type="text" | ||
name="name" | ||
id="admin-group-add-name" | ||
onChange={handleChange} | ||
placeholder="Group name" | ||
value={uploadFileData.enclosure} | ||
> | ||
Enclosure: | ||
</InputContainer> | ||
</div> | ||
</div> | ||
<div className="col-lg-8 col-md-12 col-sm-12 col-12"> | ||
<Button type="submit" onClick={handleSubmit} className="mt-4"> | ||
{loading ? ( | ||
<Spinner | ||
as="span" | ||
animation="border" | ||
size="sm" | ||
role="status" | ||
aria-hidden="true" | ||
/> | ||
) : ( | ||
"Add" | ||
)} | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}; | ||
|
||
export default ImportLicense; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
/* | ||
Copyright (C) 2021 Shruti Agarwal ([email protected]), Aman Dwivedi ([email protected]) | ||
Copyright (C) 2021 Shruti Agarwal ([email protected]), Aman Dwivedi ([email protected]) , Samuel Dushimimana ([email protected]) | ||
SPDX-License-Identifier: GPL-2.0 | ||
|
@@ -16,7 +16,11 @@ | |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
import { getAllLicenseApi, createCandidateLicenseApi } from "api/licenses"; | ||
import { | ||
getAllLicenseApi, | ||
createCandidateLicenseApi, | ||
importLicenseCsvApi, | ||
} from "api/licenses"; | ||
|
||
// Fetching the licenses with their kind i.e (candidate, main, all) | ||
export const getAllLicense = (licenseData) => { | ||
|
@@ -30,3 +34,9 @@ export const createCandidateLicense = (licenseData) => { | |
return res; | ||
}); | ||
}; | ||
|
||
export const importLicenseCsv = ({ fileInput, delimiter, enclosure }) => { | ||
return importLicenseCsvApi(fileInput, delimiter, enclosure).then((res) => { | ||
return res; | ||
}); | ||
}; |