import React, { Component } from "react"; import { connect } from "react-redux"; import { Redirect } from "react-router-dom"; import { Container, Form, Header, Input, Label, Message } from "semantic-ui-react"; import { clearPriceRequestError, clearPriceRequestSuccess, setFormPriceAmount } from "../../../actions/price/reducer.actions"; import { updatePriceRequest } from "../../../actions/price/saga.actions"; import Error from "../../Shared/Error"; class UpdatePriceForm extends Component { constructor(props) { super(props); // Get referenced employee const { selfUser } = props; const employeeUUID = this.props.match.params.providerUUID; const employees = ((selfUser || {}).client || {}).employees || []; const employee = employees.filter(employee => employee.uuid === employeeUUID)[0] || null; // Get referenced price const priceUUID = this.props.match.params.priceUUID; const price = (employee.prices || []).filter( price => price.uuid === priceUUID && !price.deleted )[0] || null; this.props.dispatch(setFormPriceAmount((price || {}).amount || "")); this.state = { price, employee }; } componentWillMount = () => { this.props.dispatch(clearPriceRequestError()); this.props.dispatch(clearPriceRequestSuccess()); }; changeAmount = event => { this.props.dispatch(setFormPriceAmount(event.target.value)); }; onSubmitPrice = event => { event.preventDefault(); const { amount } = this.props; const { price } = this.state; this.props.dispatch( updatePriceRequest({ uuid: (price || {}).uuid, amount }) ); }; render() { const { isSendingPriceRequest, priceRequestError, priceRequestSuccess, amount, selfUser } = this.props; const { employee, price } = this.state; if (!selfUser.client) { return ; } return ( ); } } const UpdatePriceFormView = ({ isSendingPriceRequest, priceRequestError, priceRequestSuccess, employee, price, amount, changeAmount, onSubmitPrice }) => (
Update Assigned Work
{employee && ( Employee Information UUID: {employee.uuid} Provider Email: {(employee.provider || {}).email || "No Email!"} Provider Name:{" "} {`${(employee.provider || {}).first_name} ${ (employee.provider || {}).last_name }`.trim() || "No Name!"} Provider Phone Number:{" "} {`${((employee.provider || {}).userinfo || {}).phone_number || "No Number!"}`} Approved: {"" + employee.approved} Deleted: {"" + employee.deleted} )} {!employee && ( Invalid Employee

No accessable employee exists for given UUID.

)}
Update Price successful!

Price successfully created.

{!!priceRequestSuccess && ( )}
Update Price
); function mapStateToProps(state) { return { ...state.price, selfUser: state.user.selfUser }; } export default connect(mapStateToProps)(UpdatePriceForm);