├── .babelrc ├── .eslintrc.js ├── .gitignore ├── LICENSE ├── README.md ├── cronJobs ├── .babelrc ├── .gitignore ├── handler.js ├── package.json ├── serverless.yml ├── src │ ├── lib │ │ └── getRootURL.js │ └── server ├── webpack.config.js └── yarn.lock ├── now.json ├── package.json ├── webApp ├── .babelrc ├── components │ ├── CopyButton.js │ ├── DescriptionEditor.js │ ├── Header.js │ ├── IncomeReport.js │ ├── MenuDrop.js │ ├── Modal.js │ ├── Notifier.js │ ├── SelectList.js │ ├── SharedStyles.js │ └── Toggle.js ├── env-config.js ├── lib │ ├── api.js │ ├── context.js │ ├── getRootURL.js │ ├── notifier.js │ ├── withAuth.js │ └── withLayout.js ├── package.json ├── pages │ ├── _document.js │ ├── checkout.js │ ├── contact.js │ ├── index.js │ ├── login.js │ ├── mentors.js │ ├── rate.js │ └── signup.js ├── server │ ├── api.js │ ├── app.js │ ├── auth.js │ ├── aws.js │ ├── constants.js │ ├── emailTemplates.js │ ├── gmail │ │ ├── accessRevoked.js │ │ ├── api.js │ │ ├── checkLabelsAndFilters.js │ │ ├── checkSentEmails.js │ │ ├── createFilter.js │ │ ├── createLabels.js │ │ ├── index.js │ │ ├── migrate.js │ │ ├── passportStrategy.js │ │ └── setHistoryStartId.js │ ├── log.js │ ├── models │ │ ├── BlackList.js │ │ ├── Invitation.js │ │ ├── Payment.js │ │ ├── Rating.js │ │ └── User.js │ ├── public-api.js │ ├── sitemap.js │ ├── stripe.js │ └── utils │ │ └── slugify.js ├── static │ └── nprogress.css ├── test │ └── unit │ │ └── utils │ │ └── slugify.test.js └── yarn.lock └── yarn.lock /.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["env"] 3 | } 4 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | parser: 'babel-eslint', 3 | extends: 'airbnb', 4 | env: { 5 | browser: true 6 | }, 7 | plugins: ['react', 'jsx-a11y', 'import'], 8 | rules: { 9 | 'max-len': ['error', 100], 10 | semi: ['error', 'never'], 11 | 'comma-dangle': ['error', 'never'], 12 | 'arrow-parens': ['error', 'as-needed'], 13 | 'no-mixed-operators': 'off', 14 | 'no-underscore-dangle': ['error', { allow: ['_id'] }], 15 | 'react/react-in-jsx-scope': 'off', 16 | 'react/jsx-filename-extension': [ 17 | 'error', 18 | { 19 | extensions: ['.js'] 20 | } 21 | ] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | *.swp 3 | .meteor-spk 4 | *.sublime-workspace 5 | tmp/ 6 | node_modules/ 7 | npm-debug.log 8 | .vscode/ 9 | .build/* 10 | 11 | .DS_Store 12 | 13 | # build output 14 | .next 15 | 16 | .vscode/ 17 | node_modules/ 18 | 19 | webApp/node_modules/ 20 | webApp/.build/* 21 | webApp/.next 22 | webApp/.coverage 23 | webApp/.env 24 | 25 | cronJobs/node_modules/ 26 | cronJobs/.env -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Tima 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Harbor 2 | Open source web app built with React/Material-UI/Next/Express/Mongoose/MongoDB. 3 | 4 | This app allows anyone with a Gmail account to receive payments for sending advice via email. 5 | 6 | 7 | ## How can I use this app? 8 | 9 | You can learn: 10 | - React/Material-UI/Next/Express/Mongoose/MongoDB boilerplate ([up-to-date boilerplate](https://github.com/builderbook/builderbook)) 11 | - Google OAuth API, 12 | - Stripe connected accounts, Stripe payments, Stripe invoices API, 13 | - Gmail API 14 | 15 | 16 | ## Screenshots 17 | 18 | Mentor settings page 19 | ![harbor-mentor-page](https://user-images.githubusercontent.com/10218864/35487210-e5c3dd44-042d-11e8-8e6c-2e4673fac929.png) 20 | 21 | Mentor contact page 22 | ![harbor-settings-page](https://user-images.githubusercontent.com/10218864/35487211-e5dcb77e-042d-11e8-9fa7-1fe6eb151ef4.png) 23 | 24 | Customer checkout 25 | ![habor-checkout](https://user-images.githubusercontent.com/10218864/35487337-3bbb9006-042f-11e8-80da-4cfab3a17fbb.png) 26 | 27 | 28 | ## Run locally 29 | - Clone the project and run `yarn` to add packages. 30 | - Before you start the app, create a `.env` file at the app's root. This file must have _at least three env variables_: `MONGO_URL_TEST`, `Google_clientID`, `Google_clientSecret`. We recommend free MongoDB at mLab. 31 | 32 | To use all features and third-party integrations (such as Stripe, Google OAuth), add values to all env variables in `.env` file: 33 | `.env` : 34 | ``` 35 | MONGO_URL="XXXXXX" 36 | MONGO_URL_TEST="XXXXXX" 37 | 38 | Google_clientID="XXXXXX" 39 | Google_clientSecret="XXXXXX" 40 | 41 | Amazon_accessKeyId="XXXXXX" 42 | Amazon_secretAccessKey="XXXXXX" 43 | 44 | Stripe_Test_ClientID="ca_XXXXXX" 45 | Stripe_Live_ClientID="ca_XXXXXX" 46 | Stripe_Test_SecretKey="sk_test_XXXXXX" 47 | Stripe_Live_SecretKey="sk_live_XXXXXX" 48 | Stripe_Live_PublishableKey="pk_live_XXXXXX" 49 | Stripe_Test_PublishableKey="pk_test_XXXXXX" 50 | ``` 51 | 52 | - Before you start the app, create a `env-config.js` file at the app's root. This file makes Stripe's public keys (keys that start with `pk`) available on client. Content of this file: 53 | `env-config.js` : 54 | ``` 55 | const dev = process.env.NODE_ENV !== 'production'; 56 | 57 | module.exports = { 58 | StripePublishableKey: dev 59 | ? 'pk_test_XXXXXX' 60 | : 'pk_live_XXXXXX', 61 | }; 62 | ``` 63 | 64 | - Start the app with `yarn dev`. 65 | 66 | 67 | ## Deploy 68 | Follow these steps to deploy Harbor app with Zeit's [now](https://zeit.co/now). 69 | 70 | 1. Install now: `npm install -g now` 71 | 72 | 2. Point your domain to Zeit world nameservers: [three steps](https://zeit.co/world#get-started) 73 | 74 | 3. Check the `now.json` file. If you are using `dotenv` and `.env` for env variables, no need to change `now.json`. If you make changes to the app, check up how to [configure now](https://zeit.co/docs/features/configuration). 75 | 76 | 4. Make sure you updated `ROOT_URL` in `package.json` and `lib/getRootURL.js` files. 77 | 78 | 5. Check that you have all production-level env variable in `.env`. 79 | 80 | 6. In your terminal, deploy the app by running `now`. 81 | 82 | 7. Now outputs your deployment's URL, for example: `harbor-zomcvzgtvc.now.sh`. 83 | 84 | 8. Point successful deployment to your domain, for example: `now ln harbor-zomcvzgtvc.now.sh builderbook.org`. 85 | 86 | You are done. 87 | -------------------------------------------------------------------------------- /cronJobs/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [ 3 | [ 4 | "env", 5 | { 6 | "targets": { 7 | "node": "6.10.3" 8 | } 9 | } 10 | ] 11 | ], 12 | "plugins": ["transform-object-rest-spread"] 13 | } 14 | -------------------------------------------------------------------------------- /cronJobs/.gitignore: -------------------------------------------------------------------------------- 1 | # package directories 2 | node_modules 3 | jspm_packages 4 | 5 | dist 6 | 7 | # Serverless directories 8 | .serverless -------------------------------------------------------------------------------- /cronJobs/handler.js: -------------------------------------------------------------------------------- 1 | require('dotenv').config() 2 | const mongoose = require('mongoose') 3 | 4 | const logger = require('./dist/server/log').default 5 | const checkSentEmails = require('./dist/server/gmail/checkSentEmails').default 6 | 7 | process.env.NODE_ENV = process.env.NODE_ENV2 || process.env.NODE_ENV 8 | 9 | function connectToDB() { 10 | const dev = process.env.NODE_ENV !== 'production' 11 | let MONGO_URL = dev ? process.env.MONGO_URL_TEST : process.env.MONGO_URL 12 | MONGO_URL = process.env.USE_MONGO_TEST2 ? process.env.MONGO_URL_TEST2 : MONGO_URL 13 | 14 | mongoose.Promise = global.Promise 15 | mongoose.connect(MONGO_URL, { useMongoClient: true }) 16 | } 17 | 18 | module.exports.checkSentEmailsCron = (event, context, callback) => { 19 | connectToDB() 20 | 21 | logger.info('checking sent emails') 22 | checkSentEmails().then(() => { 23 | mongoose.disconnect() 24 | logger.info('** checking sent emails: DONE') 25 | callback(null, { message: 'checking sent emails: Done', event }) 26 | }) 27 | } 28 | -------------------------------------------------------------------------------- /cronJobs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "harbor-cronjobs", 3 | "version": "0.0.1", 4 | "scripts": { 5 | "build": "babel --watch src -d dist/", 6 | "deploy": "babel src -d dist/ && serverless deploy", 7 | "invoke": "USE_MONGO_TEST2=1 NODE_ENV2=dev serverless invoke local" 8 | }, 9 | "devDependencies": { 10 | "babel-cli": "^6.26.0", 11 | "babel-plugin-transform-object-rest-spread": "^6.26.0", 12 | "babel-preset-env": "^1.6.0", 13 | "webpack": "^3.5.5" 14 | }, 15 | "dependencies": { 16 | "aws-sdk": "^2.102.0", 17 | "dotenv": "^4.0.0", 18 | "email-addresses": "^3.0.1", 19 | "googleapis": "^20.1.0", 20 | "handlebars": "^4.0.10", 21 | "moment": "^2.18.1", 22 | "mongoose": "^4.11.7", 23 | "qs": "^6.5.0", 24 | "request": "^2.81.0", 25 | "stripe": "^4.24.0", 26 | "winston": "^2.3.1" 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /cronJobs/serverless.yml: -------------------------------------------------------------------------------- 1 | # Welcome to Serverless! 2 | # 3 | # This file is the main config file for your service. 4 | # It's very minimal at this point and uses default values. 5 | # You can always add more config options for more control. 6 | # We've included some commented out config examples here. 7 | # Just uncomment any of them to get that config option. 8 | # 9 | # For full config options, check the docs: 10 | # docs.serverless.com 11 | # 12 | # Happy Coding! 13 | 14 | service: cronJobs 15 | 16 | # You can pin your service to only deploy with a specific Serverless version 17 | # Check out our docs for more details 18 | # frameworkVersion: "=X.X.X" 19 | 20 | provider: 21 | name: aws 22 | runtime: nodejs6.10 23 | region: us-east-1 24 | memory: 1536 25 | timeout: 300 26 | exclude: 27 | - src/** 28 | - webpack.config.js 29 | 30 | # you can overwrite defaults here 31 | # stage: dev 32 | 33 | # you can add statements to the Lambda function's IAM Role here 34 | # iamRoleStatements: 35 | # - Effect: "Allow" 36 | # Action: 37 | # - "s3:ListBucket" 38 | # Resource: { "Fn::Join" : ["", ["arn:aws:s3:::", { "Ref" : "ServerlessDeploymentBucket" } ] ] } 39 | # - Effect: "Allow" 40 | # Action: 41 | # - "s3:PutObject" 42 | # Resource: 43 | # Fn::Join: 44 | # - "" 45 | # - - "arn:aws:s3:::" 46 | # - "Ref" : "ServerlessDeploymentBucket" 47 | # - "/*" 48 | 49 | # you can define service wide environment variables here 50 | # environment: 51 | # variable1: value1 52 | 53 | # you can add packaging information here 54 | #package: 55 | # include: 56 | # - include-me.js 57 | # - include-me-dir/** 58 | # exclude: 59 | # - exclude-me.js 60 | # - exclude-me-dir/** 61 | 62 | functions: 63 | checkSentEmails: 64 | handler: handler.checkSentEmailsCron 65 | environment: 66 | NODE_ENV: production 67 | events: 68 | - schedule: rate(5 minutes) 69 | 70 | # The following are a few example events you can configure 71 | # NOTE: Please make sure to change your handler code to work with those events 72 | # Check the event documentation for details 73 | # events: 74 | # - http: 75 | # path: users/create 76 | # method: get 77 | # - s3: ${env:BUCKET} 78 | # - schedule: rate(10 minutes) 79 | # - sns: greeter-topic 80 | # - stream: arn:aws:dynamodb:region:XXXXXX:table/foo/stream/1970-01-01T00:00:00.000 81 | # - alexaSkill 82 | # - iot: 83 | # sql: "SELECT * FROM 'some_topic'" 84 | # - cloudwatchEvent: 85 | # event: 86 | # source: 87 | # - "aws.ec2" 88 | # detail-type: 89 | # - "EC2 Instance State-change Notification" 90 | # detail: 91 | # state: 92 | # - pending 93 | # - cloudwatchLog: '/aws/lambda/hello' 94 | # - cognitoUserPool: 95 | # pool: MyUserPool 96 | # trigger: PreSignUp 97 | 98 | # Define function environment variables here 99 | # environment: 100 | # variable2: value2 101 | 102 | # you can add CloudFormation resource templates here 103 | #resources: 104 | # Resources: 105 | # NewResource: 106 | # Type: AWS::S3::Bucket 107 | # Properties: 108 | # BucketName: my-new-bucket 109 | # Outputs: 110 | # NewOutput: 111 | # Description: "Description for the output" 112 | # Value: "Some output value" 113 | -------------------------------------------------------------------------------- /cronJobs/src/lib/getRootURL.js: -------------------------------------------------------------------------------- 1 | ../../../webApp/lib/getRootURL.js -------------------------------------------------------------------------------- /cronJobs/src/server: -------------------------------------------------------------------------------- 1 | ../../webApp/server -------------------------------------------------------------------------------- /cronJobs/webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | target: 'node', 3 | entry: './src/index.js', 4 | output: { 5 | libraryTarget: 'commonjs', 6 | filename: 'handler.js' 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /now.json: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "NODE_ENV": "production" 4 | }, 5 | 6 | "dotenv": true 7 | } -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "harbor-lambda", 3 | "version": "0.0.1", 4 | "devDependencies": { 5 | "babel-cli": "^6.24.1", 6 | "babel-eslint": "^7.2.3", 7 | "babel-preset-env": "^1.6.0", 8 | "eslint": "^3.19.0", 9 | "eslint-config-airbnb": "^15.0.1", 10 | "eslint-plugin-import": "^2.6.0", 11 | "eslint-plugin-jsx-a11y": "^5.0.3", 12 | "eslint-plugin-react": "^7.1.0" 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /webApp/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["env", "next/babel"], 3 | "plugins": [["transform-define", "./env-config.js"]] 4 | } 5 | -------------------------------------------------------------------------------- /webApp/components/CopyButton.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import PropTypes from 'prop-types' 3 | import ClipboardButton from 'react-clipboard.js' 4 | 5 | import { success } from '../lib/notifier' 6 | 7 | const styleCopyButton = { 8 | textTransform: 'none', 9 | font: '15px Muli', 10 | fontWeight: '300', 11 | letterSpacing: '0.01em', 12 | color: '#1F4167', 13 | backgroundColor: 'transparent', 14 | boxShadow: 'none', 15 | WebkitBoxShadow: 'none', 16 | MozBoxShadow: 'none', 17 | border: 'none', 18 | marginLeft: '25px', 19 | '&:hover': { 20 | opacity: '0.8' 21 | } 22 | } 23 | 24 | const CopyButton = ({ content, buttonText }) => 25 | ( 26 | success('Copied!')} 30 | > 31 | {buttonText} 32 | 33 | ) 34 | 35 | CopyButton.propTypes = { 36 | content: PropTypes.string.isRequired, 37 | buttonText: PropTypes.string.isRequired 38 | } 39 | 40 | export default CopyButton 41 | -------------------------------------------------------------------------------- /webApp/components/DescriptionEditor.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import Link from 'material-ui-icons/Link' 4 | import Button from 'material-ui/Button' 5 | import Dialog, { DialogActions, DialogContent, DialogContentText } from 'material-ui/Dialog' 6 | 7 | import { styleExternalLinkIcon, styleFlatButton } from '../components/SharedStyles' 8 | 9 | import { error } from '../lib/notifier' 10 | 11 | const styleTitle = { 12 | marginLeft: '25px', 13 | fontSize: '18px' 14 | } 15 | 16 | const styleDialogActions = { 17 | margin: '0px 20px 20px 0px' 18 | } 19 | 20 | function replaceSelectionWithHtml(html, range) { 21 | range.deleteContents() 22 | const div = document.createElement('div') 23 | div.innerHTML = html 24 | const frag = document.createDocumentFragment() 25 | 26 | let child = div.firstChild 27 | 28 | while (child) { 29 | frag.appendChild(child) 30 | child = div.firstChild 31 | } 32 | 33 | range.insertNode(frag) 34 | } 35 | 36 | class EditorDiv extends Component { 37 | static propTypes = { 38 | defaultValue: PropTypes.string.isRequired, 39 | onChange: PropTypes.func.isRequired 40 | } 41 | 42 | shouldComponentUpdate() { 43 | return false 44 | } 45 | 46 | render() { 47 | const { defaultValue } = this.props 48 | 49 | return ( 50 |
{ 56 | const text = e.target.innerText 57 | 58 | if (e.which === 8 || e.ctrlKey) { 59 | return 60 | } 61 | 62 | if (text.length > 250) { 63 | e.preventDefault() 64 | error('Description should be 250 characters or less.') 65 | } 66 | }} 67 | onInput={e => { 68 | this.props.onChange(e) 69 | }} 70 | ref={elm => { 71 | this.elm = elm 72 | }} 73 | /> 74 | ) 75 | } 76 | } 77 | 78 | class DescriptionEditor extends Component { 79 | static propTypes = { 80 | defaultValue: PropTypes.string.isRequired, 81 | onRendered: PropTypes.func.isRequired, 82 | onChange: PropTypes.func.isRequired 83 | } 84 | 85 | state = { 86 | insertLinkOpen: false 87 | } 88 | 89 | componentDidMount() { 90 | this.props.onRendered(this) 91 | } 92 | 93 | handleRequestClose = () => { 94 | this.setState({ insertLinkOpen: false }) 95 | } 96 | 97 | handleOpenInsertLinkDialog = () => { 98 | const range = window.getSelection().getRangeAt(0) 99 | if (range.toString() === '') { 100 | error('Select text to hyperlink it.') 101 | return 102 | } 103 | 104 | this.range = range 105 | this.setState({ insertLinkOpen: true }) 106 | } 107 | 108 | handleInsertLink = () => { 109 | const link = this.insertLinkInput.value 110 | if (link === '') { 111 | error('Add link') 112 | return 113 | } 114 | 115 | this.insertLinkInput.value = '' 116 | replaceSelectionWithHtml( 117 | `${this.range}`, 118 | this.range, 119 | this.editorDiv.elm 120 | ) 121 | 122 | this.props.onChange({ target: this.editorDiv.elm }) 123 | this.setState({ insertLinkOpen: false }) 124 | } 125 | 126 | render() { 127 | return ( 128 |
129 | { 133 | this.editorDiv = elm 134 | }} 135 | /> 136 | 137 | 138 | 139 | 140 |

Add link

141 | 142 | 143 | { 145 | this.insertLinkInput = elm 146 | }} 147 | /> 148 | 149 | 150 | 151 | 154 | 157 | 158 |
159 |
160 | ) 161 | } 162 | } 163 | 164 | export default DescriptionEditor 165 | -------------------------------------------------------------------------------- /webApp/components/Header.js: -------------------------------------------------------------------------------- 1 | import PropTypes from 'prop-types' 2 | import Link from 'next/link' 3 | import Router from 'next/router' 4 | import NProgress from 'nprogress' 5 | import Launch from 'material-ui-icons/Launch' 6 | import Toolbar from 'material-ui/Toolbar' 7 | import Grid from 'material-ui/Grid' 8 | import Hidden from 'material-ui/Hidden' 9 | import Button from 'material-ui/Button' 10 | import MenuDrop from './MenuDrop' 11 | import Income from './IncomeReport' 12 | 13 | import { 14 | styleFlatButton, 15 | styleRaisedButton, 16 | styleToolbar, 17 | styleExternalLinkIcon 18 | } from './SharedStyles' 19 | 20 | Router.onRouteChangeStart = () => { 21 | NProgress.start() 22 | } 23 | Router.onRouteChangeComplete = () => NProgress.done() 24 | Router.onRouteChangeError = () => NProgress.done() 25 | 26 | const optionsMenu = [ 27 | { 28 | text: 'Send feedback', 29 | url: 'https://mail.google.com/mail/?view=cm&fs=1&to=team@findharbor.com', 30 | target: '_blank', 31 | rel: 'noopener noreferrer' 32 | }, 33 | { text: 'Log out', url: '/logout', target: '_self', rel: null } 34 | ] 35 | 36 | function Header({ user }) { 37 | if (user) { 38 | return ( 39 |
40 | 41 | 42 | 43 | 44 | 45 | Settings 46 | 47 | {' '} 48 | 49 | {user.isAdmin ? ( 50 | 51 | Mentors 52 | 53 | ) : null} 54 | {' '} 55 | 56 | 57 | {!user.isStripeConnected ? ( 58 | 65 | ) : ( 66 |
67 | 68 | 69 | 74 | Stripe 75 | 76 | 77 |
78 | )} 79 |
80 | 81 |
82 | {user.avatarUrl ? ( 83 | 84 | ) : null} 85 |
86 |
87 |
88 |
89 |
90 | ) 91 | } 92 | 93 | return ( 94 |
95 | 96 | 97 | 98 | 99 | 102 | 103 | 104 | 107 | 108 | 109 | 110 | 111 |
112 | ) 113 | } 114 | 115 | Header.propTypes = { 116 | user: PropTypes.shape({ 117 | displayName: PropTypes.string, 118 | email: PropTypes.string.isRequired 119 | }) 120 | } 121 | 122 | Header.defaultProps = { 123 | user: null 124 | } 125 | 126 | export default Header 127 | -------------------------------------------------------------------------------- /webApp/components/IncomeReport.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import NProgress from 'nprogress' 3 | import PropTypes from 'prop-types' 4 | import { withStyles } from 'material-ui/styles' 5 | import List, { ListItem, ListItemText } from 'material-ui/List' 6 | import Menu, { MenuItem } from 'material-ui/Menu' 7 | import KeyboardArrowDown from 'material-ui-icons/KeyboardArrowDown' 8 | import { getIncomeReport } from '../lib/api' 9 | import { error } from '../lib/notifier' 10 | 11 | const styleSheet = { 12 | root: { 13 | width: '100%', 14 | maxWidth: '200px', 15 | display: 'inline-flex', 16 | marginRight: '20px', 17 | backgroundColor: '#F7F9FC' 18 | }, 19 | List: { 20 | padding: '0px', 21 | border: '1px solid rgba(26, 35, 126, 0.25)' 22 | }, 23 | MenuItem: { 24 | font: '14px Muli', 25 | fontWeight: '400' 26 | }, 27 | ListItem: { 28 | padding: '2px 5px', 29 | textAlign: 'center' 30 | }, 31 | ListItemText: { 32 | font: '14px Muli', 33 | fontWeight: '400', 34 | padding: '0px 5px' 35 | } 36 | } 37 | 38 | class IncomeReport extends Component { 39 | static propTypes = { 40 | classes: PropTypes.shape({}).isRequired 41 | } 42 | 43 | state = { 44 | anchorEl: undefined, 45 | open: false, 46 | selectedIndex: 0, 47 | loading: true, 48 | error: null, 49 | incomeList: [] 50 | } 51 | 52 | componentDidMount() { 53 | NProgress.start() 54 | 55 | getIncomeReport() 56 | .then(({ incomeList }) => { 57 | this.setState({ incomeList, loading: false }) 58 | NProgress.done() 59 | }) 60 | .catch(err => { 61 | this.setState({ loading: false, error: err.message || err.toString() }) 62 | error(err) 63 | NProgress.done() 64 | }) 65 | } 66 | 67 | handleClickListItem = event => { 68 | this.setState({ open: true, anchorEl: event.currentTarget }) 69 | } 70 | 71 | handleMenuItemClick = (event, index) => { 72 | this.setState({ selectedIndex: index, open: false }) 73 | } 74 | 75 | handleRequestClose = () => { 76 | this.setState({ open: false }) 77 | } 78 | 79 | render() { 80 | if (this.state.loading) { 81 | return null 82 | } 83 | 84 | if (this.state.error) { 85 | return {this.state.error} 86 | } 87 | 88 | const classes = this.props.classes 89 | 90 | const options = this.state.incomeList 91 | const selectedIndex = this.state.selectedIndex 92 | const selectedItem = options[selectedIndex] 93 | 94 | return ( 95 |
96 | 97 | 103 | 108 | 109 | 110 | 111 | 117 | {options.map((option, index) => ( 118 | this.handleMenuItemClick(event, index)} 123 | > 124 | ${option.income} in {option.month} 125 | 126 | ))} 127 | 128 |
129 | ) 130 | } 131 | } 132 | 133 | const IncomeReportWithStyle = withStyles(styleSheet)(IncomeReport) 134 | 135 | const Income = () => 136 | 137 | export default Income 138 | -------------------------------------------------------------------------------- /webApp/components/MenuDrop.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import Menu from 'material-ui/Menu' 4 | 5 | import { mentorHeaderPic } from './SharedStyles' 6 | 7 | class MenuDrop extends Component { 8 | static propTypes = { 9 | src: PropTypes.string.isRequired, 10 | alt: PropTypes.string.isRequired, 11 | options: PropTypes.arrayOf(String).isRequired 12 | } 13 | 14 | state = { 15 | open: false, 16 | anchorEl: undefined 17 | } 18 | 19 | button = undefined 20 | 21 | handleClick = event => { 22 | this.setState({ open: true, anchorEl: event.currentTarget }) 23 | } 24 | 25 | handleRequestClose = () => { 26 | this.setState({ open: false }) 27 | } 28 | 29 | render() { 30 | const { options, src, alt } = this.props 31 | 32 | return ( 33 |
34 | {alt} 42 | 49 |

50 | {options.map(option => ( 51 |

62 | ))} 63 |
64 |
65 | ) 66 | } 67 | } 68 | 69 | export default MenuDrop 70 | -------------------------------------------------------------------------------- /webApp/components/Modal.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import { withStyles } from 'material-ui/styles' 4 | import List, { ListItem, ListItemText } from 'material-ui/List' 5 | import Dialog, { DialogTitle } from 'material-ui/Dialog' 6 | import Slide from 'material-ui/transitions/Slide' 7 | import Button from 'material-ui/Button' 8 | 9 | const styleRaisedButton = { 10 | borderRadius: '0px', 11 | textTransform: 'none', 12 | font: '15px Muli', 13 | fontWeight: '600', 14 | letterSpacing: '0.01em', 15 | color: 'white', 16 | backgroundColor: '#1a237e' 17 | } 18 | 19 | const styleSheet = { 20 | Dialog: { 21 | font: '15px Muli' 22 | // width: '360px' 23 | }, 24 | DialogTitle: { 25 | font: '15px Muli', 26 | fontSize: '20px', 27 | fontWeight: '300', 28 | padding: '20px' 29 | }, 30 | ListItemText: { 31 | font: '15px Muli', 32 | fontWeight: '300' 33 | } 34 | } 35 | 36 | const SimpleDialog = ({ options, classes, onRequestClose, title, ...other }) => ( 37 | } 42 | > 43 | 44 | {title} 45 | 46 |
47 | 48 | {options.map(option => ( 49 | 50 | 51 | 52 | ))} 53 | 54 |
55 | 58 |
59 |
60 |
61 |
62 | ) 63 | 64 | SimpleDialog.propTypes = { 65 | options: PropTypes.arrayOf(String).isRequired, 66 | classes: PropTypes.shape({}).isRequired, 67 | onRequestClose: PropTypes.func.isRequired, 68 | title: PropTypes.string.isRequired 69 | } 70 | 71 | const SimpleDialogWrapped = withStyles(styleSheet)(SimpleDialog) 72 | 73 | class Modal extends Component { 74 | static propTypes = { 75 | linkText: PropTypes.string.isRequired, 76 | title: PropTypes.string.isRequired, 77 | options: PropTypes.arrayOf(String).isRequired 78 | } 79 | 80 | state = { 81 | open: false 82 | } 83 | 84 | handleRequestClose = () => { 85 | this.setState({ open: false }) 86 | } 87 | 88 | render() { 89 | const { linkText, title } = this.props 90 | const options = this.props.options 91 | return ( 92 | 93 | this.setState({ open: true })} 97 | > 98 | {linkText} 99 | 100 | 106 | 107 | ) 108 | } 109 | } 110 | 111 | export default Modal 112 | -------------------------------------------------------------------------------- /webApp/components/Notifier.js: -------------------------------------------------------------------------------- 1 | import { Component } from 'react' 2 | import Snackbar from 'material-ui/Snackbar' 3 | 4 | let openSnackbarFn 5 | 6 | class Notifier extends Component { 7 | state = { 8 | open: false, 9 | type: 'success', 10 | message: '' 11 | } 12 | 13 | componentDidMount() { 14 | openSnackbarFn = this.openSnackbar 15 | } 16 | 17 | handleSnackbarRequestClose = () => { 18 | this.setState({ 19 | open: false, 20 | message: '', 21 | type: 'success' 22 | }) 23 | } 24 | 25 | openSnackbar = ({ message, type }) => { 26 | this.setState({ open: true, message, type }) 27 | } 28 | 29 | render() { 30 | const message = ( 31 | 32 | ) 33 | 34 | return ( 35 | 45 | ) 46 | } 47 | } 48 | 49 | export function openSnackbar({ message, type }) { 50 | openSnackbarFn({ message, type }) 51 | } 52 | 53 | export default Notifier 54 | -------------------------------------------------------------------------------- /webApp/components/SelectList.js: -------------------------------------------------------------------------------- 1 | import React, { Component } from 'react' 2 | import PropTypes from 'prop-types' 3 | import { withStyles } from 'material-ui/styles' 4 | import List, { ListItem, ListItemText } from 'material-ui/List' 5 | import Menu, { MenuItem } from 'material-ui/Menu' 6 | import KeyboardArrowDown from 'material-ui-icons/KeyboardArrowDown' 7 | 8 | const styleSheet = { 9 | root: { 10 | width: '100%', 11 | maxWidth: '200px', 12 | textAlign: 'right', 13 | backgroundColor: 'white' 14 | }, 15 | List: { 16 | padding: '0px', 17 | border: '1px solid rgba(26, 35, 126, 0.25)', 18 | marginBottom: '5px' 19 | }, 20 | MenuItem: { 21 | font: '14px Muli', 22 | fontWeight: '400' 23 | }, 24 | ListItem: { 25 | padding: '8px 5px', 26 | textAlign: 'center' 27 | }, 28 | ListItemText: { 29 | font: '14px Muli', 30 | fontWeight: '300', 31 | padding: '0px 5px' 32 | } 33 | } 34 | 35 | class SelectMenuList extends Component { 36 | static propTypes = { 37 | options: PropTypes.arrayOf(String).isRequired, 38 | values: PropTypes.arrayOf(String), 39 | onClick: PropTypes.func, 40 | secondary: PropTypes.string.isRequired, 41 | classes: PropTypes.shape({}).isRequired, 42 | selectedIndex: PropTypes.number 43 | } 44 | 45 | static defaultProps = { 46 | values: null, 47 | selectedIndex: null, 48 | onClick: null 49 | } 50 | 51 | state = { 52 | anchorEl: undefined, 53 | open: false, 54 | selectedIndex: 0 55 | } 56 | 57 | button = undefined 58 | 59 | handleClickListItem = event => { 60 | this.setState({ open: true, anchorEl: event.currentTarget }) 61 | } 62 | 63 | handleMenuItemClick = (event, index) => { 64 | this.setState({ selectedIndex: index, open: false }) 65 | const { onClick, values } = this.props 66 | 67 | if (onClick && values) { 68 | onClick(values[index]) 69 | } 70 | } 71 | 72 | handleRequestClose = () => { 73 | this.setState({ open: false }) 74 | } 75 | 76 | render() { 77 | const classes = this.props.classes 78 | const options = this.props.options 79 | 80 | const { secondary } = this.props 81 | const selectedIndex = this.props.selectedIndex || this.state.selectedIndex 82 | 83 | return ( 84 |
85 | 86 | 93 | 99 | 100 | 101 | 102 | 108 | {options.map((option, index) => ( 109 | this.handleMenuItemClick(event, index)} 114 | > 115 | {option} 116 | 117 | ))} 118 | 119 |
120 | ) 121 | } 122 | } 123 | 124 | const SelectMenuListWithStyle = withStyles(styleSheet)(SelectMenuList) 125 | 126 | const SelectList = ({ options, values, onClick, secondary, selectedIndex }) => ( 127 | 134 | ) 135 | 136 | SelectList.propTypes = { 137 | options: PropTypes.arrayOf(String).isRequired, 138 | values: PropTypes.arrayOf(String).isRequired, 139 | onClick: PropTypes.func.isRequired, 140 | secondary: PropTypes.string.isRequired, 141 | selectedIndex: PropTypes.number.isRequired 142 | } 143 | 144 | export default SelectList 145 | -------------------------------------------------------------------------------- /webApp/components/SharedStyles.js: -------------------------------------------------------------------------------- 1 | // shared style 2 | 3 | const styleToolbar = { 4 | background: '#FFF', 5 | height: '64px', 6 | paddingRight: '20px' 7 | } 8 | 9 | const styleMainNavLink = { 10 | margin: '0px 20px' 11 | } 12 | 13 | const mentorHeaderPic = { 14 | borderRadius: '50%', 15 | width: '42px', 16 | height: '42px', 17 | margin: '3px 0px 0px 0px' 18 | } 19 | 20 | const mentorPagePic = { 21 | borderRadius: '50%', 22 | width: '72px', 23 | height: '72px', 24 | margin: '15px 5px 0px' 25 | } 26 | 27 | const styleExternalLinkIcon = { 28 | width: '16px', 29 | opacity: '0.7', 30 | verticalAlign: 'middle', 31 | margin: '0px 0px 3px 4px' 32 | } 33 | 34 | const styleFlatButton = { 35 | borderRadius: '2px', 36 | textTransform: 'none', 37 | font: '15px Muli', 38 | fontWeight: '400', 39 | letterSpacing: '0.01em', 40 | color: '#0D47A1', 41 | backgroundColor: 'transparent' 42 | } 43 | 44 | const styleRaisedButton = { 45 | borderRadius: '2px', 46 | textTransform: 'none', 47 | font: '15px Muli', 48 | fontWeight: '600', 49 | letterSpacing: '0.01em', 50 | color: 'white', 51 | backgroundColor: '#0D47A1', 52 | '&:hover': { 53 | backgroundColor: 'white' 54 | } 55 | } 56 | 57 | const styleLoginButton = { 58 | borderRadius: '2px', 59 | textTransform: 'none', 60 | font: '15px Muli', 61 | fontWeight: '600', 62 | letterSpacing: '0.01em', 63 | color: 'white', 64 | backgroundColor: '#DF4930' 65 | } 66 | 67 | const styleRaisedFullWidthButton = { 68 | borderRadius: '2px', 69 | textTransform: 'none', 70 | font: '16px Muli', 71 | fontWeight: '300', 72 | letterSpacing: '0.01em', 73 | color: 'white', 74 | backgroundColor: '#1a237e', 75 | width: '100%', 76 | margin: '20px auto', 77 | '&:hover': { 78 | backgroundColor: 'white' 79 | } 80 | } 81 | 82 | const styleTextField = { 83 | font: '15px Muli', 84 | color: '#222', 85 | fontWeight: '300' 86 | } 87 | 88 | const styleForm = { 89 | margin: '7% auto', 90 | width: '360px' 91 | } 92 | 93 | const styleMainDiv = { 94 | width: '90%', 95 | margin: '25px auto' 96 | } 97 | 98 | const styleTextCenter = { 99 | textAlign: 'right' 100 | } 101 | 102 | module.exports = { 103 | styleToolbar, 104 | styleMainNavLink, 105 | mentorHeaderPic, 106 | mentorPagePic, 107 | styleExternalLinkIcon, 108 | styleFlatButton, 109 | styleRaisedButton, 110 | styleLoginButton, 111 | styleRaisedFullWidthButton, 112 | styleTextField, 113 | styleForm, 114 | styleMainDiv, 115 | styleTextCenter 116 | } 117 | -------------------------------------------------------------------------------- /webApp/components/Toggle.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import PropTypes from 'prop-types' 3 | import { FormControlLabel } from 'material-ui/Form' 4 | import Switch from 'material-ui/Switch' 5 | 6 | const Toggle = ({ checked, onChange, label }) => 7 | (
8 | this.setState({ checked: checked })} 13 | onChange={onChange} 14 | /> 15 | } 16 | label={label} 17 | /> 18 |
) 19 | 20 | Toggle.propTypes = { 21 | checked: PropTypes.bool.isRequired, 22 | onChange: PropTypes.func.isRequired, 23 | label: PropTypes.string.isRequired 24 | } 25 | 26 | export default Toggle 27 | -------------------------------------------------------------------------------- /webApp/env-config.js: -------------------------------------------------------------------------------- 1 | const prod = process.env.NODE_ENV === 'production' 2 | 3 | module.exports = { 4 | StripePublishableKey: prod 5 | ? 'pk_XXXXXX' 6 | : 'pk_XXXXXX' 7 | } 8 | -------------------------------------------------------------------------------- /webApp/lib/api.js: -------------------------------------------------------------------------------- 1 | import { updateUser } from './withAuth' 2 | 3 | const BASE_PATH = '/api/v1' 4 | 5 | export const changePrice = price => 6 | fetch(`${BASE_PATH}/change-price`, { 7 | method: 'POST', 8 | credentials: 'include', 9 | headers: { 10 | 'Content-type': 'application/json; charset=UTF-8' 11 | }, 12 | body: JSON.stringify({ price }) 13 | }) 14 | .then(res => res.json()) 15 | .then(res => { 16 | if (res.error) { 17 | return Promise.reject(new Error(res.error)) 18 | } 19 | 20 | updateUser({ price }) 21 | 22 | return Promise.resolve(res) 23 | }) 24 | 25 | export const changePageStatus = (isMentorPagePublic, cb) => 26 | fetch(`${BASE_PATH}/change-status`, { 27 | method: 'POST', 28 | credentials: 'include', 29 | headers: { 30 | 'Content-type': 'application/json; charset=UTF-8' 31 | }, 32 | body: JSON.stringify({ isMentorPagePublic }) 33 | }) 34 | .then(res => res.json()) 35 | .then(res => { 36 | if (res.error) { 37 | if (cb) { 38 | cb(new Error(res.error)) 39 | } 40 | 41 | return Promise.reject(new Error(res.error)) 42 | } 43 | 44 | updateUser({ isMentorPagePublic }) 45 | if (cb) { 46 | cb(null, res) 47 | } 48 | 49 | return Promise.resolve(res) 50 | }) 51 | .catch(err => { 52 | if (cb) { 53 | cb(err) 54 | } 55 | 56 | return Promise.reject(err) 57 | }) 58 | 59 | export const changeDescription = description => 60 | fetch(`${BASE_PATH}/change-description`, { 61 | method: 'POST', 62 | credentials: 'include', 63 | headers: { 64 | 'Content-type': 'application/json; charset=UTF-8' 65 | }, 66 | body: JSON.stringify({ description }) 67 | }) 68 | .then(res => res.json()) 69 | .then(res => { 70 | if (res.error) { 71 | return Promise.reject(new Error(res.error)) 72 | } 73 | 74 | updateUser({ description }) 75 | 76 | return Promise.resolve(res) 77 | }) 78 | 79 | export const updateProfile = () => 80 | fetch(`${BASE_PATH}/update-profile`, { 81 | method: 'GET', 82 | credentials: 'include', 83 | headers: { 84 | 'Content-type': 'application/json; charset=UTF-8' 85 | } 86 | }) 87 | .then(res => res.json()) 88 | .then(res => { 89 | if (res.error) { 90 | if (res.isGoogleAccessRevokedError) { 91 | setTimeout(() => { 92 | document.location = '/login?consent=1' 93 | }, 1000) 94 | 95 | return Promise.reject(new Error('Re-login is required. Logging out...')) 96 | } 97 | 98 | return Promise.reject(new Error(res.error)) 99 | } 100 | 101 | updateUser(res) 102 | 103 | return Promise.resolve(res) 104 | }) 105 | 106 | export const checkLabelsAndFilters = () => 107 | fetch(`${BASE_PATH}/check-labels-and-filters`, { 108 | method: 'GET', 109 | credentials: 'include', 110 | headers: { 111 | 'Content-type': 'application/json; charset=UTF-8' 112 | } 113 | }) 114 | .then(res => res.json()) 115 | .then(res => { 116 | if (res.error) { 117 | if (res.isGoogleAccessRevokedError) { 118 | setTimeout(() => { 119 | document.location = '/login?consent=1' 120 | }, 1000) 121 | 122 | return Promise.reject(new Error('Re-login is required. Logging out...')) 123 | } 124 | 125 | return Promise.reject(new Error(res.error)) 126 | } 127 | 128 | return Promise.resolve(res) 129 | }) 130 | 131 | export const getIncomeReport = () => 132 | fetch(`${BASE_PATH}/get-income-report`, { 133 | credentials: 'include', 134 | headers: { 135 | 'Content-type': 'application/json; charset=UTF-8' 136 | } 137 | }) 138 | .then(res => res.json()) 139 | .then(res => { 140 | if (res.error) { 141 | return Promise.reject(new Error(res.error)) 142 | } 143 | 144 | return Promise.resolve(res) 145 | }) 146 | 147 | export const getMentorList = () => 148 | fetch(`${BASE_PATH}/get-mentor-list`, { 149 | credentials: 'include', 150 | headers: { 151 | 'Content-type': 'application/json; charset=UTF-8' 152 | } 153 | }) 154 | .then(res => res.json()) 155 | .then(res => { 156 | if (res.error) { 157 | return Promise.reject(new Error(res.error)) 158 | } 159 | 160 | return Promise.resolve(res) 161 | }) 162 | -------------------------------------------------------------------------------- /webApp/lib/context.js: -------------------------------------------------------------------------------- 1 | import { create } from 'jss' 2 | import preset from 'jss-preset-default' 3 | import { SheetsRegistry } from 'react-jss/lib/jss' 4 | import { createMuiTheme } from 'material-ui/styles' 5 | import { blue, indigo } from 'material-ui/colors' 6 | import createGenerateClassName from 'material-ui/styles/createGenerateClassName' 7 | 8 | const theme = createMuiTheme({ 9 | palette: { 10 | primary: blue, 11 | secondary: indigo 12 | } 13 | }) 14 | 15 | // Configure JSS 16 | const jss = create(preset()) 17 | jss.options.createGenerateClassName = createGenerateClassName 18 | 19 | function createContext() { 20 | return { 21 | jss, 22 | theme, 23 | // This is needed in order to deduplicate the injection of CSS in the page. 24 | sheetsManager: new Map(), 25 | // This is needed in order to inject the critical CSS. 26 | sheetsRegistry: new SheetsRegistry() 27 | } 28 | } 29 | 30 | export default function getContext() { 31 | // Make sure to create a new store for every server-side request so that data 32 | // isn't shared between connections (which would be bad) 33 | if (!process.browser) { 34 | return createContext() 35 | } 36 | 37 | // Reuse context on the client-side 38 | if (!global.__INIT_MATERIAL_UI__) { 39 | global.__INIT_MATERIAL_UI__ = createContext() 40 | } 41 | 42 | return global.__INIT_MATERIAL_UI__ 43 | } 44 | -------------------------------------------------------------------------------- /webApp/lib/getRootURL.js: -------------------------------------------------------------------------------- 1 | export default function getRootURL() { 2 | const port = process.env.PORT || 8080 3 | const ROOT_URL = 4 | process.env.NODE_ENV === 'production' 5 | ? 'https://app.findharbor.com' 6 | : `http://localhost:${port}` 7 | 8 | return ROOT_URL 9 | } 10 | -------------------------------------------------------------------------------- /webApp/lib/notifier.js: -------------------------------------------------------------------------------- 1 | import { openSnackbar } from '../components/Notifier' 2 | 3 | export function success(message) { 4 | openSnackbar({ message, type: 'success' }) 5 | } 6 | 7 | export function error(err) { 8 | openSnackbar({ message: err.message || err.toString(), type: 'error' }) 9 | } 10 | -------------------------------------------------------------------------------- /webApp/lib/withAuth.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import PropTypes from 'prop-types' 3 | import Router from 'next/router' 4 | 5 | let globalUser = null 6 | 7 | export function updateUser({ price, description, isMentorPagePublic }) { 8 | if (globalUser) { 9 | if (price) { 10 | globalUser.price = Number(price) 11 | } 12 | 13 | if (description) { 14 | globalUser.description = description 15 | } 16 | 17 | if (isMentorPagePublic !== undefined) { 18 | globalUser.isMentorPagePublic = isMentorPagePublic 19 | } 20 | } 21 | } 22 | 23 | export default (Page, { loginRequired = true, logoutRequired = false } = {}) => 24 | class BaseComponent extends React.Component { 25 | static propTypes = { 26 | user: PropTypes.shape({ 27 | displayName: PropTypes.string, 28 | email: PropTypes.string.isRequired 29 | }), 30 | isFromServer: PropTypes.bool.isRequired 31 | } 32 | 33 | static defaultProps = { 34 | user: null 35 | } 36 | 37 | static async getInitialProps(ctx) { 38 | const isFromServer = !!ctx.req 39 | const user = ctx.req ? ctx.req.user && ctx.req.user.toObject() : globalUser 40 | 41 | if (isFromServer && user) { 42 | user._id = user._id.toString() 43 | } 44 | 45 | const props = { user, isFromServer } 46 | 47 | if (Page.getInitialProps) { 48 | Object.assign(props, (await Page.getInitialProps(ctx)) || {}) 49 | } 50 | 51 | return props 52 | } 53 | 54 | componentDidMount() { 55 | if (this.props.isFromServer) { 56 | globalUser = this.props.user 57 | } 58 | 59 | if (loginRequired && !logoutRequired && !this.props.user) { 60 | Router.push('/login') 61 | return 62 | } 63 | 64 | if (logoutRequired && this.props.user) { 65 | Router.push('/') 66 | } 67 | } 68 | 69 | render() { 70 | if (loginRequired && !logoutRequired && !this.props.user) { 71 | return null 72 | } 73 | 74 | if (logoutRequired && this.props.user) { 75 | return null 76 | } 77 | 78 | return 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /webApp/lib/withLayout.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import { withStyles, MuiThemeProvider } from 'material-ui/styles' 3 | import getContext from '../lib/context' 4 | 5 | import Router from 'next/router' 6 | 7 | import Header from '../components/Header' 8 | import Notifier from '../components/Notifier' 9 | 10 | Router.onAppUpdated = function onAppUpdated(nextRoute) { 11 | location.href = nextRoute 12 | } 13 | 14 | const styles = theme => ({ 15 | '@global': { 16 | html: { 17 | WebkitFontSmoothing: 'antialiased', // Antialiasing. 18 | MozOsxFontSmoothing: 'grayscale' // Antialiasing. 19 | }, 20 | body: { 21 | font: '15px Muli', 22 | color: '#222', 23 | margin: '0px auto', 24 | fontWeight: '300', 25 | lineHeight: '1.5em', 26 | backgroundColor: '#F7F9FC' 27 | }, 28 | span: { 29 | fontFamily: 'Muli !important' 30 | } 31 | } 32 | }) 33 | 34 | let AppWrapper = props => props.children 35 | 36 | AppWrapper = withStyles(styles)(AppWrapper) 37 | 38 | function withLayout(BaseComponent, { noHeader = false } = {}) { 39 | class App extends React.Component { 40 | static getInitialProps(ctx) { 41 | if (BaseComponent.getInitialProps) { 42 | return BaseComponent.getInitialProps(ctx) 43 | } 44 | 45 | return {} 46 | } 47 | 48 | componentWillMount() { 49 | this.styleContext = getContext() 50 | } 51 | 52 | componentDidMount() { 53 | // Remove the server-side injected CSS. 54 | const jssStyles = document.querySelector('#jss-server-side') 55 | if (jssStyles && jssStyles.parentNode) { 56 | jssStyles.parentNode.removeChild(jssStyles) 57 | } 58 | } 59 | 60 | render() { 61 | return ( 62 | 66 |
67 | {noHeader ? null :
} 68 | 69 | 70 | 71 | 72 |
73 |
74 | ) 75 | } 76 | } 77 | 78 | return App 79 | } 80 | 81 | export default withLayout 82 | -------------------------------------------------------------------------------- /webApp/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "harbor", 3 | "version": "0.0.1", 4 | "scripts": { 5 | "dev": "nodemon server/app.js --watch server --exec babel-node", 6 | "dev2": "USE_MONGO_TEST2=1 nodemon server/app.js --watch server --exec babel-node", 7 | "build": "next build", 8 | "start": "NODE_ENV=production ROOT_URL=https://app.findharbor.com babel-node server/app.js", 9 | "test-gmail-sent-email": "TEST_FROM_CLI=1 babel-node server/gmail/checkSentEmails.js", 10 | "lint": "eslint components pages lib server", 11 | "test": "jest --coverage" 12 | }, 13 | "jest": { 14 | "coverageDirectory": "./.coverage", 15 | "roots": [ 16 | "test/" 17 | ] 18 | }, 19 | "dependencies": { 20 | "next": "^4.0.3", 21 | "react": "^16.0.0", 22 | "react-dom": "^16.0.0", 23 | "aws-sdk": "^2.102.0", 24 | "babel-cli": "^6.26.0", 25 | "babel-plugin-transform-define": "^1.3.0", 26 | "body-parser": "^1.17.2", 27 | "connect-mongo": "^2.0.0", 28 | "dotenv": "^4.0.0", 29 | "email-addresses": "^3.0.1", 30 | "express": "^4.15.4", 31 | "express-session": "^1.15.3", 32 | "googleapis": "^20.0.1", 33 | "handlebars": "^4.0.10", 34 | "isomorphic-fetch": "^2.2.1", 35 | "jss": "^8.1.0", 36 | "jss-preset-default": "^3.0.0", 37 | "lodash": "^4.17.4", 38 | "material-ui": "^1.0.0-alpha.21", 39 | "material-ui-icons": "^1.0.0-alpha.19", 40 | "moment": "^2.18.1", 41 | "mongoose": "^4.12.1", 42 | "nprogress": "^0.2.0", 43 | "passport": "^0.3.2", 44 | "passport-strategy": "^1.0.0", 45 | "prop-types": "^15.5.10", 46 | "qs": "^6.5.0", 47 | "react-clipboard.js": "^1.1.2", 48 | "react-jss": "^7.0.2", 49 | "react-stripe-checkout": "^2.6.3", 50 | "request": "^2.81.0", 51 | "sitemap": "^1.13.0", 52 | "stripe": "^4.24.0", 53 | "winston": "^2.3.1" 54 | }, 55 | "devDependencies": { 56 | "babel-plugin-transform-define": "^1.3.0", 57 | "babel-preset-env": "^1.6.0", 58 | "jest": "^21.2.1", 59 | "nodemon": "^1.11.0" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /webApp/pages/_document.js: -------------------------------------------------------------------------------- 1 | import React from 'react' 2 | import Document, { Head, Main, NextScript } from 'next/document' 3 | import JssProvider from 'react-jss/lib/JssProvider' 4 | import getContext from '../lib/context' 5 | 6 | class MyDocument extends Document { 7 | render() { 8 | return ( 9 | 10 | 11 | 15 | 16 | {/* Use minimum-scale=1 to enable GPU rasterization */} 17 | 24 | 25 | 26 | {/* PWA primary color */} 27 | 28 | 33 | 34 | 63 | 64 | 65 |
66 | 67 | 68 | 69 | ) 70 | } 71 | } 72 | 73 | MyDocument.getInitialProps = ctx => { 74 | // Get the context to collected side effects. 75 | const context = getContext() 76 | const page = ctx.renderPage(Component => props => ( 77 | 78 | 79 | 80 | )) 81 | 82 | return { 83 | ...page, 84 | stylesContext: context, 85 | styles: ( 86 |