├── .eslintignore ├── .eslintrc.json ├── .gitignore ├── README.md ├── craco.config.js ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── fonts │ ├── lineto-circular-pro-book.ttf │ ├── lineto-circular-pro-book.woff │ └── lineto-circular-pro-book.woff2 ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.css ├── App.test.tsx ├── App.tsx ├── assets │ ├── card-background-shape-green.svg │ ├── card-background-shape.svg │ ├── casumo-logo.svg │ ├── close.svg │ ├── edit-icon.svg │ ├── fonts │ │ ├── lineto-circular-pro-book.ttf │ │ ├── lineto-circular-pro-book.woff │ │ └── lineto-circular-pro-book.woff2 │ ├── form-error.svg │ ├── form-success.svg │ ├── mastercard-logo.svg │ └── visa-logo.svg ├── components │ ├── Card │ │ ├── index.tsx │ │ └── styles.module.scss │ └── CardDetail │ │ ├── index.tsx │ │ └── styles.module.scss ├── index.css ├── index.tsx ├── logo.svg ├── pages │ └── Home │ │ ├── index.tsx │ │ └── styles.module.scss ├── providers │ └── AppProvider.tsx ├── react-app-env.d.ts ├── reportWebVitals.ts ├── routes │ ├── MainRoute │ │ └── index.tsx │ └── Routes.tsx ├── setupTests.ts └── types │ └── card.ts ├── tailwind.config.js └── tsconfig.json /.eslintignore: -------------------------------------------------------------------------------- 1 | *.css 2 | *.svg -------------------------------------------------------------------------------- /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "browser": true, 4 | "es2021": true 5 | }, 6 | "extends": [ 7 | "plugin:react/recommended", 8 | "airbnb", 9 | "plugin:@typescript-eslint/recommended" 10 | ], 11 | "parser": "@typescript-eslint/parser", 12 | "parserOptions": { 13 | "ecmaFeatures": { 14 | "jsx": true 15 | }, 16 | "ecmaVersion": 13, 17 | "sourceType": "module" 18 | }, 19 | "plugins": [ 20 | "react", 21 | "@typescript-eslint" 22 | ], 23 | "rules": { 24 | "no-use-before-define": "off", 25 | "@typescript-eslint/no-use-before-define": ["error"], 26 | "react/jsx-filename-extension": [ "warn", {"extensions": [".tsx"]} ], 27 | "react/require-default-props": 0, 28 | "react/prop-types": "off", 29 | "react/jsx-props-no-spreading": "off", 30 | "import/extensions": [ 31 | "error", 32 | "ignorePackages", 33 | { 34 | "ts": "never", 35 | "tsx": "never" 36 | } 37 | ], 38 | "no-shadow":"off", 39 | "@typescript-eslint/no-shadow": ["error"], 40 | "@typescript-eslint/no-empty-function": "off", 41 | "jsx-a11y/label-has-associated-control": "off", 42 | "jsx-a11y/label-has-for":"off", 43 | "jsx-a11y/click-events-have-key-events": "off", 44 | "jsx-a11y/interactive-supports-focus": "off", 45 | "jsx-a11y/no-noninteractive-element-to-interactive-role": "off", 46 | "@typescript-eslint/no-explicit-any": "off" 47 | }, 48 | "settings": { 49 | "import/resolver": { 50 | "typescript": {} 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /.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 | /.idea 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 | yarn.lock 25 | -------------------------------------------------------------------------------- /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 | https://dev.to/kevin_odongo35/react-tailwind-and-typescript-35hk 46 | 47 | https://andrebnassis.medium.com/setting-eslint-on-a-react-typescript-project-2021-1190a43ffba 48 | 49 | To learn React, check out the [React documentation](https://reactjs.org/). 50 | -------------------------------------------------------------------------------- /craco.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | style: { 3 | postcss: { 4 | plugins: [ 5 | require('tailwindcss'), 6 | require('autoprefixer'), 7 | ], 8 | }, 9 | }, 10 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "test", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@craco/craco": "^6.3.0", 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 | "@types/react-router-dom": "^5.3.1", 15 | "classnames": "^2.3.1", 16 | "credit-card-type": "^9.1.0", 17 | "react": "^17.0.2", 18 | "react-dom": "^17.0.2", 19 | "react-hook-form": "^7.31.3", 20 | "react-input-mask": "^2.0.4", 21 | "react-router-dom": "^6.3.0", 22 | "react-scripts": "4.0.3", 23 | "sass": "^1.53.0", 24 | "typescript": "^4.1.2", 25 | "web-vitals": "^1.0.1" 26 | }, 27 | "scripts": { 28 | "start": "craco start", 29 | "build": "craco build", 30 | "test": "craco test", 31 | "eject": "react-scripts eject", 32 | "format": "prettier --write src/**/*.{js,jsx,ts,tsx}", 33 | "lint": "eslint --fix src/**/*.{js,jsx,ts,tsx}" 34 | }, 35 | "browserslist": { 36 | "production": [ 37 | ">0.2%", 38 | "not dead", 39 | "not op_mini all" 40 | ], 41 | "development": [ 42 | "last 1 chrome version", 43 | "last 1 firefox version", 44 | "last 1 safari version" 45 | ] 46 | }, 47 | "devDependencies": { 48 | "@types/react-input-mask": "^3.0.1", 49 | "@typescript-eslint/eslint-plugin": "^5.0.0", 50 | "@typescript-eslint/parser": "^5.0.0", 51 | "autoprefixer": "9", 52 | "eslint": "^7.32.0", 53 | "eslint-config-airbnb": "^18.2.1", 54 | "eslint-import-resolver-typescript": "^2.5.0", 55 | "eslint-plugin-import": "^2.25.2", 56 | "eslint-plugin-jsx-a11y": "^6.4.1", 57 | "eslint-plugin-react": "^7.26.1", 58 | "eslint-plugin-react-hooks": "^4.2.0", 59 | "postcss": "7", 60 | "tailwindcss": "npm:@tailwindcss/postcss7-compat" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/3solution/Casumo_Frontend_React/b390e35e05d3e76690cd927d683a1584a06a8ce0/public/favicon.ico -------------------------------------------------------------------------------- /public/fonts/lineto-circular-pro-book.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/3solution/Casumo_Frontend_React/b390e35e05d3e76690cd927d683a1584a06a8ce0/public/fonts/lineto-circular-pro-book.ttf -------------------------------------------------------------------------------- /public/fonts/lineto-circular-pro-book.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/3solution/Casumo_Frontend_React/b390e35e05d3e76690cd927d683a1584a06a8ce0/public/fonts/lineto-circular-pro-book.woff -------------------------------------------------------------------------------- /public/fonts/lineto-circular-pro-book.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/3solution/Casumo_Frontend_React/b390e35e05d3e76690cd927d683a1584a06a8ce0/public/fonts/lineto-circular-pro-book.woff2 -------------------------------------------------------------------------------- /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/3solution/Casumo_Frontend_React/b390e35e05d3e76690cd927d683a1584a06a8ce0/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/3solution/Casumo_Frontend_React/b390e35e05d3e76690cd927d683a1584a06a8ce0/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 | 40 | .card-background { 41 | background-image: url('assets/card-background-shape.svg'); 42 | background-size: contain; 43 | background-position: right; 44 | background-repeat: no-repeat; 45 | } 46 | .card-background-green { 47 | background-image: url('assets/card-background-shape-green.svg'); 48 | background-size: contain; 49 | background-position: right; 50 | background-repeat: no-repeat; 51 | } 52 | -------------------------------------------------------------------------------- /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 MainRoute from './routes/MainRoute'; 3 | import './App.css'; 4 | import AppProvider from './providers/AppProvider'; 5 | 6 | const App: React.FC = () => ( 7 | 8 | 9 | 10 | ); 11 | 12 | export default App; 13 | -------------------------------------------------------------------------------- /src/assets/card-background-shape-green.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/assets/card-background-shape.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/assets/casumo-logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/assets/close.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/assets/edit-icon.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /src/assets/fonts/lineto-circular-pro-book.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/3solution/Casumo_Frontend_React/b390e35e05d3e76690cd927d683a1584a06a8ce0/src/assets/fonts/lineto-circular-pro-book.ttf -------------------------------------------------------------------------------- /src/assets/fonts/lineto-circular-pro-book.woff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/3solution/Casumo_Frontend_React/b390e35e05d3e76690cd927d683a1584a06a8ce0/src/assets/fonts/lineto-circular-pro-book.woff -------------------------------------------------------------------------------- /src/assets/fonts/lineto-circular-pro-book.woff2: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/3solution/Casumo_Frontend_React/b390e35e05d3e76690cd927d683a1584a06a8ce0/src/assets/fonts/lineto-circular-pro-book.woff2 -------------------------------------------------------------------------------- /src/assets/form-error.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/assets/form-success.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /src/assets/mastercard-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /src/assets/visa-logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /src/components/Card/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { useEffect, useState } from 'react'; 2 | import creditCardType, { 3 | types as CardType, 4 | } from 'credit-card-type'; 5 | import classNames from 'classnames'; 6 | 7 | import { ICard } from '../../types/card'; 8 | import imgVisa from '../../assets/visa-logo.svg'; 9 | import imgMaster from '../../assets/mastercard-logo.svg'; 10 | import imgEdit from '../../assets/edit-icon.svg'; 11 | 12 | import styles from './styles.module.scss'; 13 | 14 | interface Props extends ICard { 15 | onClick?: VoidFunction; 16 | isNotEditable?: boolean; 17 | } 18 | 19 | const Card: React.FC = ({ 20 | cvc, 21 | expireDate, 22 | name, 23 | number, 24 | isNotEditable, 25 | onClick = () => {}, 26 | }) => { 27 | const [type, setType] = useState(); 28 | 29 | useEffect(() => { 30 | if (number) { 31 | creditCardType(number.toString()).filter((card) => setType(card.type)); 32 | } 33 | }, []); 34 | 35 | return ( 36 | <> 37 |
44 |
45 |
46 | Card Logo 47 |
48 |
49 | 56 | CVC 57 | 58 | {cvc} 59 |
60 |
61 | 68 | EXPIRES 69 | 70 | {expireDate} 71 |
72 |
73 |
74 | {name} 75 | 82 | { number} 83 | 84 |
85 | { !isNotEditable && ( 86 | 89 | )} 90 |
91 | 92 | ); 93 | }; 94 | 95 | export default Card; 96 | -------------------------------------------------------------------------------- /src/components/Card/styles.module.scss: -------------------------------------------------------------------------------- 1 | .wrapper { 2 | @apply relative w-full rounded-sm p-4 space-y-6 flex flex-col justify-between bg-blue; 3 | 4 | &.masterCard { 5 | @apply bg-indigo-60; 6 | } 7 | 8 | .cardTypeWrapper { 9 | @apply flex items-baseline justify-between; 10 | 11 | .logo { 12 | @apply flex-1; 13 | } 14 | 15 | .cvcWrapper { 16 | @apply flex flex-col mx-3; 17 | 18 | .title { 19 | @apply text-xs font-extrabold tracking-widest text-right text-dark-60; 20 | 21 | &.masterCard { 22 | @apply text-dark-30; 23 | } 24 | } 25 | 26 | .value { 27 | @apply font-bold text-white tracking-widest text-right text-tiny; 28 | } 29 | } 30 | } 31 | 32 | .cardNumberWrapper { 33 | @apply flex flex-col gap-y-1; 34 | 35 | .title { 36 | @apply font-bold text-white text-tiny; 37 | } 38 | 39 | .value { 40 | @apply text-tiny font-bold text-dark-60; 41 | 42 | &.masterCard { 43 | @apply text-dark-30; 44 | } 45 | } 46 | } 47 | 48 | .editButton { 49 | @apply absolute right-4 bottom-5; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/components/CardDetail/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { useContext, useEffect, useState } from 'react'; 2 | import { 3 | useForm, useFormState, Controller, useWatch, 4 | } from 'react-hook-form'; 5 | import InputMask from 'react-input-mask'; 6 | import classNames from 'classnames'; 7 | 8 | import imgClose from '../../assets/close.svg'; 9 | import imgSuccess from '../../assets/form-success.svg'; 10 | import imgError from '../../assets/form-error.svg'; 11 | import Card from '../Card'; 12 | import { ICard } from '../../types/card'; 13 | import { AppContext } from '../../providers/AppProvider'; 14 | 15 | import styles from './styles.module.scss'; 16 | 17 | type props = { 18 | onClose? : VoidFunction; 19 | selectedIndex: number; 20 | } 21 | 22 | const CardDetails: React.FC = ({ 23 | onClose = () => {}, 24 | selectedIndex, 25 | }) => { 26 | const [cardData, setCardData] = useState(); 27 | const [isExist, setIsExist] = useState(false); 28 | const { cards, setCards } = useContext(AppContext); 29 | 30 | const { 31 | register, handleSubmit, control, formState: { errors }, setValue, 32 | } = useForm(); 33 | 34 | const { isSubmitted } = useFormState({ control }); 35 | 36 | const onSubmit = (formData: ICard) => { 37 | if (selectedIndex < 0) { 38 | setCards([...cards, formData]); 39 | } else { 40 | setCards((prev) => { 41 | prev.splice(selectedIndex, 1, formData); 42 | return [...prev]; 43 | }); 44 | } 45 | onClose(); 46 | }; 47 | 48 | const onDelete = () => { 49 | cards.splice(selectedIndex, 1); 50 | setCards([...cards]); 51 | onClose(); 52 | }; 53 | 54 | const checkNumber = (value: number) => { 55 | const isNotUnique = cards.some((item: ICard) => item.number === value); 56 | const isUpdating = selectedIndex >= 0 ? cards[selectedIndex].number === value : false; 57 | const isValidNumber = isUpdating ? true : !isNotUnique; 58 | setIsExist(!isValidNumber); 59 | return isValidNumber; 60 | }; 61 | 62 | const watchedNumber = useWatch({ 63 | control, 64 | name: 'number', 65 | }); 66 | 67 | const numberErrorMsg = () => { 68 | if (!isExist && errors.number) { 69 | return errors.number.message; 70 | } if (isExist) { 71 | return 'The Number is already registered'; 72 | } return ''; 73 | }; 74 | 75 | const getFieldColor = (fieldName: string, type: 'border' | 'color') => { 76 | if (type === 'border') { 77 | return classNames( 78 | 'mt-1 w-full border-b bg-gray-50 flex', 79 | { 80 | 'border-dark-10': !errors[fieldName], 81 | 'border-green': isSubmitted && !errors[fieldName], 82 | 'border-rose': errors[fieldName], 83 | }, 84 | ); 85 | } 86 | 87 | return classNames( 88 | 'block sm:text-sm outline-none flex-1', 89 | { 90 | 'text-dark-30': !errors[fieldName], 91 | 'text-green': isSubmitted && !errors[fieldName], 92 | 'text-rose': errors[fieldName], 93 | }, 94 | ); 95 | }; 96 | 97 | useEffect(() => { 98 | setIsExist(false); 99 | }, [watchedNumber]); 100 | 101 | useEffect(() => { 102 | if (selectedIndex >= 0) { 103 | setCardData(cards[selectedIndex]); 104 | setValue('name', cards[selectedIndex].name); 105 | setValue('number', cards[selectedIndex].number); 106 | setValue('expireDate', cards[selectedIndex].expireDate); 107 | setValue('cvc', cards[selectedIndex].cvc); 108 | } 109 | }, []); 110 | 111 | return ( 112 | <> 113 |
114 |
115 | 118 |
119 |

{selectedIndex >= 0 ? 'Edit your card' : 'Add your card'}

120 | {cardData && } 121 |
122 |
123 | 126 |
129 | 136 | {isSubmitted && form-field-status} 137 |
138 | { errors.name && {errors.name.message}} 139 |
140 | 141 |
142 | 145 |
146 | checkNumber(value), 152 | }} 153 | control={control} 154 | render={({ field: { onChange, value } }) => ( 155 | 156 | {(inputProps: any) => ( 157 | 163 | )} 164 | 165 | )} 166 | /> 167 | {isSubmitted && form-field-status} 168 |
169 | {numberErrorMsg()} 170 |
171 | 172 |
173 | 176 |
177 | ( 185 | 186 | {(inputProps: any) => ( 187 | 193 | )} 194 | 195 | )} 196 | /> 197 | {isSubmitted && form-field-status} 198 |
199 | {errors.expireDate && {errors.expireDate.message}} 200 |
201 | 202 |
203 | 206 |
207 | 218 | {isSubmitted && form-field-status} 219 |
220 | {errors.cvc && {errors.cvc.message}} 221 |
222 | 223 | 224 |
225 | {selectedIndex >= 0 && } 226 |
227 |
onClose()} /> 228 | 229 | ); 230 | }; 231 | 232 | export default CardDetails; 233 | -------------------------------------------------------------------------------- /src/components/CardDetail/styles.module.scss: -------------------------------------------------------------------------------- 1 | .formWrapper { 2 | @apply absolute bottom-0 left-0 w-full flex flex-col z-20 py-4 px-5 bg-white rounded-t-md; 3 | 4 | .closeBtnWrapper { 5 | @apply text-right; 6 | } 7 | 8 | .title { 9 | @apply mb-5 text-base font-bold text-dark-90; 10 | } 11 | 12 | .itemWrapper { 13 | @apply mt-5; 14 | 15 | .title { 16 | @apply block text-sm font-bold text-dark-90 mb-0; 17 | } 18 | 19 | .error { 20 | @apply text-sm text-rose; 21 | } 22 | } 23 | 24 | .confirmBtn { 25 | @apply w-full py-3 mt-5 font-medium text-white rounded-lg bg-indigo-30; 26 | } 27 | 28 | .deleteBtn { 29 | @apply py-3 mt-1 font-medium text-dark-10; 30 | } 31 | } 32 | 33 | .area { 34 | @apply absolute bottom-0 left-0 z-10 w-full h-full bg-dark-60 opacity-60; 35 | } 36 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | @font-face { 6 | font-family: 'lineto'; 7 | src: local('lineto'), url(./assets/fonts/lineto-circular-pro-book.woff) format('truetype'); 8 | font-display: swap; 9 | } 10 | 11 | body { 12 | margin: 0; 13 | font-family: "lineto", sans-serif; 14 | -webkit-font-smoothing: antialiased; 15 | -moz-osx-font-smoothing: grayscale; 16 | } 17 | 18 | code { 19 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 20 | monospace; 21 | } 22 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import ReactDOM from 'react-dom'; 3 | import { BrowserRouter } from 'react-router-dom'; 4 | import './index.css'; 5 | import App from './App'; 6 | import reportWebVitals from './reportWebVitals'; 7 | 8 | ReactDOM.render( 9 | 10 | 11 | , 12 | document.getElementById('root'), 13 | ); 14 | 15 | // If you want to start measuring performance in your app, pass a function 16 | // to log results (for example: reportWebVitals(console.log)) 17 | // or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals 18 | reportWebVitals(); 19 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /src/pages/Home/index.tsx: -------------------------------------------------------------------------------- 1 | import React, { useContext, useState } from 'react'; 2 | 3 | import Card from '../../components/Card'; 4 | import CardDetail from '../../components/CardDetail'; 5 | import { AppContext } from '../../providers/AppProvider'; 6 | import { ICard } from '../../types/card'; 7 | 8 | import styles from './styles.module.scss'; 9 | 10 | const Home: React.FC = () => { 11 | const { cards } = useContext(AppContext); 12 | const [showModal, setShowModal] = useState(false); 13 | const [selectedIndex, setSelectedIndex] = useState(-1); 14 | 15 | const addNew = (): void => { 16 | setShowModal(true); 17 | setSelectedIndex(-1); 18 | }; 19 | 20 | const editCard = (index: number): void => { 21 | setSelectedIndex(index); 22 | setShowModal(true); 23 | }; 24 | 25 | return ( 26 |
27 | Your cards 28 | Add, edit or delete your cards any time 29 |
30 | {cards?.map((item: ICard, i: number) => ( 31 | editCard(i)} 33 | key={item.number} 34 | {...item} 35 | /> 36 | ))} 37 |
38 | 39 | {showModal && ( 40 | setShowModal(false)} selectedIndex={selectedIndex} /> 41 | )} 42 |
43 | ); 44 | }; 45 | 46 | export default Home; 47 | -------------------------------------------------------------------------------- /src/pages/Home/styles.module.scss: -------------------------------------------------------------------------------- 1 | .wrapper { 2 | @apply relative flex flex-col h-screen max-w-xl px-5 py-8 mx-auto; 3 | 4 | .title { 5 | @apply text-lg font-bold text-indigo-30; 6 | } 7 | 8 | .description { 9 | @apply mt-1 text-sm font-medium text-dark-30; 10 | } 11 | 12 | .cards { 13 | @apply flex-1 mt-8 space-y-2 overflow-y-auto; 14 | } 15 | 16 | .newBtn { 17 | @apply py-3 font-medium text-white rounded-lg bg-indigo-30; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/providers/AppProvider.tsx: -------------------------------------------------------------------------------- 1 | import React, { createContext, ReactNode, useState } from 'react'; 2 | import { ICard } from '../types/card'; 3 | 4 | type PropsType = { 5 | children: ReactNode; 6 | }; 7 | 8 | type ContextProps = { 9 | cards: ICard[]; 10 | setCards: React.Dispatch>; 11 | }; 12 | 13 | export const AppContext = createContext({ cards: [], setCards: () => {} }); 14 | 15 | const AppProvider = ({ children }: PropsType) => { 16 | const [cards, setCards] = useState([]); 17 | 18 | return ( 19 | 25 | {children} 26 | 27 | ); 28 | }; 29 | 30 | export default AppProvider; 31 | -------------------------------------------------------------------------------- /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(({ 6 | getCLS, getFID, getFCP, getLCP, getTTFB, 7 | }) => { 8 | getCLS(onPerfEntry); 9 | getFID(onPerfEntry); 10 | getFCP(onPerfEntry); 11 | getLCP(onPerfEntry); 12 | getTTFB(onPerfEntry); 13 | }); 14 | } 15 | }; 16 | 17 | export default reportWebVitals; 18 | -------------------------------------------------------------------------------- /src/routes/MainRoute/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { 3 | BrowserRouter, Navigate, Route, Routes, 4 | } from 'react-router-dom'; 5 | 6 | import Home from '../../pages/Home'; 7 | 8 | const MainRoute = () => ( 9 | 10 | 11 | } /> 12 | } /> 13 | 14 | 15 | ); 16 | 17 | export default MainRoute; 18 | -------------------------------------------------------------------------------- /src/routes/Routes.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { Switch, Route } from 'react-router-dom'; 3 | 4 | import Home from '../pages/Home'; 5 | 6 | const Routes: React.FC = () => ( 7 | 8 | 9 | 10 | ); 11 | 12 | export default Routes; 13 | -------------------------------------------------------------------------------- /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/types/card.ts: -------------------------------------------------------------------------------- 1 | export interface ICard { 2 | name?: string; 3 | number?: number; 4 | expireDate?: number; 5 | cvc?: number; 6 | } 7 | -------------------------------------------------------------------------------- /tailwind.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | purge: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html'], 3 | darkMode: false, // or 'media' or 'class' 4 | theme: { 5 | borderRadius: { 6 | none: '0', 7 | sm: '16px', 8 | md: '24px', 9 | lg: '100px', 10 | }, 11 | colors: { 12 | white: '#ffffff', 13 | indigo: { 14 | 30: '#4C00C2', 15 | 60: '#3B058E', 16 | 100: '#32007E', 17 | }, 18 | grey: '#E5E5E5', 19 | blue: '#01C9C7', 20 | dark: { 21 | 10: '#D3D8E1', 22 | 30: '#798291', 23 | 60: '#444E5D', 24 | 90: '#1A212C', 25 | }, 26 | green: '#19AC51', 27 | rose: '#FC484C', 28 | }, 29 | bgColors: { 30 | white: '#ffffff', 31 | indigo: { 32 | 30: '#4C00C2', 33 | 60: '#3B058E', 34 | 100: '#32007E', 35 | }, 36 | grey: '#E5E5E5', 37 | dark: { 38 | 10: '#D3D8E1', 39 | 30: '#798291', 40 | 60: '#444E5D', 41 | 90: '#1A212C', 42 | }, 43 | green: '#19AC51', 44 | rose: '#FC484C', 45 | }, 46 | fontSize: { 47 | xs: '10px', 48 | sm: '14px', 49 | tiny: '16px', 50 | base: '24px', 51 | lg: '30px', 52 | }, 53 | spacing: { 54 | 0: '0px', 55 | 1: '4px', 56 | 2: '8px', 57 | 3: '16px', 58 | 4: '24px', 59 | 5: '32px', 60 | 6: '40px', 61 | 7: '48px', 62 | 8: '56px', 63 | }, 64 | extend: { 65 | minHeight: { 66 | 1000: '1000px', 67 | }, 68 | }, 69 | }, 70 | variants: { 71 | extend: {}, 72 | }, 73 | plugins: [], 74 | }; 75 | -------------------------------------------------------------------------------- /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 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "noFallthroughCasesInSwitch": true, 16 | "module": "esnext", 17 | "moduleResolution": "node", 18 | "resolveJsonModule": true, 19 | "isolatedModules": true, 20 | "noEmit": true, 21 | "jsx": "react-jsx" 22 | }, 23 | "include": [ 24 | "src" 25 | ] 26 | } 27 | --------------------------------------------------------------------------------