diff --git a/src/core/router/router.component.tsx b/src/core/router/router.component.tsx index dd574f6..fdb2317 100644 --- a/src/core/router/router.component.tsx +++ b/src/core/router/router.component.tsx @@ -2,7 +2,14 @@ import React from 'react'; import { HashRouter, Switch, Route } from 'react-router-dom'; import { AuthRouterComponent } from 'common-app/auth'; import { routes } from './routes'; -import { LoginScene, TimeScene } from 'scenes'; +import { + LoginScene, + SubmoduleListScene, + ProjectListScene, + EmployeeListScene, + ProjectScene, + EmployeeScene, +} from 'scenes'; export const RouterComponent: React.FunctionComponent = () => { return ( @@ -15,8 +22,28 @@ export const RouterComponent: React.FunctionComponent = () => { /> + + + + diff --git a/src/core/router/routes.ts b/src/core/router/routes.ts index 1540691..81f6dd3 100644 --- a/src/core/router/routes.ts +++ b/src/core/router/routes.ts @@ -1,17 +1,36 @@ +import { generatePath } from 'react-router-dom'; + interface BaseRoutes { root: string; login: string; - time: string; + submoduleList: string; + projects: string; + editProject: string; + employees: string; + editEmployee: string; } const baseRoutes: BaseRoutes = { root: '/', login: '/login', - time: '/time', + submoduleList: '/submodule-list', + projects: '/projects', + editProject: '/projects/:id', + employees: '/employees', + editEmployee: '/employees/:id', }; -type Routes = Omit; +interface Routes extends Omit { + editProject: (id?: string) => string; + editEmployee: (id?: string) => string; +} export const routes: Routes = { ...baseRoutes, + editProject: id => + id ? generatePath(baseRoutes.editProject, { id }) : baseRoutes.editProject, + editEmployee: id => + id + ? generatePath(baseRoutes.editEmployee, { id }) + : baseRoutes.editEmployee, }; diff --git a/src/pods/employee-list/employee-list.component.tsx b/src/pods/employee-list/employee-list.component.tsx new file mode 100644 index 0000000..5fd645b --- /dev/null +++ b/src/pods/employee-list/employee-list.component.tsx @@ -0,0 +1,21 @@ +import React from 'react'; +import { useHistory } from 'react-router-dom'; +import { routes } from 'core/router'; + +export const EmployeeListComponent: React.FunctionComponent = () => { + const history = useHistory(); + const goToEmployee = ( + event: React.MouseEvent + ) => { + event.preventDefault(); + history.push({ + pathname: routes.editEmployee('1'), + }); + }; + return ( + <> +

Hello Employee list component

+

Go to edit employee page

+ + ); +}; diff --git a/src/pods/employee-list/index.ts b/src/pods/employee-list/index.ts new file mode 100644 index 0000000..366d073 --- /dev/null +++ b/src/pods/employee-list/index.ts @@ -0,0 +1 @@ +export * from './employee-list.component'; diff --git a/src/pods/employee/employee.component.tsx b/src/pods/employee/employee.component.tsx new file mode 100644 index 0000000..7a9b6dc --- /dev/null +++ b/src/pods/employee/employee.component.tsx @@ -0,0 +1,5 @@ +import React from 'react'; + +export const EmployeeComponent: React.FunctionComponent = () => { + return

Hello Edit employee component

; +}; diff --git a/src/pods/employee/index.ts b/src/pods/employee/index.ts new file mode 100644 index 0000000..53a7fbc --- /dev/null +++ b/src/pods/employee/index.ts @@ -0,0 +1 @@ +export * from './employee.component'; diff --git a/src/pods/login/login.container.tsx b/src/pods/login/login.container.tsx index 8158964..3409fd0 100644 --- a/src/pods/login/login.container.tsx +++ b/src/pods/login/login.container.tsx @@ -21,7 +21,7 @@ export const LoginContainer: React.FunctionComponent = () => { const userSession = mapLoginResponseToUserSession(); userSession.userName = 'Admin'; setUserSession(userSession); - history.push(routes.time); + history.push(routes.submoduleList); } else { showMessage(literals.messages.errors.invalidLogin, 'error'); } diff --git a/src/pods/project-list/index.ts b/src/pods/project-list/index.ts new file mode 100644 index 0000000..bafaa9b --- /dev/null +++ b/src/pods/project-list/index.ts @@ -0,0 +1 @@ +export * from './project-list.component'; diff --git a/src/pods/project-list/project-list.component.tsx b/src/pods/project-list/project-list.component.tsx new file mode 100644 index 0000000..60267bc --- /dev/null +++ b/src/pods/project-list/project-list.component.tsx @@ -0,0 +1,21 @@ +import React from 'react'; +import { useHistory } from 'react-router-dom'; +import { routes } from 'core/router'; + +export const ProjectListComponent: React.FunctionComponent = () => { + const history = useHistory(); + const goToProject = ( + event: React.MouseEvent + ) => { + event.preventDefault(); + history.push({ + pathname: routes.editProject('1'), + }); + }; + return ( + <> +

Hello Project list component

+

Go to edit project component

+ + ); +}; diff --git a/src/pods/project/index.ts b/src/pods/project/index.ts new file mode 100644 index 0000000..0bf05e7 --- /dev/null +++ b/src/pods/project/index.ts @@ -0,0 +1 @@ +export * from './project.component'; diff --git a/src/pods/project/project.component.tsx b/src/pods/project/project.component.tsx new file mode 100644 index 0000000..9cdbd69 --- /dev/null +++ b/src/pods/project/project.component.tsx @@ -0,0 +1,5 @@ +import React from 'react'; + +export const ProjectComponent: React.FunctionComponent = () => { + return

Hello Edit project component

; +}; diff --git a/src/pods/submodule-list/index.ts b/src/pods/submodule-list/index.ts new file mode 100644 index 0000000..b90b76b --- /dev/null +++ b/src/pods/submodule-list/index.ts @@ -0,0 +1 @@ +export * from './submodule-list.component'; diff --git a/src/pods/submodule-list/submodule-list.component.tsx b/src/pods/submodule-list/submodule-list.component.tsx new file mode 100644 index 0000000..c1c5d8d --- /dev/null +++ b/src/pods/submodule-list/submodule-list.component.tsx @@ -0,0 +1,33 @@ +import React from 'react'; +import { useHistory } from 'react-router-dom'; +import { routes } from 'core/router'; + +export const SumoduleListComponent: React.FunctionComponent = () => { + const history = useHistory(); + const goToProjectList = ( + event: React.MouseEvent + ) => { + event.preventDefault(); + history.push({ + pathname: routes.projects, + }); + }; + + const goToEmployeeList = ( + event: React.MouseEvent + ) => { + event.preventDefault(); + history.push({ + pathname: routes.employees, + }); + }; + + return ( + // Pending to use dashboard component + <> +

Hello Submodule List

+

Go to Project list page

+

Go to Employee list page

+ + ); +}; diff --git a/src/pods/time/components/actions.component.tsx b/src/pods/time/components/actions.component.tsx deleted file mode 100644 index 84ed5d1..0000000 --- a/src/pods/time/components/actions.component.tsx +++ /dev/null @@ -1,15 +0,0 @@ -import React from 'react'; -import Button from '@material-ui/core/Button'; -import { literals } from 'core/i18n'; -import * as classes from './actions.styles'; - -export const ActionsComponent: React.FC = () => ( -
- - -
-); diff --git a/src/pods/time/components/actions.styles.ts b/src/pods/time/components/actions.styles.ts deleted file mode 100644 index e27a452..0000000 --- a/src/pods/time/components/actions.styles.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { css } from 'emotion'; -import { theme } from 'core/theme'; - -export const container = css` - display: flex; - justify-content: flex-end; - margin-top: ${theme.spacing(0.2)}rem; - & > * { - min-width: ${theme.spacing(1)}rem; - margin-left: ${theme.spacing(0.2)}rem; - } -`; diff --git a/src/pods/time/components/index.ts b/src/pods/time/components/index.ts deleted file mode 100644 index 41b2139..0000000 --- a/src/pods/time/components/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './table'; -export * from './toolbar.component'; -export * from './actions.component'; diff --git a/src/pods/time/components/table/index.ts b/src/pods/time/components/table/index.ts deleted file mode 100644 index 48fa2e1..0000000 --- a/src/pods/time/components/table/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './table.component'; diff --git a/src/pods/time/components/table/table-content.component.tsx b/src/pods/time/components/table/table-content.component.tsx deleted file mode 100644 index 505d099..0000000 --- a/src/pods/time/components/table/table-content.component.tsx +++ /dev/null @@ -1,16 +0,0 @@ -import React from 'react'; -import TableBody from '@material-ui/core/TableBody'; -import { TableRowComponent } from './table-row.component'; -import * as VM from '../../time.vm'; - -interface Props { - items: VM.Project[]; - onChange: (nameProject: string, item: VM.Assignment) => void; -} -export const TableContentComponent: React.FC = ({ items, onChange }) => ( - - {items.map((item, index) => ( - - ))} - -); diff --git a/src/pods/time/components/table/table-footer.component.tsx b/src/pods/time/components/table/table-footer.component.tsx deleted file mode 100644 index 25436fc..0000000 --- a/src/pods/time/components/table/table-footer.component.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import React from 'react'; -import { cx } from 'emotion'; -import TableRow from '@material-ui/core/TableRow'; -import TableCell from '@material-ui/core/TableCell'; -import Typography from '@material-ui/core/Typography'; -import * as VM from '../../time.vm'; -import * as classes from './table-footer.styles'; - -interface Props { - counters: VM.Counter[]; -} - -export const TableFooterComponent: React.FC = ({ counters }) => { - const getClassColor = React.useCallback( - (counter: string): string => - counter === '00:00' - ? classes.color.success - : counter > '00:00' && counter <= '03:00' - ? classes.color.warning - : classes.color.error, - [classes.color] - ); - - return ( - - - - Total - - {counters.map((counter, index) => ( - - - {counter.hours} - - - ))} - - - ); -}; diff --git a/src/pods/time/components/table/table-footer.styles.ts b/src/pods/time/components/table/table-footer.styles.ts deleted file mode 100644 index 8f2f9a1..0000000 --- a/src/pods/time/components/table/table-footer.styles.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { css } from 'emotion'; -import { theme } from 'core/theme'; - -export const footer = css` - border-bottom: 0; -`; - -export const total = css` - font-weight: bold; -`; - -export const color = { - success: css` - color: ${theme.palette.success.main}; - `, - error: css` - color: ${theme.palette.error.dark}; - `, - warning: css` - color: ${theme.palette.warning.main}; - `, -}; diff --git a/src/pods/time/components/table/table-head.component.tsx b/src/pods/time/components/table/table-head.component.tsx deleted file mode 100644 index 8502f44..0000000 --- a/src/pods/time/components/table/table-head.component.tsx +++ /dev/null @@ -1,43 +0,0 @@ -import React from 'react'; -import TableHead from '@material-ui/core/TableHead'; -import TableRow from '@material-ui/core/TableRow'; -import TableCell from '@material-ui/core/TableCell'; - -const HeadCell: React.FC = ({ children }) => ( - {children} -); - -interface Props { - columns: string[]; -} - -// TODO: Pending to define the backend -const getDayOfWeek = (date: string): string => { - const [day, month, year] = date.split('/'); - const daysOfWeek = [ - 'Lunes', - 'Martes', - 'Miércoles', - 'Jueves', - 'Viernes', - 'Sábado', - 'Domingo', - ]; - const transformedDate = new Date(+year, +month, +day); - return daysOfWeek[transformedDate.getDay()]; -}; - -export const TableHeadComponent: React.FC = ({ columns }) => ( - - - - {columns.map((title, index) => ( - - {title} -
- {getDayOfWeek(title)} -
- ))} -
-
-); diff --git a/src/pods/time/components/table/table-row.component.tsx b/src/pods/time/components/table/table-row.component.tsx deleted file mode 100644 index 29645c6..0000000 --- a/src/pods/time/components/table/table-row.component.tsx +++ /dev/null @@ -1,44 +0,0 @@ -import React from 'react'; -import TableRow from '@material-ui/core/TableRow'; -import TableCell from '@material-ui/core/TableCell'; -import TextField from '@material-ui/core/TextField'; -import * as VM from '../../time.vm'; - -interface RowProps { - item: VM.Project; - onChange: (nameProject: string, item: VM.Assignment) => void; -} - -export const TableRowComponent: React.FC = ({ item, onChange }) => { - const handleOnChange = (assignmentDate: string) => ( - event: React.ChangeEvent - ) => { - const assignment: VM.Assignment = { - date: assignmentDate, - hours: event.target.value, - }; - onChange(item.name, assignment); - }; - - return ( - - - {item.name} - - {item.assignments.map((assignment, index) => ( - - - - ))} - - ); -}; diff --git a/src/pods/time/components/table/table.component.tsx b/src/pods/time/components/table/table.component.tsx deleted file mode 100644 index 0a59362..0000000 --- a/src/pods/time/components/table/table.component.tsx +++ /dev/null @@ -1,32 +0,0 @@ -import React from 'react'; -import TableContainer from '@material-ui/core/TableContainer'; -import Table from '@material-ui/core/Table'; -import { TableFooterComponent } from './table-footer.component'; -import { TableHeadComponent } from './table-head.component'; -import { TableContentComponent } from './table-content.component'; -import * as VM from '../../time.vm'; -import * as classes from './table.styles'; - -interface Props { - columns: string[]; - counters: VM.Counter[]; - items: VM.Project[]; - onChange: (nameProject: string, item: VM.Assignment) => void; -} - -export const TableComponent: React.FC = ({ - items, - onChange, - columns, - counters, -}) => { - return ( - - - - - -
-
- ); -}; diff --git a/src/pods/time/components/table/table.styles.ts b/src/pods/time/components/table/table.styles.ts deleted file mode 100644 index 4a23fe0..0000000 --- a/src/pods/time/components/table/table.styles.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { css } from 'emotion'; - -export const table = css` - min-width: 650px; -`; diff --git a/src/pods/time/components/toolbar.component.tsx b/src/pods/time/components/toolbar.component.tsx deleted file mode 100644 index c8fa919..0000000 --- a/src/pods/time/components/toolbar.component.tsx +++ /dev/null @@ -1,26 +0,0 @@ -import React from 'react'; -import Toolbar from '@material-ui/core/Toolbar'; -import Typography from '@material-ui/core/Typography'; -import Button from '@material-ui/core/Button'; -import IconButton from '@material-ui/core/IconButton'; -import LeftIcon from '@material-ui/icons/ChevronLeft'; -import RightIcon from '@material-ui/icons/ChevronRight'; -import { literals } from 'core/i18n'; -import * as classes from './toolbar.styles'; - -export const ToolbarComponent = () => { - return ( - - - - - - - - - Febrero de 2020 - - ); -}; diff --git a/src/pods/time/components/toolbar.styles.ts b/src/pods/time/components/toolbar.styles.ts deleted file mode 100644 index 85909e7..0000000 --- a/src/pods/time/components/toolbar.styles.ts +++ /dev/null @@ -1,6 +0,0 @@ -import { css } from 'emotion'; -import { theme } from 'core/theme'; - -export const menuButton = css` - margin-right: ${theme.spacing(0.1)}rem; -`; diff --git a/src/pods/time/index.ts b/src/pods/time/index.ts deleted file mode 100644 index aa9f0a7..0000000 --- a/src/pods/time/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from './time.container'; diff --git a/src/pods/time/time.api.ts b/src/pods/time/time.api.ts deleted file mode 100644 index 54e6c7b..0000000 --- a/src/pods/time/time.api.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Project } from './time.vm'; -import { mockData } from './time.mock'; - -// TODO: Pending to implement real API -const mockProjects: Project[] = mockData; - -export const getProjects = (): Promise => { - const promise = new Promise(resolve => { - setTimeout(() => { - resolve(mockProjects); - }, 2000); - }); - - return promise; -}; diff --git a/src/pods/time/time.business.test.ts b/src/pods/time/time.business.test.ts deleted file mode 100644 index 62a5dcd..0000000 --- a/src/pods/time/time.business.test.ts +++ /dev/null @@ -1,307 +0,0 @@ -import { - replaceAssignmentInProject, - calculateCounter, - getCountersFromProject, -} from './time.business'; -import * as VM from './time.vm'; - -describe('replaceAssignmentInProject =>', () => { - const testProject: VM.Project = { - name: 'testProject', - assignments: [ - { date: '1', hours: '1' }, - { date: '2', hours: '2' }, - ], - }; - - it('should return null when pass a null project', () => { - // Act - const result = replaceAssignmentInProject(null, null, null); - - // Assert - expect(result).toEqual(null); - }); - - it('should return the same project when pass a null name project', () => { - // Arrange - const expectedProject: VM.Project = { - name: 'testProject', - assignments: [ - { date: '1', hours: '1' }, - { date: '2', hours: '2' }, - ], - }; - - // Act - const result = replaceAssignmentInProject(testProject, null, null); - - // Assert - expect(result).toEqual(expectedProject); - }); - - it('should return the same project when pass a distinct name project', () => { - // Arrange - const expectedProject: VM.Project = { - name: 'testProject', - assignments: [ - { date: '1', hours: '1' }, - { date: '2', hours: '2' }, - ], - }; - - // Act - const result = replaceAssignmentInProject( - testProject, - 'irrelevantName', - null - ); - - // Assert - expect(result).toEqual(expectedProject); - }); - - it('should return the same project when pass a same name project and a null assignment', () => { - // Arrange - const expectedProject: VM.Project = { - name: 'testProject', - assignments: [ - { date: '1', hours: '1' }, - { date: '2', hours: '2' }, - ], - }; - - // Act - const result = replaceAssignmentInProject( - testProject, - testProject.name, - null - ); - - // Assert - expect(result).toEqual(expectedProject); - }); - - it('should return the same project when pass a same name project and a distinct assignment', () => { - // Arrange - const expectedProject: VM.Project = { - name: 'testProject', - assignments: [ - { date: '1', hours: '1' }, - { date: '2', hours: '2' }, - ], - }; - - // Act - const result = replaceAssignmentInProject(testProject, testProject.name, { - date: 'irrelevantDate', - hours: '0', - }); - // Assert - expect(result).toEqual(expectedProject); - }); - - it('should return the same project with updated assignments when pass a same name project and a same assignment', () => { - // Arrange - const expectedProject: VM.Project = { - name: 'testProject', - assignments: [ - { date: '1', hours: '8' }, - { date: '2', hours: '2' }, - ], - }; - - // Act - const result = replaceAssignmentInProject(testProject, testProject.name, { - date: '1', - hours: '8', - }); - - // Assert - expect(result).toEqual(expectedProject); - }); -}); - -describe('calculateCounter =>', () => { - it('Should return 00:00 as time when pass an empty projects', () => { - // Arrange - const date = ''; - const projects: VM.Project[] = []; - - const expectedCounter: VM.Counter = { - date: '', - hours: '00:00', - }; - // Act - const result = calculateCounter(date, projects); - // Assert - expect(result).toEqual(expectedCounter); - }); - - it('Should return 00:00 as time when pass an empty assignments', () => { - // Arrange - const date = ''; - const projects: VM.Project[] = [ - { - name: 'Irrelevant name 1', - assignments: [], - }, - { - name: 'Irrelevant name 2', - assignments: [], - }, - ]; - - const expectedCounter: VM.Counter = { - date: '', - hours: '00:00', - }; - // Act - const result = calculateCounter(date, projects); - // Assert - expect(result).toEqual(expectedCounter); - }); - - it('Should return a same date passed and 00:00 as time when pass an empty assignments and a valid date', () => { - // Arrange - const date = '1'; - const projects: VM.Project[] = [ - { - name: 'Irrelevant name 1', - assignments: [], - }, - { - name: 'Irrelevant name 2', - assignments: [], - }, - ]; - - const expectedCounter: VM.Counter = { - date: '1', - hours: '00:00', - }; - // Act - const result = calculateCounter(date, projects); - // Assert - expect(result).toEqual(expectedCounter); - }); - - it('Should return a valid counter when pass a valid projects', () => { - // Arrange - const date = '1'; - const projects: VM.Project[] = [ - { - name: 'Irrelevant name 1', - assignments: [ - { date: '1', hours: '00:59' }, - { date: '2', hours: '00:30' }, - ], - }, - { - name: 'Irrelevant name 2', - assignments: [ - { date: '1', hours: '04:01' }, - { date: '2', hours: '00:30' }, - ], - }, - ]; - - const expectedCounter: VM.Counter = { - date: '1', - hours: '05:00', - }; - // Act - const result = calculateCounter(date, projects); - // Assert - expect(result).toEqual(expectedCounter); - }); -}); - -describe('getCountersFromProject =>', () => { - it('Should return an empty list of counters when pass an empty dates', () => { - // Arrange - const dates = []; - const projects: VM.Project[] = [ - { - name: 'Irrelevant name 1', - assignments: [ - { date: '1', hours: '00:59' }, - { date: '2', hours: '00:30' }, - ], - }, - { - name: 'Irrelevant name 2', - assignments: [ - { date: '1', hours: '04:01' }, - { date: '2', hours: '00:30' }, - ], - }, - ]; - - const expectedCounter: VM.Counter[] = []; - // Act - const result = getCountersFromProject(dates, projects); - // Assert - expect(result).toEqual(expectedCounter); - }); - - it('Should return a valid list of counters when pass a valid dates', () => { - // Arrange - const dates = ['1']; - const projects: VM.Project[] = [ - { - name: 'Irrelevant name 1', - assignments: [ - { date: '1', hours: '00:59' }, - { date: '2', hours: '00:30' }, - ], - }, - { - name: 'Irrelevant name 2', - assignments: [ - { date: '1', hours: '04:01' }, - { date: '2', hours: '00:30' }, - ], - }, - ]; - - const expectedCounter: VM.Counter[] = [{ date: '1', hours: '05:00' }]; - // Act - const result = getCountersFromProject(dates, projects); - // Assert - expect(result).toEqual(expectedCounter); - }); - - it('Should return a valid list of counters when pass a valid dates', () => { - // Arrange - const dates = ['1', '4']; - const projects: VM.Project[] = [ - { - name: 'Irrelevant name 1', - assignments: [ - { date: '1', hours: '00:59' }, - { date: '2', hours: '00:30' }, - { date: '3', hours: '00:00' }, - { date: '4', hours: '00:30' }, - ], - }, - { - name: 'Irrelevant name 2', - assignments: [ - { date: '1', hours: '04:01' }, - { date: '2', hours: '00:30' }, - { date: '3', hours: '01:00' }, - { date: '4', hours: '02:50' }, - ], - }, - ]; - - const expectedCounter: VM.Counter[] = [ - { date: '1', hours: '05:00' }, - { date: '4', hours: '03:20' }, - ]; - // Act - const result = getCountersFromProject(dates, projects); - // Assert - expect(result).toEqual(expectedCounter); - }); -}); diff --git a/src/pods/time/time.business.ts b/src/pods/time/time.business.ts deleted file mode 100644 index b01d9ea..0000000 --- a/src/pods/time/time.business.ts +++ /dev/null @@ -1,107 +0,0 @@ -import * as VM from './time.vm'; - -const updateAssignment = ( - assignment: VM.Assignment, - updateAssignment: VM.Assignment -): VM.Assignment => - Boolean(updateAssignment) && assignment.date === updateAssignment.date - ? updateAssignment - : assignment; - -export const replaceAssignmentInProject = ( - project: VM.Project, - projectName: string, - assignmentToUpdate: VM.Assignment -): VM.Project => - Boolean(project) - ? project.name !== projectName - ? project - : { - name: projectName, - assignments: project.assignments.map(item => - updateAssignment(item, assignmentToUpdate) - ), - } - : null; - -const normalizeStringToNumber = (expression: string): number => - isNaN(parseInt(expression)) ? 0 : parseInt(expression); - -const extractHoursAndMinutesFromExpression = (timeExpression: string) => { - const splitTime = timeExpression.split(':'); - const hoursAsNumber = normalizeStringToNumber(splitTime[0]); - const minutesAsNumber = normalizeStringToNumber(splitTime[1]); - return { hoursAsNumber, minutesAsNumber }; -}; - -const addHoursFromMinutes = (minutes: number, hours: number) => { - if (minutes >= 60) { - const h = (minutes / 60) << 0; - hours += h; - minutes -= 60 * h; - } - return { hours, minutes }; -}; - -const formattedTimeExpressionFromNumbers = ( - hours: number, - minutes: number -): string => `${('0' + hours).slice(-2)}:${('0' + minutes).slice(-2)}`; - -export const calculateCounter = ( - date: string, - projects: VM.Project[] -): VM.Counter => { - const filteredProjectsByDate = - Boolean(projects) && - projects - .map(project => - project.assignments.filter(assignment => assignment.date === date) - ) - .reduce((acc, item) => [...acc, ...item], []); - - const result: VM.Counter = filteredProjectsByDate.reduce( - (acc, { hours }) => { - let { - hoursAsNumber: accHours, - minutesAsNumber: accMinutes, - } = extractHoursAndMinutesFromExpression(acc.hours); - - let { - hoursAsNumber: itemHours, - minutesAsNumber: itemMinutes, - } = extractHoursAndMinutesFromExpression(hours); - - ({ minutes: itemMinutes, hours: itemHours } = addHoursFromMinutes( - itemMinutes, - itemHours - )); - - accHours += itemHours; - accMinutes += itemMinutes; - - ({ minutes: accMinutes, hours: accHours } = addHoursFromMinutes( - accMinutes, - accHours - )); - - return { - date, - hours: formattedTimeExpressionFromNumbers(accHours, accMinutes), - }; - }, - { - date, - hours: '00:00', - } - ); - - return result; -}; - -export const getCountersFromProject = ( - dates: string[], - projects: VM.Project[] -): VM.Counter[] => - Boolean(dates) && - dates.reduce((acc, date) => [...acc, calculateCounter(date, projects)], []); diff --git a/src/pods/time/time.component.tsx b/src/pods/time/time.component.tsx deleted file mode 100644 index 0f1ee2b..0000000 --- a/src/pods/time/time.component.tsx +++ /dev/null @@ -1,42 +0,0 @@ -import React from 'react'; -import Paper from '@material-ui/core/Paper'; -import { - ActionsComponent, - TableComponent, - ToolbarComponent, -} from './components'; -import * as VM from './time.vm'; -import * as classes from './time.styles'; - -interface Props { - projects: VM.Project[]; - updateProject: (nameProject: string, assignment: VM.Assignment) => void; - columns: string[]; - counters: VM.Counter[]; -} - -export const TimeComponent: React.FC = ({ - projects, - updateProject, - columns, - counters, -}) => { - const handleOnChange = (nameProject: string, item: VM.Assignment) => { - updateProject(nameProject, item); - }; - - return ( - <> - - - - - - - ); -}; diff --git a/src/pods/time/time.container.tsx b/src/pods/time/time.container.tsx deleted file mode 100644 index 076d12a..0000000 --- a/src/pods/time/time.container.tsx +++ /dev/null @@ -1,17 +0,0 @@ -import React from 'react'; -import { TimeComponent } from './time.component'; -import { header } from './time.mock'; -import { useProjects } from './time.hooks'; - -export const TimeContainer: React.FC = () => { - const { projects, updateProject, counters } = useProjects(); - - return ( - - ); -}; diff --git a/src/pods/time/time.hooks.ts b/src/pods/time/time.hooks.ts deleted file mode 100644 index 89a7f6a..0000000 --- a/src/pods/time/time.hooks.ts +++ /dev/null @@ -1,48 +0,0 @@ -import React from 'react'; -import { trackPromise } from 'react-promise-tracker'; -import { mapProjectListAmToVm } from './time.mapper'; -import { - replaceAssignmentInProject, - getCountersFromProject, -} from './time.business'; -import * as api from './time.api'; -import * as VM from './time.vm'; - -export const useProjects = (): { - projects: VM.Project[]; - updateProject: (nameProject: string, assignment: VM.Assignment) => void; - counters: VM.Counter[]; -} => { - const [projects, setProjects] = React.useState([]); - const [counters, setCounters] = React.useState([]); - - React.useEffect(() => { - trackPromise( - api - .getProjects() - .then(mapProjectListAmToVm) - .then(setProjects) - ); - }, []); - - const updateProject = (nameProject: string, assignment: VM.Assignment) => { - const projectsToUpdate = projects.map(project => - replaceAssignmentInProject(project, nameProject, assignment) - ); - - setProjects(projectsToUpdate); - }; - - React.useEffect(() => { - if (projects.length > 0) { - const dates = projects[0].assignments.map(assignment => assignment.date); - setCounters(getCountersFromProject(dates, projects)); - } - }, [projects]); - - return { - projects, - updateProject, - counters, - }; -}; diff --git a/src/pods/time/time.mapper.ts b/src/pods/time/time.mapper.ts deleted file mode 100644 index a1c6503..0000000 --- a/src/pods/time/time.mapper.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { Project } from './time.vm'; - -export const mapProjectAmToVm = (project: Project): Project => - Boolean(project) && { ...project }; - -export const mapProjectListAmToVm = (projects: Project[]): Project[] => - Boolean(projects) && projects.map(mapProjectAmToVm); diff --git a/src/pods/time/time.mock.ts b/src/pods/time/time.mock.ts deleted file mode 100644 index cd00afe..0000000 --- a/src/pods/time/time.mock.ts +++ /dev/null @@ -1,150 +0,0 @@ -import { Project } from './time.vm'; - -export const mockData: Project[] = [ - { - name: 'Bankia', - assignments: [ - { - date: '08/02/2020', - hours: '04:00', - }, - { - date: '09/02/2020', - hours: '04:00', - }, - { - date: '10/02/2020', - hours: '00:00', - }, - { - date: '11/02/2020', - hours: '00:00', - }, - { - date: '12/02/2020', - hours: '03:30', - }, - { - date: '13/02/2020', - hours: '00:00', - }, - { - date: '14/02/2020', - hours: '00:00', - }, - ], - }, - { - name: 'Mapfre', - assignments: [ - { - date: '08/02/2020', - hours: '04:00', - }, - { - date: '09/02/2020', - hours: '04:00', - }, - { - date: '10/02/2020', - hours: '00:00', - }, - { - date: '11/02/2020', - hours: '04:00', - }, - { - date: '12/02/2020', - hours: '00:00', - }, - { - date: '13/02/2020', - hours: '00:00', - }, - { - date: '14/02/2020', - hours: '00:00', - }, - ], - }, - { - name: 'Interno', - assignments: [ - { - date: '08/02/2020', - hours: '04:00', - }, - { - date: '09/02/2020', - hours: '04:00', - }, - { - date: '10/02/2020', - hours: '00:00', - }, - { - date: '11/02/2020', - hours: '04:00', - }, - { - date: '12/02/2020', - hours: '03:30', - }, - { - date: '13/02/2020', - hours: '00:00', - }, - { - date: '14/02/2020', - hours: '00:00', - }, - ], - }, - { - name: 'Vacaciones', - assignments: [ - { - date: '08/02/2020', - hours: '00:00', - }, - { - date: '09/02/2020', - hours: '00:00', - }, - { - date: '10/02/2020', - hours: '00:00', - }, - { - date: '11/02/2020', - hours: '00:00', - }, - { - date: '12/02/2020', - hours: '00:00', - }, - { - date: '13/02/2020', - hours: '00:00', - }, - { - date: '14/02/2020', - hours: '00:00', - }, - ], - }, -]; - -export const header = mockData[0].assignments.map( - assignment => assignment.date -); - -export const counters = [ - '04:00', - '03:00', - '04:00', - '05:00', - '02:30', - '00:00', - '00:00', -]; diff --git a/src/pods/time/time.styles.ts b/src/pods/time/time.styles.ts deleted file mode 100644 index e3d0383..0000000 --- a/src/pods/time/time.styles.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { css } from 'emotion'; -import { theme } from 'core/theme'; - -export const paper = css` - padding: ${theme.spacing(0.1)}rem; - min-height: 70vh; -`; diff --git a/src/pods/time/time.vm.ts b/src/pods/time/time.vm.ts deleted file mode 100644 index fc89adc..0000000 --- a/src/pods/time/time.vm.ts +++ /dev/null @@ -1,11 +0,0 @@ -export interface Project { - name: string; - assignments: Assignment[]; -} - -export interface Assignment { - date: string; - hours: string; -} - -export type Counter = Assignment; diff --git a/src/scenes/employee-list.scene.tsx b/src/scenes/employee-list.scene.tsx new file mode 100644 index 0000000..cdc00af --- /dev/null +++ b/src/scenes/employee-list.scene.tsx @@ -0,0 +1,11 @@ +import React from 'react'; +import { AppLayout } from 'layouts'; +import { EmployeeListComponent } from 'pods/employee-list'; + +export const EmployeeListScene: React.FunctionComponent = () => { + return ( + + + + ); +}; diff --git a/src/scenes/employee.scene.tsx b/src/scenes/employee.scene.tsx new file mode 100644 index 0000000..8f07edc --- /dev/null +++ b/src/scenes/employee.scene.tsx @@ -0,0 +1,11 @@ +import React from 'react'; +import { AppLayout } from 'layouts'; +import { EmployeeComponent } from 'pods/employee'; + +export const EmployeeScene: React.FunctionComponent = () => { + return ( + + + + ); +}; diff --git a/src/scenes/index.ts b/src/scenes/index.ts index 1c10201..1815748 100644 --- a/src/scenes/index.ts +++ b/src/scenes/index.ts @@ -1,2 +1,6 @@ export * from './login.scene'; -export * from './time.scene'; +export * from './submodule-list.scene'; +export * from './project-list.scene'; +export * from './employee-list.scene'; +export * from './project.scene'; +export * from './employee.scene'; diff --git a/src/scenes/project-list.scene.tsx b/src/scenes/project-list.scene.tsx new file mode 100644 index 0000000..344434b --- /dev/null +++ b/src/scenes/project-list.scene.tsx @@ -0,0 +1,11 @@ +import React from 'react'; +import { AppLayout } from 'layouts'; +import { ProjectListComponent } from 'pods/project-list'; + +export const ProjectListScene: React.FunctionComponent = () => { + return ( + + + + ); +}; diff --git a/src/scenes/project.scene.tsx b/src/scenes/project.scene.tsx new file mode 100644 index 0000000..c99bb7a --- /dev/null +++ b/src/scenes/project.scene.tsx @@ -0,0 +1,11 @@ +import React from 'react'; +import { AppLayout } from 'layouts'; +import { ProjectComponent } from 'pods/project'; + +export const ProjectScene: React.FunctionComponent = () => { + return ( + + + + ); +}; diff --git a/src/scenes/submodule-list.scene.tsx b/src/scenes/submodule-list.scene.tsx new file mode 100644 index 0000000..4db7b4e --- /dev/null +++ b/src/scenes/submodule-list.scene.tsx @@ -0,0 +1,11 @@ +import React from 'react'; +import { AppLayout } from 'layouts'; +import { SumoduleListComponent } from 'pods/submodule-list'; + +export const SubmoduleListScene: React.FC = () => { + return ( + + + + ); +}; diff --git a/src/scenes/time.scene.tsx b/src/scenes/time.scene.tsx deleted file mode 100644 index 5ac7b69..0000000 --- a/src/scenes/time.scene.tsx +++ /dev/null @@ -1,11 +0,0 @@ -import React from 'react'; -import { AppLayout } from 'layouts'; -import { TimeContainer } from 'pods/time'; - -export const TimeScene: React.FC = () => { - return ( - - - - ); -};