File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,32 +5,36 @@ import { monthList } from 'common/constants';
55import * as classes from './report.styles' ;
66import { CommandFooterComponent } from 'common-app/command-footer' ;
77import { cx } from 'emotion' ;
8+ import { formValidation } from './report.validations' ;
9+ import { Report } from '../employee.vm' ;
810
911interface Props {
12+ report : Report ;
1013 className ?: string ;
1114 onCancel : ( ) => void ;
1215 onGenerateExcel : ( ) => void ;
1316}
1417
1518export const ReportComponent : React . FunctionComponent < Props > = ( {
19+ report,
1620 className,
1721 onCancel,
1822 onGenerateExcel,
1923} ) => {
2024 return (
2125 < Formik
22- initialValues = { { } }
26+ initialValues = { report }
2327 enableReinitialize = { true }
2428 onSubmit = { onGenerateExcel }
29+ validate = { formValidation . validateForm }
2530 >
26- { ( { values } ) => (
31+ { ( ) => (
2732 < Form className = { cx ( classes . form , className ) } >
2833 < SelectComponent
2934 name = "month"
3035 label = "Mes"
3136 items = { monthList }
3237 className = { classes . month }
33- disabled
3438 />
3539 < SelectComponent
3640 name = "year"
@@ -42,7 +46,6 @@ export const ReportComponent: React.FunctionComponent<Props> = ({
4246 } ,
4347 ] }
4448 className = { classes . year }
45- disabled
4649 />
4750 < CommandFooterComponent
4851 onCancel = { onCancel }
Original file line number Diff line number Diff line change 1+ import { ValidationSchema , Validators } from '@lemoncode/fonk' ;
2+ import { createFormikValidation } from '@lemoncode/fonk-formik' ;
3+
4+ const validationSchema : ValidationSchema = {
5+ field : {
6+ month : [
7+ {
8+ validator : Validators . required ,
9+ message : 'Campo obligatorio' ,
10+ } ,
11+ ] ,
12+ year : [
13+ {
14+ validator : Validators . required ,
15+ message : 'Campo obligatorio' ,
16+ } ,
17+ ] ,
18+ } ,
19+ } ;
20+
21+ export const formValidation = createFormikValidation ( validationSchema ) ;
Original file line number Diff line number Diff line change @@ -6,12 +6,13 @@ import {
66} from 'common/components' ;
77import AppBar from '@material-ui/core/AppBar' ;
88import { DataComponent , ProjectComponent , ReportComponent } from './components' ;
9- import { Employee } from './employee.vm' ;
9+ import { Employee , Report } from './employee.vm' ;
1010import * as classes from './employee.styles' ;
1111
1212interface Props {
1313 employee : Employee ;
1414 isEditMode : boolean ;
15+ report : Report ;
1516 onSave : ( employee : Employee ) => void ;
1617 onCancel : ( ) => void ;
1718 onGenerateExcel : ( ) => void ;
@@ -20,6 +21,7 @@ interface Props {
2021export const EmployeeComponent : React . FunctionComponent < Props > = ( {
2122 employee,
2223 isEditMode,
24+ report,
2325 onSave,
2426 onCancel,
2527 onGenerateExcel,
@@ -52,6 +54,7 @@ export const EmployeeComponent: React.FunctionComponent<Props> = ({
5254 </ TabPanelComponent >
5355 < TabPanelComponent value = { tab } index = { 2 } >
5456 < ReportComponent
57+ report = { report }
5558 className = { classes . root }
5659 onGenerateExcel = { onGenerateExcel }
5760 onCancel = { onCancel }
Original file line number Diff line number Diff line change 11import React from 'react' ;
22import { EmployeeComponent } from './employee.component' ;
3- import { Employee , createEmptyEmployee } from './employee.vm' ;
3+ import {
4+ Employee ,
5+ Report ,
6+ createEmptyEmployee ,
7+ createEmptyReport ,
8+ } from './employee.vm' ;
49import { useSnackbarContext } from 'common/components' ;
510import { trackPromise } from 'react-promise-tracker' ;
611import { getEmployeeById } from './api' ;
@@ -14,6 +19,7 @@ export const EmployeeContainer: React.FunctionComponent = () => {
1419 createEmptyEmployee ( )
1520 ) ;
1621 const [ isEditMode , setIsEditMode ] = React . useState < boolean > ( false ) ;
22+ const [ report , setReport ] = React . useState < Report > ( createEmptyReport ( ) ) ;
1723 const { showMessage } = useSnackbarContext ( ) ;
1824
1925 const onLoadEmployee = async ( ) => {
@@ -52,6 +58,7 @@ export const EmployeeContainer: React.FunctionComponent = () => {
5258 < EmployeeComponent
5359 employee = { employee }
5460 isEditMode = { isEditMode }
61+ report = { report }
5562 onSave = { handleSave }
5663 onCancel = { handleCancel }
5764 onGenerateExcel = { handleGenerateExcel }
Original file line number Diff line number Diff line change @@ -13,6 +13,11 @@ export interface ProjectSummary {
1313 projectName : string ;
1414}
1515
16+ export interface Report {
17+ month : string ;
18+ year : string ;
19+ }
20+
1621export const createEmptyEmployee = ( ) : Employee => ( {
1722 id : '' ,
1823 name : '' ,
@@ -21,3 +26,8 @@ export const createEmptyEmployee = (): Employee => ({
2126 temporalPassword : '' ,
2227 projects : [ ] ,
2328} ) ;
29+
30+ export const createEmptyReport = ( ) : Report => ( {
31+ month : '' ,
32+ year : '' ,
33+ } ) ;
You can’t perform that action at this time.
0 commit comments