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

Feat/fix crud frontend #850

Merged
merged 4 commits into from
Nov 28, 2023
Merged
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const create = async (Model, req, res) => {
// Creating a new document in the collection

req.body.removed = false;
const result = await new Model(req.body).save();

// Returning successfull response
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const update = async (Model, req, res) => {
// Find document by id and updates with the required fields
req.body.removed = false;
const result = await Model.findOneAndUpdate({ _id: req.params.id, removed: false }, req.body, {
new: true, // return the new result instead of the old one
runValidators: true,
Original file line number Diff line number Diff line change
@@ -35,7 +35,7 @@ const create = async (userModel, req, res) => {
const passwordHash = newUserPassword.generateHash(salt, password);

req.body.password = undefined;

req.body.removed = false;
const result = await new User(req.body).save();

if (!result) {
8 changes: 4 additions & 4 deletions backend/src/models/appModels/Branch.js
Original file line number Diff line number Diff line change
@@ -13,9 +13,9 @@ const schema = new mongoose.Schema({
type: String,
required: true,
},
branchManager: { type: mongoose.Schema.ObjectId, ref: 'Employee', required: true },
branchAdmin: { type: mongoose.Schema.ObjectId, ref: 'Admin', required: true },
branchEmployees: { type: mongoose.Schema.ObjectId, ref: 'Employee', required: true },
manager: { type: mongoose.Schema.ObjectId, ref: 'Employee', required: true },
admin: { type: mongoose.Schema.ObjectId, ref: 'Admin', required: true },
Employees: [{ type: mongoose.Schema.ObjectId, ref: 'Employee', required: true }],
location: {
latitude: Number,
longitude: Number,
@@ -29,7 +29,7 @@ const schema = new mongoose.Schema({
State: {
type: String,
},
postaCode: {
postalCode: {
type: Number,
},
country: {
17 changes: 10 additions & 7 deletions backend/src/models/appModels/Client.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const mongoose = require('mongoose');

const ClientSchema = new mongoose.Schema({
const schema = new mongoose.Schema({
removed: {
type: Boolean,
default: false,
@@ -14,13 +14,14 @@ const ClientSchema = new mongoose.Schema({
type: String,
default: 'company',
enum: ['company', 'people'],
required: true,
},
company: { type: mongoose.Schema.ObjectId, ref: 'Company' },
people: { type: mongoose.Schema.ObjectId, ref: 'People' },
company: { type: mongoose.Schema.ObjectId, ref: 'Company', unique: true, autopopulate: true },
people: { type: mongoose.Schema.ObjectId, ref: 'People', unique: true, autopopulate: true },
convertedFrom: { type: mongoose.Schema.ObjectId, ref: 'Lead' },
interestedIn: [{ type: mongoose.Schema.ObjectId, ref: 'Product' }],
createdBy: { type: mongoose.Schema.ObjectId, ref: 'Admin', required: true },
owner: { type: mongoose.Schema.ObjectId, ref: 'Admin' },
interestedIn: [{ type: mongoose.Schema.ObjectId, ref: 'Product', autopopulate: true }],
createdBy: { type: mongoose.Schema.ObjectId, ref: 'Admin', required: true, autopopulate: true },
assigned: { type: mongoose.Schema.ObjectId, ref: 'Admin' },
images: [
{
id: String,
@@ -69,4 +70,6 @@ const ClientSchema = new mongoose.Schema({
},
});

module.exports = mongoose.model('Client', ClientSchema);
schema.plugin(require('mongoose-autopopulate'));

module.exports = mongoose.model('Client', schema);
13 changes: 6 additions & 7 deletions backend/src/models/appModels/Company.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const mongoose = require('mongoose');

const CompanySchema = new mongoose.Schema({
const schema = new mongoose.Schema({
removed: {
type: Boolean,
default: false,
@@ -18,7 +18,6 @@ const CompanySchema = new mongoose.Schema({
legalName: {
type: String,
trim: true,
required: true,
},
hasParentCompany: {
type: Boolean,
@@ -28,9 +27,8 @@ const CompanySchema = new mongoose.Schema({
type: mongoose.Schema.ObjectId,
ref: 'Company',
},
isClient: { type: mongoose.Schema.ObjectId, ref: 'Client' },
people: [{ type: mongoose.Schema.ObjectId, ref: 'People' }],
defaultContact: { type: mongoose.Schema.ObjectId, ref: 'People' },
peoples: [{ type: mongoose.Schema.ObjectId, ref: 'People' }],
mainContact: { type: mongoose.Schema.ObjectId, ref: 'People', autopopulate: true },
icon: {
type: String,
trim: true,
@@ -110,7 +108,7 @@ const CompanySchema = new mongoose.Schema({
State: {
type: String,
},
postaCode: {
postalCode: {
type: Number,
},
country: {
@@ -211,4 +209,5 @@ const CompanySchema = new mongoose.Schema({
},
});

module.exports = mongoose.model('Company', CompanySchema);
schema.plugin(require('mongoose-autopopulate'));
module.exports = mongoose.model('Company', schema);
2 changes: 1 addition & 1 deletion backend/src/models/appModels/Employee.js
Original file line number Diff line number Diff line change
@@ -93,7 +93,7 @@ const employeeSchema = new mongoose.Schema({
State: {
type: String,
},
postaCode: {
postalCode: {
type: Number,
},
country: {
35 changes: 24 additions & 11 deletions backend/src/models/appModels/People.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const mongoose = require('mongoose');

const PeopleSchema = new mongoose.Schema({
const schema = new mongoose.Schema({
removed: {
type: Boolean,
default: false,
@@ -20,19 +20,31 @@ const PeopleSchema = new mongoose.Schema({
trim: true,
required: true,
},
isClient: { type: mongoose.Schema.ObjectId, ref: 'Client' },
company: { type: mongoose.Schema.ObjectId, ref: 'Company' },
company: { type: mongoose.Schema.ObjectId, ref: 'Company', autopopulate: true },
bio: String,
idCardNumber: {
type: String,
trim: true,
},
idCardType: String,
securitySocialNbr: String,
taxNumber: String,
birthday: Date,
birthplace: String,
gender: String,
idCardType: {
type: String,
},
securitySocialNbr: {
type: String,
},
taxNumber: {
type: String,
},
birthday: {
type: Date,
},
birthplace: {
type: String,
},
gender: {
type: String,
enum: ['male', 'female'],
},
photo: {
type: String,
},
@@ -85,7 +97,7 @@ const PeopleSchema = new mongoose.Schema({
State: {
type: String,
},
postaCode: {
postalCode: {
type: Number,
},
country: {
@@ -183,4 +195,5 @@ const PeopleSchema = new mongoose.Schema({
},
});

module.exports = mongoose.model('People', PeopleSchema);
schema.plugin(require('mongoose-autopopulate'));
module.exports = mongoose.model('People', schema);
4 changes: 2 additions & 2 deletions backend/src/models/appModels/Supplier.js
Original file line number Diff line number Diff line change
@@ -29,7 +29,7 @@ const SupplierSchema = new mongoose.Schema({
ref: 'Supplier',
},
peoples: [{ type: mongoose.Schema.ObjectId, ref: 'People' }],
defaultContact: { type: mongoose.Schema.ObjectId, ref: 'People' },
mainContact: { type: mongoose.Schema.ObjectId, ref: 'People' },
products: [{ type: mongoose.Schema.ObjectId, ref: 'Product' }],
icon: {
type: String,
@@ -109,7 +109,7 @@ const SupplierSchema = new mongoose.Schema({
State: {
type: String,
},
postaCode: {
postalCode: {
type: Number,
},
country: {
2 changes: 1 addition & 1 deletion backend/src/models/coreModels/NoCodeCollections.js
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ const noCodeCollectionsSchema = new mongoose.Schema({
default: '_id',
},
},
entityDisplayLabels: [String],
deleteModalLabels: [String],
},

collectionLabels: [
1 change: 0 additions & 1 deletion backend/src/models/coreModels/Setting.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const mongoose = require('mongoose');

const settingSchema = new mongoose.Schema({
branch: { type: mongoose.Schema.ObjectId, ref: 'Branch' },
removed: {
type: Boolean,
default: false,
2 changes: 1 addition & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
"@ant-design/pro-layout": "^7.17.16",
"@reduxjs/toolkit": "^1.9.7",
"@vitejs/plugin-react": "^4.2.0",
"antd": "^5.11.4",
"antd": "^5.11.5",
"axios": "^1.6.2",
"cross-env": "7.0.3",
"currency.js": "2.0.4",
4 changes: 2 additions & 2 deletions frontend/src/apps/ErpApp.jsx
Original file line number Diff line number Diff line change
@@ -4,8 +4,8 @@ import { Layout } from 'antd';

import { useAppContext } from '@/context/appContext';

import Navigation from '@/apps/components/Navigation';
import HeaderContent from '@/apps/components/HeaderContent';
import Navigation from '@/apps/Navigation/NavigationContainer';
import HeaderContent from '@/apps/Header/HeaderContainer';

import { useDispatch } from 'react-redux';
import { settingsAction } from '@/redux/settings/actions';
Original file line number Diff line number Diff line change
@@ -21,6 +21,7 @@ import {
MenuOutlined,
UserAddOutlined,
FileOutlined,
ShopOutlined,
} from '@ant-design/icons';

const { Sider } = Layout;
@@ -71,7 +72,16 @@ function Sidebar({ collapsible }) {
},
// { key: 'order', icon: <ShopOutlined />, label: <Link to={'/'}>Lead</Link> Order },
// { key: 'inventory', icon: <InboxOutlined />, label: <Link to={'/'}>Lead</Link> Inventory },
// { key: 'kyc', icon: <ShoppingCartOutlined />, label: <Link to={'/'}>Lead</Link> Kyc },
{
key: 'people',
icon: <UserOutlined />,
label: <Link to={'/people'}>{translate('people')}</Link>,
},
{
key: 'company',
icon: <ShopOutlined />,
label: <Link to={'/company'}>{translate('company')}</Link>,
},
{
key: 'invoice',
icon: <FileTextOutlined />,
16 changes: 14 additions & 2 deletions frontend/src/components/DataTable/DataTable.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { useCallback, useEffect } from 'react';

import { EyeOutlined, EditOutlined, DeleteOutlined, EllipsisOutlined } from '@ant-design/icons';
import { Dropdown, Table, Button } from 'antd';
import { PageHeader } from '@ant-design/pro-layout';
@@ -7,6 +8,8 @@ import { useSelector, useDispatch } from 'react-redux';
import { crud } from '@/redux/crud/actions';
import { selectListItems } from '@/redux/crud/selectors';
import useLanguage from '@/locale/useLanguage';
import { dataForTable } from '@/utils/dataStructure';
import { useMoney } from '@/settings';

import { generate as uniqueId } from 'shortid';

@@ -29,10 +32,11 @@ function AddNewItem({ config }) {
);
}
export default function DataTable({ config, extra = [] }) {
let { entity, dataTableColumns, DATATABLE_TITLE } = config;
let { entity, dataTableColumns, DATATABLE_TITLE, fields } = config;
const { crudContextAction } = useCrudContext();
const { panel, collapsedBox, modal, readBox, editBox, advancedBox } = crudContextAction;
const translate = useLanguage();
const { moneyFormatter } = useMoney();

const items = [
{
@@ -83,11 +87,19 @@ export default function DataTable({ config, extra = [] }) {
collapsedBox.open();
}

let dispatchColumns = [];
if (fields) {
dispatchColumns = [...dataForTable({ fields, translate, moneyFormatter })];
} else {
dispatchColumns = [...dataTableColumns];
}

dataTableColumns = [
...dataTableColumns,
...dispatchColumns,
{
title: '',
key: 'action',
fixed: 'right',
render: (_, record) => (
<Dropdown
menu={{
4 changes: 2 additions & 2 deletions frontend/src/components/DeleteModal/index.jsx
Original file line number Diff line number Diff line change
@@ -14,7 +14,7 @@ export default function DeleteModal({ config }) {
const translate = useLanguage();
let {
entity,
entityDisplayLabels,
deleteModalLabels,
deleteMessage = translate('are_you_sure_you_want_to_delete'),
modalTitle = translate('delete_confirmation'),
} = config;
@@ -35,7 +35,7 @@ export default function DeleteModal({ config }) {
// dispatch(crud.resetAction({actionType:"delete"})); // check here maybe it wrong
}
if (current) {
let labels = entityDisplayLabels.map((x) => valueByString(current, x)).join(' ');
let labels = deleteModalLabels.map((x) => valueByString(current, x)).join(' ');

setDisplayItem(labels);
}
7 changes: 6 additions & 1 deletion frontend/src/components/ReadItem/index.jsx
Original file line number Diff line number Diff line change
@@ -3,18 +3,23 @@ import { Row, Col } from 'antd';
import { useSelector } from 'react-redux';

import dayjs from 'dayjs';
import { dataForRead } from '@/utils/dataStructure';

import { useCrudContext } from '@/context/crud';
import { selectCurrentItem } from '@/redux/crud/selectors';
import { valueByString } from '@/utils/helpers';

import useLanguage from '@/locale/useLanguage';

export default function ReadItem({ config }) {
let { readColumns } = config;
let { readColumns, fields } = config;
const translate = useLanguage();
const { result: currentResult } = useSelector(selectCurrentItem);
const { state } = useCrudContext();
const { isReadBoxOpen } = state;
const [listState, setListState] = useState([]);

if (fields) readColumns = [...dataForRead({ fields: fields, translate: translate })];
useEffect(() => {
const list = [];
readColumns.map((props) => {
Loading