Skip to content

Commit

Permalink
landing_page: add block user option
Browse files Browse the repository at this point in the history
  • Loading branch information
yashlamba committed Sep 9, 2024
1 parent 56893c6 commit 75b4ae6
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,19 @@
// under the terms of the MIT License; see LICENSE file for more details.

import React from "react";
import { Dropdown } from "semantic-ui-react";
import {

Check failure on line 8 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/ManageButton.js

View workflow job for this annotation

GitHub Actions / JS / Tests (18.x)

Replace `⏎··Dropdown,·Modal,⏎··Button,⏎··Message⏎` with `·Dropdown,·Modal,·Button,·Message·`

Check failure on line 8 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/ManageButton.js

View workflow job for this annotation

GitHub Actions / JS / Tests (20.x)

Replace `⏎··Dropdown,·Modal,⏎··Button,⏎··Message⏎` with `·Dropdown,·Modal,·Button,·Message·`
Dropdown, Modal,
Button,
Message
} from "semantic-ui-react";
import { i18next } from "@translations/invenio_app_rdm/i18next";
import PropTypes from "prop-types";
import { http } from "react-invenio-forms";
import { APIRoutes } from "../administration/users/api/routes";


Check failure on line 18 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/ManageButton.js

View workflow job for this annotation

GitHub Actions / JS / Tests (18.x)

Replace `⏎export·const·ManageButton·=·({·recid,·recordOwnerUsername,·recordOwnerId·})·=>·{⏎` with `export·const·ManageButton·=·({·recid,·recordOwnerUsername,·recordOwnerId·})·=>·{`

Check failure on line 18 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/ManageButton.js

View workflow job for this annotation

GitHub Actions / JS / Tests (20.x)

