Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import React, { Component } from 'react';
  2. import { connect } from 'react-redux';
  3. import LayoutContentWrapper from '../../../../components/utility/layoutWrapper';
  4. import LayoutContent from '../../../../components/utility/layoutContent';
  5. import TitlePage from '../../../../components/5xmais/title-page';
  6. import HeaderPage from '../../../../components/5xmais/header-page';
  7. import LinkBackPage from '../../../../components/5xmais/link-back-page';
  8. import ErrorGetPage from '../../../../components/5xmais/error-get-page';
  9. import LayoutSection from '../../../../components/5xmais/layout-section';
  10. import Questions from '../../../../components/5xmais/questions';
  11. import ConfirmationStep from '../../../../components/5xmais/confirmation-step';
  12. import TitleSection from '../../../../components/5xmais/title-section';
  13. import Presentation from '../../../../components/5xmais/presentation';
  14. import ButtonsFixed from '../../../../components/5xmais/buttons-fixed';
  15. import message from '../../../../components/feedback/message';
  16. import {Content, PresentationStartup} from './style';
  17. import {
  18.   getErrorPage,
  19.   clearUi,
  20.   fetchingApis,
  21.   successUiLoadingApi,
  22.   clearErrosUi
  23. } from '../../../../redux/firstStage/action-creators';
  24. import {
  25.   fetchItem as fetchApplicationFormStartup
  26. } from '../../../../redux/applicationFormStartup/action-creators';
  27. import {
  28.   fetchList as fetchListQuestions,
  29.   saveItem as saveQuestion,
  30.   editItem as editQuestion
  31. } from '../../../../redux/firstStageQuestions/action-creators';
  32. import {
  33.   openAttachment,
  34.   closeAttachment,
  35.   saveItem as saveAttachment
  36. } from '../../../../redux/attachmentApplicationForm/action-creators';
  37.  
  38. class Page extends Component {
  39.   constructor(props) {
  40.     super(props);
  41.     this.idItem = this.props.match.params.id;
  42.     this.urlBackPage = this.props.match.url.split("/primeira-etapa").shift();
  43.   }
  44.  
  45.   handleSubmit = (data) => {
  46.     const {
  47.       getErrorPage,
  48.       clearErrosUi,
  49.       saveQuestion,
  50.       editQuestion
  51.     } = this.props;
  52.     clearErrosUi();
  53.     message.loading('Enviando sua resposta...', 0);
  54.     const {id} = data;
  55.     const action = (id) ? editQuestion(id, {...data}) : saveQuestion({...data});
  56.     const messageSuccess = (id) ? 'Sua resposta foi atualizada com sucessso!' : 'Sua resposta foi salva com sucesso!';
  57.     action
  58.       .then(()=>{
  59.         message.destroy();
  60.         message.success(messageSuccess, 3);
  61.       })
  62.       .catch(err => {
  63.         message.destroy();
  64.         getErrorPage(err)
  65.       })
  66.   }
  67.  
  68.   handleSubmitAttachment = (data) => {
  69.     const {saveAttachment} = this.props
  70.     return console.log('rensga')
  71.   }
  72.  
  73.   handleConfirmationStep = () => {
  74.  
  75.   }
  76.  
  77.   handleAttachment = () => {
  78.     const {openAttachment} = this.props;
  79.     console.log('open')
  80.     openAttachment()
  81.   }
  82.   handleCloseAttachment = () => {
  83.     const {closeAttachment} = this.props;
  84.     console.log('close')
  85.     closeAttachment()
  86.   }
  87.  
  88.   componentDidMount() {
  89.     const {
  90.       fetchingApis,
  91.       successUiLoadingApi,
  92.       getErrorPage,
  93.       fetchListQuestions,
  94.       fetchApplicationFormStartup
  95.     } = this.props;
  96.     fetchingApis();
  97.     fetchApplicationFormStartup(this.idItem)
  98.       .then(() => fetchListQuestions(this.idItem))
  99.       .then(() => successUiLoadingApi())
  100.       .catch(err => {getErrorPage(err)})
  101.   }
  102.  
  103.   componentWillUnmount(){
  104.     const {
  105.       clearUi
  106.     } = this.props;
  107.     clearUi();
  108.   }
  109.  
  110.   render() {
  111.     const {
  112.       isLoading,
  113.       errorPage,
  114.       firstStageQuestions,
  115.       ApplicationFormStartup,
  116.       attachment,
  117.       idToken
  118.     } = this.props;
  119.     const listAttachments = [{
  120.       uid: '-1',
  121.       name: 'xxx.png',
  122.       status: 'done',
  123.       url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
  124.       thumbUrl: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
  125.     }, {
  126.       uid: '-2',
  127.       name: 'yyy.png',
  128.       status: 'done',
  129.       url: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
  130.       thumbUrl: 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png',
  131.     }];
  132.     const questionsNotAnswered = firstStageQuestions.filter(question=>question.startupAnswer===null);
  133.     const disabledButtonConfirmation = (questionsNotAnswered.length) ? true : false;
  134.     const titleStep = (ApplicationFormStartup.applicationForm) ? ApplicationFormStartup.applicationForm.title : 'Apresentação';
  135.     const descriptionStep = (ApplicationFormStartup.applicationForm) ? ApplicationFormStartup.applicationForm.description : '';
  136.     return (
  137.       <Content>
  138.         <LayoutContentWrapper>
  139.           <TitlePage title='Primeira Etapa' />
  140.           <LayoutContent>
  141.             <HeaderPage>
  142.               <LinkBackPage url={this.urlBackPage} />
  143.             </HeaderPage>
  144.             <LayoutSection loading={isLoading}>
  145.               <PresentationStartup>
  146.                 <TitleSection title={titleStep} />
  147.                 <Presentation text={descriptionStep} />
  148.               </PresentationStartup>
  149.               <Questions
  150.                 questions = {firstStageQuestions}
  151.                 handleSubmit = {this.handleSubmit}
  152.                 applicationFormStartupId = {parseInt(this.idItem, 0)}
  153.               />
  154.               <ConfirmationStep
  155.                 text = 'Confirmar Finalização da Primeira Etapa'
  156.                 handleClick = {this.handleConfirmationStep}
  157.                 disabled = {disabledButtonConfirmation}
  158.               />
  159.             </LayoutSection>
  160.             <ButtonsFixed
  161.               handleAttachment={this.handleAttachment}
  162.               handleSubmitAttachment={this.handleSubmitAttachment}
  163.               handleCancel={this.handleCloseAttachment}
  164.               handleOk={this.handleCloseAttachment}
  165.               idToken={idToken}
  166.               visible={attachment}
  167.               listAttachments={listAttachments}
  168.             />
  169.           </LayoutContent>
  170.           <ErrorGetPage error={errorPage} />
  171.         </LayoutContentWrapper>
  172.       </Content>
  173.     );
  174.   }
  175. }
  176.  
  177. const mapStateToProps = (state) => ({
  178.   isLoading: state.FirstStage.ui.isFetching,
  179.   errorPage: state.FirstStage.ui.errorPage,
  180.   firstStageQuestions: state.FirstStageQuestions.list.data,
  181.   ApplicationFormStartup: state.ApplicationFormStartup.item.data,
  182.   idToken: state.AuthSystem.idToken,
  183.   attachment: state.AttachmentApplicationForm.ui.attachmentOpen
  184. });
  185.  
  186. const mapDispatchToProps = (dispatch) => ({
  187.   successUiLoadingApi: () => dispatch(successUiLoadingApi),
  188.   getErrorPage: (data) => dispatch(getErrorPage(data)),
  189.   fetchingApis: () => dispatch(fetchingApis),
  190.   clearUi: () => dispatch(clearUi),
  191.   fetchListQuestions: (id) => dispatch(fetchListQuestions(id)),
  192.   saveQuestion: (data) => dispatch(saveQuestion(data)),
  193.   editQuestion: (id, data) => dispatch(editQuestion(id, data)),
  194.   clearErrosUi: () => dispatch(clearErrosUi),
  195.   fetchApplicationFormStartup: (id) => dispatch(fetchApplicationFormStartup(id)),
  196.   openAttachment: () => dispatch(openAttachment),
  197.   closeAttachment: () => dispatch(closeAttachment),
  198.   saveAttachment: (data) => dispatch(saveAttachment(data)),
  199. });
  200.  
  201. export default connect(mapStateToProps, mapDispatchToProps)(Page);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement