├── src ├── react-app-env.d.ts ├── setupTests.ts ├── App.test.tsx ├── index.css ├── index.tsx ├── logo.svg ├── calcs.ts ├── About.tsx ├── serviceWorker.ts ├── Breakdown.tsx └── App.tsx ├── public ├── robots.txt └── index.html ├── .prettierrc.json ├── .gitignore ├── tsconfig.json ├── LICENSE ├── package.json └── README.md /src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "semi": false, 3 | "singleQuote": true, 4 | "trailingComma": "all", 5 | "bracketSpacing": true, 6 | "arrowParens": "avoid", 7 | "tabWidth": 4 8 | } 9 | -------------------------------------------------------------------------------- /src/setupTests.ts: -------------------------------------------------------------------------------- 1 | // jest-dom adds custom jest matchers for asserting on DOM nodes. 2 | // allows you to do things like: 3 | // expect(element).toHaveTextContent(/react/i) 4 | // learn more: https://github.com/testing-library/jest-dom 5 | import '@testing-library/jest-dom/extend-expect'; 6 | -------------------------------------------------------------------------------- /src/App.test.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import { render } from '@testing-library/react'; 3 | import App from './App'; 4 | 5 | test('renders learn react link', () => { 6 | const { getByText } = render(); 7 | const linkElement = getByText(/learn react/i); 8 | expect(linkElement).toBeInTheDocument(); 9 | }); 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | background: #072333; 3 | margin: 0; 4 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 5 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 6 | sans-serif; 7 | -webkit-font-smoothing: antialiased; 8 | -moz-osx-font-smoothing: grayscale; 9 | } 10 | 11 | code { 12 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 13 | monospace; 14 | } 15 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "dom", 6 | "dom.iterable", 7 | "esnext" 8 | ], 9 | "allowJs": true, 10 | "skipLibCheck": true, 11 | "esModuleInterop": true, 12 | "allowSyntheticDefaultImports": true, 13 | "strict": true, 14 | "forceConsistentCasingInFileNames": true, 15 | "module": "esnext", 16 | "moduleResolution": "node", 17 | "resolveJsonModule": true, 18 | "isolatedModules": true, 19 | "noEmit": true, 20 | "jsx": "react" 21 | }, 22 | "include": [ 23 | "src" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /src/index.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import ReactDOM from 'react-dom' 3 | import './index.css' 4 | import App from './App' 5 | import * as serviceWorker from './serviceWorker' 6 | 7 | const rootElement = document.getElementById('root') 8 | if (rootElement && rootElement.hasChildNodes()) { 9 | ReactDOM.hydrate(, rootElement) 10 | } else { 11 | ReactDOM.render(, rootElement) 12 | } 13 | 14 | // If you want your app to work offline and load faster, you can change 15 | // unregister() to register() below. Note this comes with some pitfalls. 16 | // Learn more about service workers: https://bit.ly/CRA-PWA 17 | serviceWorker.unregister() 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2020 Cardo Limited 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | 9 | 10 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "iiwtc", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@material-ui/core": "^4.9.5", 7 | "@material-ui/icons": "^4.9.1", 8 | "@testing-library/jest-dom": "^4.2.4", 9 | "@testing-library/react": "^9.3.2", 10 | "@testing-library/user-event": "^7.1.2", 11 | "@types/jest": "^24.0.0", 12 | "@types/node": "^12.0.0", 13 | "@types/react": "^16.9.0", 14 | "@types/react-dom": "^16.9.0", 15 | "moment": "^2.24.0", 16 | "prettier": "^1.19.1", 17 | "react": "^16.13.0", 18 | "react-dom": "^16.13.0", 19 | "react-scripts": "3.4.0", 20 | "typescript": "~3.7.2" 21 | }, 22 | "scripts": { 23 | "start": "react-scripts start", 24 | "build": "react-scripts build", 25 | "postbuild": "react-snap", 26 | "test": "react-scripts test", 27 | "eject": "react-scripts eject" 28 | }, 29 | "eslintConfig": { 30 | "extends": "react-app" 31 | }, 32 | "browserslist": { 33 | "production": [ 34 | ">0.2%", 35 | "not dead", 36 | "not op_mini all" 37 | ], 38 | "development": [ 39 | "last 1 chrome version", 40 | "last 1 firefox version", 41 | "last 1 safari version" 42 | ] 43 | }, 44 | "devDependencies": { 45 | "react-snap": "^1.23.0" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 19 | 20 | Is it worth the cost? 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | Deployed at [isitworththecost.com](https://isitworththecost.com) 2 | 3 | --- 4 | 5 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 6 | 7 | ## Available Scripts 8 | 9 | In the project directory, you can run: 10 | 11 | ### `yarn start` 12 | 13 | Runs the app in the development mode.
14 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 15 | 16 | The page will reload if you make edits.
17 | You will also see any lint errors in the console. 18 | 19 | ### `yarn test` 20 | 21 | Launches the test runner in the interactive watch mode.
22 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 23 | 24 | ### `yarn build` 25 | 26 | Builds the app for production to the `build` folder.
27 | It correctly bundles React in production mode and optimizes the build for the best performance. 28 | 29 | The build is minified and the filenames include the hashes.
30 | Your app is ready to be deployed! 31 | 32 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 33 | 34 | ### `yarn eject` 35 | 36 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 37 | 38 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 39 | 40 | Instead, it will copy all the configuration files and the transitive dependencies (webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 41 | 42 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 43 | 44 | ## Learn More 45 | 46 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 47 | 48 | To learn React, check out the [React documentation](https://reactjs.org/). 49 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /src/calcs.ts: -------------------------------------------------------------------------------- 1 | import moment from "moment"; 2 | 3 | const workingWeeksPerYear = 52 4 | 5 | const workingMonthsPerYear = 12 6 | const workingWeeksPerMonth = workingWeeksPerYear / workingMonthsPerYear 7 | const workingDaysPerWeek = 5 8 | const workingHoursPerDay = 8 9 | const workingMinsPerHour = 60 10 | 11 | const workingMinsPerDay = workingMinsPerHour * workingHoursPerDay 12 | const workingMinsPerWeek = workingMinsPerDay * workingDaysPerWeek 13 | const workingMinsPerMonth = workingMinsPerWeek * workingWeeksPerMonth 14 | const workingMinsPerYear = workingMinsPerMonth * workingMonthsPerYear 15 | 16 | export function unitToYear(period: string, value: number): number { 17 | switch (period) { 18 | case 'year': 19 | return value 20 | case 'month': 21 | return value / workingMonthsPerYear 22 | case 'week': 23 | return value / workingWeeksPerYear 24 | case 'day': 25 | return value / (workingDaysPerWeek * workingWeeksPerYear) 26 | case 'hour': 27 | return ( 28 | value / 29 | (workingHoursPerDay * workingDaysPerWeek * workingWeeksPerYear) 30 | ) 31 | case 'minute': 32 | } 33 | return ( 34 | value / 35 | (workingMinsPerHour * 36 | workingHoursPerDay * 37 | workingDaysPerWeek * 38 | workingWeeksPerYear) 39 | ) 40 | } 41 | 42 | export function yearToUnit(period: string, value: number): number { 43 | switch (period) { 44 | case 'year': 45 | return value 46 | case 'month': 47 | return value * workingMonthsPerYear 48 | case 'week': 49 | return value * workingWeeksPerYear 50 | case 'day': 51 | return value * (workingDaysPerWeek * workingWeeksPerYear) 52 | case 'hour': 53 | return ( 54 | value * 55 | (workingHoursPerDay * workingDaysPerWeek * workingWeeksPerYear) 56 | ) 57 | case 'minute': 58 | } 59 | return ( 60 | value * 61 | (workingMinsPerHour * 62 | workingHoursPerDay * 63 | workingDaysPerWeek * 64 | workingWeeksPerYear) 65 | ) 66 | } 67 | 68 | export function periodToYear(period: string, value: number): number { 69 | return yearToUnit(period, value) 70 | } 71 | export function yearToPeriod(period: string, value: number): number { 72 | return unitToYear(period, value) 73 | } 74 | 75 | export function previousUnit(unit: string): string { 76 | switch (unit) { 77 | case 'year': 78 | return 'month' 79 | case 'month': 80 | return 'hour' 81 | case 'week': 82 | return 'hour' 83 | case 'day': 84 | return 'hour' 85 | case 'hour': 86 | return 'minute' 87 | case 'minute': 88 | } 89 | return 'second' 90 | } 91 | 92 | export function format(value: number, format: string): string { 93 | if ( 94 | (value < 8 && format === 'hour') || 95 | (value < 480 && format === 'minute') 96 | ) { 97 | return moment.duration(value, format).humanize() 98 | } 99 | let val = Math.round(value).toString() 100 | let suffix = 's' 101 | 102 | if (value < 2) { 103 | val = value.toFixed(1) 104 | } 105 | if (val === '1.0') { 106 | val = 'one' 107 | suffix = '' 108 | } 109 | return `${val} ${format + suffix}` 110 | } 111 | -------------------------------------------------------------------------------- /src/About.tsx: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { 3 | createStyles, 4 | Theme, 5 | withStyles, 6 | WithStyles, 7 | } from '@material-ui/core/styles' 8 | import Dialog from '@material-ui/core/Dialog' 9 | import MuiDialogTitle from '@material-ui/core/DialogTitle' 10 | import MuiDialogContent from '@material-ui/core/DialogContent' 11 | import MuiDialogActions from '@material-ui/core/DialogActions' 12 | import IconButton from '@material-ui/core/IconButton' 13 | import CloseIcon from '@material-ui/icons/Close' 14 | import Typography from '@material-ui/core/Typography' 15 | import HelpOutlineIcon from '@material-ui/icons/HelpOutline' 16 | 17 | const styles = (theme: Theme) => 18 | createStyles({ 19 | root: { 20 | margin: 0, 21 | padding: theme.spacing(2), 22 | }, 23 | closeButton: { 24 | position: 'absolute', 25 | right: theme.spacing(1), 26 | top: theme.spacing(1), 27 | color: theme.palette.grey[500], 28 | }, 29 | }) 30 | 31 | export interface DialogTitleProps extends WithStyles { 32 | id: string 33 | children: React.ReactNode 34 | onClose: () => void 35 | } 36 | 37 | const DialogTitle = withStyles(styles)((props: DialogTitleProps) => { 38 | const { children, classes, onClose, ...other } = props 39 | return ( 40 | 41 | {children} 42 | {onClose ? ( 43 | 48 | 49 | 50 | ) : null} 51 | 52 | ) 53 | }) 54 | 55 | const DialogContent = withStyles((theme: Theme) => ({ 56 | root: { 57 | padding: theme.spacing(2), 58 | }, 59 | }))(MuiDialogContent) 60 | 61 | export default function AboutDialog() { 62 | const [open, setOpen] = React.useState(false) 63 | 64 | const handleClickOpen = () => { 65 | setOpen(true) 66 | } 67 | const handleClose = () => { 68 | setOpen(false) 69 | } 70 | 71 | return ( 72 |
73 | 74 | 75 | 76 | 81 | 82 | Is it worth the cost?
A simple service provided for 83 | free by Cardo. 84 |
85 | 86 | 87 | Queries can be directed to hey@isitworththecost.com. 88 |
89 |
90 | Thanks to{' '} 91 | 92 | xkcd - Is It Worth the Time? 93 | {' '} 94 | for inspiration. 95 |
96 |
97 |
98 | 99 | Copyright 2020 Cardo Limited 100 | 101 |
102 |
103 |
104 | ) 105 | } 106 | -------------------------------------------------------------------------------- /src/serviceWorker.ts: -------------------------------------------------------------------------------- 1 | // This optional code is used to register a service worker. 2 | // register() is not called by default. 3 | 4 | // This lets the app load faster on subsequent visits in production, and gives 5 | // it offline capabilities. However, it also means that developers (and users) 6 | // will only see deployed updates on subsequent visits to a page, after all the 7 | // existing tabs open on the page have been closed, since previously cached 8 | // resources are updated in the background. 9 | 10 | // To learn more about the benefits of this model and instructions on how to 11 | // opt-in, read https://bit.ly/CRA-PWA 12 | 13 | const isLocalhost = Boolean( 14 | window.location.hostname === 'localhost' || 15 | // [::1] is the IPv6 localhost address. 16 | window.location.hostname === '[::1]' || 17 | // 127.0.0.0/8 are considered localhost for IPv4. 18 | window.location.hostname.match( 19 | /^127(?:\.(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3}$/ 20 | ) 21 | ); 22 | 23 | type Config = { 24 | onSuccess?: (registration: ServiceWorkerRegistration) => void; 25 | onUpdate?: (registration: ServiceWorkerRegistration) => void; 26 | }; 27 | 28 | export function register(config?: Config) { 29 | if (process.env.NODE_ENV === 'production' && 'serviceWorker' in navigator) { 30 | // The URL constructor is available in all browsers that support SW. 31 | const publicUrl = new URL( 32 | process.env.PUBLIC_URL, 33 | window.location.href 34 | ); 35 | if (publicUrl.origin !== window.location.origin) { 36 | // Our service worker won't work if PUBLIC_URL is on a different origin 37 | // from what our page is served on. This might happen if a CDN is used to 38 | // serve assets; see https://github.com/facebook/create-react-app/issues/2374 39 | return; 40 | } 41 | 42 | window.addEventListener('load', () => { 43 | const swUrl = `${process.env.PUBLIC_URL}/service-worker.js`; 44 | 45 | if (isLocalhost) { 46 | // This is running on localhost. Let's check if a service worker still exists or not. 47 | checkValidServiceWorker(swUrl, config); 48 | 49 | // Add some additional logging to localhost, pointing developers to the 50 | // service worker/PWA documentation. 51 | navigator.serviceWorker.ready.then(() => { 52 | console.log( 53 | 'This web app is being served cache-first by a service ' + 54 | 'worker. To learn more, visit https://bit.ly/CRA-PWA' 55 | ); 56 | }); 57 | } else { 58 | // Is not localhost. Just register service worker 59 | registerValidSW(swUrl, config); 60 | } 61 | }); 62 | } 63 | } 64 | 65 | function registerValidSW(swUrl: string, config?: Config) { 66 | navigator.serviceWorker 67 | .register(swUrl) 68 | .then(registration => { 69 | registration.onupdatefound = () => { 70 | const installingWorker = registration.installing; 71 | if (installingWorker == null) { 72 | return; 73 | } 74 | installingWorker.onstatechange = () => { 75 | if (installingWorker.state === 'installed') { 76 | if (navigator.serviceWorker.controller) { 77 | // At this point, the updated precached content has been fetched, 78 | // but the previous service worker will still serve the older 79 | // content until all client tabs are closed. 80 | console.log( 81 | 'New content is available and will be used when all ' + 82 | 'tabs for this page are closed. See https://bit.ly/CRA-PWA.' 83 | ); 84 | 85 | // Execute callback 86 | if (config && config.onUpdate) { 87 | config.onUpdate(registration); 88 | } 89 | } else { 90 | // At this point, everything has been precached. 91 | // It's the perfect time to display a 92 | // "Content is cached for offline use." message. 93 | console.log('Content is cached for offline use.'); 94 | 95 | // Execute callback 96 | if (config && config.onSuccess) { 97 | config.onSuccess(registration); 98 | } 99 | } 100 | } 101 | }; 102 | }; 103 | }) 104 | .catch(error => { 105 | console.error('Error during service worker registration:', error); 106 | }); 107 | } 108 | 109 | function checkValidServiceWorker(swUrl: string, config?: Config) { 110 | // Check if the service worker can be found. If it can't reload the page. 111 | fetch(swUrl, { 112 | headers: { 'Service-Worker': 'script' } 113 | }) 114 | .then(response => { 115 | // Ensure service worker exists, and that we really are getting a JS file. 116 | const contentType = response.headers.get('content-type'); 117 | if ( 118 | response.status === 404 || 119 | (contentType != null && contentType.indexOf('javascript') === -1) 120 | ) { 121 | // No service worker found. Probably a different app. Reload the page. 122 | navigator.serviceWorker.ready.then(registration => { 123 | registration.unregister().then(() => { 124 | window.location.reload(); 125 | }); 126 | }); 127 | } else { 128 | // Service worker found. Proceed as normal. 129 | registerValidSW(swUrl, config); 130 | } 131 | }) 132 | .catch(() => { 133 | console.log( 134 | 'No internet connection found. App is running in offline mode.' 135 | ); 136 | }); 137 | } 138 | 139 | export function unregister() { 140 | if ('serviceWorker' in navigator) { 141 | navigator.serviceWorker.ready 142 | .then(registration => { 143 | registration.unregister(); 144 | }) 145 | .catch(error => { 146 | console.error(error.message); 147 | }); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/Breakdown.tsx: -------------------------------------------------------------------------------- 1 | import List from '@material-ui/core/List' 2 | import Divider from '@material-ui/core/Divider' 3 | import ListItem from '@material-ui/core/ListItem' 4 | import ListItemIcon from '@material-ui/core/ListItemIcon' 5 | import MoneyOffIcon from '@material-ui/icons/MoneyOff' 6 | import ListItemText from '@material-ui/core/ListItemText' 7 | import Typography from '@material-ui/core/Typography' 8 | import React from 'react' 9 | import Select from '@material-ui/core/Select' 10 | import AlarmOnIcon from '@material-ui/icons/AlarmOn' 11 | import CreditCardIcon from '@material-ui/icons/CreditCard' 12 | import { makeStyles } from '@material-ui/core/styles' 13 | import { format, previousUnit, yearToPeriod, yearToUnit } from './calcs' 14 | 15 | const useStyles = makeStyles(theme => ({ 16 | secondaryText: { 17 | // fontSize: '0.875rem', 18 | color: 'rgba(0,0,0,0.6)', 19 | }, 20 | })) 21 | 22 | function BreakdownItem({ 23 | value, 24 | onChange, 25 | id, 26 | primary, 27 | secondary, 28 | tertiary, 29 | icon, 30 | error, 31 | }: any) { 32 | const classes = useStyles() 33 | return ( 34 | 35 | {icon} 36 | 44 | {primary} 45 | 46 | } 47 | secondary={ 48 | 49 | 50 | {secondary}{' '} 51 | 52 | 65 | 66 | {tertiary} 67 | 68 | 69 | } 70 | /> 71 | 72 | ) 73 | } 74 | 75 | interface BreakdownProps { 76 | values: any 77 | costs: any 78 | handleChange: (prop: string) => any 79 | } 80 | 81 | export function Breakdown(props: BreakdownProps) { 82 | const { values, costs, handleChange } = props 83 | const costError = costs.savingsPerYear <= 0 84 | return ( 85 | 86 |

Breakdown

87 |

By using this service you will:

88 | 89 | 90 | } 105 | error={costError} 106 | /> 107 | 108 | } 125 | error={costs.freeTimePerYear < 0} 126 | /> 127 | 128 | } 145 | error={costs.paybackTimePerYear < 0} 146 | /> 147 | 148 | 149 |
150 | ) 151 | } 152 | -------------------------------------------------------------------------------- /src/App.tsx: -------------------------------------------------------------------------------- 1 | import React, { ChangeEvent, useEffect } from 'react' 2 | 3 | import { 4 | OutlinedInput, 5 | InputLabel, 6 | InputAdornment, 7 | FormControl, 8 | Paper, 9 | Container, 10 | Grid, 11 | Select, 12 | Link, 13 | IconButton, 14 | makeStyles, 15 | } from '@material-ui/core' 16 | import clsx from 'clsx' 17 | 18 | import AttachMoneyIcon from '@material-ui/icons/AttachMoney' 19 | import AccessTimeIcon from '@material-ui/icons/AccessTime' 20 | import EmojiPeopleIcon from '@material-ui/icons/EmojiPeople' 21 | import GitHubIcon from '@material-ui/icons/GitHub' 22 | import Typography from '@material-ui/core/Typography' 23 | import { Breakdown } from './Breakdown' 24 | import { periodToYear, unitToYear } from './calcs' 25 | import AboutDialog from './About' 26 | 27 | const useStyles = makeStyles(theme => ({ 28 | root: { 29 | padding: '2em 3em', 30 | marginTop: theme.spacing(2), 31 | }, 32 | margin: { 33 | margin: theme.spacing(0.5), 34 | }, 35 | withoutLabel: { 36 | marginTop: theme.spacing(3), 37 | }, 38 | textField: { 39 | maxWidth: 150, 40 | }, 41 | heading: {}, 42 | panel: {}, 43 | topControls: { 44 | float: 'right', 45 | display: 'inline-flex', 46 | }, 47 | })) 48 | 49 | function TopControls() { 50 | const classes = useStyles() 51 | return ( 52 |
53 | 54 | 55 | 56 | 57 |
58 | ) 59 | } 60 | 61 | function App() { 62 | const classes = useStyles() 63 | 64 | const [values, setValues] = React.useState({ 65 | timeCost: { value: 25, unit: 'dollars', period: 'hour' }, 66 | serviceCost: { value: 125, unit: 'dollars', period: 'month' }, 67 | trainingTime: { value: 2, unit: 'hour', period: null }, 68 | timeSavings: { value: 60, unit: 'min', period: 'day' }, 69 | peopleCount: { value: 1, unit: null, period: null }, 70 | 71 | savingPeriodCost: 'year', 72 | savingPeriodPeople: 'day', 73 | paybackPeriod: 'day', 74 | }) 75 | 76 | const [costs, setCosts] = React.useState({ 77 | employeePerYear: 0, 78 | servicePerYear: 0, 79 | trainingPerYear: 0, 80 | savingsPerYear: 0, 81 | freeTimePerYear: 0, 82 | paybackTimePerYear: 0, 83 | }) 84 | 85 | const handleChange = (prop: string, key: string | null = null) => ( 86 | event: ChangeEvent, 87 | ): void => { 88 | let val: any = event.target.value 89 | if (key === null) { 90 | setValues({ 91 | ...values, 92 | [prop]: val, 93 | }) 94 | } else { 95 | if (key === 'value' && (val < 0 || isNaN(val))) { 96 | val = 0 97 | } 98 | setValues({ 99 | ...values, 100 | [prop]: { 101 | //@ts-ignore 102 | value: values[prop].value, 103 | //@ts-ignore 104 | unit: values[prop].unit, 105 | //@ts-ignore 106 | period: values[prop].period, 107 | //@ts-ignore 108 | [key]: val, 109 | }, 110 | }) 111 | } 112 | } 113 | 114 | useEffect(() => { 115 | // save this to state for now for ease of visibility 116 | const employeePerYear = 117 | values.timeCost.value * periodToYear(values.timeCost.period, 1) 118 | const servicePerYear = 119 | values.serviceCost.value * 120 | periodToYear(values.serviceCost.period, 1) 121 | 122 | // assumes amortisation period of 1 year 123 | const trainingPerYear = 124 | unitToYear(values.trainingTime.unit, values.trainingTime.value) * 125 | employeePerYear * 126 | values.peopleCount.value 127 | 128 | const freeTimePerYear = 129 | periodToYear( 130 | values.timeSavings.period, 131 | unitToYear(values.timeSavings.unit, values.timeSavings.value), 132 | ) * values.peopleCount.value 133 | 134 | const savingsPerYear = 135 | employeePerYear * freeTimePerYear - servicePerYear - trainingPerYear 136 | 137 | const paybackTimePerYear = 138 | (trainingPerYear + servicePerYear) / employeePerYear 139 | 140 | setCosts({ 141 | employeePerYear, 142 | servicePerYear, 143 | trainingPerYear, 144 | savingsPerYear, 145 | freeTimePerYear, 146 | paybackTimePerYear, 147 | }) 148 | }, [values]) 149 | 150 | return ( 151 | 152 | 153 |
154 | 155 | 156 | Is it worth the cost? 157 | 158 | 159 | A simple check on whether purchasing a service is worth 160 | the cost. 161 | 162 |
163 | 164 | 165 |

Basics

166 |

1. Cost of your time or an employees time.

167 | 171 | 172 | Time Cost 173 | 174 | 181 | 182 | 183 | } 184 | labelWidth={80} 185 | /> 186 | 187 | 191 | 192 | per 193 | 194 | 210 | 211 |

2. Cost of the service under consideration.

212 | 216 | 217 | Service Cost 218 | 219 | 226 | 227 | 228 | } 229 | labelWidth={95} 230 | /> 231 | 232 | 236 | 237 | per 238 | 239 | 255 | 256 |

257 | 3. Estimate the training time required (one person). 258 |

259 | 264 | 265 | Training Time 266 | 267 | 274 | 275 | 276 | } 277 | labelWidth={105} 278 | /> 279 | 280 | 284 | 299 | 300 |

301 | 4. Estimate the time this service will save (one 302 | person). 303 |

304 | 308 | 309 | Time Saved 310 | 311 | 318 | 319 | 320 | } 321 | labelWidth={80} 322 | /> 323 | 324 | 328 | 339 | 340 | 344 | 345 | per 346 | 347 | 360 | 361 |

5. Number of people using the service.

362 | 366 | 367 | People 368 | 369 | 376 | 377 | 378 | } 379 | labelWidth={50} 380 | /> 381 | 382 |
383 | 384 | 389 | 390 |
391 |
392 |
393 | ) 394 | } 395 | export default App 396 | --------------------------------------------------------------------------------