Replace `⏎export·const·ManageButton·=·({·recid,·recordOwnerUsername,·recordOwnerId·})·=>·{⏎` with `export·const·ManageButton·=·({·recid,·recordOwnerUsername,·recordOwnerId·})·=>·{`
export const ManageButton = ({ recid, recordOwnerUsername, recordOwnerId }) => {

Check failure on line 19 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/ManageButton.js

View workflow job for this annotation

GitHub Actions / JS / Tests (18.x)

'recordOwnerId' is missing in props validation

Check failure on line 19 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/ManageButton.js

View workflow job for this annotation

GitHub Actions / JS / Tests (20.x)

'recordOwnerId' is missing in props validation

export const ManageButton = ({ recid, recordOwnerUsername }) => {
return (
<Dropdown
fluid
Expand All @@ -35,6 +43,9 @@ export const ManageButton = ({ recid, recordOwnerUsername }) => {
key="manage_user"
text={i18next.t("Manage user")}
/>
<Dropdown.Divider />
{recordOwnerId &&

Check failure on line 47 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/ManageButton.js

View workflow job for this annotation

GitHub Actions / JS / Tests (18.x)

Delete `⏎·········`

Check failure on line 47 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/ManageButton.js

View workflow job for this annotation

GitHub Actions / JS / Tests (20.x)

Delete `⏎·········`
<BlockUserItem recordOwnerId={recordOwnerId} />}
</Dropdown.Menu>
</Dropdown>
);
Expand All @@ -44,3 +55,55 @@ ManageButton.propTypes = {
recid: PropTypes.string.isRequired,
recordOwnerUsername: PropTypes.string.isRequired,
};

const BlockUserItem = (recordOwnerId) => {
const [modalOpen, setModalOpen] = React.useState(false);
const handleOpen = () => setModalOpen(true);
const handleClose = () => setModalOpen(false);
const blockUser = () => { http.post(APIRoutes.block({ id: recordOwnerId })) };

Check failure on line 63 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/ManageButton.js

View workflow job for this annotation

GitHub Actions / JS / Tests (18.x)

Replace `·http.post(APIRoutes.block({·id:·recordOwnerId·}))` with `⏎····http.post(APIRoutes.block({·id:·recordOwnerId·}));⏎·`

Check failure on line 63 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/ManageButton.js

View workflow job for this annotation

GitHub Actions / JS / Tests (20.x)

Replace `·http.post(APIRoutes.block({·id:·recordOwnerId·}))` with `⏎····http.post(APIRoutes.block({·id:·recordOwnerId·}));⏎·`

return (
<>
<Dropdown.Item
as="a"
className="error"
onClick={handleOpen}
key="block_user"
text={i18next.t("Block user")}
/>
<Modal
open={modalOpen}
closeIcon
onClose={handleClose}
role="dialog"
closeOnDimmerClick={false}
>
<Modal.Header as="h2">

Check failure on line 81 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/ManageButton.js

View workflow job for this annotation

GitHub Actions / JS / Tests (18.x)

Replace `⏎··········{i18next.t("Block·User")}⏎········` with `{i18next.t("Block·User")}`

Check failure on line 81 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/ManageButton.js

View workflow job for this annotation

GitHub Actions / JS / Tests (20.x)

Replace `⏎··········{i18next.t("Block·User")}⏎········` with `{i18next.t("Block·User")}`
{i18next.t("Block User")}
</Modal.Header>
<Modal.Description>
<Message
warning
icon="warning sign"
content={i18next.t(
"Blocking the user will delete all existing records of the user."
)}
/>
</Modal.Description>
<Modal.Actions>
<Button onClick={() => handleClose()} floated="left">
Cancel
</Button>
<Button
size="small"
labelPosition="left"
icon="warning"
color="red"
content={i18next.t("Block")}
onClick={blockUser}
/>
</Modal.Actions>
</Modal>
</>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export class RecordManagement extends Component {
groupsEnabled,
} = this.props;
const { error } = this.state;
const { id: recid } = record;
const { id: recid, parent: { access: { owned_by: { user: recordOwnerId } } } } = record;

Check failure on line 39 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/RecordManagement.js

View workflow job for this annotation

GitHub Actions / JS / Tests (18.x)

Replace `·id:·recid,·parent:·{·access:·{·owned_by:·{·user:·recordOwnerId·}·}·}` with `⏎······id:·recid,⏎······parent:·{⏎········access:·{⏎··········owned_by:·{·user:·recordOwnerId·},⏎········},⏎······},⏎···`

Check failure on line 39 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/RecordManagement.js

View workflow job for this annotation

GitHub Actions / JS / Tests (20.x)

Replace `·id:·recid,·parent:·{·access:·{·owned_by:·{·user:·recordOwnerId·}·}·}` with `⏎······id:·recid,⏎······parent:·{⏎········access:·{⏎··········owned_by:·{·user:·recordOwnerId·},⏎········},⏎······},⏎···`
const handleError = (errorMessage) => {
console.error(errorMessage);
this.setState({ error: errorMessage });
Expand All @@ -46,7 +46,7 @@ export class RecordManagement extends Component {
<Grid columns={1} className="record-management">
{permissions.can_moderate && (
<Grid.Column className="pb-5">
<ManageButton recid={recid} recordOwnerUsername={recordOwnerUsername} />
<ManageButton recid={recid} recordOwnerUsername={recordOwnerUsername} recordOwnerId={recordOwnerId} />

Check failure on line 49 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/RecordManagement.js

View workflow job for this annotation

GitHub Actions / JS / Tests (18.x)

Replace `·recid={recid}·recordOwnerUsername={recordOwnerUsername}·recordOwnerId={recordOwnerId}` with `⏎··············recid={recid}⏎··············recordOwnerUsername={recordOwnerUsername}⏎··············recordOwnerId={recordOwnerId}⏎···········`

Check failure on line 49 in invenio_app_rdm/theme/assets/semantic-ui/js/invenio_app_rdm/landing_page/RecordManagement.js

View workflow job for this annotation

GitHub Actions / JS / Tests (20.x)

Replace `·recid={recid}·recordOwnerUsername={recordOwnerUsername}·recordOwnerId={recordOwnerId}` with `⏎··············recid={recid}⏎··············recordOwnerUsername={recordOwnerUsername}⏎··············recordOwnerId={recordOwnerId}⏎···········`
</Grid.Column>
)}
{permissions.can_edit && !isDraft && (
Expand Down

0 comments on commit 75b4ae6

Please sign in to comment.