Advertisement
Guest User

Untitled

a guest
Mar 6th, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import * as React from 'react';
  2. import { connect } from "react-redux";
  3. import { createStyles, Theme, WithStyles, withStyles } from '@material-ui/core/styles';
  4. import { withNamespaces, WithNamespaces } from 'react-i18next';
  5. import Grid from '@material-ui/core/Grid';
  6. import BeneficiaryInfo from './beneficiaryInfo';
  7. import SelectCustomer from '../selectCustomer/selectCustomer';
  8. import Pledge from './pledge';
  9. import Clerk from './clerk';
  10. import { SecurityPlanModel, SecurityPlanState, getInitialState } from '../../store/securityPlan/securityPlan/types';
  11. import { updateSecurityPlan, fetchSecurityPlan } from '../../store/securityPlan/securityPlan/actions';
  12. import { AppState } from '../../store';
  13. import { SecurityPlanThunkDispatch } from '../../store/axiosConfig';
  14.  
  15. const styles = (theme: Theme) => createStyles({
  16.     valittuAsiakas: {
  17.         fontWeight: 'bold'
  18.     },
  19.     paper: {
  20.         padding: '24px',
  21.         textAlign: 'left',
  22.         color: theme.palette.text.primary,
  23.     }
  24. });
  25.  
  26.  
  27. export interface BeneficiaryProps extends WithStyles<typeof styles>, WithNamespaces {
  28.     securityPlanId: number;
  29.     securityPlanState: SecurityPlanState;
  30.     updateSecurityPlan: typeof updateSecurityPlan;
  31. }
  32.  
  33. export interface BeneficiaryState {
  34.     securityPlanModel: SecurityPlanModel
  35. }
  36.  
  37. class Beneficiary extends React.Component<BeneficiaryProps, BeneficiaryState> {
  38.  
  39.     readonly state = {
  40.         securityPlanModel: {
  41.             id: 0,
  42.             profileId: 0,
  43.             insuranceIsPledged: false,
  44.             termsHasBeenGivenToCustomer: false,
  45.             clerkName: "",
  46.             clerkCostcenter: "",
  47.         }
  48.     }
  49. constructor(props: BeneficiaryProps){
  50.     super(props);
  51.     this.onSecurityPlanModelChange = this.onSecurityPlanModelChange.bind(this);
  52. }
  53.  
  54.     async componentDidMount() {
  55.         // var joo = getInitialState().model;
  56.         var diipa1 = this.state.securityPlanModel;
  57.         this.setState({ securityPlanModel: { ...this.props.securityPlanState.model } })
  58.         var diipa = this.state.securityPlanModel;
  59.         //this.state.securityPlanModel = {...this.props.securityPlanState.model};
  60.     }
  61.  
  62.     render() {
  63.         return (
  64.  
  65.             <Grid container={true} spacing={24}>
  66.                 <Grid item={true} xs={12}>
  67.                     {this.props.securityPlanId !== 0 && <SelectCustomer securityPlanId={this.props.securityPlanId} />}
  68.                 </Grid>
  69.  
  70.                 <Grid item={true} xs={12}>
  71.                     <BeneficiaryInfo securityPlanId={this.props.securityPlanId} />
  72.                 </Grid>
  73.  
  74.                 <Grid item={true} xs={12}>
  75.                     <Pledge model={this.state.securityPlanModel} onChange={this.onSecurityPlanModelChange} />
  76.                 </Grid>
  77.  
  78.                 <Grid item={true} xs={12}>
  79.                     <Clerk model={this.state.securityPlanModel} onChange={this.onSecurityPlanModelChange} />
  80.                 </Grid>
  81.                 {this.state.securityPlanModel.clerkCostcenter}
  82.             </Grid>
  83.         )
  84.     }
  85.  
  86.  
  87.  
  88.  
  89.     // onSecurityPlanModelChange = (field: keyof SecurityPlanModel, value: any) => {
  90.     //     var model = { ...this.props.securityPlanState.model, [field]: value }
  91.     //     this.setState({securityPlanModel: model});
  92.     //     // this.props.updateSecurityPlan(model);
  93.     // };
  94.  
  95.     //type InputChangeHandler = (event: React.ChangeEvent<HTMLInputElement>) => void;
  96.     onSecurityPlanModelChange = (event: React.ChangeEvent<HTMLInputElement>) => {
  97.         var model = { ...this.state.securityPlanModel };
  98.         var field = event.target.name as keyof SecurityPlanModel;
  99.         var value = event.target.value;
  100.         model[field] = value;
  101.         this.setState({ securityPlanModel: model });
  102.         var state = this.state;
  103.         //this.props.updateSecurityPlan(model);
  104.     };
  105.  
  106. }
  107.  
  108.  
  109. const mapDispatchToProps = (dispatch: SecurityPlanThunkDispatch) => ({
  110.     //fetchSecurityPlan: (securityPlanId: number) => dispatch(fetchSecurityPlan(securityPlanId)),
  111.     updateSecurityPlan: (model: SecurityPlanModel) => dispatch(updateSecurityPlan(model)),
  112. });
  113.  
  114. const mapStateToProps = (state: AppState, ) => ({
  115.     securityPlanState: state.securityPlan,
  116. })
  117.  
  118. export default connect(mapStateToProps, mapDispatchToProps)(withStyles(styles)(withNamespaces()(Beneficiary)));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement