https://try.gitea.io/nadal/repository
Used this in a coding challenge after a job interview. I didn't get chosen, but I was wondering if it was because of the code quality in the project.
import React, { Component } from 'react';
import * as ExpenseActions from '../actions/ExpenseActions';
import { bindActionCreators } from 'redux';
import { connect } from 'react-redux';
import { PropTypes } from 'prop-types';
import ExpenseTable from '../components/ExpenseTable';
export class ExpenseContainer extends Component {
constructor(props) {
super(props)
}
/**
* Triggers the create action
* @method
*
*/
createExpense = (expense) => {
this.props.actions.CreateExpense(expense)
}
/**
* Triggers the start edit action
* @method
*
*/
startEditing = (id) => {
this.props.actions.StartEditing(id);
}
/**
* Triggers the cancel action
* @method
*
*/
cancelEditing = (id) => {
this.props.actions.CancelEditing(id);
}
/**
* Triggers the edit action
* @method
*
*/
editExpense = (expense) => {
this.props.actions.UpdateExpense(expense);
}
/**
* Triggers the delete action
* @method
*
*/
deleteExpense = (expense) => {
this.props.actions.DeleteExpense(expense);
}
render() {
return (
<div className="expense-container">
<ExpenseTable
subTotal={this.props.expenses.subTotal}
total={this.props.expenses.total}
expenses={this.props.expenses.expenses}
createExpense={this.createExpense}
startEditing={this.startEditing}
cancelEditing={this.cancelEditing}
editExpense={this.editExpense}
deleteExpense = {this.deleteExpense}
/>
</div>
);
}
}
ExpenseContainer.propTypes = {
actions: PropTypes.object.isRequired,
expenses: PropTypes.object.isRequired
}
function mapStateToProps(state, ownProps) {
return {
expenses: state.expenses
}
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators(ExpenseActions, dispatch)
}
}
export default connect(mapStateToProps, mapDispatchToProps)(ExpenseContainer);
Aside the fact, I could have used a hook called useSelector
and useDispatch
. I am not sure how I could have made it better. The backend side, I am not too sure if there's anything wrong with it, because I am not too familiar with Node/Express. Try to be as nitpicky as possible.