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

[#944] delete button fixed according to role #946

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions frontend/src/lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ const config = {
id: 1,
name: "Super Admin",
filter_form: false,
delete_data: true,
page_access: [
"profile",
"user",
Expand Down Expand Up @@ -61,6 +62,7 @@ const config = {
id: 2,
name: "County Admin",
filter_form: false,
delete_data: true,
page_access: [
"profile",
"user",
Expand Down Expand Up @@ -89,6 +91,7 @@ const config = {
id: 3,
name: "Data Approver",
filter_form: 1,
delete_data: false,
page_access: [
"profile",
"control-center",
Expand All @@ -108,6 +111,7 @@ const config = {
id: 4,
name: "Data Entry Staff",
filter_form: 1,
delete_data: false,
page_access: [
"profile",
"form",
Expand Down
17 changes: 13 additions & 4 deletions frontend/src/pages/manage-data/DataDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useCallback, useEffect, useMemo, useState } from "react";
import { Table, Button, Space, Spin, Alert } from "antd";
import { LoadingOutlined, HistoryOutlined } from "@ant-design/icons";
import { EditableCell } from "../../components";
import { api, store } from "../../lib";
import { api, config, store } from "../../lib";
import { useNotification } from "../../util/hooks";
import { flatten, isEqual } from "lodash";
import { HistoryTable } from "../../components";
Expand Down Expand Up @@ -169,6 +169,13 @@ const DataDetail = ({
: false;
}, [dataset]);

const deleteData = useMemo(() => {
const currentUser = config.roles.find(
(role) => role.name === authUser?.role_detail?.name
);
return currentUser?.delete_data;
}, [authUser]);

return loading ? (
<Space style={{ paddingTop: 18, color: "#9e9e9e" }} size="middle">
<Spin indicator={<LoadingOutlined style={{ color: "#1b91ff" }} spin />} />
Expand Down Expand Up @@ -246,9 +253,11 @@ const DataDetail = ({
>
Save Edits
</Button>
<Button type="danger" onClick={() => setDeleteData(record)}>
Delete
</Button>
{deleteData && (
<Button type="danger" onClick={() => setDeleteData(record)}>
Delete
</Button>
)}
</Space>
</div>
)}
Expand Down