Skip to content

Commit

Permalink
added isDisabled feature
Browse files Browse the repository at this point in the history
  • Loading branch information
foyzulkarim committed May 8, 2022
1 parent 3847db3 commit 8a79b47
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 55 deletions.
46 changes: 3 additions & 43 deletions client-pro/src/pages/permission/manage/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,6 @@ const EntryForm = (props) => {
}
}, [reload]);

const onFinish = async (values) => {
console.log('values', values);

if (!values.hasOwnProperty('isDisabled')) {
values.isDisabled = false;
}

if (!values.hasOwnProperty('isAllowed')) {
values.isAllowed = false;
}

const result = await save({ ...values, ...role, ...resource });
console.log('resource', result);
if (result instanceof Error) {
message.error(result.message);
}
else {
message.success(result.message);
form.resetFields();
// setRole(null);
}
};

const updatePermission = async (entity) => {
const { createdBy, updatedBy, createdAt, updatedAt, __v, ...payload } = entity;
console.log('entity', payload);
Expand Down Expand Up @@ -122,10 +99,7 @@ const EntryForm = (props) => {
return (
<Checkbox
name="isAllowed"
// initialValue={entity.isAllowed}
// value={entity.isAllowed}
onChange={(val) => {
console.log('val', val);
updatePermission({ ...entity, isAllowed: val.target.checked });
}}
checked={entity.isAllowed}
Expand All @@ -146,28 +120,14 @@ const EntryForm = (props) => {
<Checkbox
name="isDisabled"
value={entity.isDisabled}
onChange={(value) => {
console.log('value', value);
onChange={(val) => {
updatePermission({ ...entity, isDisabled: val.target.checked });
}}
checked={entity.isDisabled}
/>
);
}
},
// {
// title: 'Actions',
// dataIndex: 'option',
// valueType: 'option',
// render: (_, record) => [
// <a
// key="config"
// onClick={() => {
// showDeleteConfirm(record);
// }}
// >
// Delete
// </a>,
// ],
// },
];

return (
Expand Down
53 changes: 44 additions & 9 deletions client-pro/src/pages/product/product-list/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,51 @@ import { Button, message, Pagination, Form, Row, Col, Input, DatePicker, Modal }
import React, { useState, useRef, useEffect } from 'react';
import { PageContainer, } from '@ant-design/pro-layout';
import ProTable from '@ant-design/pro-table';
import { history } from 'umi';
import { history, useAccess } from 'umi';
import { count, search, remove } from '../product-service';

const DeleteButton = (props) => {

const { confirm } = Modal;
const { elementId } = props;

const showDeleteConfirm = (product) => {
confirm({
title: `Do you Want to delete ${product.name}?`,
icon: <ExclamationCircleOutlined />,
content: `${product.name} will be deleted permanently.`,
okText: 'Yes',
okType: 'danger',
cancelText: 'No',
onOk: async () => {
console.log('OK');
const r = await remove(product._id);
if (r.success) {
message.success(r.message);
setFetchRoles(true);
}
},
onCancel() {
console.log('Cancel');
},
});
};

const access = useAccess();
const isVisible = access.canShow(elementId);
if (isVisible) {
const isDisabled = access.isDisabled(elementId);
return isDisabled ? <span>Delete</span> : <a
key="config"
onClick={() => {
showDeleteConfirm(props.record);
}}
>
Delete
</a>;
}
return null;
}

const TableList = () => {
const actionRef = useRef();
Expand Down Expand Up @@ -127,14 +169,7 @@ const TableList = () => {
dataIndex: 'option',
valueType: 'option',
render: (_, record) => [
<a
key="config"
onClick={() => {
showDeleteConfirm(record);
}}
>
Delete
</a>,
<DeleteButton key="delete" record={record} elementId='product-list-delete-btn' />,
],
},
];
Expand Down
9 changes: 6 additions & 3 deletions server/src/core/controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const { NotFound } = require("../common/errors");
const {
getById,
search,
getDropdownData,
count,
save,
update,
Expand Down Expand Up @@ -54,7 +53,9 @@ const saveHandler = async (req, res, next) => {
const { body } = req;
const id = await save(body, ModelName);
req.log.info({ id }, `${ModelName} created`);
return res.status(201).send(id);
return res
.status(201)
.send({ success: true, message: `${ModelName} created` });
} catch (error) {
return next(error, req, res);
}
Expand All @@ -65,7 +66,9 @@ const updateHandler = async (req, res, next) => {
const ModelName = req.modelName;
const { body } = req;
const id = await update(body, ModelName);
return res.status(200).send(id);
return res
.status(200)
.send({ success: true, message: `${ModelName} updated` });
} catch (error) {
return next(error, req, res);
}
Expand Down

0 comments on commit 8a79b47

Please sign in to comment.