Skip to content

Commit 043f364

Browse files
author
Antonio Contreras LEMONCODE
committed
Fix text field component and login pod and fix other components
1 parent d86937c commit 043f364

11 files changed

Lines changed: 122 additions & 81 deletions

File tree

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,23 @@
11
import React from 'react';
2-
import { FieldRenderProps } from 'react-final-form';
2+
import { useField } from 'formik';
33
import MuiTextField, { TextFieldProps } from '@material-ui/core/TextField';
44

5-
type Props = Partial<FieldRenderProps<any, any>>;
6-
7-
export const TextFieldComponent: React.FunctionComponent<Props &
8-
TextFieldProps> = props => {
9-
const { input, meta, ...rest } = props;
10-
const textFieldProps = Boolean(input) ? input : rest;
11-
let inputProps = rest.inputProps;
12-
if (input) {
13-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
14-
const { name, onChange, value, ...restInputProps } = input;
15-
inputProps = restInputProps;
16-
}
17-
5+
export const TextFieldComponent: React.FunctionComponent<TextFieldProps> = props => {
6+
const [field, meta] = useField(props.name);
7+
const textFieldProps = Boolean(field) ? field : props;
188
const hasError = Boolean(meta && meta.touched && meta.error);
199

2010
return (
2111
<MuiTextField
22-
{...rest}
12+
{...props}
2313
name={textFieldProps.name}
2414
onChange={textFieldProps.onChange}
15+
onBlur={textFieldProps.onBlur}
2516
value={textFieldProps.value}
2617
error={hasError}
2718
helperText={hasError ? meta.error : ''}
28-
inputProps={inputProps}
2919
fullWidth={true}
20+
margin="normal"
3021
/>
3122
);
3223
};

src/common/constants/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './months';

src/common/constants/months.ts

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import { Lookup } from '../models';
2+
3+
export const monthList: Lookup[] = [
4+
{
5+
id: '1',
6+
name: 'Enero',
7+
},
8+
{
9+
id: '2',
10+
name: 'Febrero',
11+
},
12+
{
13+
id: '3',
14+
name: 'Marzo',
15+
},
16+
{
17+
id: '4',
18+
name: 'Abril',
19+
},
20+
{
21+
id: '5',
22+
name: 'Mayo',
23+
},
24+
{
25+
id: '6',
26+
name: 'Junio',
27+
},
28+
{
29+
id: '7',
30+
name: 'Julio',
31+
},
32+
{
33+
id: '8',
34+
name: 'Agosto',
35+
},
36+
{
37+
id: '9',
38+
name: 'Septiembre',
39+
},
40+
{
41+
id: '10',
42+
name: 'Octubre',
43+
},
44+
{
45+
id: '11',
46+
name: 'Noviembre',
47+
},
48+
{
49+
id: '12',
50+
name: 'Dicienbre',
51+
},
52+
];

src/pods/employee/api/employee.api-model.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ export interface Employee {
33
name: string;
44
email: string;
55
isActive: boolean;
6-
temporalKey: string;
7-
projects: ProjectSummary[];
6+
temporalPassword?: string;
7+
projects?: ProjectSummary[];
88
}
99

1010
export interface ProjectSummary {
1111
id: string;
12-
isAssigned: boolean;
12+
isAssigned?: boolean;
1313
employeeName: string;
1414
}

src/pods/employee/api/employee.mock-data.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ export const mockEmployee: Employee = {
2828
name: 'Prueba Nombre',
2929
email: 'prueba@email.com',
3030
isActive: true,
31-
temporalKey: 'clave',
31+
temporalPassword: 'admin',
3232
projects: mockProjectSummaryList,
3333
};

src/pods/employee/components/data.component.tsx

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import { Employee } from '../employee.vm';
99
interface Props {
1010
employee: Employee;
1111
className?: string;
12-
onSave: (employee: Employee) => void;
1312
isEditMode: boolean;
13+
onSave: (employee: Employee) => void;
1414
onCancel: () => void;
1515
}
1616

@@ -21,7 +21,6 @@ export const DataComponent: React.FunctionComponent<Props> = ({
2121
isEditMode,
2222
onCancel,
2323
}) => {
24-
console.log(employee);
2524
return (
2625
<Formik
2726
initialValues={employee}
@@ -37,38 +36,29 @@ export const DataComponent: React.FunctionComponent<Props> = ({
3736
InputProps={{
3837
readOnly: true,
3938
}}
40-
value={employee.id}
4139
/>
4240
{!isEditMode && (
4341
<TextFieldComponent
4442
label="Clave Temporal"
45-
name="temporalKey"
46-
className={classes.temporalKey}
47-
disabled
48-
value={employee.temporalKey}
43+
name="temporalPassword"
44+
className={classes.temporalPassword}
4945
/>
5046
)}
5147
<TextFieldComponent
5248
label="Nombre"
5349
name="name"
5450
className={classes.name}
55-
disabled
56-
value={employee.name}
5751
/>
5852
<TextFieldComponent
5953
label="Email"
6054
name="email"
6155
className={classes.email}
62-
disabled
63-
value={employee.email}
6456
/>
6557
<CheckboxComponent
6658
name="isActive"
6759
label="Activo"
6860
color="primary"
6961
className={classes.isActive}
70-
disabled
71-
value={employee.isActive}
7262
/>
7363
<CommandFooterComponent
7464
onCancel={onCancel}

src/pods/employee/components/data.styles.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ interface Props {
88
const getDynamicAreaNames = (props: Props) => {
99
return props.isEditMode
1010
? `'id employeeName'`
11-
: `'id temporalKey' 'employeeName .'`;
11+
: `'id temporalPassword' 'employeeName .'`;
1212
};
1313

1414
export const form = (props: Props) => css`
1515
display: grid;
1616
grid-template-columns: 1fr;
1717
grid-template-areas:
1818
'id'
19-
${props.isEditMode ? '' : `'temporalKey'`}
19+
${props.isEditMode ? '' : `'temporalPassword'`}
2020
'employeeName'
2121
'email'
2222
'isActive'
@@ -39,8 +39,8 @@ export const id = css`
3939
grid-area: id;
4040
`;
4141

42-
export const temporalKey = css`
43-
grid-area: temporalKey;
42+
export const temporalPassword = css`
43+
grid-area: temporalPassword;
4444
`;
4545

4646
export const name = css`

src/pods/employee/components/project-row.component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export const EmployeeRowComponent: React.FunctionComponent<Props> = ({
1515
return (
1616
<RowComponent>
1717
<CellComponent>
18-
<Checkbox checked={row.isAssigned} disabled />
18+
<Checkbox checked={row.isAssigned} color="primary" />
1919
</CellComponent>
2020
<CellComponent>{row.employeeName}</CellComponent>
2121
</RowComponent>

src/pods/employee/components/report.component.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import React from 'react';
22
import { Formik, Form } from 'formik';
33
import { SelectComponent } from 'common/components';
4+
import { monthList } from 'common/constants';
45
import * as classes from './report.styles';
56
import { CommandFooterComponent } from 'common-app/command-footer';
67
import { cx } from 'emotion';
@@ -27,16 +28,21 @@ export const ReportComponent: React.FunctionComponent<Props> = ({
2728
<SelectComponent
2829
name="month"
2930
label="Mes"
30-
items={[]}
31-
disabled
31+
items={monthList}
3232
className={classes.month}
33+
disabled
3334
/>
3435
<SelectComponent
3536
name="year"
3637
label="Año"
37-
items={[]}
38-
disabled
38+
items={[
39+
{
40+
id: '2020',
41+
name: '2020',
42+
},
43+
]}
3944
className={classes.year}
45+
disabled
4046
/>
4147
<CommandFooterComponent
4248
onCancel={onCancel}

src/pods/employee/employee.vm.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ export interface Employee {
33
name: string;
44
email: string;
55
isActive: boolean;
6-
temporalKey: string;
6+
temporalPassword?: string;
77
projects: ProjectSummary[];
88
}
99

1010
export interface ProjectSummary {
1111
id: string;
12-
isAssigned: boolean;
12+
isAssigned?: boolean;
1313
employeeName: string;
1414
}
1515

@@ -18,6 +18,6 @@ export const createEmptyEmployee = (): Employee => ({
1818
name: '',
1919
email: '',
2020
isActive: false,
21-
temporalKey: '',
21+
temporalPassword: '',
2222
projects: [],
2323
});

0 commit comments

Comments
 (0)