Skip to content

Commit

Permalink
feature(requests-table):Implement requests table [Finishes #171380698]
Browse files Browse the repository at this point in the history
  • Loading branch information
the22mastermind committed Jun 13, 2020
1 parent 8c78fbd commit 89d8953
Show file tree
Hide file tree
Showing 54 changed files with 1,605 additions and 110 deletions.
12 changes: 10 additions & 2 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"presets": ["@babel/preset-env","@babel/preset-react"],
"plugins": ["transform-class-properties"]
"presets": [
"@babel/preset-env",
"@babel/preset-react"
],
"plugins": [
"transform-class-properties",
"@babel/plugin-proposal-class-properties",
"@babel/plugin-transform-regenerator",
"@babel/plugin-transform-runtime"
]
}
10 changes: 10 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: "2"
checks:
method-lines:
config:
threshold: 40
method-complexity:
config:
threshold: 6
exclude_patterns:
- "**/__tests__/"
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
}
],
"react/no-array-index-key": 0,
"jsx-a11y/anchor-is-valid": 0
"jsx-a11y/anchor-is-valid": 0,
"no-shadow": 0,
"no-nested-ternary": 0,
"react/jsx-props-no-spreading": 0
}
}
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
'!src/entry/server.js',
'!src/utils/customMessages.js',
'!webpack.config.js',
'!src/assets/**',
],
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: ['/node_modules/', '/__tests__'],
Expand Down
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,19 @@
"homepage": "https://github.com/Stackup-Rwanda/stackup2-barefoot-frontend#readme",
"dependencies": {
"@babel/core": "^7.9.6",
"@babel/plugin-transform-runtime": "^7.10.1",
"@babel/polyfill": "^7.10.1",
"@babel/preset-env": "^7.10.2",
"@babel/preset-react": "^7.9.4",
"@material-ui/core": "^4.10.0",
"@material-ui/icons": "^4.9.1",
"@material-ui/lab": "^4.0.0-alpha.55",
"@storybook/addon-actions": "^5.3.18",
"@storybook/addon-links": "^5.3.18",
"@storybook/addons": "^5.3.18",
"@storybook/react": "^5.3.18",
"@testing-library/react": "^10.0.4",
"axios": "^0.19.2",
"babel-eslint": "^10.1.0",
"babel-jest": "^26.0.1",
"babel-loader": "^8.1.0",
Expand All @@ -59,23 +64,28 @@
"jest": "^26.0.1",
"jest-html-reporters": "^1.2.1",
"jest-transform-stub": "^2.0.0",
"less-loader": "^6.1.0",
"mini-css-extract-plugin": "^0.9.0",
"prop-types": "^15.7.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-loader-spinner": "^3.1.14",
"react-redux": "^7.2.0",
"react-router-dom": "^5.2.0",
"react-slick": "^0.26.1",
"react-test-renderer": "^16.13.1",
"redux": "^4.0.5",
"redux-devtools-extension": "^2.13.8",
"redux-mock-store": "^1.5.4",
"redux-thunk": "^2.3.0",
"slick-carousel": "^1.8.1",
"style-loader": "^1.2.1",
"webpack": "^4.43.0",
"webpack-cli": "^3.3.11",
"webpack-dev-server": "^3.11.0"
},
"devDependencies": {
"dotenv-webpack": "^1.8.0",
"eslint": "^6.8.0",
"eslint-config-airbnb": "^18.1.0",
"eslint-plugin-import": "^2.20.2",
Expand Down
35 changes: 0 additions & 35 deletions src/__tests__/App.test.js

This file was deleted.

32 changes: 32 additions & 0 deletions src/__tests__/data/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const requests = {
tripRequests: [
{
id: 1,
trips: [
{
travelDate: '2020-09-15',
travelFrom: 'Kigali',
travelTo: 'Durban',
},
],
travelReason: 'Africa Tech Summit',
accommodation: true,
status: 'pending',
},
{
id: 2,
trips: [
{
travelDate: '2020-09-10',
travelFrom: 'Kigali',
travelTo: 'Dubai',
},
],
travelReason: 'Africa Tech Summit',
accommodation: true,
status: 'pending',
},
],
};

export default requests;
5 changes: 0 additions & 5 deletions src/actions/actions.js

This file was deleted.

6 changes: 5 additions & 1 deletion src/assets/styles/sass/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ body {
}

.testimony-item {
display: flex;
display: flex !important;
flex-direction: row;
justify-content: center;
align-items: center;
Expand Down Expand Up @@ -169,6 +169,10 @@ body {
font-size: 14pt;
}

.testimony-description {
margin-left: 2px;
}

.testimony-author {
font-size: 10pt;
}
Expand Down
22 changes: 22 additions & 0 deletions src/components/CustomCard/__tests__/CustomCard.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/* eslint-disable no-undef */
import React from 'react';
import { createMount } from '@material-ui/core/test-utils';
import Link from '@material-ui/core/Link';
import { cleanup } from '@testing-library/react';
import CustomCard from '../CustomCard';

const title = 'Our Company';
const items = ['Careers', 'About', 'Vision'];

describe('<CustomCard />', () => {
afterEach(() => cleanup);

it('Should match the CustomCard snapshot', () => {
const component = createMount()(
<CustomCard title={title} items={items} />,
);

expect(component.html).toMatchSnapshot();
expect(component.find(Link)).toHaveLength(3);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`<CustomCard /> Should match the CustomCard snapshot 1`] = `[Function]`;
121 changes: 121 additions & 0 deletions src/components/RequestsTable/RequestsTable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
import React from 'react';
import PropTypes, { object } from 'prop-types';
import { withStyles, makeStyles } from '@material-ui/core/styles';
import Table from '@material-ui/core/Table';
import TableBody from '@material-ui/core/TableBody';
import TableCell from '@material-ui/core/TableCell';
import TableContainer from '@material-ui/core/TableContainer';
import TableHead from '@material-ui/core/TableHead';
import TableRow from '@material-ui/core/TableRow';
import RemoveCircleOutline from '@material-ui/icons/RemoveCircleOutline';
import CheckCircleOutline from '@material-ui/icons/CheckCircleOutline';
import ActionsMenu from '../../views/ActionsMenu/ActionsMenu';

const StyledTableCell = withStyles((theme) => ({
head: {
backgroundColor: theme.palette.secondary.contrastText,
color: theme.palette.primary.dark,
},
body: {
fontSize: 14,
},
}))(TableCell);

const StyledTableRow = withStyles((theme) => ({
root: {
'&:nth-of-type(odd)': {
backgroundColor: theme.palette.action.hover,
},
},
}))(TableRow);

const useStyles = makeStyles({
table: {
minWidth: 700,
},
tableCell: {
fontSize: 12,
},
tableIcons: {
fontSize: 16,
},
noData: {
fontSize: 14,
color: '#777777',
backgroundColor: '#FFFFFF',
textAlign: 'center',
},
});

const requesterActions = [
{
id: 1,
name: 'Edit',
},
{
id: 2,
name: 'Book Accommodation',
},
{
id: 3,
name: 'Rate Accommodation',
},
{
id: 4,
name: 'Like/Dislike Accommodation',
},
];

const RequestsTable = ({ requests }) => {
const classes = useStyles();

return (
<TableContainer>
<Table className={classes.table} aria-label="customized table">
<TableHead>
<TableRow>
<StyledTableCell className={classes.tableCell}>Date</StyledTableCell>
<StyledTableCell className={classes.tableCell} align="left">Departure</StyledTableCell>
<StyledTableCell className={classes.tableCell} align="left">Destination</StyledTableCell>
<StyledTableCell className={classes.tableCell} align="left">Reason</StyledTableCell>
<StyledTableCell className={classes.tableCell} align="left">Accommodation</StyledTableCell>
<StyledTableCell className={classes.tableCell} align="center">Status</StyledTableCell>
<StyledTableCell className={classes.tableCell} align="center" />
</TableRow>
</TableHead>
<TableBody>
{requests.length > 0 ? (requests.map((row) => (
<StyledTableRow key={row.id}>
<StyledTableCell className={classes.tableCell} component="th" scope="row">
{row.trips[0].travelDate}
</StyledTableCell>
<StyledTableCell className={classes.tableCell} align="left">{row.trips[0].travelFrom}</StyledTableCell>
<StyledTableCell className={classes.tableCell} align="left">{row.trips[0].travelTo}</StyledTableCell>
<StyledTableCell className={classes.tableCell} align="left">{row.travelReason}</StyledTableCell>
<StyledTableCell className={classes.tableCell} align="left">{row.accommodation ? 'Yes' : 'No'}</StyledTableCell>
<StyledTableCell className={classes.tableCell} align="center">
{row.status === 'pending' ? <RemoveCircleOutline className={classes.tableIcons} htmlColor="#DADADA" /> : <CheckCircleOutline className={classes.tableIcons} htmlColor="#00A799" />}
</StyledTableCell>
<StyledTableCell align="center">
<ActionsMenu actions={requesterActions} />
</StyledTableCell>
</StyledTableRow>
))
) : (
<StyledTableRow>
<StyledTableCell className={classes.noData} component="th" scope="row" align="center" colSpan={7}>
Oops! Looks like you have not yet made any requests.
</StyledTableCell>
</StyledTableRow>
)}
</TableBody>
</Table>
</TableContainer>
);
};

RequestsTable.propTypes = {
requests: PropTypes.arrayOf(object).isRequired,
};

export default RequestsTable;
Loading

0 comments on commit 89d8953

Please sign in to comment.