From 8a79b47501a981d08a08d970986fcd2dd878cd55 Mon Sep 17 00:00:00 2001 From: Foyzul Karim Date: Sun, 8 May 2022 14:23:57 +1000 Subject: [PATCH] added isDisabled feature --- .../src/pages/permission/manage/index.jsx | 46 ++-------------- .../src/pages/product/product-list/index.jsx | 53 +++++++++++++++---- server/src/core/controller.js | 9 ++-- 3 files changed, 53 insertions(+), 55 deletions(-) diff --git a/client-pro/src/pages/permission/manage/index.jsx b/client-pro/src/pages/permission/manage/index.jsx index f1cdc48..03eb01d 100644 --- a/client-pro/src/pages/permission/manage/index.jsx +++ b/client-pro/src/pages/permission/manage/index.jsx @@ -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); @@ -122,10 +99,7 @@ const EntryForm = (props) => { return ( { - console.log('val', val); updatePermission({ ...entity, isAllowed: val.target.checked }); }} checked={entity.isAllowed} @@ -146,28 +120,14 @@ const EntryForm = (props) => { { - console.log('value', value); + onChange={(val) => { + updatePermission({ ...entity, isDisabled: val.target.checked }); }} + checked={entity.isDisabled} /> ); } }, - // { - // title: 'Actions', - // dataIndex: 'option', - // valueType: 'option', - // render: (_, record) => [ - // { - // showDeleteConfirm(record); - // }} - // > - // Delete - // , - // ], - // }, ]; return ( diff --git a/client-pro/src/pages/product/product-list/index.jsx b/client-pro/src/pages/product/product-list/index.jsx index e4f3107..fb7e966 100644 --- a/client-pro/src/pages/product/product-list/index.jsx +++ b/client-pro/src/pages/product/product-list/index.jsx @@ -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: , + 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 ? Delete : { + showDeleteConfirm(props.record); + }} + > + Delete + ; + } + return null; +} const TableList = () => { const actionRef = useRef(); @@ -127,14 +169,7 @@ const TableList = () => { dataIndex: 'option', valueType: 'option', render: (_, record) => [ - { - showDeleteConfirm(record); - }} - > - Delete - , + , ], }, ]; diff --git a/server/src/core/controller.js b/server/src/core/controller.js index 4df24cc..d30c9f5 100644 --- a/server/src/core/controller.js +++ b/server/src/core/controller.js @@ -2,7 +2,6 @@ const { NotFound } = require("../common/errors"); const { getById, search, - getDropdownData, count, save, update, @@ -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); } @@ -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); }