forked from bigbluebutton/greenlight
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
implementing CSV User import, rubocop -A changes, updating node packa…
…ges, updating gems
- Loading branch information
1 parent
2907612
commit 08e2c4b
Showing
27 changed files
with
1,186 additions
and
505 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,3 +1,3 @@ | ||
web: bin/rails server -p $PORT | ||
web: ruby bin/rails server -p $PORT | ||
js: yarn build:development | ||
css: yarn build:development:css --watch | ||
css: yarn build:development:css --watch |
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
62 changes: 62 additions & 0 deletions
62
app/javascript/components/admin/manage_users/forms/CsvSignUpForm.jsx
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,62 @@ | ||
|
||
// BigBlueButton open source conferencing system - http://www.bigbluebutton.org/. | ||
// | ||
// Copyright (c) 2022 BigBlueButton Inc. and by respective authors (see below). | ||
// | ||
// This program is free software; you can redistribute it and/or modify it under the | ||
// terms of the GNU Lesser General Public License as published by the Free Software | ||
// Foundation; either version 3.0 of the License, or (at your option) any later | ||
// version. | ||
// | ||
// Greenlight 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 Lesser General Public License for more details. | ||
// | ||
// You should have received a copy of the GNU Lesser General Public License along | ||
// with Greenlight; if not, see <http://www.gnu.org/licenses/>. | ||
|
||
import React from 'react'; | ||
import { Button, Stack } from 'react-bootstrap'; | ||
import PropTypes from 'prop-types'; | ||
import { useTranslation } from 'react-i18next'; | ||
import Spinner from '../../../shared_components/utilities/Spinner'; | ||
import useAdminCreateUser from '../../../../hooks/mutations/admin/manage_users/useAdminCreateUser'; | ||
|
||
|
||
export default function UserSignupForm({ handleClose, users }) { | ||
const { t } = useTranslation(); | ||
const createUserAPI = useAdminCreateUser({ onSettled: handleClose }); | ||
|
||
async function handleSubmit() { | ||
for (const user of users) { | ||
try { | ||
await createUserAPI.mutateAsync(user); | ||
console.log('User created successfully:', user.email); | ||
} catch (error) { | ||
console.error('Error creating user:', user.email, error); | ||
} | ||
} | ||
} | ||
|
||
return ( | ||
|
||
<Stack className="mt-1" direction="horizontal" gap={1}> | ||
<Button variant="neutral" className="ms-auto" onClick={handleClose}> | ||
{t('close')} | ||
</Button> | ||
<Button variant="brand" onClick={() => handleSubmit()} disabled={createUserAPI.isLoading}> | ||
{createUserAPI.isLoading && <Spinner className="me-2" />} | ||
{t('admin.manage_users.create_account')} | ||
</Button> | ||
</Stack> | ||
|
||
); | ||
} | ||
|
||
UserSignupForm.propTypes = { | ||
handleClose: PropTypes.func, | ||
}; | ||
|
||
UserSignupForm.defaultProps = { | ||
handleClose: () => { }, | ||
}; |
81 changes: 81 additions & 0 deletions
81
app/javascript/components/admin/manage_users/forms/ImportFromCSV.jsx
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,81 @@ | ||
import React, { useState } from 'react'; | ||
import { Button, Table, Form } from 'react-bootstrap'; | ||
import Papa from 'papaparse'; | ||
import CsvSignUpForm from './CsvSignUpForm'; | ||
|
||
const CsvUploadAndDisplay = () => { | ||
const [csvData, setCsvData] = useState([]); | ||
const [error, setError] = useState(null); | ||
const handleFileUpload = (event) => { | ||
const file = event.target.files[0]; | ||
if (file) { | ||
Papa.parse(file, { | ||
header: true, | ||
complete: (results) => { | ||
if (results.errors.length) { | ||
setError(results.errors[0].message); | ||
} else { | ||
setCsvData(results.data); | ||
setError(null); | ||
} | ||
}, | ||
error: (error) => { | ||
setError(error.message); | ||
}, | ||
}); | ||
} | ||
}; | ||
|
||
return ( | ||
<div className='d-flex flex-column gap-4'> | ||
<Form.Group controlId="formFile" className="mb-3"> | ||
<Form.Label>Upload CSV File</Form.Label> | ||
<Form.Control type="file" accept=".csv" onChange={handleFileUpload} /> | ||
</Form.Group> | ||
{error && <div className="alert alert-danger">{error}</div>} | ||
{csvData.length > 0 && ( | ||
<CsvSignUpForm | ||
users={csvData.map((data) => ({ | ||
name: data.name, | ||
email: data.email, | ||
role: data.role, | ||
password: "Fe99b949!" + generateRandomFiveDigitNumber(), | ||
verified: data.verified.toLowerCase() === 'true', | ||
}))} | ||
/> | ||
)} | ||
{csvData.length > 0 && ( | ||
<div className='w-full h-96 overflow-scroll'> | ||
<Table striped bordered hover > | ||
<thead> | ||
<tr> | ||
{Object.keys(csvData[0]).map((key) => ( | ||
<th key={key}>{key}</th> | ||
))} | ||
</tr> | ||
</thead> | ||
<tbody> | ||
{csvData.map((row, index) => ( | ||
<tr key={index}> | ||
{Object.values(row).map((value, idx) => ( | ||
<td key={idx}>{value}</td> | ||
))} | ||
</tr> | ||
))} | ||
</tbody> | ||
</Table> | ||
</div> | ||
)} | ||
|
||
</div> | ||
); | ||
}; | ||
|
||
export default CsvUploadAndDisplay; | ||
|
||
function generateRandomFiveDigitNumber() { | ||
const min = 10000; | ||
const max = 99999; | ||
return Math.floor(Math.random() * (max - min + 1)) + min; | ||
} | ||
|
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
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
Oops, something went wrong.