diff --git a/frontend/.eslintrc.json b/frontend/.eslintrc.json index f32ecee..a881257 100644 --- a/frontend/.eslintrc.json +++ b/frontend/.eslintrc.json @@ -21,6 +21,7 @@ "import/no-cycle": 0, "no-unused-expressions": 0, "react/jsx-props-no-spreading": 0, - "react/prop-types": 0 + "react/prop-types": 0, + "react/function-component-definition": 0 } } diff --git a/frontend/.vscode/settings.json b/frontend/.vscode/settings.json index 406a7d2..a172093 100644 --- a/frontend/.vscode/settings.json +++ b/frontend/.vscode/settings.json @@ -1,8 +1,8 @@ { "[javascript]": { - "editor.defaultFormatter": "dbaeumer.vscode-eslint" + "editor.defaultFormatter": "rvest.vs-code-prettier-eslint" }, "[javascriptreact]": { - "editor.defaultFormatter": "dbaeumer.vscode-eslint" + "editor.defaultFormatter": "rvest.vs-code-prettier-eslint" } } diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 95f206c..48ae934 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -3049,6 +3049,15 @@ "@types/node": "*" } }, + "@types/hoist-non-react-statics": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/@types/hoist-non-react-statics/-/hoist-non-react-statics-3.3.1.tgz", + "integrity": "sha512-iMIqiko6ooLrTh1joXodJK5X9xeEALT1kM5G3ZLhD3hszxBdIEd5C75U834D9mLcINgD4OyZf5uQXjkuYydWvA==", + "requires": { + "@types/react": "*", + "hoist-non-react-statics": "^3.3.0" + } + }, "@types/html-minifier-terser": { "version": "6.1.0", "resolved": "https://registry.npmjs.org/@types/html-minifier-terser/-/html-minifier-terser-6.1.0.tgz", @@ -3126,6 +3135,11 @@ "resolved": "https://registry.npmjs.org/@types/prettier/-/prettier-2.6.0.tgz", "integrity": "sha512-G/AdOadiZhnJp0jXCaBQU449W2h716OW/EoXeYkCytxKL06X1WCXB4DZpp8TpZ8eyIJVS1cw4lrlkkSYU21cDw==" }, + "@types/prop-types": { + "version": "15.7.5", + "resolved": "https://registry.npmjs.org/@types/prop-types/-/prop-types-15.7.5.tgz", + "integrity": "sha512-JCB8C6SnDoQf0cNycqd/35A7MjcnK+ZTqE7judS6o7utxUCg6imJg3QK2qzHKszlTjcj2cn+NwMB2i96ubpj7w==" + }, "@types/q": { "version": "1.5.5", "resolved": "https://registry.npmjs.org/@types/q/-/q-1.5.5.tgz", @@ -3141,6 +3155,27 @@ "resolved": "https://registry.npmjs.org/@types/range-parser/-/range-parser-1.2.4.tgz", "integrity": "sha512-EEhsLsD6UsDM1yFhAvy0Cjr6VwmpMWqFBCb9w07wVugF7w9nfajxLuVmngTIpgS6svCnm6Vaw+MZhoDCKnOfsw==" }, + "@types/react": { + "version": "18.0.5", + "resolved": "https://registry.npmjs.org/@types/react/-/react-18.0.5.tgz", + "integrity": "sha512-UPxNGInDCIKlfqBrm8LDXYWNfLHwIdisWcsH5GpMyGjhEDLFgTtlRBaoWuCua9HcyuE0rMkmAeZ3FXV1pYLIYQ==", + "requires": { + "@types/prop-types": "*", + "@types/scheduler": "*", + "csstype": "^3.0.2" + } + }, + "@types/react-redux": { + "version": "7.1.24", + "resolved": "https://registry.npmjs.org/@types/react-redux/-/react-redux-7.1.24.tgz", + "integrity": "sha512-7FkurKcS1k0FHZEtdbbgN8Oc6b+stGSfZYjQGicofJ0j4U0qIn/jaSvnP2pLwZKiai3/17xqqxkkrxTgN8UNbQ==", + "requires": { + "@types/hoist-non-react-statics": "^3.3.0", + "@types/react": "*", + "hoist-non-react-statics": "^3.3.0", + "redux": "^4.0.0" + } + }, "@types/resolve": { "version": "1.17.1", "resolved": "https://registry.npmjs.org/@types/resolve/-/resolve-1.17.1.tgz", @@ -3154,6 +3189,11 @@ "resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.1.tgz", "integrity": "sha512-xoDlM2S4ortawSWORYqsdU+2rxdh4LRW9ytc3zmT37RIKQh6IHyKwwtKhKis9ah8ol07DCkZxPt8BBvPjC6v4g==" }, + "@types/scheduler": { + "version": "0.16.2", + "resolved": "https://registry.npmjs.org/@types/scheduler/-/scheduler-0.16.2.tgz", + "integrity": "sha512-hppQEBDmlwhFAXKJX2KnWLYu5yMfi91yazPb2l+lbJiwW+wdo1gNeRA+3RgNSO39WYX2euey41KEwnqesU2Jew==" + }, "@types/serve-index": { "version": "1.9.1", "resolved": "https://registry.npmjs.org/@types/serve-index/-/serve-index-1.9.1.tgz", @@ -5575,6 +5615,12 @@ "minimatch": "^3.0.4" } }, + "eslint-plugin-prefer-arrow-functions": { + "version": "3.1.4", + "resolved": "https://registry.npmjs.org/eslint-plugin-prefer-arrow-functions/-/eslint-plugin-prefer-arrow-functions-3.1.4.tgz", + "integrity": "sha512-LSO8VibqBKqzelr+L21mEIfachavCon+1SEumCJ6U8Ze2q0pntyojmomcVwd9RZBjrP+HV6k1Osz0B3Xwdq8WA==", + "dev": true + }, "eslint-plugin-react": { "version": "7.29.4", "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.29.4.tgz", @@ -10228,6 +10274,26 @@ "prop-types": "^15.7.2" } }, + "react-redux": { + "version": "7.2.8", + "resolved": "https://registry.npmjs.org/react-redux/-/react-redux-7.2.8.tgz", + "integrity": "sha512-6+uDjhs3PSIclqoCk0kd6iX74gzrGc3W5zcAjbrFgEdIjRSQObdIwfx80unTkVUYvbQ95Y8Av3OvFHq1w5EOUw==", + "requires": { + "@babel/runtime": "^7.15.4", + "@types/react-redux": "^7.1.20", + "hoist-non-react-statics": "^3.3.2", + "loose-envify": "^1.4.0", + "prop-types": "^15.7.2", + "react-is": "^17.0.2" + }, + "dependencies": { + "react-is": { + "version": "17.0.2", + "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz", + "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==" + } + } + }, "react-refresh": { "version": "0.11.0", "resolved": "https://registry.npmjs.org/react-refresh/-/react-refresh-0.11.0.tgz", @@ -10530,6 +10596,14 @@ } } }, + "redux": { + "version": "4.1.2", + "resolved": "https://registry.npmjs.org/redux/-/redux-4.1.2.tgz", + "integrity": "sha512-SH8PglcebESbd/shgf6mii6EIoRM0zrQyjcuQ+ojmfxjTtE0z9Y8pa62iA/OJ58qjP6j27uyW4kUF4jl/jd6sw==", + "requires": { + "@babel/runtime": "^7.9.2" + } + }, "regenerate": { "version": "1.4.2", "resolved": "https://registry.npmjs.org/regenerate/-/regenerate-1.4.2.tgz", diff --git a/frontend/package.json b/frontend/package.json index 483df2a..4b657df 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -12,8 +12,10 @@ "react-dom": "^18.0.0", "react-icons": "^4.3.1", "react-phone-input-2": "^2.15.0", + "react-redux": "^7.2.8", "react-router-dom": "^6.3.0", "react-scripts": "5.0.1", + "redux": "^4.1.2", "web-vitals": "^2.1.4" }, "devDependencies": { @@ -21,6 +23,7 @@ "eslint-config-airbnb": "^19.0.4", "eslint-plugin-import": "^2.22.1", "eslint-plugin-jsx-a11y": "^6.3.1", + "eslint-plugin-prefer-arrow-functions": "^3.1.4", "eslint-plugin-react": "^7.21.4", "eslint-plugin-react-hooks": "^4.1.2" }, diff --git a/frontend/public/index.html b/frontend/public/index.html index aa069f2..c676152 100644 --- a/frontend/public/index.html +++ b/frontend/public/index.html @@ -1,14 +1,12 @@ - + + - + - React App - - + OpenCommerce + + +
- - + + + \ No newline at end of file diff --git a/frontend/src/App.css b/frontend/src/App.css new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index c508dde..afe8887 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -1,42 +1,26 @@ import React from 'react'; -import { - ChakraProvider, - Box, - Text, - Link, - VStack, - Code, - Grid, - theme, -} from '@chakra-ui/react'; -import { ColorModeSwitcher } from './ColorModeSwitcher'; -import { Logo } from './Logo'; +import { ChakraProvider, theme } from '@chakra-ui/react'; +import { BrowserRouter, Routes, Route } from 'react-router-dom'; +import { Provider } from 'react-redux'; +import NavBar from './global/components/Navbar'; +import store from './redux/store'; -function App() { - return ( - - - - - - - - Edit src/App.js and save to reload. - - - Learn Chakra - - - - - - ); -} +// Pages +import Home from './pages/Home/index'; -export default App; +export default () => ( + + + + +
+ +
+ + )} /> + + + + + +); diff --git a/frontend/src/Logo.js b/frontend/src/Logo.js deleted file mode 100644 index b6d19a1..0000000 --- a/frontend/src/Logo.js +++ /dev/null @@ -1,18 +0,0 @@ -import React from 'react'; -import { Image, keyframes, usePrefersReducedMotion } from '@chakra-ui/react'; -import logo from './logo.svg'; - -const spin = keyframes` - from { transform: rotate(0deg); } - to { transform: rotate(360deg); } -`; - -export const Logo = props => { - const prefersReducedMotion = usePrefersReducedMotion(); - - const animation = prefersReducedMotion - ? undefined - : `${spin} infinite 20s linear`; - - return ; -}; diff --git a/frontend/src/auth/index.js b/frontend/src/auth/index.js new file mode 100644 index 0000000..389f490 --- /dev/null +++ b/frontend/src/auth/index.js @@ -0,0 +1,7 @@ +export const LoadUser = () => { + +}; + +export const Validate = () => { + +}; diff --git a/frontend/src/ColorModeSwitcher.js b/frontend/src/global/components/ColorModeSwitcher.jsx similarity index 92% rename from frontend/src/ColorModeSwitcher.js rename to frontend/src/global/components/ColorModeSwitcher.jsx index 9766bf4..be8a680 100644 --- a/frontend/src/ColorModeSwitcher.js +++ b/frontend/src/global/components/ColorModeSwitcher.jsx @@ -2,7 +2,7 @@ import React from 'react'; import { useColorMode, useColorModeValue, IconButton } from '@chakra-ui/react'; import { FaMoon, FaSun } from 'react-icons/fa'; -export const ColorModeSwitcher = props => { +export default (props) => { const { toggleColorMode } = useColorMode(); const text = useColorModeValue('dark', 'light'); const SwitchIcon = useColorModeValue(FaMoon, FaSun); diff --git a/frontend/src/global/components/Navbar.jsx b/frontend/src/global/components/Navbar.jsx new file mode 100644 index 0000000..0a8180b --- /dev/null +++ b/frontend/src/global/components/Navbar.jsx @@ -0,0 +1,30 @@ +import React from 'react'; +import { + Breadcrumb, + BreadcrumbItem, + BreadcrumbLink, + BreadcrumbSeparator, +} from '@chakra-ui/react'; +import ColorModeSwitcher from './ColorModeSwitcher'; + +export default () => ( + + + Home + + + + + + Docs + + + + + + Breadcrumb + + + + +); diff --git a/frontend/src/index.js b/frontend/src/index.js index 0668dfc..9c54f05 100644 --- a/frontend/src/index.js +++ b/frontend/src/index.js @@ -1,24 +1,8 @@ -import { ColorModeScript } from '@chakra-ui/react'; -import React, { StrictMode } from 'react'; -import ReactDOM from 'react-dom'; +import { createRoot } from 'react-dom/client'; + import App from './App'; -import reportWebVitals from './reportWebVitals'; -import * as serviceWorker from './serviceWorker'; +import './App.css'; -ReactDOM.render( - - - - , - document.getElementById('root') -); - -// If you want your app to work offline and load faster, you can change -// unregister() to register() below. Note this comes with some pitfalls. -// Learn more about service workers: https://cra.link/PWA -serviceWorker.unregister(); - -// If you want to start measuring performance in your app, pass a function -// to log results (for example: reportWebVitals(console.log)) -// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals -reportWebVitals(); +const container = document.getElementById('root'); +const root = createRoot(container); +root.render(App()); diff --git a/frontend/src/logo.svg b/frontend/src/logo.svg deleted file mode 100644 index 620fe26..0000000 --- a/frontend/src/logo.svg +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/frontend/src/pages/Home/index.jsx b/frontend/src/pages/Home/index.jsx new file mode 100644 index 0000000..7115279 --- /dev/null +++ b/frontend/src/pages/Home/index.jsx @@ -0,0 +1,6 @@ +import React from 'react'; +import { Heading } from '@chakra-ui/react'; + +export default () => ( + Henlo World +); diff --git a/frontend/src/redux/reducers.js b/frontend/src/redux/reducers.js new file mode 100644 index 0000000..0c95a32 --- /dev/null +++ b/frontend/src/redux/reducers.js @@ -0,0 +1,38 @@ +const defaultState = { + isAuthenticated: false, + user: null, + i18n: null, + langs: null, +}; + +// eslint-disable-next-line default-param-last +export default (state = defaultState, action) => { + switch (action.type) { + case 'SET_USER': + return { + ...state, + user: { + ...action.user, + }, + isAuthenticated: true, + }; + case 'CLEAR_USER': + return { + ...state, + user: null, + isAuthenticated: false, + }; + case 'SET_I18N': + return { + ...state, + i18n: action.data, + }; + case 'SET_LANGS': + return { + ...state, + langs: action.data, + }; + default: + return state; + } +}; diff --git a/frontend/src/redux/store.js b/frontend/src/redux/store.js new file mode 100644 index 0000000..b5736c4 --- /dev/null +++ b/frontend/src/redux/store.js @@ -0,0 +1,4 @@ +import { createStore } from 'redux'; +import Reducer from './reducers'; + +export default createStore(Reducer); diff --git a/frontend/src/reportWebVitals.js b/frontend/src/reportWebVitals.js deleted file mode 100644 index 5253d3a..0000000 --- a/frontend/src/reportWebVitals.js +++ /dev/null @@ -1,13 +0,0 @@ -const reportWebVitals = onPerfEntry => { - if (onPerfEntry && onPerfEntry instanceof Function) { - import('web-vitals').then(({ getCLS, getFID, getFCP, getLCP, getTTFB }) => { - getCLS(onPerfEntry); - getFID(onPerfEntry); - getFCP(onPerfEntry); - getLCP(onPerfEntry); - getTTFB(onPerfEntry); - }); - } -}; - -export default reportWebVitals; diff --git a/frontend/src/serviceWorker.js b/frontend/src/serviceWorker.js deleted file mode 100644 index 7574e58..0000000 --- a/frontend/src/serviceWorker.js +++ /dev/null @@ -1,141 +0,0 @@ -// This optional code is used to register a service worker. -// register() is not called by default. - -// This lets the app load faster on subsequent visits in production, and gives -// it offline capabilities. However, it also means that developers (and users) -// will only see deployed updates on subsequent visits to a page, after all the -// existing tabs open on the page have been closed, since previously cached -// resources are updated in the background. - -// To learn more about the benefits of this model and instructions on how to -// opt-in, read https://cra.link/PWA - -const isLocalhost = Boolean( - window.location.hostname === 'localhost' || - // [::1] is the IPv6 localhost address. - window.location.hostname === '[::1]' || - // 127.0.0.0/8 are considered localhost for IPv4. - window.location.hostname.match( - /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ - ) -); - -export function register(config) { - if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { - // The URL constructor is available in all browsers that support SW. - const publicUrl = new URL(process.env.PUBLIC_URL, window.location.href); - if (publicUrl.origin !== window.location.origin) { - // Our service worker won't work if PUBLIC_URL is on a different origin - // from what our page is served on. This might happen if a CDN is used to - // serve assets; see https://github.com/facebook/create-react-app/issues/2374 - return; - } - - window.addEventListener('load', () => { - const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; - - if (isLocalhost) { - // This is running on localhost. Let's check if a service worker still exists or not. - checkValidServiceWorker(swUrl, config); - - // Add some additional logging to localhost, pointing developers to the - // service worker/PWA documentation. - navigator.serviceWorker.ready.then(() => { - console.log( - 'This web app is being served cache-first by a service ' + - 'worker. To learn more, visit https://cra.link/PWA' - ); - }); - } else { - // Is not localhost. Just register service worker - registerValidSW(swUrl, config); - } - }); - } -} - -function registerValidSW(swUrl, config) { - navigator.serviceWorker - .register(swUrl) - .then(registration => { - registration.onupdatefound = () => { - const installingWorker = registration.installing; - if (installingWorker == null) { - return; - } - installingWorker.onstatechange = () => { - if (installingWorker.state === 'installed') { - if (navigator.serviceWorker.controller) { - // At this point, the updated precached content has been fetched, - // but the previous service worker will still serve the older - // content until all client tabs are closed. - console.log( - 'New content is available and will be used when all ' + - 'tabs for this page are closed. See https://cra.link/PWA.' - ); - - // Execute callback - if (config && config.onUpdate) { - config.onUpdate(registration); - } - } else { - // At this point, everything has been precached. - // It is the perfect time to display a - // "Content is cached for offline use." message. - console.log('Content is cached for offline use.'); - - // Execute callback - if (config && config.onSuccess) { - config.onSuccess(registration); - } - } - } - }; - }; - }) - .catch(error => { - console.error('Error during service worker registration:', error); - }); -} - -function checkValidServiceWorker(swUrl, config) { - // Check if the service worker can be found. If it can't reload the page. - fetch(swUrl, { - headers: { 'Service-Worker': 'script' }, - }) - .then(response => { - // Ensure service worker exists, and that we really are getting a JS file. - const contentType = response.headers.get('content-type'); - if ( - response.status === 404 || - (contentType != null && contentType.indexOf('javascript') === -1) - ) { - // No service worker found. Probably a different app. Reload the page. - navigator.serviceWorker.ready.then(registration => { - registration.unregister().then(() => { - window.location.reload(); - }); - }); - } else { - // Service worker found. Proceed as normal. - registerValidSW(swUrl, config); - } - }) - .catch(() => { - console.log( - 'No internet connection found. App is running in offline mode.' - ); - }); -} - -export function unregister() { - if ('serviceWorker' in navigator) { - navigator.serviceWorker.ready - .then(registration => { - registration.unregister(); - }) - .catch(error => { - console.error(error.message); - }); - } -} diff --git a/frontend/src/setupTests.js b/frontend/src/setupTests.js deleted file mode 100644 index 8f2609b..0000000 --- a/frontend/src/setupTests.js +++ /dev/null @@ -1,5 +0,0 @@ -// jest-dom adds custom jest matchers for asserting on DOM nodes. -// allows you to do things like: -// expect(element).toHaveTextContent(/react/i) -// learn more: https://github.com/testing-library/jest-dom -import '@testing-library/jest-dom'; diff --git a/frontend/src/test-utils.js b/frontend/src/test-utils.js deleted file mode 100644 index c125384..0000000 --- a/frontend/src/test-utils.js +++ /dev/null @@ -1,12 +0,0 @@ -import React from 'react'; -import { render } from '@testing-library/react'; -import { ChakraProvider, theme } from '@chakra-ui/react'; - -const AllProviders = ({ children }) => ( - {children} -); - -const customRender = (ui, options) => - render(ui, { wrapper: AllProviders, ...options }); - -export { customRender as render };