When click “delete” from ViewCustomer.js as below code, I get the following error:
"Match error: Expected particular constructor", path: ""
import React from 'react';
import PropTypes from 'prop-types';
import { ButtonToolbar, ButtonGroup, Button } from 'react-bootstrap';
import { createContainer } from 'meteor/react-meteor-data';
import { Meteor } from 'meteor/meteor';
import { Customers } from '../../api/customers';
import NotFound from './NotFound';
const handleRemove = (customerId, history) => {
if (confirm('Are you sure? This is permanent!')) {
Meteor.call('customers.remove', customerId, (error) => {
if (error) {
console.log('danger');
} else {
console.log('success');
history.push('/customers');
}
});
}
};
const renderCustomer = (cust, match, history) => (cust ? (
<div className="ViewCustomer">
<div className="page-header clearfix">
<h4 className="pull-left">{ cust && cust.firstname }</h4>
<ButtonToolbar className="pull-right">
<ButtonGroup bsSize="small">
<Button onClick={() => history.push(`${match.url}/edit`)}>Edit</Button>
<Button onClick={() => handleRemove(cust._id, history)} className="text-danger">Delete</Button>
</ButtonGroup>
</ButtonToolbar>
</div>
{ cust && cust.firstname }
</div>
) : <NotFound />);
const ViewCustomer = ({ cust, match, history }) => (
renderCustomer(cust, match, history)
);
ViewCustomer.propTypes = {
cust: PropTypes.object.isRequired,
match: PropTypes.object.isRequired,
history: PropTypes.object.isRequired,
};
export default createContainer(({ match }) => {
const customerId = match.params._id;
const subscription = Meteor.subscribe('customers.view', customerId);
return {
cust: Customers.findOne(customerId) || {},
};
}, ViewCustomer);
and api/customers.js
import { Meteor } from 'meteor/meteor';
import { Mongo } from 'meteor/mongo';
import { check } from 'meteor/check';
export const Customers = new Mongo.Collection('customers');
Meteor.methods({
'customers.insert': function customersInsert(cust) {
check(cust, {
custId: String,
firstname: String,
lastname: String,
phoneno: String,
email: String,
address: String,
remark: String,
});
try {
return Customers.insert({ owner: this.userId, ...cust });
} catch (exception) {
throw new Meteor.Error('500', exception);
}
},
'customers.update': function customersUpdate(cust) {
check(cust, {
_id: String,
custId: String,
firstname: String,
lastname: String,
phoneno: String,
email: String,
address: String,
remark: String,
});
try {
const customerId = cust._id;
Customers.update(customerId, { $set: cust });
return customerId;
} catch (exception) {
throw new Meteor.Error('500', exception);
}
},
'customers.remove': function customerRemove(customerId) {
check(customerId, Mongo.ObjectID);
try {
return Customers.remove(customerId);
} catch (exception) {
throw new Meteor.Error('500', exception);
}
},
});
Please help me to solve this problem.