Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { useState } from 'react';
  2. import PropTypes from 'prop-types';
  3.  
  4. import Textarea from 'Components/Inputs/Textarea';
  5. import Dropdown from 'Components/Dropdown';
  6. import TextInput from 'Components/Inputs/TextInput';
  7. import DateInput from 'Components/Inputs/DateInput';
  8. import CurrencyInput from 'Components/Inputs/CurrencyInput';
  9. import BaseReportField from '../../Fields/BaseReportField';
  10.  
  11. import {
  12.   GuaranteeRepeaterContainer,
  13.   Wrapper,
  14.   InputsWrapper,
  15.   AlignElement
  16. } from './GuaranteeRepeater.styles';
  17.  
  18. const technicalFormOptions = [
  19.   { label: '', value: 'option-0' },
  20.   { label: 'Garanzia Reale Ipoteca', value: 'option-1' },
  21.   { label: 'Garanzia Reale Pegno', value: 'option-2' },
  22.   { label: 'Garanzia Personale Fideiussione Specifica', value: 'option-3' },
  23.   { label: 'Garanzia Personale Fideiussione Omnibus', value: 'option-4' }
  24. ];
  25.  
  26. const ifPersonalGuarantee = [
  27.   { label: '', value: 'option-0' },
  28.   {
  29.     label: 'Garanzia da Amministrazioni centrali o settore pubblico',
  30.     value: 'option-1'
  31.   },
  32.   { label: 'Garanzia da banche', value: 'option-2' },
  33.   { label: 'Garanzia da intermediari finanziari: Confidi', value: 'option-3' },
  34.   { label: 'Garanzia da intermediari finanziari: Altro', value: 'option-4' },
  35.   { label: 'Garanzia da società non finanziarie', value: 'option-5' },
  36.   { label: 'Altre garanzie personali', value: 'option-6' },
  37.   { label: 'Altro', value: 'altro' },
  38.   { label: 'Non applicabile', value: 'option-8' }
  39. ];
  40.  
  41. const ifRealMortgageGuarantee = [
  42.   { label: '', value: 'option-0' },
  43.   {
  44.     label: 'Immobiliare: Residenzialea',
  45.     value: 'option-1'
  46.   },
  47.   { label: 'Immobiliare: Commerciale', value: 'option-2' },
  48.   { label: 'Immobiliare: Uffici', value: 'option-3' },
  49.   { label: 'Immobiliare: Hotel', value: 'option-4' },
  50.   { label: 'Immobiliare: Industriale', value: 'option-5' },
  51.   { label: 'Immobiliare: Terreni', value: 'option-6' },
  52.   { label: 'Immobiliare: Altro', value: 'option-7' },
  53.   { label: 'Immobiliare: Misto Residenziale-Commerciale', value: 'option-8' },
  54.   { label: 'Immobiliare: Misto Residenziale-Industriale', value: 'option-9' },
  55.   { label: 'Immobiliare: Misto Commerciale-Industriale', value: 'option-10' },
  56.   { label: 'Altro', value: 'altro' },
  57.   { label: 'Non applicabile', value: 'option-12' }
  58. ];
  59.  
  60. const ifRealPledgeGuarantee = [
  61.   { label: '', value: 'option-0' },
  62.   {
  63.     label: 'Beni Strumentali: Industriale',
  64.     value: 'option-1'
  65.   },
  66.   { label: 'Beni Strumentali: settore automobilistico', value: 'option-2' },
  67.   { label: 'Beni Strumentali: aviazione', value: 'option-3' },
  68.   { label: 'Beni Strumentali: navigazione', value: 'option-4' },
  69.   { label: 'Liquidità', value: 'option-5' },
  70.   { label: 'Azioni', value: 'option-6' },
  71.   { label: 'Titoli obbligazionari', value: 'option-7' },
  72.   { label: 'Commodities', value: 'option-8' },
  73.   { label: 'Altri strumenti finanziari', value: 'option-9' },
  74.   { label: 'Altro', value: 'altro' },
  75.   { label: 'Non applicabile', value: 'option-11' }
  76. ];
  77.  
  78. const mortgageOptions = [
  79.   { label: '', value: 'option-0' },
  80.   { label: '1° Grado', value: 'option-1' },
  81.   { label: '2° Grado', value: 'option-2' },
  82.   { label: 'Altro', value: 'option-3' }
  83. ];
  84.  
  85. const GuaranteeRepeater = ({ pathname }) => {
  86.   const [otherValueStatus, setOtherValueStatus] = useState(false);
  87.   const [categoryFormOptions, setCategoryFormOptions] = useState([
  88.     { label: '', value: 'option' }
  89.   ]);
  90.  
  91.   const technicalFormOptionsHandler = value => {
  92.     if (value === 'option-1') {
  93.       setCategoryFormOptions([...ifRealMortgageGuarantee]);
  94.     } else if (value === 'option-2') {
  95.       setCategoryFormOptions([...ifRealPledgeGuarantee]);
  96.     } else if (value === 'option-0') {
  97.       setCategoryFormOptions([{ label: '', value: 'option-0' }]);
  98.       if (otherValueStatus) {
  99.         setOtherValueStatus(false);
  100.       }
  101.     } else {
  102.       setCategoryFormOptions([...ifPersonalGuarantee]);
  103.     }
  104.   };
  105.  
  106.   const otherValueStatusHandler = value => {
  107.     if (value === 'altro') {
  108.       setOtherValueStatus(true);
  109.     } else {
  110.       setOtherValueStatus(false);
  111.     }
  112.   };
  113.  
  114.   return (
  115.     <GuaranteeRepeaterContainer>
  116.       <Wrapper pathname={pathname}>
  117.         <BaseReportField label="ID Garanzia" field={<TextInput />} />
  118.         <BaseReportField label="ID Posizione" field={<TextInput />} />
  119.         <BaseReportField label="ID Garante" field={<TextInput />} />
  120.         <BaseReportField
  121.           label="Forma Tecnica"
  122.           field={
  123.             <Dropdown
  124.               title=""
  125.               options={technicalFormOptions}
  126.               onChange={technicalFormOptionsHandler}
  127.             />
  128.           }
  129.         />
  130.         <BaseReportField
  131.           label="Categoria Forma Tecnica"
  132.           field={
  133.             <Dropdown
  134.               options={categoryFormOptions}
  135.               onChange={otherValueStatusHandler}
  136.             />
  137.           }
  138.         />
  139.         {otherValueStatus && (
  140.           <AlignElement>
  141.             <BaseReportField
  142.               label="Descrivi Altro"
  143.               field={
  144.                 <Textarea
  145.                   placeholder="Aggiungi una descrizione"
  146.                   expand={true}
  147.                 />
  148.               }
  149.             />
  150.           </AlignElement>
  151.         )}
  152.         <InputsWrapper pathname={pathname}>
  153.           <BaseReportField label="Valore Garanzia" field={<CurrencyInput />} />
  154.           <BaseReportField label="Data di Iscrizione" field={<DateInput />} />
  155.           <BaseReportField label="Data della Garanzia " field={<DateInput />} />
  156.         </InputsWrapper>
  157.         <BaseReportField
  158.           label="Grado Ipoteca"
  159.           field={<Dropdown options={mortgageOptions} />}
  160.         />
  161.         <InputsWrapper pathname={pathname}>
  162.           <BaseReportField
  163.             label="Gravami Precedenti"
  164.             field={<CurrencyInput />}
  165.           />
  166.           <BaseReportField
  167.             label="Ipoteche di Pari Grado"
  168.             field={<CurrencyInput />}
  169.           />
  170.         </InputsWrapper>
  171.       </Wrapper>
  172.     </GuaranteeRepeaterContainer>
  173.   );
  174. };
  175.  
  176. GuaranteeRepeater.propTypes = {
  177.   pathname: PropTypes.string
  178. };
  179.  
  180. GuaranteeRepeater.defaultProps = {
  181.   pathname: ''
  182. };
  183.  
  184. export default GuaranteeRepeater;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement