├── .babelrc.js ├── .eslintignore ├── .eslintrc.js ├── .gitignore ├── .prettierignore ├── .prettierrc ├── .vscode └── settings.json ├── README.md ├── package.json ├── src ├── @types │ └── declarations.d.ts ├── app-routes.tsx ├── app.tsx ├── assets │ ├── .gitkeep │ ├── fonts │ │ └── Be_Vietnam_Pro │ │ │ ├── BeVietnamPro-Italic.ttf │ │ │ ├── BeVietnamPro-Medium.ttf │ │ │ ├── BeVietnamPro-MediumItalic.ttf │ │ │ ├── BeVietnamPro-Regular.ttf │ │ │ ├── BeVietnamPro-SemiBold.ttf │ │ │ └── BeVietnamPro-SemiBoldItalic.ttf │ └── images │ │ └── background_header.jpg ├── components │ ├── app-bar │ │ ├── app-bar.tsx │ │ └── index.ts │ ├── base │ │ ├── base-confirm-dialog.tsx │ │ ├── base-dialog.tsx │ │ ├── box.tsx │ │ ├── container.tsx │ │ ├── document.tsx │ │ ├── editable-area-marker.tsx │ │ ├── editable-area-wrapper.tsx │ │ ├── editable-date-picker.tsx │ │ ├── editable-text.tsx │ │ ├── index.ts │ │ ├── page.tsx │ │ ├── section-title.tsx │ │ ├── styled-button.tsx │ │ └── typography.tsx │ ├── common │ │ ├── index.ts │ │ └── snackbar.tsx │ ├── footer │ │ ├── footer.tsx │ │ └── index.ts │ ├── invoice-download-button │ │ ├── index.ts │ │ └── invoice-download-button.tsx │ ├── invoice-paper │ │ ├── index.ts │ │ └── invoice-paper.tsx │ ├── invoice-settings │ │ ├── index.ts │ │ └── invoice-settings.tsx │ ├── invoices │ │ ├── add-invoice-item.tsx │ │ ├── dialog-recipient.tsx │ │ ├── dialog-sender.tsx │ │ ├── index.ts │ │ ├── invoice-company-logo.tsx │ │ ├── invoice-editable.tsx │ │ ├── invoice-editable │ │ │ └── invoice-editable-content-no-data.tsx │ │ ├── invoice-footer.tsx │ │ ├── invoice-info.tsx │ │ ├── invoice-line-item-header.tsx │ │ ├── invoice-line-item.tsx │ │ ├── invoice-payment-info.tsx │ │ ├── invoice-pdf.tsx │ │ ├── invoice-recipient.tsx │ │ ├── invoice-sender.tsx │ │ ├── invoice-summary.tsx │ │ ├── invoice-term-and-condition.tsx │ │ └── invoice-title.tsx │ ├── layout │ │ ├── index.ts │ │ └── layout.tsx │ └── pdf-preview │ │ ├── index.ts │ │ └── pdf-preview.tsx ├── config │ ├── common │ │ ├── app-config.ts │ │ ├── index.ts │ │ └── interface.ts │ ├── index.ts │ └── theme │ │ ├── index.ts │ │ ├── palette.ts │ │ ├── shadows.ts │ │ ├── shape.ts │ │ └── typography.ts ├── constants │ └── index.ts ├── context │ ├── generator-context.tsx │ ├── index.ts │ └── invoice-context.tsx ├── hooks │ ├── index.ts │ ├── useGenerator.ts │ └── useInvoice.tsx ├── index.html ├── index.tsx ├── interfaces │ ├── address.ts │ ├── common.ts │ ├── company.ts │ ├── invoice.ts │ ├── paper.ts │ ├── pdf-styles.ts │ ├── person.ts │ └── settings.ts ├── providers │ ├── index.ts │ ├── invoice-provider.tsx │ ├── localization-provider.tsx │ ├── redux-provider.tsx │ └── theme-provider.tsx ├── routes.tsx ├── screens │ ├── home-screen │ │ ├── home-screen.tsx │ │ └── index.ts │ ├── index.ts │ └── invoice-generator-screen │ │ ├── index.ts │ │ └── invoice-generator-screen.tsx ├── store │ ├── app │ │ ├── app-actions.enum.ts │ │ ├── app-actions.ts │ │ ├── app-reducer.ts │ │ └── app.interfaces.ts │ ├── config-store.ts │ ├── hooks.ts │ ├── index.ts │ ├── invoice │ │ ├── invoice-actions.enum.ts │ │ ├── invoice-actions.ts │ │ ├── invoice-reducer.ts │ │ └── invoice.interfaces.ts │ ├── root-reducer.ts │ └── settings │ │ ├── settings-actions.enum.ts │ │ ├── settings-actions.ts │ │ └── settings-reducer.ts ├── styles │ ├── _global.scss │ └── styles.scss └── utils │ ├── currency.ts │ ├── index.ts │ ├── invoice.ts │ └── theme.ts ├── tsconfig.json ├── webpack-config ├── plugins.js ├── rules.js └── utils.js ├── webpack.config.babel.js └── yarn.lock /.babelrc.js: -------------------------------------------------------------------------------- 1 | module.exports = (api) => { 2 | const mode = process.env.NODE_ENV ?? 'production'; 3 | 4 | api.cache.using(() => mode); 5 | 6 | return { 7 | presets: [ 8 | [ 9 | '@babel/preset-env', 10 | { 11 | targets: { 12 | browsers: ['>1%', 'last 4 versions', 'not ie < 9'], 13 | }, 14 | useBuiltIns: 'usage', 15 | debug: false, 16 | corejs: 3, 17 | }, 18 | ], 19 | '@babel/preset-react', 20 | ], 21 | plugins: [ 22 | '@babel/plugin-proposal-class-properties', 23 | '@babel/plugin-proposal-export-namespace-from', 24 | '@babel/plugin-syntax-dynamic-import', 25 | '@babel/plugin-proposal-throw-expressions', 26 | '@babel/plugin-proposal-object-rest-spread', 27 | // Applies the react-refresh Babel plugin on development mode only 28 | mode !== 'production' && 'react-refresh/babel', 29 | ].filter(Boolean), 30 | }; 31 | }; 32 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | build 3 | webpack-config 4 | .eslintrc.js 5 | webpack.config.js 6 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | 3 | module.exports = { 4 | parser: '@typescript-eslint/parser', // Specifies the ESLint parser 5 | plugins: ['@typescript-eslint', 'react'], 6 | env: { 7 | browser: true, 8 | jest: true, 9 | }, 10 | extends: [ 11 | 'plugin:@typescript-eslint/recommended', // Uses the recommended rules from the @typescript-eslint/eslint-plugin 12 | 'prettier', 13 | ], 14 | parserOptions: { 15 | project: path.resolve(__dirname, './tsconfig.json'), 16 | tsconfigRootDir: __dirname, 17 | ecmaVersion: 'latest', // Allows for the parsing of modern ECMAScript features 18 | sourceType: 'module', // Allows for the use of imports 19 | ecmaFeatures: { 20 | jsx: true, // Allows for the parsing of JSX 21 | }, 22 | }, 23 | rules: { 24 | // Place to specify ESLint rules. Can be used to overwrite rules specified from the extended configs 25 | '@typescript-eslint/no-unused-vars': 'off', 26 | '@typescript-eslint/ban-ts-comment': 'off', 27 | // These rules don't add much value, are better covered by TypeScript and good definition files 28 | 'react/no-direct-mutation-state': 'off', 29 | 'react/no-deprecated': 'off', 30 | 'react/no-string-refs': 'off', 31 | 'react/require-render-return': 'off', 32 | 'react/jsx-filename-extension': [ 33 | 'warn', 34 | { 35 | extensions: ['.jsx', '.tsx'], 36 | }, 37 | ], 38 | 'react/prop-types': 'off', // Is this incompatible with TS props type? idk. 39 | '@typescript-eslint/explicit-function-return-type': ['error', { allowExpressions: true }], 40 | 'react/react-in-jsx-scope': 'off', // suppress errors for missing 'import React' in files 41 | 'react/jsx-props-no-spreading': 'off', 42 | }, 43 | settings: { 44 | react: { 45 | version: 'detect', // Tells eslint-plugin-react to automatically detect the version of React to use 46 | }, 47 | }, 48 | }; 49 | -------------------------------------------------------------------------------- /.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 | /dist 14 | 15 | # misc 16 | .DS_Store 17 | .env.local 18 | .env.development.local 19 | .env.test.local 20 | .env.production.local 21 | .idea 22 | 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | *.d.ts 2 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "useTabs": false, 3 | "tabWidth": 2, 4 | "singleQuote": true, 5 | "trailingComma": "all", 6 | "semi": true, 7 | "arrowParens": "always", 8 | "bracketSpacing": true, 9 | "endOfLine": "auto", 10 | "printWidth": 120, 11 | "overrides": [ 12 | { 13 | "files": ["*.ts"], 14 | "options": { 15 | "parser": "typescript" 16 | } 17 | }, 18 | { 19 | "files": ["*.tsx"], 20 | "options": { 21 | "parser": "typescript", 22 | "jsxBracketSameLine": false, 23 | "jsxSingleQuote": false 24 | } 25 | } 26 | ] 27 | } 28 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.defaultFormatter": "esbenp.prettier-vscode", 3 | "editor.formatOnSave": true, 4 | "eslint.alwaysShowStatus": true, 5 | "editor.codeActionsOnSave": { 6 | "source.fixAll.eslint": true 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # React Simple Invoice Generator 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-simple-invoice-generator", 3 | "version": "0.1.1", 4 | "description": "Simple invoice generator", 5 | "license": "MIT", 6 | "author": "Riski ", 7 | "main": "webpack.config.babel.js", 8 | "private": false, 9 | "scripts": { 10 | "build": "cross-env NODE_ENV=production webpack --config webpack.config.babel.js", 11 | "profile": "cross-env NODE_ENV=production webpack --profile --json --config webpack.config.babel.js > ./dist/profile.json && webpack-bundle-analyzer ./dist/profile.json", 12 | "start": "cross-env WEBPACK_IS_DEV_SERVER=true NODE_ENV=development webpack serve --config webpack.config.babel.js" 13 | }, 14 | "dependencies": { 15 | "@atlaskit/spinner": "^15.1.12", 16 | "@date-io/date-fns": "^2.14.0", 17 | "@emotion/react": "^11.9.0", 18 | "@emotion/styled": "^11.8.1", 19 | "@faker-js/faker": "^7.1.0", 20 | "@mui/icons-material": "^5.6.1", 21 | "@mui/material": "^5.6.1", 22 | "@mui/x-date-pickers": "^5.0.0-alpha.6", 23 | "@react-pdf/renderer": "^2.1.2", 24 | "@testing-library/jest-dom": "^5.16.4", 25 | "@testing-library/react": "^12.1.5", 26 | "@testing-library/user-event": "^13.5.0", 27 | "assert": "^2.0.0", 28 | "browserify-zlib": "^0.2.0", 29 | "buffer": "^6.0.3", 30 | "date-fns": "^2.28.0", 31 | "process": "^0.11.10", 32 | "react": "17.0.2", 33 | "react-dom": "17.0.2", 34 | "react-redux": "^8.0.0", 35 | "react-router-dom": "6", 36 | "redux": "^4.1.2", 37 | "redux-persist": "^6.0.0", 38 | "stream-browserify": "^3.0.0", 39 | "util": "^0.12.4" 40 | }, 41 | "devDependencies": { 42 | "@babel/core": "^7.17.9", 43 | "@babel/plugin-proposal-class-properties": "^7.16.7", 44 | "@babel/plugin-proposal-export-default-from": "^7.16.7", 45 | "@babel/plugin-proposal-export-namespace-from": "^7.16.7", 46 | "@babel/plugin-proposal-object-rest-spread": "^7.17.3", 47 | "@babel/plugin-proposal-throw-expressions": "^7.16.7", 48 | "@babel/plugin-syntax-dynamic-import": "^7.8.3", 49 | "@babel/plugin-transform-runtime": "^7.17.0", 50 | "@babel/preset-env": "^7.16.11", 51 | "@babel/preset-react": "^7.16.7", 52 | "@babel/register": "^7.17.7", 53 | "@pmmmwh/react-refresh-webpack-plugin": "^0.5.5", 54 | "@teamsupercell/typings-for-css-modules-loader": "^2.5.1", 55 | "@types/jest": "^27.4.1", 56 | "@types/node": "^16.11.26", 57 | "@types/react": "^18.0.5", 58 | "@types/react-dom": "^18.0.1", 59 | "@typescript-eslint/eslint-plugin": "^5.19.0", 60 | "@typescript-eslint/parser": "^5.19.0", 61 | "autoprefixer": "^10.4.7", 62 | "babel-eslint": "^10.1.0", 63 | "babel-loader": "^8.2.4", 64 | "clean-webpack-plugin": "^4.0.0", 65 | "copy-webpack-plugin": "^10.2.4", 66 | "core-js": "^3.22.0", 67 | "cross-env": "^7.0.3", 68 | "css-loader": "^6.7.1", 69 | "cssnano": "^5.1.10", 70 | "dotenv-webpack": "^7.1.0", 71 | "eslint": "^8.13.0", 72 | "eslint-config-airbnb-base": "^15.0.0", 73 | "eslint-config-airbnb-typescript": "^17.0.0", 74 | "eslint-config-prettier": "^8.5.0", 75 | "eslint-import-resolver-alias": "^1.1.2", 76 | "eslint-plugin-import": "^2.26.0", 77 | "eslint-plugin-jsx-a11y": "^6.5.1", 78 | "eslint-plugin-react": "^7.29.4", 79 | "eslint-plugin-react-hooks": "^4.4.0", 80 | "eslint-webpack-plugin": "^3.1.1", 81 | "fork-ts-checker-webpack-plugin": "^7.2.6", 82 | "html-loader": "^3.1.0", 83 | "html-webpack-plugin": "^5.5.0", 84 | "less": "^4.1.2", 85 | "less-loader": "^11.0.0", 86 | "mini-css-extract-plugin": "^2.6.0", 87 | "path": "^0.12.7", 88 | "postcss": "^8.4.14", 89 | "postcss-loader": "^7.0.0", 90 | "prettier": "^2.6.2", 91 | "pretty-quick": "^3.1.3", 92 | "react-refresh": "^0.12.0", 93 | "resolve-url-loader": "^5.0.0", 94 | "sass": "^1.52.1", 95 | "sass-loader": "^13.0.0", 96 | "sass-resources-loader": "^2.2.5", 97 | "style-loader": "^3.3.1", 98 | "terser-webpack-plugin": "^5.3.1", 99 | "ts-loader": "^9.2.8", 100 | "typescript": "^4.6.3", 101 | "url-loader": "^4.1.1", 102 | "webpack": "^5.72.0", 103 | "webpack-bundle-analyzer": "^4.5.0", 104 | "webpack-cli": "^4.9.2", 105 | "webpack-dev-server": "^4.8.1", 106 | "webpack-merge": "^5.8.0" 107 | }, 108 | "browserslist": { 109 | "production": [ 110 | ">0.2%", 111 | "not dead", 112 | "not op_mini all" 113 | ], 114 | "development": [ 115 | "last 1 chrome version", 116 | "last 1 firefox version", 117 | "last 1 safari version" 118 | ] 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/@types/declarations.d.ts: -------------------------------------------------------------------------------- 1 | declare const IS_PROD: boolean; 2 | declare const IS_DEV: boolean; 3 | declare const IS_DEV_SERVER: boolean; 4 | 5 | 6 | declare module "*.scss" { 7 | const content: { [className: string]: string }; 8 | export = content; 9 | } 10 | 11 | declare module "*.less" { 12 | const content: { [className: string]: string }; 13 | export = content; 14 | } 15 | 16 | declare module "*.svg" { 17 | import React = require("react"); 18 | const ReactComponent: React.FunctionComponent>; 19 | export default ReactComponent; 20 | } 21 | 22 | declare module '*.json' { 23 | const content: Record; 24 | export default content; 25 | } 26 | 27 | declare module "*.png" { 28 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 29 | const value: any; 30 | export default value; 31 | } 32 | declare module "*.jpg" { 33 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 34 | const value: any; 35 | export default value; 36 | } 37 | declare module "*.webp" { 38 | // eslint-disable-next-line @typescript-eslint/no-explicit-any 39 | const value: any; 40 | export default value; 41 | } 42 | -------------------------------------------------------------------------------- /src/app-routes.tsx: -------------------------------------------------------------------------------- 1 | // React 2 | import { FC, Suspense } from 'react'; 3 | 4 | // Hooks router. 5 | import { useRoutes } from 'react-router-dom'; 6 | 7 | // Routes object. 8 | import routes from './routes'; 9 | 10 | const AppRoutes: FC = () => { 11 | return {useRoutes(routes())}; 12 | }; 13 | 14 | export default AppRoutes; 15 | -------------------------------------------------------------------------------- /src/app.tsx: -------------------------------------------------------------------------------- 1 | import { FC } from 'react'; 2 | 3 | // Router. 4 | import { BrowserRouter } from 'react-router-dom'; 5 | 6 | // Context providers. 7 | import { ThemeProvider, LocalizationProvider, InvoiceProvider } from '@/providers'; 8 | 9 | // App route switch. 10 | import AppRoutes from '@/app-routes'; 11 | import { useAppSelector } from './store'; 12 | 13 | // Global components. 14 | import { Snackbar } from '@/components/common'; 15 | 16 | const App: FC = () => { 17 | const { invoice_data } = useAppSelector((state) => state.invoice); 18 | return ( 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | ); 30 | }; 31 | 32 | export default App; 33 | -------------------------------------------------------------------------------- /src/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiriski/react-simple-invoice-generator/7f4f0c59267b8874bb133d893c3fe8484e6a4944/src/assets/.gitkeep -------------------------------------------------------------------------------- /src/assets/fonts/Be_Vietnam_Pro/BeVietnamPro-Italic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiriski/react-simple-invoice-generator/7f4f0c59267b8874bb133d893c3fe8484e6a4944/src/assets/fonts/Be_Vietnam_Pro/BeVietnamPro-Italic.ttf -------------------------------------------------------------------------------- /src/assets/fonts/Be_Vietnam_Pro/BeVietnamPro-Medium.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiriski/react-simple-invoice-generator/7f4f0c59267b8874bb133d893c3fe8484e6a4944/src/assets/fonts/Be_Vietnam_Pro/BeVietnamPro-Medium.ttf -------------------------------------------------------------------------------- /src/assets/fonts/Be_Vietnam_Pro/BeVietnamPro-MediumItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiriski/react-simple-invoice-generator/7f4f0c59267b8874bb133d893c3fe8484e6a4944/src/assets/fonts/Be_Vietnam_Pro/BeVietnamPro-MediumItalic.ttf -------------------------------------------------------------------------------- /src/assets/fonts/Be_Vietnam_Pro/BeVietnamPro-Regular.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiriski/react-simple-invoice-generator/7f4f0c59267b8874bb133d893c3fe8484e6a4944/src/assets/fonts/Be_Vietnam_Pro/BeVietnamPro-Regular.ttf -------------------------------------------------------------------------------- /src/assets/fonts/Be_Vietnam_Pro/BeVietnamPro-SemiBold.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiriski/react-simple-invoice-generator/7f4f0c59267b8874bb133d893c3fe8484e6a4944/src/assets/fonts/Be_Vietnam_Pro/BeVietnamPro-SemiBold.ttf -------------------------------------------------------------------------------- /src/assets/fonts/Be_Vietnam_Pro/BeVietnamPro-SemiBoldItalic.ttf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiriski/react-simple-invoice-generator/7f4f0c59267b8874bb133d893c3fe8484e6a4944/src/assets/fonts/Be_Vietnam_Pro/BeVietnamPro-SemiBoldItalic.ttf -------------------------------------------------------------------------------- /src/assets/images/background_header.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hiriski/react-simple-invoice-generator/7f4f0c59267b8874bb133d893c3fe8484e6a4944/src/assets/images/background_header.jpg -------------------------------------------------------------------------------- /src/components/app-bar/app-bar.tsx: -------------------------------------------------------------------------------- 1 | import { FC, useEffect, useState } from 'react'; 2 | 3 | // Mui components. 4 | import { AppBar as MuiAppBar, Container, IconButton, Typography, Box } from '@mui/material'; 5 | 6 | // Config. 7 | import { AppConfig } from '@/config'; 8 | import { grey } from '@mui/material/colors'; 9 | 10 | const AppBar: FC = () => { 11 | const [zIndex, setZIndex] = useState(3); 12 | 13 | useEffect(() => { 14 | document.addEventListener('scroll', () => { 15 | const scrollCheck = window.scrollY; 16 | if (scrollCheck > 60) { 17 | setZIndex(1); 18 | } else { 19 | setZIndex(3); 20 | } 21 | }); 22 | }, []); 23 | 24 | return ( 25 | 26 | 27 | 28 | 29 | {AppConfig.appName} 30 | 31 | {AppConfig.appDescription} 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | ); 45 | }; 46 | 47 | export default AppBar; 48 | -------------------------------------------------------------------------------- /src/components/app-bar/index.ts: -------------------------------------------------------------------------------- 1 | export { default as AppBar } from './app-bar'; 2 | -------------------------------------------------------------------------------- /src/components/base/base-confirm-dialog.tsx: -------------------------------------------------------------------------------- 1 | import { FC, ReactNode } from 'react'; 2 | 3 | // Base components. 4 | import { BaseDialog } from '@/components/base'; 5 | 6 | // Interfaces. 7 | import { SxProps } from '@mui/material'; 8 | 9 | interface Props { 10 | open: boolean; 11 | title: string; 12 | icon?: ReactNode; 13 | onClose: () => void; 14 | onConfirm: () => void; 15 | children: ReactNode; 16 | sx?: SxProps; 17 | } 18 | 19 | const BaseConfirmDialog: FC = (props) => { 20 | const { open, onClose, title, children, icon, onConfirm, sx } = props; 21 | 22 | return ( 23 | 24 | {children} 25 | 26 | ); 27 | }; 28 | 29 | export default BaseConfirmDialog; 30 | -------------------------------------------------------------------------------- /src/components/base/base-dialog.tsx: -------------------------------------------------------------------------------- 1 | import { FC, forwardRef, ReactElement, ReactNode } from 'react'; 2 | 3 | // Mui components. 4 | import Zoom, { ZoomProps } from '@mui/material/Zoom'; 5 | import Dialog, { DialogProps } from '@mui/material/Dialog'; 6 | import { Box, DialogActions, DialogContent, DialogTitle, IconButton, SxProps } from '@mui/material'; 7 | 8 | // Mui icons. 9 | import CloseIcon from '@mui/icons-material/Close'; 10 | import StyledButton from './styled-button'; 11 | 12 | // Transition component. 13 | const Transition = forwardRef( 14 | (props, ref): ReactElement => , 15 | ); 16 | 17 | interface Props extends Omit { 18 | paperStyles?: SxProps; 19 | title: ReactNode; 20 | icon?: ReactNode; 21 | onConfirm: () => void; 22 | confirmButtonText?: string; 23 | disableCloseButton?: boolean; 24 | disableCancelButton?: boolean; 25 | cancelButtonText?: string; 26 | } 27 | 28 | const BaseDialog: FC = (props) => { 29 | const { 30 | sx, 31 | open, 32 | icon, 33 | title, 34 | onClose, 35 | children, 36 | paperStyles, 37 | onConfirm, 38 | confirmButtonText, 39 | disableCloseButton, 40 | disableCancelButton, 41 | cancelButtonText, 42 | ...rest 43 | } = props; 44 | return ( 45 | theme.spacing(4, 6), 65 | // md: (theme) => theme.spacing(7, 9), 66 | // }, 67 | ...paperStyles, 68 | }, 69 | }} 70 | sx={{ ...sx }} 71 | {...rest} 72 | > 73 | {icon && {icon}} 74 | {title} 75 | 76 | {!disableCloseButton && ( 77 | void} 79 | sx={{ position: 'absolute', top: (theme) => theme.spacing(2.6), right: (theme) => theme.spacing(3) }} 80 | > 81 | 82 | 83 | )} 84 | {children} 85 | 86 | {!disableCancelButton && ( 87 | void} disableHoverEffect color="dark" size="medium" variant="text"> 88 | {cancelButtonText} 89 | 90 | )} 91 | 92 | {confirmButtonText} 93 | 94 | 95 | 96 | ); 97 | }; 98 | 99 | BaseDialog.defaultProps = { 100 | disableCancelButton: false, 101 | cancelButtonText: 'Cancel', 102 | confirmButtonText: 'Ok', 103 | }; 104 | 105 | export default BaseDialog; 106 | -------------------------------------------------------------------------------- /src/components/base/box.tsx: -------------------------------------------------------------------------------- 1 | import { FC, ReactNode } from 'react'; 2 | 3 | // React Pdf. 4 | import { View as PDFView } from '@react-pdf/renderer'; 5 | 6 | // Mui components. 7 | import MuiBox from '@mui/material/Box'; 8 | 9 | // Hooks. 10 | import { useGenerator } from '@/hooks/useGenerator'; 11 | 12 | // Interfaces. 13 | import { SxProps } from '@mui/material'; 14 | import { PdfStyle } from '@/interfaces/pdf-styles'; 15 | 16 | interface Props { 17 | children?: ReactNode; 18 | style?: SxProps | PdfStyle; 19 | fixed?: boolean; 20 | onClick?: () => void; 21 | } 22 | 23 | const Box: FC = ({ style, children, fixed, onClick }) => { 24 | const { editable, debug } = useGenerator(); 25 | 26 | return editable ? ( 27 | 28 | {children} 29 | 30 | ) : ( 31 | 32 | {children} 33 | 34 | ); 35 | }; 36 | 37 | export default Box; 38 | -------------------------------------------------------------------------------- /src/components/base/container.tsx: -------------------------------------------------------------------------------- 1 | import { FC, ReactNode } from 'react'; 2 | 3 | // React Pdf. 4 | import { View as PDFView } from '@react-pdf/renderer'; 5 | 6 | // Mui components. 7 | import MuiBox from '@mui/material/Box'; 8 | 9 | // Hooks. 10 | import { useGenerator } from '@/hooks/useGenerator'; 11 | 12 | interface Props { 13 | children?: ReactNode; 14 | } 15 | 16 | const containerStyles = { 17 | display: 'flex', 18 | flexDirection: 'column', 19 | flex: 1, 20 | padding: '40px', 21 | borderRadius: 3, 22 | overflow: 'hidden', 23 | }; 24 | 25 | const Container: FC = ({ children }) => { 26 | const { editable, debug } = useGenerator(); 27 | 28 | return editable ? ( 29 | {children} 30 | ) : ( 31 | 32 | {children} 33 | 34 | ); 35 | }; 36 | 37 | export default Container; 38 | -------------------------------------------------------------------------------- /src/components/base/document.tsx: -------------------------------------------------------------------------------- 1 | import { FC, ReactNode } from 'react'; 2 | 3 | // React Pdf. 4 | import { Document as PDFDocument } from '@react-pdf/renderer'; 5 | 6 | // Mui components. 7 | import { Box } from '@mui/material'; 8 | 9 | // Hooks. 10 | import { useGenerator } from '@/hooks/useGenerator'; 11 | 12 | interface Props { 13 | children: ReactNode; 14 | } 15 | 16 | const Document: FC = ({ children }) => { 17 | const { editable } = useGenerator(); 18 | return editable ? ( 19 | 20 | {children} 21 | 22 | ) : ( 23 | {children} 24 | ); 25 | }; 26 | export default Document; 27 | -------------------------------------------------------------------------------- /src/components/base/editable-area-marker.tsx: -------------------------------------------------------------------------------- 1 | import { FC } from 'react'; 2 | import Box from '@mui/material/Box'; 3 | 4 | const EditableAreaMarker: FC = () => ( 5 | theme.transitions.create(['transform', 'background-color', 'border']), 17 | }} 18 | /> 19 | ); 20 | 21 | export default EditableAreaMarker; 22 | -------------------------------------------------------------------------------- /src/components/base/editable-area-wrapper.tsx: -------------------------------------------------------------------------------- 1 | import { FC, ReactNode } from 'react'; 2 | import { Box } from '@/components/base'; 3 | import { useGenerator } from '@/hooks'; 4 | import { createSpacing } from '@/utils'; 5 | import { useTheme } from '@mui/material'; 6 | 7 | interface Props { 8 | children: ReactNode; 9 | } 10 | 11 | const EditableAreaWrapper: FC = ({ children }) => { 12 | const { editable } = useGenerator(); 13 | const { palette } = useTheme(); 14 | return ( 15 | 34 | {children} 35 | 36 | ); 37 | }; 38 | 39 | export default EditableAreaWrapper; 40 | -------------------------------------------------------------------------------- /src/components/base/editable-date-picker.tsx: -------------------------------------------------------------------------------- 1 | import { FC } from 'react'; 2 | import TextField from '@mui/material/TextField'; 3 | import { MobileDatePicker } from '@mui/x-date-pickers/MobileDatePicker'; 4 | 5 | interface Props { 6 | label?: string; 7 | name: 'date' | 'due'; 8 | value: string; 9 | onChange: (property: 'date' | 'due', value: string) => void; 10 | } 11 | 12 | const EditableDatePicker: FC = ({ label, name, value, onChange }) => { 13 | const handleChange = (newValue: Date | null): void => { 14 | onChange(name, String(newValue)); 15 | }; 16 | 17 | return ( 18 | ( 25 | theme.palette.primary.light, 39 | '& .MuiOutlinedInput-notchedOutline': { 40 | border: '1px solid #bed1e4 !important', 41 | }, 42 | }, 43 | '&.Mui-focused': { 44 | backgroundColor: (theme) => theme.palette.primary.light, 45 | '& .MuiOutlinedInput-notchedOutline': { 46 | border: '1px solid #bed1e4 !important', 47 | }, 48 | }, 49 | }} 50 | {...params} 51 | /> 52 | )} 53 | /> 54 | ); 55 | }; 56 | 57 | export default EditableDatePicker; 58 | -------------------------------------------------------------------------------- /src/components/base/editable-text.tsx: -------------------------------------------------------------------------------- 1 | import { FC } from 'react'; 2 | 3 | // React Pdf. 4 | import { Text as PDFText } from '@react-pdf/renderer'; 5 | 6 | // Mui components. 7 | import { InputBaseProps } from '@mui/material/InputBase'; 8 | import OutlinedInput from '@mui/material/OutlinedInput'; 9 | 10 | // Mui styles. 11 | import { styled } from '@mui/material/styles'; 12 | 13 | // Hooks. 14 | import { useGenerator } from '@/hooks/useGenerator'; 15 | 16 | // Utilities. 17 | import { getTypographyColor, getTypographyFontSize } from '@/utils'; 18 | 19 | // Interfaces. 20 | import { PdfStyle } from '@/interfaces/pdf-styles'; 21 | import { SxProps, TypeText, TypographyVariant } from '@mui/material'; 22 | 23 | // Styled components. 24 | const StyledInputBase = styled(OutlinedInput)(({ theme }) => ({ 25 | // position: 'relative', 26 | padding: '0 !important', 27 | '& .MuiInputBase-input.MuiInputBase-inputSizeSmall': { 28 | padding: '2.4px 8px !important', 29 | }, 30 | '& .MuiInputBase-sizeSmall.MuiInputBase-multiline': { 31 | padding: '2.4px 8px !important', 32 | }, 33 | '& .MuiOutlinedInput-notchedOutline': { 34 | border: '1px solid transparent !important', 35 | }, 36 | '&:hover': { 37 | backgroundColor: theme.palette.primary.light, 38 | '& .MuiOutlinedInput-notchedOutline': { 39 | border: '1px solid #bed1e4 !important', 40 | }, 41 | }, 42 | '&.Mui-focused': { 43 | backgroundColor: theme.palette.primary.light, 44 | '& .MuiOutlinedInput-notchedOutline': { 45 | border: '1px solid #bed1e4 !important', 46 | }, 47 | }, 48 | })); 49 | 50 | interface Props extends Omit { 51 | style?: SxProps | PdfStyle; 52 | variant?: TypographyVariant; 53 | color?: keyof TypeText; 54 | } 55 | 56 | const EditableText: FC = (props) => { 57 | const { editable, debug } = useGenerator(); 58 | 59 | const { variant, color, value, style, ...rest } = props; 60 | 61 | return editable ? ( 62 | 63 | ) : ( 64 | 71 | {String(value)} 72 | 73 | ); 74 | }; 75 | 76 | EditableText.defaultProps = { 77 | variant: 'body1', 78 | color: 'primary', 79 | }; 80 | 81 | export default EditableText; 82 | -------------------------------------------------------------------------------- /src/components/base/index.ts: -------------------------------------------------------------------------------- 1 | export { default as Box } from './box'; 2 | export { default as Page } from './page'; 3 | export { default as Document } from './document'; 4 | export { default as Container } from './container'; 5 | export { default as Typography } from './typography'; 6 | export { default as BaseDialog } from './base-dialog'; 7 | export { default as SectionTitle } from './section-title'; 8 | export { default as EditableText } from './editable-text'; 9 | export { default as StyledButton } from './styled-button'; 10 | export { default as BaseConfirmDialog } from './base-confirm-dialog'; 11 | export { default as EditableAreaMarker } from './editable-area-marker'; 12 | export { default as EditableAreaWrapper } from './editable-area-wrapper'; 13 | -------------------------------------------------------------------------------- /src/components/base/page.tsx: -------------------------------------------------------------------------------- 1 | import { FC, ReactNode } from 'react'; 2 | 3 | // React Pdf. 4 | import { Page as PDFPage } from '@react-pdf/renderer'; 5 | 6 | // Base components. 7 | import { Box } from '@/components/base'; 8 | 9 | // Hooks. 10 | import { useGenerator } from '@/hooks/useGenerator'; 11 | 12 | interface Props { 13 | children: ReactNode; 14 | } 15 | 16 | const Page: FC = ({ children }) => { 17 | const { editable } = useGenerator(); 18 | 19 | return editable ? ( 20 | {children} 21 | ) : ( 22 | 30 | {children} 31 | 32 | ); 33 | }; 34 | export default Page; 35 | -------------------------------------------------------------------------------- /src/components/base/section-title.tsx: -------------------------------------------------------------------------------- 1 | import { FC, ReactNode } from 'react'; 2 | 3 | // Mui components. 4 | import MuiTypography from '@mui/material/Typography'; 5 | 6 | // Base components. 7 | import { Typography } from '@/components/base'; 8 | 9 | // Hooks. 10 | import { useGenerator } from '@/hooks/useGenerator'; 11 | 12 | // Utilities. 13 | import { createSpacing } from '@/utils/theme'; 14 | 15 | interface Props { 16 | children: ReactNode; 17 | } 18 | 19 | const SectionTitle: FC = ({ children }) => { 20 | const { editable } = useGenerator(); 21 | return editable ? ( 22 | 26 | {children} 27 | 28 | ) : ( 29 | 39 | {children} 40 | 41 | ); 42 | }; 43 | 44 | export default SectionTitle; 45 | -------------------------------------------------------------------------------- /src/components/base/styled-button.tsx: -------------------------------------------------------------------------------- 1 | import { fontFamily } from '@/config/theme/typography'; 2 | import Spinner from '@atlaskit/spinner'; 3 | import { Theme } from '@mui/material'; 4 | import Box from '@mui/material/Box'; 5 | import { ButtonProps } from '@mui/material/Button'; 6 | import { red } from '@mui/material/colors'; 7 | import { styled } from '@mui/material/styles'; 8 | import { FC, MouseEvent, ReactElement, ReactNode } from 'react'; 9 | 10 | const selectorCircleSvgSpinner = "& [class$='-Spinner'] > svg > circle"; 11 | 12 | interface BaseButtonProps 13 | extends Pick { 14 | onClick?: (e: MouseEvent) => void | undefined; 15 | variant?: 'contained' | 'outlined' | 'text'; 16 | color?: 'default' | 'primary' | 'secondary' | 'dark' | 'light' | 'error'; 17 | size?: 'small' | 'medium' | 'large'; 18 | disableHoverEffect?: boolean; 19 | isLoading?: boolean; 20 | } 21 | 22 | interface StyledButtonRootProps extends BaseButtonProps { 23 | theme?: Theme; 24 | } 25 | 26 | const StyledButtonRoot = styled('button', { 27 | shouldForwardProp: (prop) => 28 | prop !== 'variant' && 29 | prop !== 'color' && 30 | prop !== 'size' && 31 | prop !== 'disableHoverEffect' && 32 | prop !== 'fullWidth' && 33 | prop !== 'isLoading', 34 | })(({ theme, color, variant, size, disableHoverEffect, fullWidth, isLoading }) => ({ 35 | fontFamily, 36 | cursor: 'pointer', 37 | minWidth: 40, 38 | lineHeight: 1.5, 39 | borderRadius: 5, 40 | 41 | display: 'inline-flex', 42 | alignItems: 'center', 43 | userSelect: 'none', 44 | transform: 'unset', 45 | position: 'relative', 46 | overflow: 'hidden', 47 | border: 'none', 48 | whiteSpace: 'nowrap', 49 | WebkitTapHighlightColor: 'transparent', 50 | verticalAlign: 'middle', 51 | outline: 'none !important', 52 | transition: theme.transitions.create(['transform']), 53 | 54 | // Full width button 55 | ...(fullWidth && { 56 | width: '100%', 57 | justifyContent: 'center', 58 | }), 59 | 60 | // hover 61 | '&:hover': { 62 | ...(!disableHoverEffect && { 63 | transform: 'translateY(-2px)', 64 | }), 65 | }, 66 | 67 | '& svg': { 68 | fontSize: 20, 69 | }, 70 | 71 | // sizes and variants 72 | ...(size === 'small' && 73 | variant === 'outlined' && { 74 | padding: '4px 10px', 75 | }), 76 | ...(size === 'medium' && 77 | variant === 'outlined' && { 78 | padding: '6px 14px', 79 | }), 80 | ...(size === 'large' && 81 | variant === 'outlined' && { 82 | padding: '10px 18px', 83 | fontSize: 15, 84 | }), 85 | 86 | ...(size === 'small' && 87 | variant !== 'outlined' && { 88 | padding: '6px 12px', 89 | }), 90 | ...(size === 'medium' && 91 | variant !== 'outlined' && { 92 | padding: '8px 16px', 93 | }), 94 | ...(size === 'large' && 95 | variant !== 'outlined' && { 96 | padding: '12px 26px', 97 | fontSize: 15, 98 | }), 99 | 100 | // variants 101 | ...(variant !== 'contained' && { 102 | backgroundColor: 'transparent', 103 | boxShadow: 'none !important', 104 | }), 105 | 106 | // colors & variants 107 | ...(color === 'default' && 108 | variant === 'contained' && { 109 | backgroundColor: theme.palette.text.primary, 110 | color: theme.palette.primary.contrastText, 111 | [selectorCircleSvgSpinner]: { 112 | stroke: `${theme.palette.primary.contrastText} !important`, 113 | }, 114 | }), 115 | ...(color === 'primary' && 116 | variant === 'contained' && { 117 | backgroundColor: theme.palette.primary.main, 118 | color: theme.palette.primary.contrastText, 119 | // boxShadow: '0 6px 22px 0 rgb(18 124 113 / 12%)', 120 | [selectorCircleSvgSpinner]: { 121 | stroke: `${theme.palette.primary.contrastText} !important`, 122 | }, 123 | }), 124 | ...(color === 'secondary' && 125 | variant === 'contained' && { 126 | backgroundColor: theme.palette.secondary.main, 127 | color: theme.palette.primary.contrastText, 128 | [selectorCircleSvgSpinner]: { 129 | stroke: `${theme.palette.secondary.contrastText} !important`, 130 | }, 131 | }), 132 | ...(color === 'dark' && 133 | variant === 'contained' && { 134 | backgroundColor: '#313d56', 135 | color: theme.palette.primary.contrastText, 136 | [selectorCircleSvgSpinner]: { 137 | stroke: `${theme.palette.primary.main} !important`, 138 | }, 139 | }), 140 | ...(color === 'light' && 141 | variant === 'contained' && { 142 | backgroundColor: theme.palette.primary.contrastText, 143 | color: theme.palette.text.primary, 144 | [selectorCircleSvgSpinner]: { 145 | stroke: `${theme.palette.primary.contrastText} !important`, 146 | }, 147 | }), 148 | ...(color === 'error' && 149 | variant === 'contained' && { 150 | backgroundColor: red[500], 151 | color: theme.palette.primary.contrastText, 152 | [selectorCircleSvgSpinner]: { 153 | stroke: `${theme.palette.primary.contrastText} !important`, 154 | }, 155 | }), 156 | 157 | ...(color === 'primary' && 158 | variant === 'outlined' && { 159 | border: `2px solid ${theme.palette.primary.main}`, 160 | color: theme.palette.primary.main, 161 | [selectorCircleSvgSpinner]: { 162 | stroke: `${theme.palette.primary.main} !important`, 163 | }, 164 | }), 165 | ...(color === 'secondary' && 166 | variant === 'outlined' && { 167 | border: `2px solid ${theme.palette.secondary.main}`, 168 | color: theme.palette.secondary.main, 169 | [selectorCircleSvgSpinner]: { 170 | stroke: `${theme.palette.secondary.main} !important`, 171 | }, 172 | }), 173 | ...(color === 'dark' && 174 | variant === 'outlined' && { 175 | border: `2px solid #313d56`, 176 | color: '#313d56', 177 | [selectorCircleSvgSpinner]: { 178 | stroke: `${theme.palette.text.primary} !important`, 179 | }, 180 | }), 181 | ...(color === 'light' && 182 | variant === 'outlined' && { 183 | border: `2px solid #fbfbfb`, 184 | color: `#fbfbfb`, 185 | [selectorCircleSvgSpinner]: { 186 | stroke: `${theme.palette.primary.contrastText} !important`, 187 | }, 188 | }), 189 | ...(color === 'error' && 190 | variant === 'outlined' && { 191 | border: `2px solid ${red[500]}`, 192 | color: `${red[500]}`, 193 | [selectorCircleSvgSpinner]: { 194 | stroke: `${theme.palette.primary.contrastText} !important`, 195 | }, 196 | }), 197 | 198 | ...(color === 'primary' && 199 | variant === 'text' && { 200 | color: theme.palette.primary.main, 201 | [selectorCircleSvgSpinner]: { 202 | stroke: `${theme.palette.primary.main} !important`, 203 | }, 204 | }), 205 | ...(color === 'secondary' && 206 | variant === 'text' && { 207 | color: theme.palette.secondary.main, 208 | [selectorCircleSvgSpinner]: { 209 | stroke: `${theme.palette.secondary.main} !important`, 210 | }, 211 | }), 212 | ...(color === 'dark' && 213 | variant === 'text' && { 214 | color: '#313d56', 215 | [selectorCircleSvgSpinner]: { 216 | stroke: `${theme.palette.text.primary} !important`, 217 | }, 218 | }), 219 | ...(color === 'light' && 220 | variant === 'text' && { 221 | color: theme.palette.primary.contrastText, 222 | [selectorCircleSvgSpinner]: { 223 | stroke: `${theme.palette.primary.contrastText} !important`, 224 | }, 225 | }), 226 | ...(color === 'error' && 227 | variant === 'text' && { 228 | color: red[500], 229 | [selectorCircleSvgSpinner]: { 230 | stroke: `${theme.palette.primary.contrastText} !important`, 231 | }, 232 | }), 233 | })); 234 | 235 | type Props = BaseButtonProps; 236 | 237 | const StyledButton: FC = (props) => { 238 | const { children, onClick, disableHoverEffect, startIcon, endIcon, isLoading, ...rest } = props; 239 | 240 | const renderSpinner = (placement?: 'start' | 'end'): ReactElement => ( 241 | 242 | 243 | 244 | ); 245 | 246 | // Handle button click. 247 | const handleClick = (e: MouseEvent): void | undefined => { 248 | if (!onClick) return; 249 | else { 250 | if (isLoading) e.preventDefault(); 251 | else onClick(e); 252 | } 253 | }; 254 | 255 | return ( 256 | 257 | {startIcon && !isLoading && ( 258 | 259 | {startIcon} 260 | 261 | )} 262 | {isLoading && renderSpinner('start')} 263 | {children} 264 | {endIcon && !isLoading && ( 265 | 266 | {endIcon} 267 | 268 | )} 269 | 270 | ); 271 | }; 272 | 273 | StyledButton.defaultProps = { 274 | color: 'primary', 275 | variant: 'contained', 276 | size: 'medium', 277 | disableHoverEffect: false, 278 | }; 279 | 280 | export default StyledButton; 281 | -------------------------------------------------------------------------------- /src/components/base/typography.tsx: -------------------------------------------------------------------------------- 1 | import { FC } from 'react'; 2 | 3 | // React Pdf. 4 | import { Text as PDFText } from '@react-pdf/renderer'; 5 | 6 | // Mui components. 7 | import MuiTypography from '@mui/material/Typography'; 8 | 9 | // Hooks. 10 | import { useGenerator } from '@/hooks/useGenerator'; 11 | 12 | // Utilities. 13 | import { getTypographyColor, getTypographyFontSize } from '@/utils'; 14 | 15 | // Interfaces. 16 | import { PdfStyle } from '@/interfaces/pdf-styles'; 17 | import { SxProps, TypeText, TypographyVariant } from '@mui/material'; 18 | import { TypographyProps as MuiTypographyProps } from '@mui/material/Typography'; 19 | 20 | interface Props extends Pick { 21 | style?: SxProps | PdfStyle; 22 | variant?: TypographyVariant; 23 | color?: keyof TypeText; 24 | fixed?: boolean; 25 | } 26 | 27 | const Typography: FC = (props) => { 28 | const { editable, debug } = useGenerator(); 29 | 30 | const { variant, color, style, children, fixed } = props; 31 | 32 | return editable ? ( 33 | 34 | {children} 35 | 36 | ) : ( 37 | 45 | {children} 46 | 47 | ); 48 | }; 49 | 50 | Typography.defaultProps = { 51 | variant: 'body1', 52 | color: 'primary', 53 | }; 54 | 55 | export default Typography; 56 | -------------------------------------------------------------------------------- /src/components/common/index.ts: -------------------------------------------------------------------------------- 1 | export { default as Snackbar } from './snackbar'; 2 | -------------------------------------------------------------------------------- /src/components/common/snackbar.tsx: -------------------------------------------------------------------------------- 1 | import { FC, SyntheticEvent, useEffect } from 'react'; 2 | 3 | // Mui components. 4 | import { Snackbar as MuiSnackbar, Alert } from '@mui/material'; 5 | 6 | // Action creators. 7 | import { app_resetAlert } from '@/store/app/app-actions'; 8 | 9 | // Hooks. 10 | import { useDispatch } from 'react-redux'; 11 | import { useAppSelector } from '@/store'; 12 | 13 | const Snackbar: FC = () => { 14 | const dispatch = useDispatch(); 15 | 16 | // Alert state. 17 | const { autoHideDuration, show, severity, messages, variant } = useAppSelector((state) => state.app.alert); 18 | 19 | /** 20 | * Handle close alert. 21 | * 22 | * @param {SyntheticEvent | Event} e 23 | * @param {string} reason 24 | * @return { void | undefined } void 25 | */ 26 | const handleClose = (e: SyntheticEvent | Event, reason?: string): void | undefined => { 27 | if (reason === 'clickaway') { 28 | return; 29 | } 30 | dispatch(app_resetAlert()); 31 | }; 32 | 33 | useEffect(() => { 34 | if (show) { 35 | setTimeout(() => handleClose, autoHideDuration); 36 | } 37 | }, [show]); 38 | 39 | if (show) 40 | return ( 41 | 42 | 43 | {messages} 44 | 45 | 46 | ); 47 | 48 | return null; 49 | }; 50 | 51 | export default Snackbar; 52 | -------------------------------------------------------------------------------- /src/components/footer/footer.tsx: -------------------------------------------------------------------------------- 1 | import { FC } from 'react'; 2 | 3 | // Mui components. 4 | import { Box, Typography } from '@mui/material'; 5 | 6 | // Mui icons. 7 | import FavoriteIcon from '@mui/icons-material/Favorite'; 8 | 9 | const Footer: FC = () => { 10 | return ( 11 | 15 | 16 | Made with 17 | 18 | at South Beach 19 | 20 | Pelabuhanratu, Indonesia 21 | 22 | ); 23 | }; 24 | 25 | export default Footer; 26 | -------------------------------------------------------------------------------- /src/components/footer/index.ts: -------------------------------------------------------------------------------- 1 | export { default as Footer } from './footer'; 2 | -------------------------------------------------------------------------------- /src/components/invoice-download-button/index.ts: -------------------------------------------------------------------------------- 1 | export { default as InvoiceDownloadButton } from './invoice-download-button'; 2 | -------------------------------------------------------------------------------- /src/components/invoice-download-button/invoice-download-button.tsx: -------------------------------------------------------------------------------- 1 | import { FC, useCallback, useEffect, useMemo } from 'react'; 2 | 3 | // React Pdf. 4 | import { Document, Page, Text, usePDF } from '@react-pdf/renderer'; 5 | 6 | // Mui components. 7 | import { Box, IconButton, Typography } from '@mui/material'; 8 | 9 | // Context. 10 | import { generatorContext } from '@/context/generator-context'; 11 | 12 | // Faker 13 | // import { faker } from '@faker-js/faker'; 14 | 15 | // Components. 16 | import { InvoicePdf } from '../invoices'; 17 | import { StyledButton } from '@/components/base'; 18 | 19 | /** Mui icons. */ 20 | import DownloadIcon from '@mui/icons-material/Download'; 21 | import CloseIcon from '@mui/icons-material/Close'; 22 | 23 | // date fns 24 | import { format } from 'date-fns'; 25 | 26 | interface PdfDocumentProps { 27 | invoice: IInvoice; 28 | } 29 | const PdfDocument: FC = ({ invoice }) => ; 30 | 31 | // Interfaces. 32 | import { useAppSelector } from '@/store'; 33 | import { IInvoice } from '@/interfaces/invoice'; 34 | import { ISetInvoice } from '@/store/invoice/invoice-actions'; 35 | import { useInvoice } from '@/hooks'; 36 | import { ArrowDownward } from '@mui/icons-material'; 37 | 38 | const BUTTON_SIZE = 50; 39 | 40 | interface Props { 41 | setInvoice: (invoice: IInvoice) => ISetInvoice; 42 | } 43 | const InvoiceDownloadButton: FC = ({ setInvoice }) => { 44 | const { invoice_data: persistedInvoice } = useAppSelector((state) => state.invoice); 45 | const { invoice } = useInvoice(); 46 | 47 | const [pdfInstance, updatePdfInstance] = usePDF({ 48 | document: persistedInvoice ? ( 49 | 50 | ) : ( 51 | 52 | 53 | Opss... 54 | 55 | 56 | ), 57 | }); 58 | 59 | useEffect(() => { 60 | const intervalAutoSaveInvoice = setInterval(() => { 61 | setInvoice(invoice); 62 | updatePdfInstance(); 63 | }, 2000); 64 | return () => clearInterval(intervalAutoSaveInvoice); 65 | }, [invoice]); 66 | 67 | const handleDownloadPdf = (): void => { 68 | setInvoice(invoice); 69 | 70 | // updatePdfInstance(); 71 | 72 | fetch(String(pdfInstance.url), { 73 | method: 'GET', 74 | headers: { 'Content-Type': pdfInstance.blob?.type || 'application/pdf' }, 75 | }) 76 | .then((response) => response.blob()) 77 | .then((blob) => { 78 | // Create blob link to download 79 | const url = window.URL.createObjectURL(new Blob([blob])); 80 | const link = document.createElement('a'); 81 | link.href = url; 82 | 83 | const invoiceFileName = persistedInvoice.fileName 84 | ? `${persistedInvoice.fileName}_${format(new Date(persistedInvoice.date), 'dd/MM/yyyy')} + .pdf` 85 | : `invoice_${format(new Date(persistedInvoice.date), 'dd/MM/yyyy')}.pdf`; 86 | 87 | // Set attribute link download 88 | link.setAttribute('download', invoiceFileName); 89 | 90 | // Append link to the element; 91 | document.body.appendChild(link); 92 | 93 | // Finally download file. 94 | link.click(); 95 | 96 | // Clean up and remove it from dom 97 | link.parentNode?.removeChild(link); 98 | }); 99 | }; 100 | /** Set persisted invoice */ 101 | useEffect(() => { 102 | if (!persistedInvoice) setInvoice(invoice); 103 | }, [persistedInvoice]); 104 | 105 | return ( 106 | 107 | 117 | {!pdfInstance.error ? ( 118 | !pdfInstance.loading && ( 119 | theme.transitions.create(['width']), 127 | textAlign: 'center', 128 | overflow: 'hidden', 129 | '& .MuiTypography-root': { 130 | transform: 'translateX(150px)', 131 | transition: (theme) => theme.transitions.create(['transform', 'width']), 132 | fontSize: 0, 133 | }, 134 | '&:hover': { 135 | backgroundColor: 'secondary.main', 136 | width: 180, 137 | '& .MuiTypography-root': { 138 | transform: 'translateX(0px)', 139 | fontSize: 13, 140 | }, 141 | '& svg': { 142 | mr: 2, 143 | }, 144 | }, 145 | }} 146 | onClick={handleDownloadPdf} 147 | > 148 | 149 | Download PDF 150 | 151 | ) 152 | ) : ( 153 | }> 154 | Error 155 | 156 | )} 157 | 158 | 159 | ); 160 | }; 161 | 162 | export default InvoiceDownloadButton; 163 | -------------------------------------------------------------------------------- /src/components/invoice-paper/index.ts: -------------------------------------------------------------------------------- 1 | export { default as InvoicePaper } from './invoice-paper'; 2 | -------------------------------------------------------------------------------- /src/components/invoice-paper/invoice-paper.tsx: -------------------------------------------------------------------------------- 1 | import { FC, ReactNode } from 'react'; 2 | 3 | // Mui components. 4 | import { Paper, SxProps } from '@mui/material'; 5 | 6 | interface Props { 7 | children: ReactNode; 8 | sx?: SxProps; 9 | } 10 | 11 | // Page size. 12 | const ACTUALLY_PAPER_SIZE: Record = { 13 | width: '210mm', 14 | height: '297mm', 15 | }; 16 | 17 | const InvoicePaper: FC = ({ children, sx }) => { 18 | return ( 19 | 26 | {children} 27 | 28 | ); 29 | }; 30 | 31 | export default InvoicePaper; 32 | -------------------------------------------------------------------------------- /src/components/invoice-settings/index.ts: -------------------------------------------------------------------------------- 1 | export { default as InvoiceSettings } from './invoice-settings'; 2 | -------------------------------------------------------------------------------- /src/components/invoice-settings/invoice-settings.tsx: -------------------------------------------------------------------------------- 1 | import { FC } from 'react'; 2 | 3 | // Mui components. 4 | import { Paper, SxProps, Typography } from '@mui/material'; 5 | 6 | // Mui icons. 7 | import ConstructionIcon from '@mui/icons-material/Construction'; 8 | interface Props { 9 | sx?: SxProps; 10 | } 11 | 12 | const InvoiceSettings: FC = ({ sx }) => { 13 | return ( 14 | 26 | 27 | Invoice Settings 28 | 29 | ); 30 | }; 31 | 32 | export default InvoiceSettings; 33 | -------------------------------------------------------------------------------- /src/components/invoices/add-invoice-item.tsx: -------------------------------------------------------------------------------- 1 | import { FC } from 'react'; 2 | 3 | // Mui components. 4 | import { Typography, Box, Tooltip } from '@mui/material'; 5 | 6 | // Mui icons. 7 | import AddIcon from '@mui/icons-material/Add'; 8 | 9 | // Hooks. 10 | import { useGenerator } from '@/hooks/useGenerator'; 11 | 12 | // Hooks. 13 | import { useDispatch } from 'react-redux'; 14 | import { useTheme } from '@mui/material'; 15 | import { useInvoice } from '@/hooks'; 16 | 17 | const AddInvoiceItem: FC = () => { 18 | const dispatch = useDispatch(); 19 | const { append } = useInvoice(); 20 | const { editable } = useGenerator(); 21 | 22 | // Mui theme. 23 | const { palette } = useTheme(); 24 | 25 | const handleAddNewLine = (): void => { 26 | append({ 27 | description: '', 28 | quantity: '1', 29 | rate: '0', 30 | }); 31 | }; 32 | 33 | if (editable) { 34 | return ( 35 | 36 | 59 | 60 | Add new row 61 | 62 | 63 | ); 64 | } 65 | 66 | return null; 67 | }; 68 | 69 | export default AddInvoiceItem; 70 | -------------------------------------------------------------------------------- /src/components/invoices/dialog-recipient.tsx: -------------------------------------------------------------------------------- 1 | import { ChangeEvent, FC, useCallback, useEffect, useState } from 'react'; 2 | 3 | // Base components. 4 | import { BaseDialog } from '@/components/base'; 5 | 6 | // Hooks. 7 | import { useAppSelector } from '@/store'; 8 | import { useDispatch } from 'react-redux'; 9 | import { invoice_setDialogRecipient } from '@/store/invoice/invoice-actions'; 10 | import { Grid, recomposeColor, TextField } from '@mui/material'; 11 | import { useInvoice } from '@/hooks'; 12 | 13 | // Interfaces. 14 | import { IInvoiceRecipient } from '@/interfaces/invoice'; 15 | 16 | const DialogRecipient: FC = () => { 17 | const dispatch = useDispatch(); 18 | const { updateRecipient, invoice } = useInvoice(); 19 | const { invoice_openDialogRecipient: open } = useAppSelector((state) => state.invoice); 20 | 21 | const [recipient, setRecipient] = useState(invoice.recipient); 22 | 23 | /** 24 | * Handle close dialog. 25 | * @return {void} 26 | */ 27 | const handleClose = (): void => { 28 | dispatch(invoice_setDialogRecipient(false)); 29 | }; 30 | 31 | /** 32 | * Handle input change. 33 | * 34 | * @param { ChangeEvent} e 35 | */ 36 | const handleChange = (e: ChangeEvent): void => { 37 | setRecipient({ 38 | ...recipient, 39 | [e.target.name]: e.target.value, 40 | }); 41 | }; 42 | 43 | /** 44 | * Handle submit 45 | * 46 | */ 47 | const handleSubmit = useCallback(() => { 48 | updateRecipient(recipient); 49 | handleClose(); 50 | }, [recipient]); 51 | 52 | return ( 53 | 63 | 64 | 65 | 74 | 75 | 76 | 85 | 86 | 87 | 96 | 97 | 98 | 107 | 108 | 109 | 120 | 121 | 122 | 133 | 134 | 135 | 144 | 145 | 146 | 155 | 156 | 157 | 166 | 167 | 168 | 169 | ); 170 | }; 171 | 172 | export default DialogRecipient; 173 | -------------------------------------------------------------------------------- /src/components/invoices/dialog-sender.tsx: -------------------------------------------------------------------------------- 1 | import { ChangeEvent, FC, useCallback, useState } from 'react'; 2 | 3 | // Base components. 4 | import { BaseDialog } from '@/components/base'; 5 | 6 | // Hooks. 7 | import { useAppSelector } from '@/store'; 8 | import { useDispatch } from 'react-redux'; 9 | import { invoice_setDialogSender } from '@/store/invoice/invoice-actions'; 10 | import { Grid, TextField } from '@mui/material'; 11 | import { useInvoice } from '@/hooks'; 12 | 13 | // Interfaces. 14 | import { IInvoiceSender } from '@/interfaces/invoice'; 15 | 16 | const DialogSender: FC = () => { 17 | const dispatch = useDispatch(); 18 | const { updateSender, invoice } = useInvoice(); 19 | const { invoice_openDialogSender: open } = useAppSelector((state) => state.invoice); 20 | 21 | const [sender, setSender] = useState(invoice.sender); 22 | 23 | /** 24 | * Handle close dialog. 25 | * @return {void} 26 | */ 27 | const handleClose = (): void => { 28 | dispatch(invoice_setDialogSender(false)); 29 | }; 30 | 31 | /** 32 | * Handle input change. 33 | * 34 | * @param { ChangeEvent} e 35 | */ 36 | const handleChange = (e: ChangeEvent): void => { 37 | setSender({ 38 | ...sender, 39 | [e.target.name]: e.target.value, 40 | }); 41 | }; 42 | 43 | /** 44 | * Handle submit 45 | * 46 | */ 47 | const handleSubmit = useCallback(() => { 48 | updateSender(sender); 49 | handleClose(); 50 | }, [sender]); 51 | 52 | return ( 53 | 63 | 64 | 65 | 74 | 75 | 76 | 85 | 86 | 87 | 96 | 97 | 98 | 107 | 108 | 109 | 120 | 121 | 122 | 133 | 134 | 135 | 144 | 145 | 146 | 155 | 156 | 157 | 166 | 167 | 168 | 169 | ); 170 | }; 171 | 172 | export default DialogSender; 173 | -------------------------------------------------------------------------------- /src/components/invoices/index.ts: -------------------------------------------------------------------------------- 1 | export { default as InvoiceEditable } from './invoice-editable'; 2 | export { default as InvoicePdf } from './invoice-pdf'; 3 | -------------------------------------------------------------------------------- /src/components/invoices/invoice-company-logo.tsx: -------------------------------------------------------------------------------- 1 | import { FC, ReactNode, useRef } from 'react'; 2 | 3 | // Mui components. 4 | import MuiBox from '@mui/material/Box'; 5 | import Typography from '@mui/material/Typography'; 6 | 7 | // Mui icons. 8 | import UploadFileIcon from '@mui/icons-material/UploadFile'; 9 | 10 | // React Pdf. 11 | import { Image } from '@react-pdf/renderer'; 12 | 13 | // Base components. 14 | import { Box, EditableAreaMarker, EditableAreaWrapper, StyledButton } from '@/components/base'; 15 | 16 | // Hooks. 17 | import { useGenerator } from '@/hooks/useGenerator'; 18 | import { DeleteOutline } from '@mui/icons-material'; 19 | 20 | interface Props { 21 | logo?: string; 22 | onUploadImage: (image: string) => void; 23 | } 24 | 25 | interface PlaceholderProps { 26 | hasLogo: boolean; 27 | children?: ReactNode; 28 | } 29 | const Placeholder: FC = ({ hasLogo, children }) => { 30 | return ( 31 | (hasLogo ? '2px dashed transparent' : `2px dashed ${theme.palette.primary.main}`), 38 | boxShadow: hasLogo ? 'none' : '4px 4px 0px rgb(0 0 0 / 4%)', 39 | borderRadius: 2, 40 | display: 'flex', 41 | alignItems: 'center', 42 | justifyContent: 'center', 43 | flexDirection: 'column', 44 | transition: (theme) => theme.transitions.create(['all']), 45 | '& .choose-image': { 46 | display: 'none', 47 | }, 48 | '&:hover': { 49 | opacity: 1, 50 | backgroundColor: 'primary.light', 51 | border: (theme) => `2px dashed ${theme.palette.primary.main}`, 52 | boxShadow: '4px 4px 0px rgb(0 0 0 / 4%)', 53 | '& .choose-image': { 54 | display: 'inline-flex', 55 | }, 56 | '& img': { 57 | display: 'none', 58 | }, 59 | }, 60 | }} 61 | > 62 | {children} 63 | 64 | ); 65 | }; 66 | 67 | const InvoiceCompanyLogo: FC = ({ logo, onUploadImage }) => { 68 | const { editable } = useGenerator(); 69 | 70 | const inputRef = useRef(null); 71 | 72 | const handleUpload = (): void => { 73 | inputRef?.current?.click(); 74 | }; 75 | 76 | const handleChange = (): void => { 77 | if (inputRef?.current?.files) { 78 | const files = inputRef.current.files; 79 | 80 | if (files.length > 0) { 81 | const reader = new FileReader(); 82 | 83 | reader.addEventListener('load', () => { 84 | if (typeof reader.result === 'string') { 85 | onUploadImage(reader.result); 86 | } 87 | }); 88 | 89 | reader.readAsDataURL(files[0]); 90 | } 91 | } 92 | }; 93 | 94 | const onRemoveImage = (): void => { 95 | onUploadImage(''); 96 | }; 97 | 98 | return editable ? ( 99 | 100 | 104 | {logo ? ( 105 | 106 | <> 107 | 111 | 112 | Upload Image 113 | 114 | 115 | 116 | 117 | ) : ( 118 | 119 | 120 | Upload Image 121 | 122 | )} 123 | 124 | {/* Input */} 125 | 134 | 135 | {logo && ( 136 | 137 | }> 138 | Remove Logo 139 | 140 | 141 | )} 142 | 143 | ) : ( 144 | 145 | {logo ? : } 146 | 147 | ); 148 | }; 149 | export default InvoiceCompanyLogo; 150 | -------------------------------------------------------------------------------- /src/components/invoices/invoice-editable.tsx: -------------------------------------------------------------------------------- 1 | import { FC, useMemo } from 'react'; 2 | 3 | // Mui components. 4 | import { Box } from '@/components/base'; 5 | 6 | // Base components. 7 | import { Document, Page, Container } from '@/components/base'; 8 | 9 | // Invoice components. 10 | import InvoiceInfo from './invoice-info'; 11 | import DialogSender from './dialog-sender'; 12 | import InvoiceFooter from './invoice-footer'; 13 | import InvoiceSender from './invoice-sender'; 14 | import InvoiceSummary from './invoice-summary'; 15 | import AddInvoiceItem from './add-invoice-item'; 16 | import DialogRecipient from './dialog-recipient'; 17 | import InvoiceLineItem from './invoice-line-item'; 18 | import InvoiceTitle from '../invoices/invoice-title'; 19 | import InvoicePaymentInfo from './invoice-payment-info'; 20 | import InvoiceItemHeader from './invoice-line-item-header'; 21 | import InvoiceCompanyLogo from '../invoices/invoice-company-logo'; 22 | import InvoiceTermAndConditions from './invoice-term-and-condition'; 23 | import InvoiceRecipient from '@/components/invoices/invoice-recipient'; 24 | 25 | // Hooks. 26 | import { useGenerator } from '@/hooks/useGenerator'; 27 | 28 | // Interfaces. 29 | import { IInvoiceLineItem, IInvoicePaymentInfo } from '@/interfaces/invoice'; 30 | import { useInvoice } from '@/hooks'; 31 | import { useDispatch } from 'react-redux'; 32 | import { app_setAlert } from '@/store/app/app-actions'; 33 | import { invoice_setDialogRecipient, invoice_setDialogSender } from '@/store/invoice/invoice-actions'; 34 | 35 | const InvoiceEditable: FC = () => { 36 | const dispatch = useDispatch(); 37 | const { editable } = useGenerator(); 38 | const { invoice, handleChangeLineItem, updateLogo } = useInvoice(); 39 | 40 | const subTotal = useMemo(() => { 41 | let subTotal = 0; 42 | invoice.items.forEach((i) => { 43 | const quantityNumber = parseFloat(i.quantity); 44 | const rateNumber = parseFloat(i.rate); 45 | const amount = quantityNumber && rateNumber ? quantityNumber * rateNumber : 0; 46 | 47 | subTotal += amount; 48 | }); 49 | 50 | return subTotal; 51 | }, [invoice.items]); 52 | 53 | const saleTax = useMemo(() => { 54 | const taxRate = parseFloat(String(invoice.taxRate)) || 0; 55 | return subTotal ? (subTotal * taxRate) / 100 : 0; 56 | }, [invoice.items, invoice.taxRate]); 57 | 58 | /** 59 | * I can't use it in child components. 60 | */ 61 | const handleShowAlert = (item: IInvoiceLineItem): void => { 62 | dispatch( 63 | app_setAlert({ 64 | show: true, 65 | messages: `Item ${item.description} has been removed!`, 66 | severity: 'success', 67 | }), 68 | ); 69 | }; 70 | 71 | const onOpenDialogEditRecipient = (): void => { 72 | dispatch(invoice_setDialogRecipient(true)); 73 | }; 74 | 75 | const onOpenDialogEditSender = (): void => { 76 | dispatch(invoice_setDialogSender(true)); 77 | }; 78 | 79 | return ( 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | {Array.isArray(invoice.items) && 99 | invoice.items.length > 0 && 100 | // Render invoice items 101 | invoice.items.map((item, index) => ( 102 | 110 | ))} 111 | 112 | {editable && } 113 | 114 | 115 | {/* Invoice Summary & Payment Info */} 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | {/* Invoice Term & Conditions */} 126 | 127 | 128 | 129 | 130 | 131 | {/* Footer messages */} 132 | 133 | 134 | 135 | ); 136 | }; 137 | export default InvoiceEditable; 138 | -------------------------------------------------------------------------------- /src/components/invoices/invoice-editable/invoice-editable-content-no-data.tsx: -------------------------------------------------------------------------------- 1 | import { FC, ReactNode } from 'react'; 2 | 3 | // Mui components. 4 | import Box from '@mui/material/Box'; 5 | import Typography from '@mui/material/Typography'; 6 | 7 | interface Props { 8 | title: string; 9 | subtitle?: string; 10 | icon: ReactNode; 11 | } 12 | 13 | const InvoiceEditableContentNoData: FC = ({ title, subtitle, icon }) => { 14 | return ( 15 | 19 | {icon} 20 | 28 | {title} 29 | {subtitle && ( 30 | 31 | {subtitle} 32 | 33 | )} 34 | 35 | 36 | ); 37 | }; 38 | 39 | export default InvoiceEditableContentNoData; 40 | -------------------------------------------------------------------------------- /src/components/invoices/invoice-footer.tsx: -------------------------------------------------------------------------------- 1 | import { FC } from 'react'; 2 | 3 | // Base components. 4 | import { Box, Typography } from '@/components/base'; 5 | 6 | // Hooks 7 | import { useGenerator } from '@/hooks/useGenerator'; 8 | import palette from '@/config/theme/palette'; 9 | 10 | interface Props { 11 | message?: string; 12 | } 13 | 14 | const InvoiceFooter: FC = ({ message }) => { 15 | const { editable } = useGenerator(); 16 | 17 | return ( 18 | 30 | 31 | {message} 32 | 33 | 34 | ); 35 | }; 36 | 37 | export default InvoiceFooter; 38 | -------------------------------------------------------------------------------- /src/components/invoices/invoice-info.tsx: -------------------------------------------------------------------------------- 1 | import { ChangeEvent, FC, memo } from 'react'; 2 | 3 | // Base components. 4 | import { Box, EditableText, Typography } from '@/components/base'; 5 | 6 | // Hooks 7 | import { useGenerator } from '@/hooks/useGenerator'; 8 | import EditableDatePicker from '../base/editable-date-picker'; 9 | import { useInvoice } from '@/hooks'; 10 | 11 | // Date fns 12 | import { format } from 'date-fns'; 13 | 14 | // Styles. 15 | const lineStyle = { display: 'flex', flexDirection: 'row', alignItems: 'center' }; 16 | const textStyle = { fontWeight: 600 }; 17 | 18 | interface Props { 19 | invoiceNumber: string; 20 | date: string; 21 | due: string; 22 | } 23 | 24 | const InvoiceInfo: FC = ({ invoiceNumber, date, due }) => { 25 | const { editable } = useGenerator(); 26 | 27 | const { invoice, setInvoice } = useInvoice(); 28 | 29 | const onChangeInvoiceNumber = (e: ChangeEvent): void => { 30 | setInvoice({ ...invoice, [e.target.name]: e.target.value }); 31 | }; 32 | 33 | const onChangeDate = (property: 'date' | 'due', value: string): void => { 34 | setInvoice({ ...invoice, [property]: value }); 35 | }; 36 | 37 | return ( 38 | 39 | 40 | Invoice No : 41 | {editable ? ( 42 | 43 | ) : ( 44 | {invoiceNumber} 45 | )} 46 | 47 | 48 | Invoice Date : 49 | {editable ? ( 50 | 51 | ) : ( 52 | {format(new Date(date), 'dd/MM/yyyy')} 53 | )} 54 | 55 | 56 | Due Date : 57 | {editable ? ( 58 | 59 | ) : ( 60 | {format(new Date(due), 'dd/MM/yyyy')} 61 | )} 62 | 63 | 64 | ); 65 | }; 66 | 67 | const MemoizedInvoiceInfo = memo(InvoiceInfo); 68 | export default MemoizedInvoiceInfo; 69 | -------------------------------------------------------------------------------- /src/components/invoices/invoice-line-item-header.tsx: -------------------------------------------------------------------------------- 1 | import { FC, ReactElement } from 'react'; 2 | 3 | // Base components. 4 | import { Box, Typography } from '@/components/base'; 5 | 6 | // Hooks. 7 | import { useGenerator } from '@/hooks/useGenerator'; 8 | 9 | // Styles. 10 | const colStyles = { 11 | position: 'relative', 12 | display: 'flex', 13 | flexDirection: 'column', 14 | alignItems: 'flex-start', 15 | justifyContent: 'center', 16 | }; 17 | 18 | const InvoiceItemHeader: FC = () => { 19 | const { editable } = useGenerator(); 20 | 21 | const renderDivider: ReactElement = ( 22 | 23 | ); 24 | 25 | return ( 26 | 40 | <> 41 | 42 | 47 | {'Item Description'} 48 | 49 | 50 | 51 | {renderDivider} 52 | {'Qty'} 53 | 54 | 55 | {renderDivider} 56 | {'Rate'} 57 | 58 | 59 | {renderDivider} 60 | {'Amount'} 61 | 62 | 63 | 64 | ); 65 | }; 66 | 67 | export default InvoiceItemHeader; 68 | -------------------------------------------------------------------------------- /src/components/invoices/invoice-line-item.tsx: -------------------------------------------------------------------------------- 1 | import { ChangeEvent, FC } from 'react'; 2 | 3 | // Mui components. 4 | import Tooltip from '@mui/material/Tooltip'; 5 | import Fab from '@mui/material/Fab'; 6 | import MuiTypography from '@mui/material/Typography'; 7 | 8 | // Mui icons. 9 | import CloseIcon from '@mui/icons-material/Close'; 10 | 11 | // Base components. 12 | import { Box, Typography, EditableText } from '@/components/base'; 13 | 14 | // Hooks. 15 | import { useGenerator } from '@/hooks/useGenerator'; 16 | 17 | // Utilities. 18 | // import { formatRupiah } from '@/utils/currency'; 19 | 20 | // Interfaces 21 | import { IInvoiceLineItem } from '@/interfaces/invoice'; 22 | import { useInvoice } from '@/hooks'; 23 | 24 | // Utils 25 | import { calculateAmount } from '@/utils/invoice'; 26 | 27 | // Styles. 28 | const colStyles = { 29 | position: 'relative', 30 | display: 'flex', 31 | flexDirection: 'column', 32 | justifyContent: 'center', 33 | }; 34 | 35 | const textStyles = { 36 | marginLeft: '12px', 37 | }; 38 | 39 | interface Props { 40 | item: IInvoiceLineItem; 41 | index: number; 42 | lastItem: boolean; 43 | onChange: (index: number, property: keyof IInvoiceLineItem, value: string) => void; 44 | dispatchAlert: (item: IInvoiceLineItem) => void; 45 | } 46 | 47 | const IInvoiceLineItem: FC = ({ item, index, lastItem, onChange, dispatchAlert }) => { 48 | const { editable } = useGenerator(); 49 | const { remove } = useInvoice(); 50 | 51 | const handleChange = (e: ChangeEvent): void => { 52 | onChange(index, e.target.name as keyof IInvoiceLineItem, e.target.value); 53 | }; 54 | 55 | /** 56 | * Handle remove item. 57 | */ 58 | const handleRemoveItem = (): void => { 59 | remove(index); 60 | dispatchAlert(item); 61 | }; 62 | 63 | return ( 64 | 82 | 83 | 91 | 92 | 93 | 100 | 101 | 102 | 103 | 104 | 105 | {calculateAmount(item.quantity, item.rate)} 106 | 107 | 108 | {editable && ( 109 | theme.transitions.create(['transform', 'width']), 124 | '&:hover': { 125 | width: 85, 126 | '& h6': { 127 | display: 'inline-flex', 128 | transform: 'scale(1)', 129 | }, 130 | }, 131 | }} 132 | > 133 | {/* Remove button */} 134 | 135 | <> 136 | 137 | 141 | Remove 142 | 143 | 144 | 145 | 146 | )} 147 | 148 | ); 149 | }; 150 | 151 | export default IInvoiceLineItem; 152 | -------------------------------------------------------------------------------- /src/components/invoices/invoice-payment-info.tsx: -------------------------------------------------------------------------------- 1 | import { ChangeEvent, FC } from 'react'; 2 | 3 | // Base components. 4 | import { Box, EditableText, Typography } from '@/components/base'; 5 | 6 | // Hooks. 7 | import { useGenerator } from '@/hooks/useGenerator'; 8 | 9 | // Utilities. 10 | import { createSpacing } from '@/utils'; 11 | import { useInvoice } from '@/hooks'; 12 | import { IInvoicePaymentInfo } from '@/interfaces/invoice'; 13 | 14 | // Styles. 15 | const lineStyle = { display: 'flex', flexDirection: 'row', alignItems: 'center' }; 16 | 17 | interface Props { 18 | paymentInfo: IInvoicePaymentInfo; 19 | } 20 | 21 | const InvoicePaymentInfo: FC = ({ paymentInfo }) => { 22 | const { editable } = useGenerator(); 23 | const { invoice, setInvoice } = useInvoice(); 24 | 25 | const handleChange = (e: ChangeEvent): void => { 26 | setInvoice({ 27 | ...invoice, 28 | paymentInfo: { 29 | ...invoice.paymentInfo, 30 | [e.target.name]: e.target.value, 31 | }, 32 | }); 33 | }; 34 | 35 | return ( 36 | 37 | 38 | {'Payment Info :'} 39 | 40 | 41 | Account : 42 | {editable ? ( 43 | 49 | ) : ( 50 | {paymentInfo.accountNumber} 51 | )} 52 | 53 | 54 | A/C Name : 55 | {editable ? ( 56 | 62 | ) : ( 63 | {paymentInfo.accountName} 64 | )} 65 | 66 | 67 | Bank Details : 68 | {editable ? ( 69 | 75 | ) : ( 76 | {paymentInfo.bankAccount} 77 | )} 78 | 79 | 80 | ); 81 | }; 82 | 83 | export default InvoicePaymentInfo; 84 | -------------------------------------------------------------------------------- /src/components/invoices/invoice-pdf.tsx: -------------------------------------------------------------------------------- 1 | import { FC, useMemo } from 'react'; 2 | 3 | // React Pdf. 4 | import { Font } from '@react-pdf/renderer'; 5 | 6 | // Mui components. 7 | import { Box } from '@/components/base'; 8 | 9 | // Base components. 10 | import { Document, Page, Container } from '@/components/base'; 11 | 12 | // Invoice components. 13 | import InvoiceInfo from './invoice-info'; 14 | import InvoiceFooter from './invoice-footer'; 15 | import InvoiceSender from './invoice-sender'; 16 | import InvoiceSummary from './invoice-summary'; 17 | import InvoiceLineItem from './invoice-line-item'; 18 | import InvoiceTitle from '../invoices/invoice-title'; 19 | import InvoicePaymentInfo from './invoice-payment-info'; 20 | import InvoiceItemHeader from './invoice-line-item-header'; 21 | import InvoiceCompanyLogo from '../invoices/invoice-company-logo'; 22 | import InvoiceTermAndConditions from './invoice-term-and-condition'; 23 | import InvoiceRecipient from '@/components/invoices/invoice-recipient'; 24 | 25 | // Hooks. 26 | // import { useGenerator } from '@/hooks/useGenerator'; 27 | 28 | // Interfaces. 29 | import { IInvoice, IInvoicePaymentInfo } from '@/interfaces/invoice'; 30 | 31 | interface Props { 32 | invoice: IInvoice; 33 | } 34 | 35 | /** 36 | * Register fonts. 37 | */ 38 | const baseUrlFont = IS_PROD 39 | ? 'https://invoice.riski.me/assets/fonts/Be_Vietnam_Pro' 40 | : 'http://local-cdn.test/fonts/Be_Vietnam_Pro'; 41 | 42 | Font.register({ 43 | family: 'Be Vietnam Pro', 44 | fonts: [ 45 | { 46 | src: baseUrlFont + '/BeVietnamPro-Regular.ttf', 47 | }, // font-style: normal, font-weight: normal 48 | { 49 | src: baseUrlFont + '/BeVietnamPro-Italic.ttf', 50 | fontStyle: 'italic', 51 | }, 52 | { 53 | src: baseUrlFont + '/BeVietnamPro-Medium.ttf', 54 | fontStyle: 'normal', 55 | fontWeight: 500, 56 | }, 57 | { 58 | src: baseUrlFont + '/BeVietnamPro-MediumItalic.ttf', 59 | fontStyle: 'italic', 60 | fontWeight: 500, 61 | }, 62 | { 63 | src: baseUrlFont + '/BeVietnamPro-SemiBold.ttf', 64 | fontStyle: 'normal', 65 | fontWeight: 700, 66 | }, 67 | { 68 | src: baseUrlFont + '/BeVietnamPro-SemiBoldItalic.ttf', 69 | fontStyle: 'italic', 70 | fontWeight: 700, 71 | }, 72 | ], 73 | }); 74 | 75 | /** 76 | * Main Invoice Component. 77 | */ 78 | const InvoicePdf: FC = ({ invoice }) => { 79 | const subTotal = useMemo(() => { 80 | let subTotal = 0; 81 | invoice.items.forEach((i) => { 82 | const quantityNumber = parseFloat(i.quantity); 83 | const rateNumber = parseFloat(i.rate); 84 | const amount = quantityNumber && rateNumber ? quantityNumber * rateNumber : 0; 85 | 86 | subTotal += amount; 87 | }); 88 | 89 | return subTotal; 90 | }, [invoice.items]); 91 | 92 | const saleTax = useMemo(() => { 93 | const taxRate = parseFloat(String(invoice.taxRate)) || 0; 94 | return subTotal ? (subTotal * taxRate) / 100 : 0; 95 | }, [invoice.items, invoice.taxRate]); 96 | 97 | return ( 98 | 99 | 100 | 101 | 102 | 103 | 104 | null} /> 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | {Array.isArray(invoice.items) && invoice.items.length > 0 115 | ? // Render invoice items 116 | invoice.items.map((item, index) => ( 117 | null} 119 | onChange={() => null} 120 | key={String(index)} 121 | index={index} 122 | item={item} 123 | lastItem={invoice.items.length - 1 === index} 124 | /> 125 | )) 126 | : null} 127 | 128 | 129 | {/* Invoice Summary & Payment Info */} 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | {/* Invoice Term & Conditions */} 140 | 141 | 142 | 143 | 144 | 145 | {/* Footer messages */} 146 | 147 | 148 | 149 | ); 150 | }; 151 | export default InvoicePdf; 152 | -------------------------------------------------------------------------------- /src/components/invoices/invoice-recipient.tsx: -------------------------------------------------------------------------------- 1 | import { FC } from 'react'; 2 | 3 | // Mui icons. 4 | import ContactPageIcon from '@mui/icons-material/ContactPage'; 5 | 6 | // Base components. 7 | import { SectionTitle, Typography, Box, EditableAreaMarker, EditableAreaWrapper } from '@/components/base'; 8 | 9 | // Hooks. 10 | import { useGenerator } from '@/hooks/useGenerator'; 11 | 12 | // Utilities. 13 | import { createSpacing } from '@/utils'; 14 | 15 | // Interfaces. 16 | import { IInvoiceRecipient } from '@/interfaces/invoice'; 17 | import InvoiceEditableContentNoData from './invoice-editable/invoice-editable-content-no-data'; 18 | 19 | interface Props { 20 | recipient: IInvoiceRecipient; 21 | handleOpenDialog?: () => void; 22 | } 23 | 24 | const InvoiceRecipient: FC = ({ recipient, handleOpenDialog }) => { 25 | const { editable } = useGenerator(); 26 | 27 | const checkProperties = (obj: Record): any => { 28 | for (const key in obj) { 29 | if (obj[key] !== null && obj[key] != '') return true; 30 | else return false; 31 | } 32 | }; 33 | 34 | const hasRecipient = (): boolean => { 35 | return checkProperties(recipient as unknown as Record); 36 | }; 37 | 38 | return ( 39 | 40 | void}> 41 | BILLED TO : 42 | {hasRecipient() ? ( 43 | <> 44 | {recipient.companyName && ( 45 | 46 | 47 | {recipient.companyName} 48 | 49 | 50 | )} 51 | 52 | <> 53 | {recipient.addressLine1 ? recipient.addressLine1 + ', ' : null} 54 | {recipient.addressLine2 || null} 55 | 56 | 57 | 58 | <> 59 | {recipient.city ? recipient.city + ', ' : null} 60 | {recipient.state || null} 61 | 62 | 63 | 64 | {recipient.country || null} 65 | {recipient.postalCode || null} 66 | {recipient.email || null} 67 | {recipient.phone || null} 68 | 69 | ) : editable ? ( 70 | } 74 | /> 75 | ) : null} 76 | 77 | {editable && } 78 | 79 | ); 80 | }; 81 | 82 | export default InvoiceRecipient; 83 | -------------------------------------------------------------------------------- /src/components/invoices/invoice-sender.tsx: -------------------------------------------------------------------------------- 1 | import { FC } from 'react'; 2 | 3 | // Base components. 4 | import { Box, Typography, EditableAreaWrapper, EditableAreaMarker } from '@/components/base'; 5 | 6 | // Mui icons. 7 | import ContactPageIcon from '@mui/icons-material/ContactPage'; 8 | 9 | // Hooks. 10 | import { useGenerator } from '@/hooks/useGenerator'; 11 | 12 | // Utilities. 13 | import { createSpacing } from '@/utils/theme'; 14 | 15 | // Interfaces. 16 | import { IInvoiceSender } from '@/interfaces/invoice'; 17 | // import { useInvoice } from '@/hooks'; 18 | import InvoiceEditableContentNoData from './invoice-editable/invoice-editable-content-no-data'; 19 | 20 | interface Props { 21 | from: IInvoiceSender; 22 | handleOpenDialog?: () => void; 23 | } 24 | 25 | const InvoiceSender: FC = ({ from, handleOpenDialog }) => { 26 | const { editable } = useGenerator(); 27 | 28 | const checkProperties = (obj: Record): any => { 29 | for (const key in obj) { 30 | if (obj[key] !== null && obj[key] != '') return true; 31 | else return false; 32 | } 33 | }; 34 | 35 | const hasSender = (): boolean => { 36 | return checkProperties(from as unknown as Record); 37 | }; 38 | 39 | return ( 40 | 41 | void}> 42 | {hasSender() ? ( 43 | <> 44 | {from.companyName && ( 45 | 46 | 47 | {from.companyName} 48 | 49 | 50 | )} 51 | 52 | <> 53 | {from.addressLine1 ? from.addressLine1 + ', ' : null} 54 | {from.addressLine2 || null} 55 | 56 | 57 | 58 | <> 59 | {from.city ? from.city + ', ' : null} 60 | {from.state || null} 61 | 62 | 63 | 64 | {from.country || null} 65 | {from.postalCode || null} 66 | {from.email || null} 67 | {from.phone || null} 68 | 69 | ) : editable ? ( 70 | } 74 | /> 75 | ) : null} 76 | 77 | {editable && } 78 | 79 | ); 80 | }; 81 | 82 | export default InvoiceSender; 83 | -------------------------------------------------------------------------------- /src/components/invoices/invoice-summary.tsx: -------------------------------------------------------------------------------- 1 | import { ChangeEvent, FC, useMemo } from 'react'; 2 | 3 | // Base components. 4 | import { Box, EditableText, Typography } from '@/components/base'; 5 | 6 | // Hooks. 7 | import { useGenerator } from '@/hooks/useGenerator'; 8 | 9 | // Utilities. 10 | // import { formatRupiah } from '@/utils/currency'; 11 | import { useInvoice } from '@/hooks'; 12 | 13 | // Styles. 14 | const rowStyles = { 15 | width: '100%', 16 | display: 'flex', 17 | flexDirection: 'row', 18 | alignItems: 'center', 19 | justifyContent: 'flex-start', 20 | backgroundColor: '#ffffff', 21 | }; 22 | const colStyles = { 23 | position: 'relative', 24 | display: 'flex', 25 | }; 26 | 27 | interface Props { 28 | subTotal: number; 29 | taxRate?: number; 30 | saleTax?: number; 31 | } 32 | 33 | const InvoiceSummary: FC = ({ subTotal, taxRate, saleTax }) => { 34 | const { editable } = useGenerator(); 35 | const { updateTaxRate } = useInvoice(); 36 | 37 | const total = useMemo(() => { 38 | return (typeof subTotal !== 'undefined' && typeof saleTax !== 'undefined' ? subTotal + saleTax : 0).toFixed(2); 39 | }, [subTotal, saleTax]); 40 | 41 | const onChangeTaxRate = (e: ChangeEvent): void => { 42 | updateTaxRate(Number(e.target.value)); 43 | }; 44 | 45 | return ( 46 | 47 | 56 | 57 | 62 | {'Sub Total'} 63 | 64 | 65 | 66 | {subTotal} 67 | 68 | 69 | 70 | {/* Tax */} 71 | 77 | 78 | 79 | 85 | {'Tax '} 86 | 87 | 93 | {editable ? ( 94 | <> 95 | 102 | % 103 | 104 | ) : ( 105 | `(${taxRate}%)` 106 | )} 107 | 108 | 109 | 110 | 111 | {Number(saleTax)} 112 | 113 | 114 | 115 | {/* Total */} 116 | 125 | 126 | 131 | {'Total'} 132 | 133 | 134 | 135 | {total} 136 | 137 | 138 | 139 | ); 140 | }; 141 | 142 | export default InvoiceSummary; 143 | -------------------------------------------------------------------------------- /src/components/invoices/invoice-term-and-condition.tsx: -------------------------------------------------------------------------------- 1 | import { ChangeEvent, FC } from 'react'; 2 | 3 | // Base components. 4 | import { Box, EditableText, Typography } from '@/components/base'; 5 | 6 | // Utilities. 7 | import { createSpacing } from '@/utils/theme'; 8 | 9 | // Interfaces. 10 | import { useGenerator } from '@/hooks/useGenerator'; 11 | import { useInvoice } from '@/hooks'; 12 | 13 | interface Props { 14 | terms: string; 15 | } 16 | 17 | const InvoiceTermAndConditions: FC = ({ terms }) => { 18 | const { editable } = useGenerator(); 19 | const { invoice, setInvoice } = useInvoice(); 20 | 21 | const handleChange = (e: ChangeEvent): void => { 22 | setInvoice({ ...invoice, terms: e.target.value }); 23 | }; 24 | 25 | return ( 26 | 27 | 28 | {'Terms & Conditions'} 29 | 30 | {editable ? ( 31 | 40 | ) : ( 41 | {terms} 42 | )} 43 | 44 | ); 45 | }; 46 | 47 | export default InvoiceTermAndConditions; 48 | -------------------------------------------------------------------------------- /src/components/invoices/invoice-title.tsx: -------------------------------------------------------------------------------- 1 | import { FC } from 'react'; 2 | 3 | // Base components. 4 | import { Typography, Box } from '@/components/base'; 5 | 6 | // Hooks. 7 | import { useGenerator } from '@/hooks/useGenerator'; 8 | 9 | interface Props { 10 | title: string; 11 | } 12 | 13 | const InvoiceTitle: FC = ({ title }) => { 14 | const { editable } = useGenerator(); 15 | return ( 16 | 17 | 18 | {title} 19 | 20 | 21 | ); 22 | }; 23 | 24 | export default InvoiceTitle; 25 | -------------------------------------------------------------------------------- /src/components/layout/index.ts: -------------------------------------------------------------------------------- 1 | export { default as Layout } from './layout'; 2 | -------------------------------------------------------------------------------- /src/components/layout/layout.tsx: -------------------------------------------------------------------------------- 1 | import { FC, ReactNode } from 'react'; 2 | 3 | // Mui components. 4 | import { Box, Container } from '@mui/material'; 5 | import { useMediaQuery, useTheme } from '@mui/material'; 6 | 7 | // App bar 8 | import { AppBar } from '@/components//app-bar'; 9 | 10 | // Background image 11 | import backgroundImage from '@/assets/images/background_header.jpg'; 12 | import { Footer } from '@/components/footer'; 13 | 14 | interface Props { 15 | children: ReactNode; 16 | } 17 | 18 | const Layout: FC = ({ children }) => { 19 | const theme = useTheme(); 20 | 21 | const isMatchMobileView = useMediaQuery(theme.breakpoints.down('sm')); 22 | 23 | return ( 24 | 25 | {/* App bar */} 26 | 27 | 28 | {/* Background layout */} 29 | 41 | 42 | {children} 43 | 44 | 45 |