Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.42 KB | None | 0 0
  1. import React, { FC, useEffect } from 'react';
  2. import { Col, Row } from 'react-bootstrap';
  3. import useForm from 'react-hook-form';
  4. import { RouteComponentProps } from 'react-router';
  5. import { EditForm, EditViewProps, ERROR, findByExample, InputGroupInline, InputType, showToast, WindowComponent } from 'summer';
  6. import { CLASS_NAME, LivroFolha } from '../../../models/dtos/mcg/livroFolha';
  7.  
  8. interface LivroFolhaEditViewProps extends EditViewProps<LivroFolha> {}
  9.  
  10. function validateExtras(formData: any): string[] {
  11. const errors = [];
  12.  
  13. if (formData.diarioFolha === 1) {
  14. errors.push('Página Inicial - Diário não pode ser igual a 1, caso não deseje configura-lá utilize 0');
  15. }
  16.  
  17. if (formData.caixaFolha === 1) {
  18. errors.push('Página Inicial - Caixa não pode ser igual a 1, caso não deseje configura-lá utilize 0');
  19. }
  20.  
  21. if (formData.razaoFolha === 1) {
  22. errors.push('Página Inicial - Razão não pode ser igual a 1, caso não deseje configura-lá utilize 0.');
  23. }
  24.  
  25. if (formData.lalurAFolha === 1) {
  26. errors.push("Página Inicial - Lalur Parte 'A' não pode ser igual a 1, caso não deseje configura-lá utilize 0");
  27. }
  28. return errors;
  29. }
  30.  
  31. const LivroFolhaEditView: FC<LivroFolhaEditViewProps & RouteComponentProps> = props => {
  32. const { reset, ...formProps } = useForm({ mode: 'onBlur' });
  33.  
  34. useEffect(() => {
  35. const example: LivroFolha = { id: null, entity: null };
  36. findByExample(example, CLASS_NAME, {
  37. errorFunction: (mensagem: string): void => {
  38. showToast(mensagem, ERROR);
  39. },
  40. thenFunction: (result: LivroFolha): void => {
  41. setTimeout(() => reset(result), 500);
  42. },
  43. });
  44. }, [reset]);
  45.  
  46. return (
  47. <WindowComponent>
  48. <EditForm formProps={formProps} editViewProps={props} dtoClassName={CLASS_NAME} validateExtras={validateExtras}>
  49. <Row>
  50. <label>
  51. <strong>Básico</strong>
  52. </label>
  53. <Col xs={3}>
  54. <label>
  55. <strong>Nº Livro</strong>
  56. </label>
  57. <InputGroupInline
  58. formProps={{ ...formProps, validation: { required: true } }}
  59. id="tiDiarioLivro"
  60. label="Diário"
  61. type={InputType.NUMBER}
  62. isPrependLabel={true}
  63. />
  64. <InputGroupInline
  65. formProps={{ ...formProps, validation: { required: true } }}
  66. id="tiCaixaLivro"
  67. label="Caixa"
  68. type={InputType.NUMBER}
  69. isPrependLabel={true}
  70. />
  71. <InputGroupInline
  72. formProps={{ ...formProps, validation: { required: true } }}
  73. id="tiRazaoLivro"
  74. label="Razão"
  75. type={InputType.NUMBER}
  76. isPrependLabel={true}
  77. />
  78. <InputGroupInline
  79. formProps={{ ...formProps, validation: { required: true } }}
  80. id="tiLalurALivro"
  81. label="Lalur Parte 'A'"
  82. type={InputType.NUMBER}
  83. isPrependLabel={true}
  84. />
  85. </Col>
  86. <Col xs={2}>
  87. <label>
  88. <strong>Página Inicial</strong>
  89. </label>
  90. <InputGroupInline formProps={{ ...formProps, validation: { required: true } }} id="tiDiarioFolha" type={InputType.NUMBER} />
  91. <InputGroupInline
  92. formProps={{ ...formProps, validation: { required: true } }}
  93. id="tiCaixaFolha"
  94. type={InputType.NUMBER}
  95. value="@{pm.livroFolha.caixaFolha}"
  96. />
  97. <InputGroupInline formProps={{ ...formProps, validation: { required: true } }} id="tiRazaoLivro" type={InputType.NUMBER} />
  98. <InputGroupInline formProps={{ ...formProps, validation: { required: true } }} id="tiLalurAFolha" type={InputType.NUMBER} />
  99. </Col>
  100. <label>
  101. <strong>SPED</strong>
  102. </label>
  103. <Col xs={3}>
  104. <label>
  105. <strong>Nº de Ordem</strong>
  106. </label>
  107. <InputGroupInline
  108. formProps={{ ...formProps, validation: { required: true } }}
  109. id="tiDiarioGeral"
  110. label="G - Diário Geral"
  111. type={InputType.NUMBER}
  112. isPrependLabel={true}
  113. />
  114. </Col>
  115. </Row>
  116. </EditForm>
  117. </WindowComponent>
  118. );
  119. };
  120.  
  121. export default LivroFolhaEditView;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement