Skip to content

Commit

Permalink
🐛 minor bugs fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
Salah Eddine Lalami committed Oct 28, 2023
1 parent df43aea commit cb25544
Show file tree
Hide file tree
Showing 12 changed files with 112 additions and 120 deletions.
100 changes: 64 additions & 36 deletions frontend/src/modules/DashboardModule/components/RecentTable/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,55 +4,83 @@ import { Descriptions, Dropdown, Menu, Table } from 'antd';
import { request } from '@/request';
import useFetch from '@/hooks/useFetch';

import {
EllipsisOutlined,
EyeOutlined,
EditOutlined,
DeleteOutlined,
FilePdfOutlined,
} from '@ant-design/icons';
import { EllipsisOutlined, EyeOutlined, EditOutlined, FilePdfOutlined } from '@ant-design/icons';
import { useDispatch, useSelector } from 'react-redux';
import { erp } from '@/redux/erp/actions';
import { selectCurrentLang } from '@/redux/lang/selectors';
import { useHistory } from 'react-router-dom';
import { DOWNLOAD_BASE_URL } from '@/config/serverApiConfig';
import useResponsiveTable from '@/hooks/useResponsiveTable';

function DropDownRowMenu({ row, entity }) {
export default function RecentTable({ ...props }) {
let { entity, dataTableColumns } = props;

const items = [
{
label: 'Show',
key: 'read',
icon: <EyeOutlined />,
},
{
label: 'Edit',
key: 'edit',
icon: <EditOutlined />,
},
{
label: 'Download',
key: 'download',
icon: <FilePdfOutlined />,
},
];

const history = useHistory();
const Show = () => {
history.push(`/${entity}/read/${row._id}`);
};
function Edit() {
history.push(`/${entity}/update/${row._id}`);
}
function Download() {
window.open(`${DOWNLOAD_BASE_URL}${entity}/${entity}-${row._id}.pdf`, '_blank');
}
const dispatch = useDispatch();

return (
<Menu style={{ width: 130 }}>
<Menu.Item icon={<EyeOutlined />} onClick={Show}>
Show
</Menu.Item>
<Menu.Item icon={<EditOutlined />} onClick={Edit}>
Edit
</Menu.Item>
<Menu.Item onClick={Download} icon={<FilePdfOutlined />}>
Download
</Menu.Item>
</Menu>
);
}
const handleRead = (record) => {
dispatch(erp.currentItem({ data: record }));
history.push(`/${entity}/read/${record._id}`);
};
const handleEdit = (record) => {
dispatch(erp.currentAction({ actionType: 'update', data: record }));
history.push(`/${entity}/update/${record._id}`);
};
const handleDownload = (record) => {
window.open(`${DOWNLOAD_BASE_URL}${entity}/${entity}-${record._id}.pdf`, '_blank');
};

export default function RecentTable({ ...props }) {
let { entity, dataTableColumns } = props;
dataTableColumns = [
...dataTableColumns,
{
title: '',
render: (row) => (
<Dropdown overlay={DropDownRowMenu({ row, entity })} trigger={['click']}>
<EllipsisOutlined style={{ cursor: 'pointer', fontSize: '24px' }} />
key: 'action',
render: (_, record) => (
<Dropdown
menu={{
items,
onClick: ({ key }) => {
switch (key) {
case 'read':
handleRead(record);
break;
case 'edit':
handleEdit(record);
break;
case 'download':
handleDownload(record);
break;

default:
break;
}
// else if (key === '2')handleCloseTask
},
}}
trigger={['click']}
>
<EllipsisOutlined
style={{ cursor: 'pointer', fontSize: '24px' }}
onClick={(e) => e.preventDefault()}
/>
</Dropdown>
),
},
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DataTableDropMenu from './components/DataTableDropMenu';
export default function EmailDataTableModule({ config }) {
return (
<ErpLayout>
<ErpPanel config={config} DataTableDropMenu={DataTableDropMenu}></ErpPanel>
<ErpPanel config={config}></ErpPanel>
</ErpLayout>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default function EmailForm({ current = null }) {
};

return (
<>
<Row>
<Form.Item label="Available Variables">{displayLabels(current?.emailVariables)}</Form.Item>
<Form.Item label="Subject" name="emailSubject">
<Input />
Expand All @@ -45,6 +45,6 @@ export default function EmailForm({ current = null }) {
</Button>
</Form.Item>
</Col>
</>
</Row>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export default function UpdateEmailModule({ config }) {
onClick={() => {
history.push(`/${config.entity.toLowerCase()}`);
}}
key="emailform404"
>
Back to Quote Page
</Button>
Expand Down
21 changes: 11 additions & 10 deletions frontend/src/modules/ErpPanelModule/DataTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,20 +22,21 @@ import useResponsiveTable from '@/hooks/useResponsiveTable';

import { DOWNLOAD_BASE_URL } from '@/config/serverApiConfig';

function AddNewItem({ config }) {
function AddNewItem({ config, hasCreate = true }) {
const history = useHistory();
const { ADD_NEW_ENTITY, entity } = config;
const { erpContextAction } = useErpContext();
const { createPanel } = erpContextAction;
const handelClick = () => {

const handleClick = () => {
history.push(`/${entity.toLowerCase()}/create`);
};

return (
<Button onClick={handelClick} type="primary" icon={<PlusOutlined />}>
{ADD_NEW_ENTITY}
</Button>
);
if (hasCreate)
return (
<Button onClick={handleClick} type="primary" icon={<PlusOutlined />}>
{ADD_NEW_ENTITY}
</Button>
);
else return null;
}

export default function DataTable({ config, extra = [] }) {
Expand Down Expand Up @@ -178,7 +179,7 @@ export default function DataTable({ config, extra = [] }) {
<Button onClick={handelDataTableLoad} key={`${uniqueId()}`} icon={<RedoOutlined />}>
Refresh
</Button>,
create ? <AddNewItem config={config} key={`${uniqueId()}`} /> : <></>,
<AddNewItem config={config} key={`${uniqueId()}`} hasCreate={create} />,
]}
style={{
padding: '20px 0px',
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/modules/ErpPanelModule/ReadItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export default function ReadItem({ config, selectedItem }) {
const [currentErp, setCurrentErp] = useState(selectedItem ?? resetErp);

useEffect(() => {
const controller = new AbortController();
if (currentResult) {
const { items, invoice, ...others } = currentResult;

Expand All @@ -114,7 +113,10 @@ export default function ReadItem({ config, selectedItem }) {
setCurrentErp({ ...invoice.items, ...others, ...invoice });
}
}
return () => controller.abort();
return () => {
setItemsList([]);
setCurrentErp(resetErp);
};
}, [currentResult]);

return (
Expand Down
11 changes: 10 additions & 1 deletion frontend/src/modules/ErpPanelModule/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,17 @@ export default function ErpPanel({ config, extra }) {
const dispatch = useDispatch();
const { state } = useErpContext();
const { deleteModal } = state;
useLayoutEffect(() => {

const dispatcher = () => {
dispatch(erp.resetState());
};

useLayoutEffect(() => {
const controller = new AbortController();
dispatcher();
return () => {
controller.abort();
};
}, []);

return (
Expand Down
26 changes: 14 additions & 12 deletions frontend/src/pages/AdvancedSettings/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,32 +52,34 @@ export default function AdvancedSettings() {
title: 'enabled',
dataIndex: 'enabled',
key: 'enabled',
render: (text, row) => {
onCell: (record, rowIndex) => {
return {
props: {
style: {
width: '60px',
},
},
children: (
<Switch
disabled={row.isCoreSetting}
checked={row.enabled}
checkedChildren={<CheckOutlined />}
unCheckedChildren={<CloseOutlined />}
/>
),
};
},
render: (_, record) => {
return (
<Switch
disabled={record.isCoreSetting}
checked={record.enabled}
checkedChildren={<CheckOutlined />}
unCheckedChildren={<CloseOutlined />}
/>
);
},
},
];

const lang = useSelector(selectCurrentLang);

const Labels = {
PANEL_TITLE: lang.setting,
DATATABLE_TITLE: lang.setting_list,
ADD_NEW_ENTITY: lang.add_new_setting,
PANEL_TITLE: lang.settings,
DATATABLE_TITLE: lang.settings_list,
ADD_NEW_ENTITY: lang.add_new_settings,
ENTITY_NAME: lang.setting,
CREATE_ENTITY: lang.save,
UPDATE_ENTITY: lang.update,
Expand Down
6 changes: 1 addition & 5 deletions frontend/src/pages/Email/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,12 @@ export default function AdvancedSettings() {
{
title: 'Template Name',
dataIndex: 'emailName',
key: 'emailName',
},
{
title: 'Subject',
dataIndex: 'emailSubject',
key: 'emailSubject',
render: (text, row) => {
return {
children: <span>{text}</span>,
};
},
},
];

Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/Invoice/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export default function Invoice() {
{
title: 'Total',
dataIndex: 'total',
render: (total) => moneyRowFormatter({ amount: total }),
onCell: (total) => moneyRowFormatter({ amount: total }),
},
{
title: 'Balance',
dataIndex: 'credit',
render: (credit) => moneyRowFormatter({ amount: credit }),
onCell: (credit) => moneyRowFormatter({ amount: credit }),
},
{
title: 'Status',
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/pages/Quote/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ export default function Quote() {
{
title: 'SubTotal',
dataIndex: 'subTotal',
render: (amount) => moneyRowFormatter({ amount }),
onCell: (subTotal) => moneyRowFormatter({ amount: subTotal }),
},
{
title: 'Total',
dataIndex: 'total',
render: (amount) => moneyRowFormatter({ amount }),
onCell: (total) => moneyRowFormatter({ amount: total }),
},

{
Expand Down

0 comments on commit cb25544

Please sign in to comment.