Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// @flow
import * as React from 'react';
import PercentageInput from '../../common/inputs/PercentageInput';
import { formatNumber } from '../../../utils/converters';
type propTypes = {
object: Object,
onChange: Function,
carrier: Object,
onEveryChange: Function,
};
export default class CarrierRow extends React.Component<propTypes> {
onChange = (field: string, value: any) => {
let { onChange, object, carrier } = this.props;
let newCP = _.clone(object.carrier_participations);
let CP = _.find(object.carrier_participations, (c) => c.carrier_id === carrier.carrier_id);
let IN = _.findIndex(object.carrier_participations, (c) => c.carrier_id === carrier.carrier_id);
let U = Object.assign({}, CP, { override_participation_pct: value});
newCP[IN] = U;
onChange && onChange('carrier_participations', newCP);
}
onEveryChange = (field: string, value: any) => {
let { onEveryChange, object, carrier } = this.props;
let newCP = _.clone(object.carrier_participations);
let CP = _.find(object.carrier_participations, (c) => c.carrier_id === carrier.carrier_id);
let IN = _.findIndex(object.carrier_participations, (c) => c.carrier_id === carrier.carrier_id);
let U = Object.assign({}, CP, { override_participation_pct: value});
newCP[IN] = U;
onEveryChange && onEveryChange('carrier_participations', newCP);
}
render() {
let { onChange, onEveryChange, object, carrier } = this.props;
let inputProps = {
className: 'size-5',
};
let CP = Object.assign({},
_.find(object.carrier_participations, (c) => c.carrier_id === carrier.carrier_id),
{_errors: {}})
return (
<div className="row">
<div className="width-remaining">
<label className="frm-lbl">{carrier.short_name}</label>
</div>
<div className="size-3 text-cell num">
{formatNumber(carrier.default_participation_pct, undefined, '%', 0)}
</div>
<PercentageInput object={CP} onChange={this.onChange} onEveryChange={this.onEveryChange} {...inputProps} name="override_participation_pct" />
<div className="size-3 text-cell num">
{formatNumber(carrier.actual_allocated_pct, undefined, '%', 0)}
</div>
<div className="size-5 text-cell num">
{formatNumber(carrier.actual_allocated_premium, '$', undefined, 0)}
</div>
</div>
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment