├── .github └── CODEOWNERS ├── src ├── react-app-env.d.ts ├── styles │ └── scrollbar.css ├── config │ ├── index.tsx │ └── localhost.tsx ├── modules │ ├── API.tsx │ ├── student │ │ ├── studentService.tsx │ │ ├── studentSelectors.tsx │ │ ├── studentReducers.tsx │ │ └── studentActions.tsx │ └── store.tsx ├── setupTests.ts ├── App.test.tsx ├── reportWebVitals.ts ├── index.tsx ├── App.tsx ├── logo.svg └── views │ ├── Students.tsx │ └── StudentView.tsx ├── public ├── robots.txt ├── favicon.ico ├── logo192.png ├── logo512.png ├── manifest.json └── index.html ├── .gitignore ├── .vscode └── settings.json ├── tsconfig.json ├── package.json └── README.md /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @james-gates-0212 2 | -------------------------------------------------------------------------------- /src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supercodestart/frontend-assessment/HEAD/public/favicon.ico -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supercodestart/frontend-assessment/HEAD/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/supercodestart/frontend-assessment/HEAD/public/logo512.png -------------------------------------------------------------------------------- /src/styles/scrollbar.css: -------------------------------------------------------------------------------- 1 | 2 | .scroll-content .scrollbar-track { 3 | background-color: transparent; 4 | } 5 | -------------------------------------------------------------------------------- /src/config/index.tsx: -------------------------------------------------------------------------------- 1 | 2 | const config = require(`./${ 3 | process.env.REACT_APP_ENVIRONMENT 4 | }`).default; 5 | 6 | export default config; 7 | -------------------------------------------------------------------------------- /src/config/localhost.tsx: -------------------------------------------------------------------------------- 1 | 2 | const config = { 3 | API: { 4 | baseUrl: 'https://api.hatchways.io', 5 | }, 6 | }; 7 | 8 | export default config; 9 | -------------------------------------------------------------------------------- /src/modules/API.tsx: -------------------------------------------------------------------------------- 1 | import Axios from 'axios'; 2 | import config from '../config'; 3 | 4 | const API = Axios.create({ 5 | baseURL: config.API.baseUrl, 6 | }); 7 | 8 | export default API; 9 | -------------------------------------------------------------------------------- /src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom'; 6 | -------------------------------------------------------------------------------- /src/modules/student/studentService.tsx: -------------------------------------------------------------------------------- 1 | import API from '../API'; 2 | 3 | class StudentService { 4 | static async all() { 5 | const response = await API.get( 6 | '/assessment/students' 7 | ); 8 | return response.data.students || []; 9 | } 10 | } 11 | 12 | export default StudentService; 13 | -------------------------------------------------------------------------------- /src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render, screen } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | render(); 7 | const linkElement = screen.getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "typescript.updateImportsOnFileMove.enabled": "never", 3 | "typescript.preferences.importModuleSpecifier": "non-relative", 4 | "workbench.colorCustomizations": { 5 | "titleBar.activeForeground": "#000", 6 | "titleBar.inactiveForeground": "#000000CC", 7 | "titleBar.activeBackground": "#ffc600", 8 | "titleBar.inactiveBackground": "#ffc600CC" 9 | }, 10 | "editor.tabSize": 2 11 | } 12 | -------------------------------------------------------------------------------- /src/reportWebVitals.ts: -------------------------------------------------------------------------------- 1 | import { ReportHandler } from 'web-vitals'; 2 | 3 | const reportWebVitals = (onPerfEntry?: ReportHandler) => { 4 | if (onPerfEntry && onPerfEntry instanceof Function) { 5 | import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { 6 | getCLS(onPerfEntry); 7 | getFID(onPerfEntry); 8 | getFCP(onPerfEntry); 9 | getLCP(onPerfEntry); 10 | getTTFB(onPerfEntry); 11 | }); 12 | } 13 | }; 14 | 15 | export default reportWebVitals; 16 | -------------------------------------------------------------------------------- /src/modules/student/studentSelectors.tsx: -------------------------------------------------------------------------------- 1 | import { createSelector } from 'reselect'; 2 | 3 | const selectRaw = (state: any) => state.students; 4 | 5 | const selectLoading = createSelector( 6 | [selectRaw], 7 | (raw) => Boolean(raw.loading), 8 | ); 9 | 10 | const selectStudents = createSelector( 11 | [selectRaw], 12 | (raw) => raw.students, 13 | ); 14 | 15 | const StudentSelectors = { 16 | selectRaw, 17 | selectLoading, 18 | selectStudents, 19 | }; 20 | 21 | export default StudentSelectors; 22 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import App from './App'; 4 | import reportWebVitals from './reportWebVitals'; 5 | 6 | ReactDOM.render( 7 | 8 | 9 | , 10 | document.getElementById('root') 11 | ); 12 | 13 | 14 | // If you want to start measuring performance in your app, pass a function 15 | // to log results (for example: reportWebVitals(console.log)) 16 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 17 | reportWebVitals(); 18 | -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /src/modules/store.tsx: -------------------------------------------------------------------------------- 1 | import { applyMiddleware, combineReducers, createStore } from 'redux'; 2 | import { composeWithDevTools } from 'redux-devtools-extension'; 3 | import thunkMiddleware from 'redux-thunk'; 4 | import StudentActions from './student/studentActions'; 5 | import students from './student/studentReducers'; 6 | 7 | let store; 8 | 9 | function configureStore(preloadedState?) { 10 | const middlewares = [ 11 | thunkMiddleware 12 | ].filter(Boolean); 13 | 14 | store = createStore( 15 | combineReducers({ 16 | students, 17 | }), 18 | preloadedState, 19 | composeWithDevTools(applyMiddleware(...middlewares)), 20 | ); 21 | 22 | store.dispatch(StudentActions.doInit()); 23 | 24 | return store; 25 | } 26 | 27 | export default configureStore; 28 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "noFallthroughCasesInSwitch": true, 4 | "typeRoots": ["node_modules/@types"], 5 | "target": "es5", 6 | "module": "esnext", 7 | "baseUrl": "./", 8 | "esModuleInterop": true, 9 | "skipLibCheck": true, 10 | "forceConsistentCasingInFileNames": true, 11 | "lib": [ 12 | "dom", 13 | "dom.iterable", 14 | "esnext" 15 | ], 16 | "allowJs": true, 17 | "allowSyntheticDefaultImports": true, 18 | "moduleResolution": "node", 19 | "resolveJsonModule": true, 20 | "isolatedModules": true, 21 | "noEmit": true, 22 | "jsx": "react-jsx", 23 | "noImplicitAny": false, 24 | "noImplicitThis": true, 25 | "strictNullChecks": false, 26 | "downlevelIteration": true, 27 | "strict": true 28 | }, 29 | "include": ["src"] 30 | } 31 | -------------------------------------------------------------------------------- /src/modules/student/studentReducers.tsx: -------------------------------------------------------------------------------- 1 | import StudentActions from './studentActions'; 2 | 3 | interface StateType { 4 | loading: boolean; 5 | students: Array; 6 | } 7 | 8 | 9 | const initialState: StateType = { 10 | loading: true, 11 | students: [], 12 | }; 13 | 14 | function students(state = initialState, { type, payload }) { 15 | 16 | if (type === StudentActions.INIT_STARTED) { 17 | return { 18 | ...state, 19 | loading: true, 20 | }; 21 | } 22 | 23 | if (type === StudentActions.INIT_SUCCESS) { 24 | return { 25 | ...state, 26 | loading: false, 27 | students: payload, 28 | }; 29 | } 30 | 31 | if (type === StudentActions.INIT_ERROR) { 32 | return { 33 | ...state, 34 | loading: false, 35 | students: [], 36 | }; 37 | } 38 | 39 | return state; 40 | 41 | } 42 | 43 | export default students; 44 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 14 | React App 15 | 16 | 17 | 18 | 19 | 20 |
21 | 22 | 23 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import { Card, CssBaseline, Grid } from '@mui/material'; 2 | import React from 'react'; 3 | import { Provider } from 'react-redux'; 4 | import Scrollbar from 'react-smooth-scrollbar-z'; 5 | import configureStore from './modules/store'; 6 | import Students from './views/Students'; 7 | 8 | const store = configureStore(); 9 | 10 | function App() { 11 | return ( 12 | 13 | 14 | 21 | 24 | 28 | 29 | 30 | 31 | 32 | 33 | ); 34 | } 35 | 36 | export default App; 37 | -------------------------------------------------------------------------------- /src/modules/student/studentActions.tsx: -------------------------------------------------------------------------------- 1 | import StudentService from "./studentService"; 2 | 3 | const PREFIX = 'STUDENT'; 4 | 5 | const StudentActions = { 6 | 7 | INIT_STARTED: `${PREFIX}_INIT_STARTED`, 8 | INIT_SUCCESS: `${PREFIX}_INIT_SUCCESS`, 9 | INIT_ERROR: `${PREFIX}_INIT_ERROR`, 10 | 11 | doInit: () => async (dispatch) => { 12 | try { 13 | 14 | dispatch({ 15 | type: StudentActions.INIT_STARTED, 16 | }); 17 | 18 | const students = await StudentService.all(); 19 | 20 | dispatch({ 21 | type: StudentActions.INIT_SUCCESS, 22 | payload: students, 23 | }); 24 | } 25 | catch (error) { 26 | dispatch({ 27 | type: StudentActions.INIT_ERROR, 28 | }) 29 | } 30 | }, 31 | 32 | toggleExpand: (students, id) => async (dispatch) => { 33 | dispatch({ 34 | type: StudentActions.INIT_STARTED, 35 | }); 36 | const student = students.find((student) => student.id === id); 37 | student.expand = !student.expand; 38 | dispatch({ 39 | type: StudentActions.INIT_SUCCESS, 40 | payload: [...students], 41 | }); 42 | }, 43 | 44 | addTag: (students, id, tag) => async (dispatch) => { 45 | dispatch({ 46 | type: StudentActions.INIT_STARTED, 47 | }); 48 | const student = students.find((student) => student.id === id); 49 | if (!student.tags) { 50 | student.tags = []; 51 | } 52 | student.tags.push(tag); 53 | dispatch({ 54 | type: StudentActions.INIT_SUCCESS, 55 | payload: students, 56 | }); 57 | }, 58 | 59 | }; 60 | 61 | export default StudentActions; 62 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "frontend-assessment", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@emotion/react": "^11.9.3", 7 | "@emotion/styled": "^11.9.3", 8 | "@mui/icons-material": "^5.8.4", 9 | "@mui/material": "^5.8.4", 10 | "@testing-library/jest-dom": "5.16.2", 11 | "@testing-library/react": "12.1.2", 12 | "@testing-library/user-event": "13.5.0", 13 | "@types/jest": "27.4.0", 14 | "@types/node": "16.11.21", 15 | "@types/react": "17.0.38", 16 | "@types/react-dom": "17.0.11", 17 | "@types/react-redux": "7.1.15", 18 | "axios": "^0.27.2", 19 | "react": "17.0.2", 20 | "react-dom": "17.0.2", 21 | "react-redux": "7.2.2", 22 | "react-scripts": "5.0.1", 23 | "react-smooth-scrollbar-z": "^2.1.0-z", 24 | "redux": "4.0.5", 25 | "redux-devtools-extension": "2.13.8", 26 | "redux-thunk": "2.3.0", 27 | "reselect": "4.0.0", 28 | "typescript": "4.7.3", 29 | "web-vitals": "2.1.4" 30 | }, 31 | "scripts": { 32 | "start": "npm run start:localhost", 33 | "build": "react-scripts build", 34 | "test": "react-scripts test", 35 | "eject": "react-scripts eject", 36 | "start:localhost": "cross-env REACT_APP_ENVIRONMENT=localhost react-scripts start" 37 | }, 38 | "eslintConfig": { 39 | "extends": [ 40 | "react-app", 41 | "react-app/jest" 42 | ] 43 | }, 44 | "browserslist": { 45 | "production": [ 46 | ">0.2%", 47 | "not dead", 48 | "not op_mini all" 49 | ], 50 | "development": [ 51 | "last 1 chrome version", 52 | "last 1 firefox version", 53 | "last 1 safari version" 54 | ] 55 | }, 56 | "devDependencies": { 57 | "cross-env": "7.0.3" 58 | }, 59 | "resolutions": { 60 | "react-error-overlay": "6.0.11", 61 | "@types/react": "17.0.38", 62 | "@types/react-dom": "17.0.11" 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Getting Started with Create React App 2 | 3 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 4 | 5 | ## Available Scripts 6 | 7 | In the project directory, you can run: 8 | 9 | ### `yarn start` 10 | 11 | Runs the app in the development mode.\ 12 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 13 | 14 | The page will reload if you make edits.\ 15 | You will also see any lint errors in the console. 16 | 17 | ### `yarn test` 18 | 19 | Launches the test runner in the interactive watch mode.\ 20 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 21 | 22 | ### `yarn build` 23 | 24 | Builds the app for production to the `build` folder.\ 25 | It correctly bundles React in production mode and optimizes the build for the best performance. 26 | 27 | The build is minified and the filenames include the hashes.\ 28 | Your app is ready to be deployed! 29 | 30 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 31 | 32 | ### `yarn eject` 33 | 34 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 35 | 36 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 37 | 38 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 39 | 40 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 41 | 42 | ## Learn More 43 | 44 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 45 | 46 | To learn React, check out the [React documentation](https://reactjs.org/). 47 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/views/Students.tsx: -------------------------------------------------------------------------------- 1 | import { Box, CircularProgress, Divider, Grid, List, ListItem, TextField } from '@mui/material'; 2 | import { useState } from 'react'; 3 | import { useSelector } from 'react-redux'; 4 | import StudentSelectors from '../modules/student/studentSelectors'; 5 | import StudentView from './StudentView'; 6 | import Scrollbar from 'react-smooth-scrollbar-z'; 7 | import '../styles/scrollbar.css'; 8 | 9 | function Students() { 10 | const loading = useSelector(StudentSelectors.selectLoading); 11 | const students = useSelector(StudentSelectors.selectStudents); 12 | 13 | const [name, setName] = useState(''); 14 | const [tag, setTag] = useState(''); 15 | 16 | const filterStudentByNameAndTag = (student) => { 17 | const filterNameRE = name.toLowerCase(); 18 | const filterTagRE = tag.toLowerCase(); 19 | return ( 20 | ( 21 | name === '' || 22 | [ 23 | student.firstName, 24 | student.lastName 25 | ].join(' ').toLowerCase().indexOf(filterNameRE) >= 0 26 | ) && 27 | ( 28 | tag === '' || 29 | ( 30 | student.tags && 31 | student.tags.find((tag) => tag.toLowerCase().indexOf(filterTagRE) >= 0) 32 | ) 33 | ) 34 | ); 35 | }; 36 | 37 | return ( 38 | <> 39 | 40 | { setName(e.target.value.trim()) }} 44 | fullWidth 45 | autoFocus 46 | /> 47 | { setTag(e.target.value.trim()) }} 51 | fullWidth 52 | /> 53 | 54 | { 55 | loading ? ( 56 | 57 | 58 | 59 | ) : ( 60 | 63 | 68 | { 69 | students.filter(filterStudentByNameAndTag).map((student, index) => ( 70 | 71 | { 72 | index > 0 && ( 73 | 74 | ) 75 | } 76 | 77 | 78 | 79 | 80 | )) 81 | } 82 | 83 | 84 | ) 85 | } 86 | 87 | ); 88 | } 89 | 90 | export default Students; 91 | -------------------------------------------------------------------------------- /src/views/StudentView.tsx: -------------------------------------------------------------------------------- 1 | import { Grid, Avatar, Typography, IconButton, TextField, Chip, Stack } from "@mui/material"; 2 | import AddIcon from '@mui/icons-material/Add'; 3 | import RemoveIcon from '@mui/icons-material/Remove'; 4 | import { useDispatch, useSelector } from 'react-redux'; 5 | import StudentActions from "../modules/student/studentActions"; 6 | import StudentSelectors from "../modules/student/studentSelectors"; 7 | import { useState } from "react"; 8 | 9 | function StudentView(student) { 10 | 11 | const dispatch = useDispatch(); 12 | const [expand, setExpand] = useState(student.expand); 13 | const [tags, setTags] = useState(student.tags || []); 14 | const students = useSelector(StudentSelectors.selectStudents); 15 | 16 | const toggleExpand = () => { 17 | setExpand(!expand); 18 | dispatch(StudentActions.toggleExpand(students, student.id)); 19 | }; 20 | 21 | const onTagInputKeyDown = (e) => { 22 | if (e.keyCode === 13) { 23 | const tag = e.target.value.trim(); 24 | if (tag === '' || tags.find((t) => t.toLowerCase() === tag.toLowerCase())) { 25 | return; 26 | } 27 | tags.push(tag); 28 | e.target.value = ''; 29 | setTags([...tags]); 30 | dispatch(StudentActions.addTag(students, student.id, tag)); 31 | } 32 | }; 33 | 34 | const listTestGrades = (student) => { 35 | return ( 36 | <> 37 |

38 | { 39 | student.grades.map((grade, index) => ( 40 | 41 | Test{index + 1}: 45 | {grade}%
46 |
47 | )) 48 | } 49 | 50 | ); 51 | }; 52 | 53 | return ( 54 | 55 | 56 | 57 | 62 | 63 | 64 | 65 | 66 | {student.firstName} {student.lastName} 70 | 71 | {expand ? : } 72 | 73 | 74 | 75 | 76 | Email: {student.email}
77 | Company: {student.company}
78 | Skill: {student.skill}
79 | Average: {student.grades.length > 0 ? student.grades.reduce((total, grade) => total = Number.parseInt(total) + Number.parseInt(grade)) / student.grades.length : 0}% 80 | {expand && listTestGrades(student)} 81 |
82 | { 83 | tags.length > 0 && ( 84 | 85 | { 86 | tags.map((tag) => ) 87 | } 88 | 89 | ) 90 | } 91 | 97 |
98 |
99 |
100 | ); 101 | } 102 | 103 | export default StudentView; 104 | --------------------------------------------------------------------------------