├── .env ├── .eslintignore ├── .eslintrc.json ├── .gitignore ├── .prettierignore ├── .prettierrc.json ├── README.md ├── config-overrides.js ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.css ├── App.test.tsx ├── App.tsx ├── assets │ └── json │ │ ├── countries.json │ │ └── menu.json ├── components │ └── tables │ │ ├── index.tsx │ │ └── styles.module.less ├── constants │ └── redux.ts ├── index.css ├── index.tsx ├── logo.svg ├── pages │ └── index.tsx ├── react-app-env.d.ts ├── reportWebVitals.ts ├── setupTests.ts ├── store │ ├── index.ts │ └── universityData │ │ ├── action.ts │ │ ├── index.ts │ │ ├── selector.ts │ │ └── type.ts └── types │ └── global.d.ts ├── tsconfig.json └── yarn.lock /.env: -------------------------------------------------------------------------------- 1 | PORT=3005 -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | *.css 2 | *.svg -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | "parser": "@typescript-eslint/parser", 4 | "extends": [ 5 | "plugin:@typescript-eslint/recommended-requiring-type-checking", 6 | "plugin:react/recommended", 7 | "plugin:react-hooks/recommended", 8 | "plugin:jsx-a11y/recommended", 9 | "plugin:prettier/recommended", 10 | "prettier" 11 | ], 12 | "plugins": [ 13 | "@typescript-eslint" 14 | ], 15 | "parserOptions": { 16 | "ecmaVersion": 2018, 17 | "project": "./tsconfig.json" 18 | }, 19 | "env": { 20 | "browser": true, 21 | "node": true, 22 | "es6": true, 23 | "jest": true 24 | }, 25 | "ignorePatterns": [ 26 | "tailwind.config..js", 27 | "gatsby-browser.js", 28 | "gatsby-config.js", 29 | "gatsby-node.js", 30 | ".eslintrc.js" 31 | ], 32 | "rules": { 33 | "react/prop-types": 0, 34 | "react/no-array-index-key": 0, 35 | "react-hooks/exhaustive-deps": [ 36 | "warn" 37 | ], 38 | "@typescript-eslint/camelcase": 0, 39 | "@typescript-eslint/no-use-before-define": 0, 40 | "@typescript-eslint/explicit-member-accessibility": 0, 41 | "@typescript-eslint/explicit-function-return-type": 0, 42 | "@typescript-eslint/no-explicit-any": 0, 43 | "@typescript-eslint/ban-ts-ignore": 0, 44 | "@typescript-eslint/no-dupe-class-members": 0, 45 | "@typescript-eslint/unbound-method": 0, 46 | "no-underscore-dangle": 0, 47 | "no-nested-ternary": 0, 48 | "jsx-a11y/anchor-is-valid": [ 49 | "error", 50 | { 51 | "components": [ 52 | "Link" 53 | ], 54 | "specialLink": [ 55 | "hrefLeft", 56 | "hrefRight" 57 | ], 58 | "aspects": [ 59 | "invalidHref", 60 | "preferButton" 61 | ] 62 | } 63 | ], 64 | "jsx-a11y/label-has-associated-control": "off", 65 | "jsx-a11y/label-has-for": "off", 66 | "jsx-a11y/no-onchange": 0, 67 | "react-hooks/rules-of-hooks": "error", 68 | "react/jsx-props-no-spreading": "off", 69 | "no-multiple-empty-lines": "off", 70 | "@typescript-eslint/no-unsafe-assignment": "off", 71 | "@typescript-eslint/restrict-template-expressions": "warn", 72 | "@typescript-eslint/no-unused-vars": "warn", 73 | "@typescript-eslint/no-unsafe-return": "off", 74 | "@typescript-eslint/no-unsafe-call": "off", 75 | "@typescript-eslint/no-unsafe-member-access": "off", 76 | "@typescript-eslint/no-floating-promises": "off", 77 | "react/require-default-props": "off", 78 | "react/display-name": "off", 79 | "react/no-unescaped-entities": "off", 80 | "prettier/prettier": [ 81 | "error", 82 | { 83 | "endOfLine": "auto" 84 | } 85 | ] 86 | }, 87 | "settings": { 88 | "import/parsers": { 89 | "@typescript-eslint/parser": [ 90 | ".ts", 91 | ".tsx" 92 | ] 93 | }, 94 | "import/resolver": { 95 | "typescript": { 96 | "alwaysTryTypes": true, 97 | "project": "packages/*/tsconfig.json" 98 | } 99 | } 100 | } 101 | } -------------------------------------------------------------------------------- /.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 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | # Ignore artifacts: 3 | build 4 | coverage -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "tabWidth": 2, 4 | "useTabs": false, 5 | "semi": true, 6 | "singleQuote": true, 7 | "trailingComma": "es5", 8 | "bracketSpacing": true, 9 | "jsxBracketSameLine": false, 10 | "arrowParens": "avoid", 11 | "rangeStart": 0, 12 | "rangeEnd": 9007199254740991, 13 | "requirePragma": false, 14 | "insertPragma": false, 15 | "proseWrap": "preserve" 16 | } -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /config-overrides.js: -------------------------------------------------------------------------------- 1 | /* config-overrides.js */ 2 | const { override, addLessLoader } = require('customize-cra'); 3 | 4 | module.exports = override( 5 | addLessLoader({ 6 | // If you are using less-loader@5 or older version, please spread the lessOptions to options directly. 7 | lessOptions: { 8 | javascriptEnabled: true, 9 | // modifyVars: { '@base-color': '#f44336' } 10 | } 11 | }) 12 | ); 13 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test-enterprise", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@reduxjs/toolkit": "^1.6.1", 7 | "@testing-library/jest-dom": "^5.11.4", 8 | "@testing-library/react": "^11.1.0", 9 | "@testing-library/user-event": "^12.1.10", 10 | "@types/jest": "^26.0.15", 11 | "@types/node": "^12.0.0", 12 | "@types/react": "^17.0.0", 13 | "@types/react-dom": "^17.0.0", 14 | "axios": "^0.21.1", 15 | "customize-cra": "^1.0.0", 16 | "less": "^^3.11.1", 17 | "less-loader": "^6.0.0", 18 | "react": "^17.0.2", 19 | "react-app-rewired": "^2.1.8", 20 | "react-dom": "^17.0.2", 21 | "react-redux": "^7.2.4", 22 | "react-scripts": "4.0.3", 23 | "rsuite": "^4.10.2", 24 | "typescript": "^4.1.2", 25 | "web-vitals": "^1.0.1" 26 | }, 27 | "scripts": { 28 | "start": "react-app-rewired start", 29 | "build": "react-app-rewired build", 30 | "test": "react-scripts test --env=jsdom", 31 | "eject": "react-app-rewired eject", 32 | "lint": "eslint src --ext .js,.jsx,.ts,.tsx --fix" 33 | }, 34 | "eslintConfig": { 35 | "extends": [ 36 | "react-app", 37 | "react-app/jest" 38 | ] 39 | }, 40 | "browserslist": { 41 | "production": [ 42 | ">0.2%", 43 | "not dead", 44 | "not op_mini all" 45 | ], 46 | "development": [ 47 | "last 1 chrome version", 48 | "last 1 firefox version", 49 | "last 1 safari version" 50 | ] 51 | }, 52 | "devDependencies": { 53 | "@typescript-eslint/eslint-plugin": "^4.29.3", 54 | "@typescript-eslint/parser": "^4.29.3", 55 | "eslint": "^7.32.0", 56 | "eslint-config-airbnb": "^18.2.1", 57 | "eslint-config-prettier": "^8.3.0", 58 | "eslint-import-resolver-typescript": "^2.4.0", 59 | "eslint-plugin-import": "^2.24.1", 60 | "eslint-plugin-jsx-a11y": "^6.4.1", 61 | "eslint-plugin-prettier": "^3.4.1", 62 | "eslint-plugin-react": "^7.24.0", 63 | "eslint-plugin-react-hooks": "^4.2.0", 64 | "lint-staged": "^11.1.2", 65 | "prettier": "^2.3.2" 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darkhorse07232020/RSuite.js-Example-with-Redux-in-React-Typescript/fb5d3578a600cbe16ba1203472511d4f493a1677/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darkhorse07232020/RSuite.js-Example-with-Redux-in-React-Typescript/fb5d3578a600cbe16ba1203472511d4f493a1677/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/darkhorse07232020/RSuite.js-Example-with-Redux-in-React-Typescript/fb5d3578a600cbe16ba1203472511d4f493a1677/public/logo512.png -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /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 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import './App.css'; 3 | import 'rsuite/lib/styles/themes/dark/index.less'; 4 | import MainPage from './pages'; 5 | 6 | function App() { 7 | return ( 8 |
9 | 10 |
11 | ); 12 | } 13 | 14 | export default App; 15 | -------------------------------------------------------------------------------- /src/assets/json/countries.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "value": "United States", 4 | "label": "United States" 5 | }, 6 | { 7 | "value": "Turkey", 8 | "label": "Turkey" 9 | }, 10 | { 11 | "value": "United Kingdom", 12 | "label": "United Kingdom" 13 | }, 14 | { 15 | "value": "Germany", 16 | "label": "Germany" 17 | } 18 | ] -------------------------------------------------------------------------------- /src/assets/json/menu.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "value": "default", 4 | "label": "Default" 5 | }, 6 | { 7 | "value": "green", 8 | "label": "Green" 9 | }, 10 | { 11 | "value": "red", 12 | "label": "Red" 13 | }, 14 | { 15 | "value": "purple", 16 | "label": "Purple" 17 | } 18 | ] -------------------------------------------------------------------------------- /src/components/tables/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useMemo, useState } from 'react'; 2 | import { useDispatch, useSelector } from 'react-redux'; 3 | import { Button, Input, SelectPicker, Table } from 'rsuite'; 4 | import TablePagination from 'rsuite/lib/Table/TablePagination'; 5 | import { STATUSES } from 'constants/redux'; 6 | import { getUniversityData } from 'store/universityData'; 7 | import { universityActionState, selectUniversity } from 'store/universityData/selector'; 8 | import CountryList from 'assets/json/countries.json'; 9 | 10 | const Tables: React.FC = () => { 11 | const { Column, HeaderCell, Cell } = Table; 12 | const universityList = useSelector(selectUniversity); 13 | const isLoading = useSelector(universityActionState) === STATUSES.PENDING; 14 | const dispatch = useDispatch(); 15 | const [displayLength, setLength] = useState(10); 16 | const [page, setPage] = useState(1); 17 | const [countryName, setCountryName] = useState(CountryList[0].label); 18 | const [universityName, setUniversityName] = useState(''); 19 | 20 | const handleChangeLength = (dataKey: number) => { 21 | setPage(1); 22 | setLength(dataKey); 23 | }; 24 | 25 | const getData = () => 26 | dispatch( 27 | getUniversityData({ 28 | country: countryName, 29 | name: universityName, 30 | }) 31 | ); 32 | 33 | useEffect(() => { 34 | getData(); 35 | // eslint-disable-next-line react-hooks/exhaustive-deps 36 | }, []); 37 | 38 | const tableData = useMemo( 39 | () => 40 | universityList.filter((_item, index) => { 41 | const start = displayLength * (page - 1); 42 | const end = start + displayLength; 43 | return index >= start && index < end; 44 | }), 45 | [displayLength, page, universityList] 46 | ); 47 | return ( 48 |
49 |
50 |
51 | 52 | 58 |
59 |
60 | 61 | 62 |
63 | 66 |
67 | 68 | 69 | Country 70 | 71 | 72 | 73 | 74 | Name 75 | 76 | 77 | 78 | 79 | Website 80 | 81 | 82 | 83 | 84 | Domain 85 | 86 | 87 |
88 | 89 | 106 |
107 | ); 108 | }; 109 | 110 | export default Tables; 111 | -------------------------------------------------------------------------------- /src/components/tables/styles.module.less: -------------------------------------------------------------------------------- 1 | .green { 2 | &.rs-btn-primary { 3 | background-color: green; 4 | } 5 | } -------------------------------------------------------------------------------- /src/constants/redux.ts: -------------------------------------------------------------------------------- 1 | export const STATUSES = { 2 | INITIAL: 0, 3 | PENDING: 1, 4 | FULFILLED: 2, 5 | REJECTED: 3, 6 | }; 7 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import { Provider } from 'react-redux'; 4 | import './index.css'; 5 | import store from 'store'; 6 | import App from './App'; 7 | import reportWebVitals from './reportWebVitals'; 8 | 9 | ReactDOM.render( 10 | 11 | 12 | 13 | 14 | , 15 | document.getElementById('root') 16 | ); 17 | 18 | // If you want to start measuring performance in your app, pass a function 19 | // to log results (for example: reportWebVitals(console.log)) 20 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 21 | reportWebVitals(); 22 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/pages/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Container, Content } from 'rsuite'; 3 | import Tables from 'components/tables'; 4 | 5 | const MainPage: React.FC = () => { 6 | return ( 7 | 8 | 9 | 10 | 11 | 12 | ); 13 | }; 14 | 15 | export default MainPage; 16 | -------------------------------------------------------------------------------- /src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /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/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/store/index.ts: -------------------------------------------------------------------------------- 1 | import { configureStore } from '@reduxjs/toolkit'; 2 | import UniversityReducer from './universityData'; 3 | 4 | const store = configureStore({ 5 | reducer: { 6 | university: UniversityReducer, 7 | }, 8 | }); 9 | 10 | export default store; 11 | 12 | // Infer the `RootState` and `AppDispatch` types from the store itself 13 | export type RootState = ReturnType; 14 | 15 | // Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState} 16 | export type AppDispatch = typeof store.dispatch; 17 | -------------------------------------------------------------------------------- /src/store/universityData/action.ts: -------------------------------------------------------------------------------- 1 | import { createAsyncThunk } from '@reduxjs/toolkit'; 2 | import axios from 'axios'; 3 | 4 | const getUniversityData = createAsyncThunk('university/get', async (params: IUniversityAPIParams) => { 5 | const response = await axios.get('http://universities.hipolabs.com/search', { 6 | params, 7 | }); 8 | return response.data; 9 | }); 10 | 11 | export default getUniversityData; 12 | -------------------------------------------------------------------------------- /src/store/universityData/index.ts: -------------------------------------------------------------------------------- 1 | import { Action, createSlice, PayloadAction } from '@reduxjs/toolkit'; 2 | import { STATUSES } from 'constants/redux'; 3 | import getUniversityData from './action'; 4 | import { UniversityData } from './type'; 5 | 6 | const initialState: UniversityData = { 7 | status: STATUSES.INITIAL, 8 | data: [], 9 | }; 10 | 11 | const isPendingAction = (action: Action) => action.type.startsWith('university') && action.type.endsWith('pending'); 12 | 13 | const isRejectionAction = (action: Action) => action.type.startsWith('university') && action.type.endsWith('rejected'); 14 | 15 | const setData = (state: UniversityData, universityList: IUniversity[]) => { 16 | state.data = universityList; 17 | }; 18 | 19 | const resetData = (state: UniversityData) => { 20 | state.data = []; 21 | }; 22 | 23 | export const UniversitySlice = createSlice({ 24 | name: 'university', 25 | initialState, 26 | reducers: {}, 27 | extraReducers: builder => { 28 | builder 29 | .addCase(getUniversityData.fulfilled.type, (state: UniversityData, action: PayloadAction) => { 30 | state.status = STATUSES.FULFILLED; 31 | setData(state, action.payload); 32 | }) 33 | .addMatcher(isPendingAction, (state: UniversityData) => { 34 | state.status = STATUSES.PENDING; 35 | }) 36 | .addMatcher(isRejectionAction, (state: UniversityData) => { 37 | state.status = STATUSES.REJECTED; 38 | resetData(state); 39 | }); 40 | }, 41 | }); 42 | 43 | export { getUniversityData }; 44 | 45 | export default UniversitySlice.reducer; 46 | -------------------------------------------------------------------------------- /src/store/universityData/selector.ts: -------------------------------------------------------------------------------- 1 | import type { RootState } from 'store'; 2 | 3 | // Other code such as selectors can use the imported `RootState` type 4 | export const selectUniversity = (state: RootState) => state.university.data; 5 | export const universityActionState = (state: RootState) => state.university.status; 6 | -------------------------------------------------------------------------------- /src/store/universityData/type.ts: -------------------------------------------------------------------------------- 1 | interface UniversityData { 2 | status: number; 3 | data: IUniversity[]; 4 | } 5 | 6 | export type { UniversityData }; 7 | -------------------------------------------------------------------------------- /src/types/global.d.ts: -------------------------------------------------------------------------------- 1 | interface IUniversity { 2 | country: string; 3 | 'state-province': string; 4 | web_pages: Array; 5 | alpha_two_code: string; 6 | name: string; 7 | domains: Array; 8 | } 9 | 10 | interface IUniversityAPIParams { 11 | country: string; 12 | name?: string; 13 | } 14 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "strict": true, 13 | "forceConsistentCasingInFileNames": true, 14 | "noFallthroughCasesInSwitch": true, 15 | "module": "esnext", 16 | "moduleResolution": "node", 17 | "resolveJsonModule": true, 18 | "isolatedModules": true, 19 | "noEmit": true, 20 | "jsx": "react-jsx", 21 | "baseUrl": "src", 22 | "allowSyntheticDefaultImports": true 23 | }, 24 | "include": [ 25 | "src" 26 | ] 27 | } 28 | --------------------------------------------------------------------------------