Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/pods/project/components/data.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Formik, Form } from 'formik';
import { TextFieldComponent, CheckboxComponent } from 'common/components';
import { CommandFooterComponent } from '../../../common-app/command-footer';
import { Project } from '../project.vm';
import { formValidation } from './data.validations';

interface Props {
project: Project;
Expand All @@ -18,7 +19,12 @@ export const DataComponent: React.FunctionComponent<Props> = ({
className,
}) => {
return (
<Formik initialValues={project} enableReinitialize={true} onSubmit={onSave}>
<Formik
initialValues={project}
enableReinitialize={true}
onSubmit={onSave}
validate={formValidation.validateForm}
>
{() => (
<Form className={className}>
<TextFieldComponent
Expand Down
11 changes: 11 additions & 0 deletions src/pods/project/components/data.validations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ValidationSchema, Validators } from '@lemoncode/fonk';
import { createFormikValidation } from '@lemoncode/fonk-formik';

const validationSchema: ValidationSchema = {
field: {
name: [Validators.required],
externalId: [Validators.required],
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

External ID is optional

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

},
};

export const formValidation = createFormikValidation(validationSchema);
15 changes: 12 additions & 3 deletions src/pods/project/components/report.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,35 @@ import { monthList } from 'common/constants';
import { CommandFooterComponent } from 'common-app/command-footer';
import { cx } from 'emotion';
import * as classes from './report.styles';
import { formValidation } from './report.validations';
import { Report } from '../project.vm';

interface Props {
report: Report;
onCancel: () => void;
className: string;
onGenerateExcel: (report: Report) => void;
}

export const ReportComponent: React.FunctionComponent<Props> = ({
report,
onGenerateExcel,
onCancel,
className,
}) => {
return (
<Formik initialValues={{}} enableReinitialize={true} onSubmit={console.log}>
<Formik
initialValues={report}
enableReinitialize={true}
onSubmit={onGenerateExcel}
validate={formValidation.validateForm}
>
{() => (
<Form className={cx(classes.form, className)}>
<SelectComponent
name="month"
label="Mes"
items={monthList}
disabled
className={classes.month}
/>
<SelectComponent
Expand All @@ -35,7 +45,6 @@ export const ReportComponent: React.FunctionComponent<Props> = ({
name: '2020',
},
]}
disabled
className={classes.year}
/>
<CommandFooterComponent
Expand Down
11 changes: 11 additions & 0 deletions src/pods/project/components/report.validations.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ValidationSchema, Validators } from '@lemoncode/fonk';
import { createFormikValidation } from '@lemoncode/fonk-formik';

const validationSchema: ValidationSchema = {
field: {
month: [Validators.required],
year: [Validators.required],
},
};

export const formValidation = createFormikValidation(validationSchema);
11 changes: 10 additions & 1 deletion src/pods/project/project.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ import * as classes from './project.styles';
interface Props {
isEditMode: boolean;
project: Project;
report: Report;
onGenerateExcel: (report: Report) => void;
onSave: (project: Project) => void;
onCancel: () => void;
}

export const ProjectComponent: React.FunctionComponent<Props> = ({
isEditMode,
project,
report,
onGenerateExcel,
onSave,
onCancel,
}) => {
Expand Down Expand Up @@ -52,7 +56,12 @@ export const ProjectComponent: React.FunctionComponent<Props> = ({
/>
</TabPanelComponent>
<TabPanelComponent value={tab} index={2}>
<ReportComponent onCancel={onCancel} className={classes.root} />
<ReportComponent
report={report}
onCancel={onCancel}
className={classes.root}
onGenerateExcel={onGenerateExcel}
/>
</TabPanelComponent>
</>
);
Expand Down
15 changes: 14 additions & 1 deletion src/pods/project/project.container.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ import { useSnackbarContext } from 'common/components';
import { getProjectById } from './api';
import { trackPromise } from 'react-promise-tracker';
import { mapProjectFromApiToVm } from './project.mapper';
import { Project, createEmptyProject } from './project.vm';
import {
Project,
createEmptyProject,
Report,
createEmptyReport,
} from './project.vm';
import { isEditModeHelper } from 'common/helpers';

export const ProjectContainer: React.FunctionComponent = () => {
const { id } = useParams();
const [project, setProject] = React.useState<Project>(createEmptyProject());
const [isEditMode, setIsEditMode] = React.useState<boolean>(false);
const [report, setReport] = React.useState<Report>(createEmptyReport());
const { showMessage } = useSnackbarContext();

const onLoadProject = async () => {
Expand All @@ -33,6 +39,11 @@ export const ProjectContainer: React.FunctionComponent = () => {
history.back();
};

const handleGenerateExcel = (report: Report) => {
// Pending to create real implementation
console.log('Excel creado');
};

React.useEffect(() => {
const isEditMode = isEditModeHelper(id);
setIsEditMode(isEditMode);
Expand All @@ -45,8 +56,10 @@ export const ProjectContainer: React.FunctionComponent = () => {
<ProjectComponent
isEditMode={isEditMode}
project={project}
report={report}
onSave={handleSave}
onCancel={handleCancel}
onGenerateExcel={handleGenerateExcel}
/>
);
};
10 changes: 10 additions & 0 deletions src/pods/project/project.vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ export interface EmployeeSummary {
employeeName: string;
}

export interface Report {
month: string;
year: string;
}

export const createEmptyProject = (): Project => ({
id: '',
name: '',
Expand All @@ -21,3 +26,8 @@ export const createEmptyProject = (): Project => ({
isActive: false,
employees: [],
});

export const createEmptyReport = (): Report => ({
month: '',
year: '',
});