diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..4370a5a --- /dev/null +++ b/.prettierrc @@ -0,0 +1,8 @@ +{ + "arrowParens": "avoid", + "bracketSameLine": true, + "semi": false, + "singleQuote": true, + "tabWidth": 4, + "trailingComma": "all" + } \ No newline at end of file diff --git a/bun.lockb b/bun.lockb index 789c31e..2a890bb 100644 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/eslint.config.js b/eslint.config.js index 092408a..691a34c 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -3,26 +3,35 @@ import globals from 'globals' import reactHooks from 'eslint-plugin-react-hooks' import reactRefresh from 'eslint-plugin-react-refresh' import tseslint from 'typescript-eslint' +import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended' export default tseslint.config( - { ignores: ['dist'] }, - { - extends: [js.configs.recommended, ...tseslint.configs.recommended], - files: ['**/*.{ts,tsx}'], - languageOptions: { - ecmaVersion: 2020, - globals: globals.browser, + { ignores: ['dist'] }, + { + extends: [ + js.configs.recommended, + ...tseslint.configs.recommendedTypeChecked, + ...tseslint.configs.stylisticTypeChecked, + eslintPluginPrettierRecommended, + ], + files: ['**/*.{ts,tsx}'], + languageOptions: { + ecmaVersion: 2020, + globals: globals.browser, + parserOptions: { + project: './tsconfig.node.json', + }, + }, + plugins: { + 'react-hooks': reactHooks, + 'react-refresh': reactRefresh, + }, + rules: { + ...reactHooks.configs.recommended.rules, + 'react-refresh/only-export-components': [ + 'warn', + { allowConstantExport: true }, + ], + }, }, - plugins: { - 'react-hooks': reactHooks, - 'react-refresh': reactRefresh, - }, - rules: { - ...reactHooks.configs.recommended.rules, - 'react-refresh/only-export-components': [ - 'warn', - { allowConstantExport: true }, - ], - }, - }, ) diff --git a/package-lock.json b/package-lock.json index 8f699fc..5d1fec9 100644 --- a/package-lock.json +++ b/package-lock.json @@ -27,6 +27,8 @@ "@types/react-dom": "^18.3.0", "@vitejs/plugin-react-swc": "^3.7.1", "eslint": "^9.12.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-prettier": "^5.2.1", "eslint-plugin-react-hooks": "^5.1.0-rc-fb9a90fa48-20240614", "eslint-plugin-react-refresh": "^0.4.12", "globals": "^15.10.0", @@ -1956,6 +1958,19 @@ "node": ">= 8" } }, + "node_modules/@pkgr/core": { + "version": "0.1.1", + "resolved": "https://registry.npmjs.org/@pkgr/core/-/core-0.1.1.tgz", + "integrity": "sha512-cq8o4cWH0ibXh9VGi5P20Tu9XF/0fFXl9EUinr9QfTM7a7p0oTA4iJRCQWppXR1Pg8dSM0UCItCkPwsk9qWWYA==", + "dev": true, + "license": "MIT", + "engines": { + "node": "^12.20.0 || ^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, "node_modules/@popperjs/core": { "version": "2.11.8", "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.8.tgz", @@ -3534,6 +3549,50 @@ } } }, + "node_modules/eslint-config-prettier": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-prettier/-/eslint-config-prettier-9.1.0.tgz", + "integrity": "sha512-NSWl5BFQWEPi1j4TjVNItzYV7dZXZ+wP6I6ZhrBGpChQhZRUaElihE9uRRkcbRnNb76UMKDF3r+WTmNcGPKsqw==", + "dev": true, + "license": "MIT", + "bin": { + "eslint-config-prettier": "bin/cli.js" + }, + "peerDependencies": { + "eslint": ">=7.0.0" + } + }, + "node_modules/eslint-plugin-prettier": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/eslint-plugin-prettier/-/eslint-plugin-prettier-5.2.1.tgz", + "integrity": "sha512-gH3iR3g4JfF+yYPaJYkN7jEl9QbweL/YfkoRlNnuIEHEz1vHVlCmWOS+eGGiRuzHQXdJFCOTxRgvju9b8VUmrw==", + "dev": true, + "license": "MIT", + "dependencies": { + "prettier-linter-helpers": "^1.0.0", + "synckit": "^0.9.1" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/eslint-plugin-prettier" + }, + "peerDependencies": { + "@types/eslint": ">=8.0.0", + "eslint": ">=8.0.0", + "eslint-config-prettier": "*", + "prettier": ">=3.0.0" + }, + "peerDependenciesMeta": { + "@types/eslint": { + "optional": true + }, + "eslint-config-prettier": { + "optional": true + } + } + }, "node_modules/eslint-plugin-react-hooks": { "version": "5.1.0-rc-fb9a90fa48-20240614", "resolved": "https://registry.npmjs.org/eslint-plugin-react-hooks/-/eslint-plugin-react-hooks-5.1.0-rc-fb9a90fa48-20240614.tgz", @@ -3734,6 +3793,13 @@ "dev": true, "license": "MIT" }, + "node_modules/fast-diff": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/fast-diff/-/fast-diff-1.3.0.tgz", + "integrity": "sha512-VxPP4NqbUjj6MaAOafWeUn2cXWLcCtljklUtZf0Ind4XQ+QPtmA0b18zZy0jIQx+ExRVCR/ZQpBmik5lXshNsw==", + "dev": true, + "license": "Apache-2.0" + }, "node_modules/fast-glob": { "version": "3.3.2", "resolved": "https://registry.npmjs.org/fast-glob/-/fast-glob-3.3.2.tgz", @@ -4699,6 +4765,36 @@ "node": ">= 0.8.0" } }, + "node_modules/prettier": { + "version": "3.3.3", + "resolved": "https://registry.npmjs.org/prettier/-/prettier-3.3.3.tgz", + "integrity": "sha512-i2tDNA0O5IrMO757lfrdQZCc2jPNDVntV0m/+4whiDfWaTKfMNgR7Qz0NAeGz/nRqF4m5/6CLzbP4/liHt12Ew==", + "dev": true, + "license": "MIT", + "peer": true, + "bin": { + "prettier": "bin/prettier.cjs" + }, + "engines": { + "node": ">=14" + }, + "funding": { + "url": "https://github.com/prettier/prettier?sponsor=1" + } + }, + "node_modules/prettier-linter-helpers": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz", + "integrity": "sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w==", + "dev": true, + "license": "MIT", + "dependencies": { + "fast-diff": "^1.1.2" + }, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/progress": { "version": "2.0.3", "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz", @@ -5106,6 +5202,23 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/synckit": { + "version": "0.9.2", + "resolved": "https://registry.npmjs.org/synckit/-/synckit-0.9.2.tgz", + "integrity": "sha512-vrozgXDQwYO72vHjUb/HnFbQx1exDjoKzqx23aXEg2a9VIg2TSFZ8FmeZpTjUCFMYw7mpX4BE2SFu8wI7asYsw==", + "dev": true, + "license": "MIT", + "dependencies": { + "@pkgr/core": "^0.1.0", + "tslib": "^2.6.2" + }, + "engines": { + "node": "^14.18.0 || >=16.0.0" + }, + "funding": { + "url": "https://opencollective.com/unts" + } + }, "node_modules/text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", diff --git a/package.json b/package.json index 3dd6026..bcee038 100644 --- a/package.json +++ b/package.json @@ -30,6 +30,8 @@ "@types/react-dom": "^18.3.0", "@vitejs/plugin-react-swc": "^3.7.1", "eslint": "^9.12.0", + "eslint-config-prettier": "^9.1.0", + "eslint-plugin-prettier": "^5.2.1", "eslint-plugin-react-hooks": "^5.1.0-rc-fb9a90fa48-20240614", "eslint-plugin-react-refresh": "^0.4.12", "globals": "^15.10.0", diff --git a/src/app.tsx b/src/app.tsx index 7ad454c..66a8e95 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -1,173 +1,169 @@ -import { useState } from "react"; - -import Box from "@mui/material/Box"; -import Container from "@mui/material/Container"; - -import DisclaimerDialog from "./components/disclaimer-dialog"; -import Header from "./components/header"; -import Footer from "./components/footer"; -import Stepper from "./components/stepper"; +// vendors +import { useState } from 'react' +import { Box, Container, Fade } from '@mui/material' +// components +import DonationDialog from './components/donation-dialog' +import DisclaimerDialog from './components/disclaimer-dialog' +import Footer from './components/footer' +import Form from './components/form' +import Header from './components/header' +import ResultBox from './components/result-box' +import Stepper from './components/stepper' +import SavedCalculation from './components/saved-calculation' // import Notification from './components/Notification'; -import DonationDialog from "./components/donation-dialog"; -import SavedCalculation from "./components/saved-calculation"; -import Form from "./components/form"; -import ResultBox from "./components/result-box"; -import vars from "./helpers/vars.ts"; -import { Fade } from "@mui/material"; +import vars from './helpers/vars' const INPUT_CODES = [ - [ - "BM", - "BLM", - // 'TBK', // skipped because 100% cut - "BMTG", - ], - [ - "BGP", - // 'JK', // skipped because 100% cut - "BR", - // 'BP', // skipped because 100% cut - "BK", - "PBB", - "totalWeight", - ], -]; + [ + 'BM', + 'BLM', + // 'TBK', // skipped because 100% cut + 'BMTG', + ], + [ + 'BGP', + // 'JK', // skipped because 100% cut + 'BR', + // 'BP', // skipped because 100% cut + 'BK', + 'PBB', + 'totalWeight', + ], +] export default function App() { - vars.formValues = useState({}); - vars.activeStep = useState(0); - - // const [notifications, setNotifications] = useState([]) - - // window.onmessage = (event) => { - // if (event.data.notification) { - // const notification = { - // id: event.data.messageId || Date.now(), - // text: event.data.notification.body || 'terjadi kesalahan', - // isShow: true, - // buttonText: event.data.data.buttonText, - // buttonUrl: event.data.data.buttonUrl - // } - - // notifications.push() - // setNotifications([...notifications]) - // } - // }; - - const [isTextFieldErrors, setIsTextFieldErrors] = useState({}); - - const getInvalidTextFieldIds = () => { - return INPUT_CODES[vars.activeStep[0]].filter( - (inputId) => - vars.formValues[0][inputId] === "" || isNaN(vars.formValues[0][inputId]) - ); - }; - - const hasErrors = () => { - const invalidTextFieldIds = getInvalidTextFieldIds(); - return invalidTextFieldIds.length !== 0; - }; - - const isFormValuesValid = () => { - const invalidTextFieldIds = getInvalidTextFieldIds(); - - setIsTextFieldErrors( - Object.fromEntries( - invalidTextFieldIds.map((elementId) => [elementId, true]) - ) - ); - - if (!hasErrors()) { - return true; - } - - return false; - }; - - const handleNext = () => { - if (isFormValuesValid()) { - return vars.activeStep[1](vars.activeStep[0] + 1); - } - }; - - const handlePrev = () => vars.activeStep[1]((prev: number) => prev - 1); - - return ( - -
- - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - -