Initial commit
30
website/.editorconfig
Normal file
@@ -0,0 +1,30 @@
|
||||
# http://editorconfig.org
|
||||
|
||||
# A special property that should be specified at the top of the file outside of
|
||||
# any sections. Set to true to stop .editor config file search on current file
|
||||
root = true
|
||||
|
||||
[*]
|
||||
# Indentation style
|
||||
# Possible values - tab, space
|
||||
indent_style = space
|
||||
|
||||
# Indentation size in single-spaced characters
|
||||
# Possible values - an integer, tab
|
||||
indent_size = 2
|
||||
|
||||
# Line ending file format
|
||||
# Possible values - lf, crlf, cr
|
||||
end_of_line = lf
|
||||
|
||||
# File character encoding
|
||||
# Possible values - latin1, utf-8, utf-16be, utf-16le
|
||||
charset = utf-8
|
||||
|
||||
# Denotes whether to trim whitespace at the end of lines
|
||||
# Possible values - true, false
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
# Denotes whether file should end with a newline
|
||||
# Possible values - true, false
|
||||
insert_final_newline = true
|
||||
5
website/.eslintignore
Normal file
@@ -0,0 +1,5 @@
|
||||
blueprints/**/files/**
|
||||
coverage/**
|
||||
node_modules/**
|
||||
dist/**
|
||||
src/index.html
|
||||
27
website/.eslintrc
Normal file
@@ -0,0 +1,27 @@
|
||||
{
|
||||
"parser": "babel-eslint",
|
||||
"extends": [
|
||||
"standard",
|
||||
"standard-react"
|
||||
],
|
||||
"plugins": [
|
||||
"babel",
|
||||
"react",
|
||||
"promise"
|
||||
],
|
||||
"env": {
|
||||
"browser" : true
|
||||
},
|
||||
"globals": {
|
||||
"__DEV__" : false,
|
||||
"__TEST__" : false,
|
||||
"__PROD__" : false,
|
||||
"__COVERAGE__" : false
|
||||
},
|
||||
"rules": {
|
||||
"key-spacing" : 0,
|
||||
"jsx-quotes" : [2, "prefer-single"],
|
||||
"object-curly-spacing" : [2, "always"],
|
||||
"space-before-function-paren": ["error", "never"]
|
||||
}
|
||||
}
|
||||
7
website/.gitignore
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
node_modules/
|
||||
coverage/
|
||||
dist/
|
||||
.DS_Store
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
17
website/build/asset-manifest.json
Normal file
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"main.css": "static/css/main.b7f40099.css",
|
||||
"main.css.map": "static/css/main.b7f40099.css.map",
|
||||
"main.js": "static/js/main.0feff0e8.js",
|
||||
"main.js.map": "static/js/main.0feff0e8.js.map",
|
||||
"static/media/extensive-tracking.jpg": "static/media/extensive-tracking.30e779c7.jpg",
|
||||
"static/media/flags.png": "static/media/flags.9c74e172.png",
|
||||
"static/media/icons.eot": "static/media/icons.674f50d2.eot",
|
||||
"static/media/icons.svg": "static/media/icons.912ec66d.svg",
|
||||
"static/media/icons.ttf": "static/media/icons.b06871f2.ttf",
|
||||
"static/media/icons.woff": "static/media/icons.fee66e71.woff",
|
||||
"static/media/icons.woff2": "static/media/icons.af7ae505.woff2",
|
||||
"static/media/masthead-main.png": "static/media/masthead-main.d693e54f.png",
|
||||
"static/media/on-site-support.jpg": "static/media/on-site-support.33bd1985.jpg",
|
||||
"static/media/package-building.jpg": "static/media/package-building.a6760708.jpg",
|
||||
"static/media/pre-transitioning.jpg": "static/media/pre-transitioning.3c463a20.jpg"
|
||||
}
|
||||
BIN
website/build/favicon.ico
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
website/build/favicon.png
Normal file
|
After Width: | Height: | Size: 910 B |
1
website/build/index.html
Normal file
@@ -0,0 +1 @@
|
||||
<!DOCTYPE html><html lang="en"><head><title>Transition Management Resources</title><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><link rel="shortcut icon" href="/favicon.png"><link href="/static/css/main.b7f40099.css" rel="stylesheet"></head><body><div id="root"></div><script type="text/javascript" src="/static/js/main.0feff0e8.js"></script></body></html>
|
||||
1
website/build/service-worker.js
Normal file
@@ -0,0 +1 @@
|
||||
"use strict";function setOfCachedUrls(e){return e.keys().then(function(e){return e.map(function(e){return e.url})}).then(function(e){return new Set(e)})}var precacheConfig=[["index.html","126facc11926a6f959086e2959a7770d"],["static/css/main.b7f40099.css","4fd28be2ca811a2f8586205d31a8d4ce"],["static/js/main.0feff0e8.js","85f38f3b5f4c9732f4b87d6226f21b2a"],["static/media/extensive-tracking.30e779c7.jpg","30e779c7aeb3f0930f0be1bba2793e46"],["static/media/flags.9c74e172.png","9c74e172f87984c48ddf5c8108cabe67"],["static/media/icons.674f50d2.eot","674f50d287a8c48dc19ba404d20fe713"],["static/media/icons.912ec66d.svg","912ec66d7572ff821749319396470bde"],["static/media/icons.af7ae505.woff2","af7ae505a9eed503f8b8e6982036873e"],["static/media/icons.b06871f2.ttf","b06871f281fee6b241d60582ae9369b9"],["static/media/icons.fee66e71.woff","fee66e712a8a08eef5805a46892932ad"],["static/media/masthead-main.d693e54f.png","d693e54ff591fe3586a5892ff490b8f9"],["static/media/on-site-support.33bd1985.jpg","33bd198571ce8fc479bceb92ea9ac445"],["static/media/package-building.a6760708.jpg","a676070868179299328607a1f91bed11"],["static/media/pre-transitioning.3c463a20.jpg","3c463a203156bbfbfb1331d8f2f8164b"]],cacheName="sw-precache-v3-sw-precache-webpack-plugin-"+(self.registration?self.registration.scope:""),ignoreUrlParametersMatching=[/^utm_/],addDirectoryIndex=function(e,t){var n=new URL(e);return"/"===n.pathname.slice(-1)&&(n.pathname+=t),n.toString()},cleanResponse=function(e){return e.redirected?("body"in e?Promise.resolve(e.body):e.blob()).then(function(t){return new Response(t,{headers:e.headers,status:e.status,statusText:e.statusText})}):Promise.resolve(e)},createCacheKey=function(e,t,n,a){var r=new URL(e);return a&&r.pathname.match(a)||(r.search+=(r.search?"&":"")+encodeURIComponent(t)+"="+encodeURIComponent(n)),r.toString()},isPathWhitelisted=function(e,t){if(0===e.length)return!0;var n=new URL(t).pathname;return e.some(function(e){return n.match(e)})},stripIgnoredUrlParameters=function(e,t){var n=new URL(e);return n.hash="",n.search=n.search.slice(1).split("&").map(function(e){return e.split("=")}).filter(function(e){return t.every(function(t){return!t.test(e[0])})}).map(function(e){return e.join("=")}).join("&"),n.toString()},hashParamName="_sw-precache",urlsToCacheKeys=new Map(precacheConfig.map(function(e){var t=e[0],n=e[1],a=new URL(t,self.location),r=createCacheKey(a,hashParamName,n,/\.\w{8}\./);return[a.toString(),r]}));self.addEventListener("install",function(e){e.waitUntil(caches.open(cacheName).then(function(e){return setOfCachedUrls(e).then(function(t){return Promise.all(Array.from(urlsToCacheKeys.values()).map(function(n){if(!t.has(n)){var a=new Request(n,{credentials:"same-origin"});return fetch(a).then(function(t){if(!t.ok)throw new Error("Request for "+n+" returned a response with status "+t.status);return cleanResponse(t).then(function(t){return e.put(n,t)})})}}))})}).then(function(){return self.skipWaiting()}))}),self.addEventListener("activate",function(e){var t=new Set(urlsToCacheKeys.values());e.waitUntil(caches.open(cacheName).then(function(e){return e.keys().then(function(n){return Promise.all(n.map(function(n){if(!t.has(n.url))return e.delete(n)}))})}).then(function(){return self.clients.claim()}))}),self.addEventListener("fetch",function(e){if("GET"===e.request.method){var t,n=stripIgnoredUrlParameters(e.request.url,ignoreUrlParametersMatching);t=urlsToCacheKeys.has(n);t||(n=addDirectoryIndex(n,"index.html"),t=urlsToCacheKeys.has(n));!t&&"navigate"===e.request.mode&&isPathWhitelisted(["^(?!\\/__).*"],e.request.url)&&(n=new URL("/index.html",self.location).toString(),t=urlsToCacheKeys.has(n)),t&&e.respondWith(caches.open(cacheName).then(function(e){return e.match(urlsToCacheKeys.get(n)).then(function(e){if(e)return e;throw Error("The cached response that was expected is missing.")})}).catch(function(t){return console.warn('Couldn\'t serve response for "%s" from cache: %O',e.request.url,t),fetch(e.request)}))}});
|
||||
355
website/build/static/css/main.b7f40099.css
Normal file
1
website/build/static/css/main.b7f40099.css.map
Normal file
2
website/build/static/js/main.0feff0e8.js
Normal file
1
website/build/static/js/main.0feff0e8.js.map
Normal file
BIN
website/build/static/media/extensive-tracking.30e779c7.jpg
Normal file
|
After Width: | Height: | Size: 250 KiB |
BIN
website/build/static/media/flags.9c74e172.png
Normal file
|
After Width: | Height: | Size: 28 KiB |
BIN
website/build/static/media/icons.674f50d2.eot
Normal file
2671
website/build/static/media/icons.912ec66d.svg
Normal file
|
After Width: | Height: | Size: 434 KiB |
BIN
website/build/static/media/icons.af7ae505.woff2
Normal file
BIN
website/build/static/media/icons.b06871f2.ttf
Normal file
BIN
website/build/static/media/icons.fee66e71.woff
Normal file
BIN
website/build/static/media/masthead-main.d693e54f.png
Normal file
|
After Width: | Height: | Size: 1.3 MiB |
BIN
website/build/static/media/on-site-support.33bd1985.jpg
Normal file
|
After Width: | Height: | Size: 272 KiB |
BIN
website/build/static/media/package-building.a6760708.jpg
Normal file
|
After Width: | Height: | Size: 199 KiB |
BIN
website/build/static/media/pre-transitioning.3c463a20.jpg
Normal file
|
After Width: | Height: | Size: 299 KiB |
93
website/config/env.js
Normal file
@@ -0,0 +1,93 @@
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
const paths = require('./paths');
|
||||
|
||||
// Make sure that including paths.js after env.js will read .env variables.
|
||||
delete require.cache[require.resolve('./paths')];
|
||||
|
||||
const NODE_ENV = process.env.NODE_ENV;
|
||||
if (!NODE_ENV) {
|
||||
throw new Error(
|
||||
'The NODE_ENV environment variable is required but was not specified.'
|
||||
);
|
||||
}
|
||||
|
||||
// https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use
|
||||
var dotenvFiles = [
|
||||
`${paths.dotenv}.${NODE_ENV}.local`,
|
||||
`${paths.dotenv}.${NODE_ENV}`,
|
||||
// Don't include `.env.local` for `test` environment
|
||||
// since normally you expect tests to produce the same
|
||||
// results for everyone
|
||||
NODE_ENV !== 'test' && `${paths.dotenv}.local`,
|
||||
paths.dotenv,
|
||||
].filter(Boolean);
|
||||
|
||||
// Load environment variables from .env* files. Suppress warnings using silent
|
||||
// if this file is missing. dotenv will never modify any environment variables
|
||||
// that have already been set. Variable expansion is supported in .env files.
|
||||
// https://github.com/motdotla/dotenv
|
||||
// https://github.com/motdotla/dotenv-expand
|
||||
dotenvFiles.forEach(dotenvFile => {
|
||||
if (fs.existsSync(dotenvFile)) {
|
||||
require('dotenv-expand')(
|
||||
require('dotenv').config({
|
||||
path: dotenvFile,
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
// We support resolving modules according to `NODE_PATH`.
|
||||
// This lets you use absolute paths in imports inside large monorepos:
|
||||
// https://github.com/facebookincubator/create-react-app/issues/253.
|
||||
// It works similar to `NODE_PATH` in Node itself:
|
||||
// https://nodejs.org/api/modules.html#modules_loading_from_the_global_folders
|
||||
// Note that unlike in Node, only *relative* paths from `NODE_PATH` are honored.
|
||||
// Otherwise, we risk importing Node.js core modules into an app instead of Webpack shims.
|
||||
// https://github.com/facebookincubator/create-react-app/issues/1023#issuecomment-265344421
|
||||
// We also resolve them to make sure all tools using them work consistently.
|
||||
const appDirectory = fs.realpathSync(process.cwd());
|
||||
process.env.NODE_PATH = (process.env.NODE_PATH || '')
|
||||
.split(path.delimiter)
|
||||
.filter(folder => folder && !path.isAbsolute(folder))
|
||||
.map(folder => path.resolve(appDirectory, folder))
|
||||
.join(path.delimiter);
|
||||
|
||||
// Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
|
||||
// injected into the application via DefinePlugin in Webpack configuration.
|
||||
const REACT_APP = /^REACT_APP_/i;
|
||||
|
||||
function getClientEnvironment(publicUrl) {
|
||||
const raw = Object.keys(process.env)
|
||||
.filter(key => REACT_APP.test(key))
|
||||
.reduce(
|
||||
(env, key) => {
|
||||
env[key] = process.env[key];
|
||||
return env;
|
||||
},
|
||||
{
|
||||
// Useful for determining whether we’re running in production mode.
|
||||
// Most importantly, it switches React into the correct mode.
|
||||
NODE_ENV: process.env.NODE_ENV || 'development',
|
||||
// Useful for resolving the correct path to static assets in `public`.
|
||||
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
|
||||
// This should only be used as an escape hatch. Normally you would put
|
||||
// images into the `src` and `import` them in code to get their paths.
|
||||
PUBLIC_URL: publicUrl,
|
||||
}
|
||||
);
|
||||
// Stringify all values so we can feed into Webpack DefinePlugin
|
||||
const stringified = {
|
||||
'process.env': Object.keys(raw).reduce((env, key) => {
|
||||
env[key] = JSON.stringify(raw[key]);
|
||||
return env;
|
||||
}, {}),
|
||||
};
|
||||
|
||||
return { raw, stringified };
|
||||
}
|
||||
|
||||
module.exports = getClientEnvironment;
|
||||
14
website/config/jest/cssTransform.js
Normal file
@@ -0,0 +1,14 @@
|
||||
'use strict';
|
||||
|
||||
// This is a custom Jest transformer turning style imports into empty objects.
|
||||
// http://facebook.github.io/jest/docs/en/webpack.html
|
||||
|
||||
module.exports = {
|
||||
process() {
|
||||
return 'module.exports = {};';
|
||||
},
|
||||
getCacheKey() {
|
||||
// The output is always the same.
|
||||
return 'cssTransform';
|
||||
},
|
||||
};
|
||||
12
website/config/jest/fileTransform.js
Normal file
@@ -0,0 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
|
||||
// This is a custom Jest transformer turning file imports into filenames.
|
||||
// http://facebook.github.io/jest/docs/en/webpack.html
|
||||
|
||||
module.exports = {
|
||||
process(src, filename) {
|
||||
return `module.exports = ${JSON.stringify(path.basename(filename))};`;
|
||||
},
|
||||
};
|
||||
55
website/config/paths.js
Normal file
@@ -0,0 +1,55 @@
|
||||
'use strict';
|
||||
|
||||
const path = require('path');
|
||||
const fs = require('fs');
|
||||
const url = require('url');
|
||||
|
||||
// Make sure any symlinks in the project folder are resolved:
|
||||
// https://github.com/facebookincubator/create-react-app/issues/637
|
||||
const appDirectory = fs.realpathSync(process.cwd());
|
||||
const resolveApp = relativePath => path.resolve(appDirectory, relativePath);
|
||||
|
||||
const envPublicUrl = process.env.PUBLIC_URL;
|
||||
|
||||
function ensureSlash(path, needsSlash) {
|
||||
const hasSlash = path.endsWith('/');
|
||||
if (hasSlash && !needsSlash) {
|
||||
return path.substr(path, path.length - 1);
|
||||
} else if (!hasSlash && needsSlash) {
|
||||
return `${path}/`;
|
||||
} else {
|
||||
return path;
|
||||
}
|
||||
}
|
||||
|
||||
const getPublicUrl = appPackageJson =>
|
||||
envPublicUrl || require(appPackageJson).homepage;
|
||||
|
||||
// We use `PUBLIC_URL` environment variable or "homepage" field to infer
|
||||
// "public path" at which the app is served.
|
||||
// Webpack needs to know it to put the right <script> hrefs into HTML even in
|
||||
// single-page apps that may serve index.html for nested URLs like /todos/42.
|
||||
// We can't use a relative path in HTML because we don't want to load something
|
||||
// like /todos/42/static/js/bundle.7289d.js. We have to know the root.
|
||||
function getServedPath(appPackageJson) {
|
||||
const publicUrl = getPublicUrl(appPackageJson);
|
||||
const servedUrl =
|
||||
envPublicUrl || (publicUrl ? url.parse(publicUrl).pathname : '/');
|
||||
return ensureSlash(servedUrl, true);
|
||||
}
|
||||
|
||||
// config after eject: we're in ./config/
|
||||
module.exports = {
|
||||
dotenv: resolveApp('.env'),
|
||||
appBuild: resolveApp('build'),
|
||||
appPublic: resolveApp('public'),
|
||||
appHtml: resolveApp('public/index.html'),
|
||||
appIndexJs: resolveApp('src/index.js'),
|
||||
appPackageJson: resolveApp('package.json'),
|
||||
appSrc: resolveApp('src'),
|
||||
yarnLockFile: resolveApp('yarn.lock'),
|
||||
testsSetup: resolveApp('src/setupTests.js'),
|
||||
appNodeModules: resolveApp('node_modules'),
|
||||
publicUrl: getPublicUrl(resolveApp('package.json')),
|
||||
servedPath: getServedPath(resolveApp('package.json')),
|
||||
};
|
||||
22
website/config/polyfills.js
Normal file
@@ -0,0 +1,22 @@
|
||||
'use strict';
|
||||
|
||||
if (typeof Promise === 'undefined') {
|
||||
// Rejection tracking prevents a common issue where React gets into an
|
||||
// inconsistent state due to an error, but it gets swallowed by a Promise,
|
||||
// and the user has no idea what causes React's erratic future behavior.
|
||||
require('promise/lib/rejection-tracking').enable();
|
||||
window.Promise = require('promise/lib/es6-extensions.js');
|
||||
}
|
||||
|
||||
// fetch() polyfill for making API calls.
|
||||
require('whatwg-fetch');
|
||||
|
||||
// Object.assign() is commonly used with React.
|
||||
// It will use the native implementation if it's present and isn't buggy.
|
||||
Object.assign = require('object-assign');
|
||||
|
||||
// In tests, polyfill requestAnimationFrame since jsdom doesn't provide it yet.
|
||||
// We don't polyfill it in the browser--this is user's responsibility.
|
||||
if (process.env.NODE_ENV === 'test') {
|
||||
require('raf').polyfill(global);
|
||||
}
|
||||
271
website/config/webpack.config.dev.js
Normal file
@@ -0,0 +1,271 @@
|
||||
'use strict';
|
||||
|
||||
const autoprefixer = require('autoprefixer');
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const CaseSensitivePathsPlugin = require('case-sensitive-paths-webpack-plugin');
|
||||
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
||||
const WatchMissingNodeModulesPlugin = require('react-dev-utils/WatchMissingNodeModulesPlugin');
|
||||
const eslintFormatter = require('react-dev-utils/eslintFormatter');
|
||||
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
||||
const getClientEnvironment = require('./env');
|
||||
const paths = require('./paths');
|
||||
|
||||
// Webpack uses `publicPath` to determine where the app is being served from.
|
||||
// In development, we always serve from the root. This makes config easier.
|
||||
const publicPath = '/';
|
||||
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
||||
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
||||
// Omit trailing slash as %PUBLIC_PATH%/xyz looks better than %PUBLIC_PATH%xyz.
|
||||
const publicUrl = '';
|
||||
// Get environment variables to inject into our app.
|
||||
const env = getClientEnvironment(publicUrl);
|
||||
const srcPath = path.resolve(__dirname, '../src/')
|
||||
|
||||
// This is the development configuration.
|
||||
// It is focused on developer experience and fast rebuilds.
|
||||
// The production configuration is different and lives in a separate file.
|
||||
module.exports = {
|
||||
// You may want 'eval' instead if you prefer to see the compiled output in DevTools.
|
||||
// See the discussion in https://github.com/facebookincubator/create-react-app/issues/343.
|
||||
devtool: 'cheap-module-source-map',
|
||||
// These are the "entry points" to our application.
|
||||
// This means they will be the "root" imports that are included in JS bundle.
|
||||
// The first two entry points enable "hot" CSS and auto-refreshes for JS.
|
||||
entry: [
|
||||
// We ship a few polyfills by default:
|
||||
require.resolve('./polyfills'),
|
||||
// Include an alternative client for WebpackDevServer. A client's job is to
|
||||
// connect to WebpackDevServer by a socket and get notified about changes.
|
||||
// When you save a file, the client will either apply hot updates (in case
|
||||
// of CSS changes), or refresh the page (in case of JS changes). When you
|
||||
// make a syntax error, this client will display a syntax error overlay.
|
||||
// Note: instead of the default WebpackDevServer client, we use a custom one
|
||||
// to bring better experience for Create React App users. You can replace
|
||||
// the line below with these two lines if you prefer the stock client:
|
||||
// require.resolve('webpack-dev-server/client') + '?/',
|
||||
// require.resolve('webpack/hot/dev-server'),
|
||||
require.resolve('react-dev-utils/webpackHotDevClient'),
|
||||
// Finally, this is your app's code:
|
||||
paths.appIndexJs,
|
||||
// We include the app code last so that if there is a runtime error during
|
||||
// initialization, it doesn't blow up the WebpackDevServer client, and
|
||||
// changing JS code would still trigger a refresh.
|
||||
],
|
||||
output: {
|
||||
// Add /* filename */ comments to generated require()s in the output.
|
||||
pathinfo: true,
|
||||
// This does not produce a real file. It's just the virtual path that is
|
||||
// served by WebpackDevServer in development. This is the JS bundle
|
||||
// containing code from all our entry points, and the Webpack runtime.
|
||||
filename: 'static/js/bundle.js',
|
||||
// There are also additional JS chunk files if you use code splitting.
|
||||
chunkFilename: 'static/js/[name].chunk.js',
|
||||
// This is the URL that app is served from. We use "/" in development.
|
||||
publicPath: publicPath,
|
||||
// Point sourcemap entries to original disk location (format as URL on Windows)
|
||||
devtoolModuleFilenameTemplate: info =>
|
||||
path.resolve(info.absoluteResourcePath).replace(/\\/g, '/'),
|
||||
},
|
||||
resolve: {
|
||||
// This allows you to set a fallback for where Webpack should look for modules.
|
||||
// We placed these paths second because we want `node_modules` to "win"
|
||||
// if there are any conflicts. This matches Node resolution mechanism.
|
||||
// https://github.com/facebookincubator/create-react-app/issues/253
|
||||
modules: ['node_modules', paths.appNodeModules].concat(
|
||||
// It is guaranteed to exist because we tweak it in `env.js`
|
||||
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
||||
),
|
||||
// These are the reasonable defaults supported by the Node ecosystem.
|
||||
// We also include JSX as a common component filename extension to support
|
||||
// some tools, although we do not recommend using it, see:
|
||||
// https://github.com/facebookincubator/create-react-app/issues/290
|
||||
// `web` extension prefixes have been added for better support
|
||||
// for React Native Web.
|
||||
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
|
||||
alias: {
|
||||
// Support React Native Web
|
||||
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
||||
'react-native': 'react-native-web',
|
||||
'styles': path.join(srcPath, '/assets/styles/'),
|
||||
'images': path.join(srcPath, '/assets/images/'),
|
||||
'icons': path.join(srcPath, '/assets/icons/'),
|
||||
'data': path.join(srcPath, '/assets/data/'),
|
||||
'fonts': path.join(srcPath, '/assets/fonts/'),
|
||||
'src': srcPath,
|
||||
},
|
||||
plugins: [
|
||||
// Prevents users from importing files from outside of src/ (or node_modules/).
|
||||
// This often causes confusion because we only process files within src/ with babel.
|
||||
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
||||
// please link the files into your node_modules/ and let module-resolution kick in.
|
||||
// Make sure your source files are compiled, as they will not be processed in any way.
|
||||
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
||||
],
|
||||
},
|
||||
module: {
|
||||
strictExportPresence: true,
|
||||
rules: [
|
||||
// TODO: Disable require.ensure as it's not a standard language feature.
|
||||
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
|
||||
// { parser: { requireEnsure: false } },
|
||||
|
||||
// First, run the linter.
|
||||
// It's important to do this before Babel processes the JS.
|
||||
{
|
||||
test: /\.(js|jsx|mjs)$/,
|
||||
enforce: 'pre',
|
||||
use: [
|
||||
{
|
||||
options: {
|
||||
formatter: eslintFormatter,
|
||||
eslintPath: require.resolve('eslint'),
|
||||
|
||||
},
|
||||
loader: require.resolve('eslint-loader'),
|
||||
},
|
||||
],
|
||||
include: paths.appSrc,
|
||||
},
|
||||
{
|
||||
// "oneOf" will traverse all following loaders until one will
|
||||
// match the requirements. When no loader matches it will fall
|
||||
// back to the "file" loader at the end of the loader list.
|
||||
oneOf: [
|
||||
// "url" loader works like "file" loader except that it embeds assets
|
||||
// smaller than specified limit in bytes as data URLs to avoid requests.
|
||||
// A missing `test` is equivalent to a match.
|
||||
{
|
||||
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
||||
loader: require.resolve('url-loader'),
|
||||
options: {
|
||||
limit: 10000,
|
||||
name: 'static/media/[name].[hash:8].[ext]',
|
||||
},
|
||||
},
|
||||
// Process JS with Babel.
|
||||
{
|
||||
test: /\.(js|jsx|mjs)$/,
|
||||
include: paths.appSrc,
|
||||
loader: require.resolve('babel-loader'),
|
||||
options: {
|
||||
|
||||
// This is a feature of `babel-loader` for webpack (not Babel itself).
|
||||
// It enables caching results in ./node_modules/.cache/babel-loader/
|
||||
// directory for faster rebuilds.
|
||||
cacheDirectory: true,
|
||||
},
|
||||
},
|
||||
// "postcss" loader applies autoprefixer to our CSS.
|
||||
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
||||
// "style" loader turns CSS into JS modules that inject <style> tags.
|
||||
// In production, we use a plugin to extract that CSS to a file, but
|
||||
// in development "style" loader enables hot editing of CSS.
|
||||
{
|
||||
test: /\.(sass|scss)$/,
|
||||
use: [
|
||||
require.resolve('style-loader'),
|
||||
{
|
||||
loader: require.resolve('css-loader'),
|
||||
options: {
|
||||
importLoaders: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
loader: require.resolve('sass-loader'),
|
||||
},
|
||||
{
|
||||
loader: require.resolve('postcss-loader'),
|
||||
options: {
|
||||
// Necessary for external CSS imports to work
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2677
|
||||
ident: 'postcss',
|
||||
plugins: () => [
|
||||
require('postcss-flexbugs-fixes'),
|
||||
autoprefixer({
|
||||
browsers: [
|
||||
'>1%',
|
||||
'last 4 versions',
|
||||
'Firefox ESR',
|
||||
'not ie < 9', // React doesn't support IE8 anyway
|
||||
],
|
||||
flexbox: 'no-2009',
|
||||
}),
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
// "file" loader makes sure those assets get served by WebpackDevServer.
|
||||
// When you `import` an asset, you get its (virtual) filename.
|
||||
// In production, they would get copied to the `build` folder.
|
||||
// This loader doesn't use a "test" so it will catch all modules
|
||||
// that fall through the other loaders.
|
||||
{
|
||||
// Exclude `js` files to keep "css" loader working as it injects
|
||||
// it's runtime that would otherwise processed through "file" loader.
|
||||
// Also exclude `html` and `json` extensions so they get processed
|
||||
// by webpacks internal loaders.
|
||||
exclude: [/\.(js|jsx|mjs)$/, /\.html$/, /\.json$/],
|
||||
loader: require.resolve('file-loader'),
|
||||
options: {
|
||||
name: 'static/media/[name].[hash:8].[ext]',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
// ** STOP ** Are you adding a new loader?
|
||||
// Make sure to add the new loader(s) before the "file" loader.
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
// Makes some environment variables available in index.html.
|
||||
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
||||
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||
// In development, this will be an empty string.
|
||||
new InterpolateHtmlPlugin(env.raw),
|
||||
// Generates an `index.html` file with the <script> injected.
|
||||
new HtmlWebpackPlugin({
|
||||
inject: true,
|
||||
template: paths.appHtml,
|
||||
}),
|
||||
// Add module names to factory functions so they appear in browser profiler.
|
||||
new webpack.NamedModulesPlugin(),
|
||||
// Makes some environment variables available to the JS code, for example:
|
||||
// if (process.env.NODE_ENV === 'development') { ... }. See `./env.js`.
|
||||
new webpack.DefinePlugin(env.stringified),
|
||||
// This is necessary to emit hot updates (currently CSS only):
|
||||
new webpack.HotModuleReplacementPlugin(),
|
||||
// Watcher doesn't work well if you mistype casing in a path so we use
|
||||
// a plugin that prints an error when you attempt to do this.
|
||||
// See https://github.com/facebookincubator/create-react-app/issues/240
|
||||
new CaseSensitivePathsPlugin(),
|
||||
// If you require a missing module and then `npm install` it, you still have
|
||||
// to restart the development server for Webpack to discover it. This plugin
|
||||
// makes the discovery automatic so you don't have to restart.
|
||||
// See https://github.com/facebookincubator/create-react-app/issues/186
|
||||
new WatchMissingNodeModulesPlugin(paths.appNodeModules),
|
||||
// Moment.js is an extremely popular library that bundles large locale files
|
||||
// by default due to how Webpack interprets its code. This is a practical
|
||||
// solution that requires the user to opt into importing specific locales.
|
||||
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
||||
// You can remove this if you don't use Moment.js:
|
||||
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
||||
],
|
||||
// Some libraries import Node modules but don't use them in the browser.
|
||||
// Tell Webpack to provide empty mocks for them so importing them works.
|
||||
node: {
|
||||
dgram: 'empty',
|
||||
fs: 'empty',
|
||||
net: 'empty',
|
||||
tls: 'empty',
|
||||
child_process: 'empty',
|
||||
},
|
||||
// Turn off performance hints during development because we don't do any
|
||||
// splitting or minification in interest of speed. These warnings become
|
||||
// cumbersome.
|
||||
performance: {
|
||||
hints: false,
|
||||
},
|
||||
};
|
||||
354
website/config/webpack.config.prod.js
Normal file
@@ -0,0 +1,354 @@
|
||||
'use strict';
|
||||
|
||||
const autoprefixer = require('autoprefixer');
|
||||
const path = require('path');
|
||||
const webpack = require('webpack');
|
||||
const HtmlWebpackPlugin = require('html-webpack-plugin');
|
||||
const ExtractTextPlugin = require('extract-text-webpack-plugin');
|
||||
const ManifestPlugin = require('webpack-manifest-plugin');
|
||||
const InterpolateHtmlPlugin = require('react-dev-utils/InterpolateHtmlPlugin');
|
||||
const SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
|
||||
const eslintFormatter = require('react-dev-utils/eslintFormatter');
|
||||
const ModuleScopePlugin = require('react-dev-utils/ModuleScopePlugin');
|
||||
const paths = require('./paths');
|
||||
const getClientEnvironment = require('./env');
|
||||
|
||||
// Webpack uses `publicPath` to determine where the app is being served from.
|
||||
// It requires a trailing slash, or the file assets will get an incorrect path.
|
||||
const publicPath = paths.servedPath;
|
||||
// Some apps do not use client-side routing with pushState.
|
||||
// For these, "homepage" can be set to "." to enable relative asset paths.
|
||||
const shouldUseRelativeAssetPaths = publicPath === './';
|
||||
// Source maps are resource heavy and can cause out of memory issue for large source files.
|
||||
const shouldUseSourceMap = process.env.GENERATE_SOURCEMAP !== 'false';
|
||||
// `publicUrl` is just like `publicPath`, but we will provide it to our app
|
||||
// as %PUBLIC_URL% in `index.html` and `process.env.PUBLIC_URL` in JavaScript.
|
||||
// Omit trailing slash as %PUBLIC_URL%/xyz looks better than %PUBLIC_URL%xyz.
|
||||
const publicUrl = publicPath.slice(0, -1);
|
||||
// Get environment variables to inject into our app.
|
||||
const env = getClientEnvironment(publicUrl);
|
||||
const srcPath = path.resolve(__dirname, '../src/')
|
||||
|
||||
// Assert this just to be safe.
|
||||
// Development builds of React are slow and not intended for production.
|
||||
if (env.stringified['process.env'].NODE_ENV !== '"production"') {
|
||||
throw new Error('Production builds must have NODE_ENV=production.');
|
||||
}
|
||||
|
||||
// Note: defined here because it will be used more than once.
|
||||
const cssFilename = 'static/css/[name].[contenthash:8].scss';
|
||||
|
||||
// ExtractTextPlugin expects the build output to be flat.
|
||||
// (See https://github.com/webpack-contrib/extract-text-webpack-plugin/issues/27)
|
||||
// However, our output is structured with css, js and media folders.
|
||||
// To have this structure working with relative paths, we have to use custom options.
|
||||
const extractTextPluginOptions = shouldUseRelativeAssetPaths
|
||||
? // Making sure that the publicPath goes back to to build folder.
|
||||
{ publicPath: Array(cssFilename.split('/').length).join('../') }
|
||||
: {};
|
||||
|
||||
// This is the production configuration.
|
||||
// It compiles slowly and is focused on producing a fast and minimal bundle.
|
||||
// The development configuration is different and lives in a separate file.
|
||||
module.exports = {
|
||||
// Don't attempt to continue if there are any errors.
|
||||
bail: true,
|
||||
// We generate sourcemaps in production. This is slow but gives good results.
|
||||
// You can exclude the *.map files from the build during deployment.
|
||||
devtool: shouldUseSourceMap ? 'source-map' : false,
|
||||
// In production, we only want to load the polyfills and the app code.
|
||||
entry: [require.resolve('./polyfills'), paths.appIndexJs],
|
||||
output: {
|
||||
// The build folder.
|
||||
path: paths.appBuild,
|
||||
// Generated JS file names (with nested folders).
|
||||
// There will be one main bundle, and one file per asynchronous chunk.
|
||||
// We don't currently advertise code splitting but Webpack supports it.
|
||||
filename: 'static/js/[name].[chunkhash:8].js',
|
||||
chunkFilename: 'static/js/[name].[chunkhash:8].chunk.js',
|
||||
// We inferred the "public path" (such as / or /my-project) from homepage.
|
||||
publicPath: publicPath,
|
||||
// Point sourcemap entries to original disk location (format as URL on Windows)
|
||||
devtoolModuleFilenameTemplate: info =>
|
||||
path
|
||||
.relative(paths.appSrc, info.absoluteResourcePath)
|
||||
.replace(/\\/g, '/'),
|
||||
},
|
||||
resolve: {
|
||||
// This allows you to set a fallback for where Webpack should look for modules.
|
||||
// We placed these paths second because we want `node_modules` to "win"
|
||||
// if there are any conflicts. This matches Node resolution mechanism.
|
||||
// https://github.com/facebookincubator/create-react-app/issues/253
|
||||
modules: ['node_modules', paths.appNodeModules].concat(
|
||||
// It is guaranteed to exist because we tweak it in `env.js`
|
||||
process.env.NODE_PATH.split(path.delimiter).filter(Boolean)
|
||||
),
|
||||
// These are the reasonable defaults supported by the Node ecosystem.
|
||||
// We also include JSX as a common component filename extension to support
|
||||
// some tools, although we do not recommend using it, see:
|
||||
// https://github.com/facebookincubator/create-react-app/issues/290
|
||||
// `web` extension prefixes have been added for better support
|
||||
// for React Native Web.
|
||||
extensions: ['.web.js', '.mjs', '.js', '.json', '.web.jsx', '.jsx'],
|
||||
alias: {
|
||||
// Support React Native Web
|
||||
// https://www.smashingmagazine.com/2016/08/a-glimpse-into-the-future-with-react-native-for-web/
|
||||
'react-native': 'react-native-web',
|
||||
'styles': path.join(srcPath, '/assets/styles/'),
|
||||
'images': path.join(srcPath, '/assets/images/'),
|
||||
'icons': path.join(srcPath, '/assets/icons/'),
|
||||
'data': path.join(srcPath, '/assets/data/'),
|
||||
'fonts': path.join(srcPath, '/assets/fonts/'),
|
||||
'src': srcPath,
|
||||
},
|
||||
plugins: [
|
||||
// Prevents users from importing files from outside of src/ (or node_modules/).
|
||||
// This often causes confusion because we only process files within src/ with babel.
|
||||
// To fix this, we prevent you from importing files out of src/ -- if you'd like to,
|
||||
// please link the files into your node_modules/ and let module-resolution kick in.
|
||||
// Make sure your source files are compiled, as they will not be processed in any way.
|
||||
new ModuleScopePlugin(paths.appSrc, [paths.appPackageJson]),
|
||||
],
|
||||
},
|
||||
module: {
|
||||
strictExportPresence: true,
|
||||
rules: [
|
||||
// TODO: Disable require.ensure as it's not a standard language feature.
|
||||
// We are waiting for https://github.com/facebookincubator/create-react-app/issues/2176.
|
||||
// { parser: { requireEnsure: false } },
|
||||
|
||||
// First, run the linter.
|
||||
// It's important to do this before Babel processes the JS.
|
||||
{
|
||||
test: /\.(js|jsx|mjs)$/,
|
||||
enforce: 'pre',
|
||||
use: [
|
||||
{
|
||||
options: {
|
||||
formatter: eslintFormatter,
|
||||
eslintPath: require.resolve('eslint'),
|
||||
|
||||
},
|
||||
loader: require.resolve('eslint-loader'),
|
||||
},
|
||||
],
|
||||
include: paths.appSrc,
|
||||
},
|
||||
{
|
||||
// "oneOf" will traverse all following loaders until one will
|
||||
// match the requirements. When no loader matches it will fall
|
||||
// back to the "file" loader at the end of the loader list.
|
||||
oneOf: [
|
||||
// "url" loader works just like "file" loader but it also embeds
|
||||
// assets smaller than specified size as data URLs to avoid requests.
|
||||
{
|
||||
test: [/\.bmp$/, /\.gif$/, /\.jpe?g$/, /\.png$/],
|
||||
loader: require.resolve('url-loader'),
|
||||
options: {
|
||||
limit: 10000,
|
||||
name: 'static/media/[name].[hash:8].[ext]',
|
||||
},
|
||||
},
|
||||
// Process JS with Babel.
|
||||
{
|
||||
test: /\.(js|jsx|mjs)$/,
|
||||
include: paths.appSrc,
|
||||
loader: require.resolve('babel-loader'),
|
||||
options: {
|
||||
|
||||
compact: true,
|
||||
},
|
||||
},
|
||||
// The notation here is somewhat confusing.
|
||||
// "postcss" loader applies autoprefixer to our CSS.
|
||||
// "css" loader resolves paths in CSS and adds assets as dependencies.
|
||||
// "style" loader normally turns CSS into JS modules injecting <style>,
|
||||
// but unlike in development configuration, we do something different.
|
||||
// `ExtractTextPlugin` first applies the "postcss" and "css" loaders
|
||||
// (second argument), then grabs the result CSS and puts it into a
|
||||
// separate file in our build process. This way we actually ship
|
||||
// a single CSS file in production instead of JS code injecting <style>
|
||||
// tags. If you use code splitting, however, any async bundles will still
|
||||
// use the "style" loader inside the async code so CSS from them won't be
|
||||
// in the main CSS file.
|
||||
{
|
||||
test: /\.(sass|scss)$/,
|
||||
loader: ExtractTextPlugin.extract(
|
||||
Object.assign(
|
||||
{
|
||||
fallback: {
|
||||
loader: require.resolve('style-loader'),
|
||||
options: {
|
||||
hmr: false,
|
||||
},
|
||||
},
|
||||
use: [
|
||||
{
|
||||
loader: require.resolve('css-loader'),
|
||||
options: {
|
||||
importLoaders: 1,
|
||||
minimize: true,
|
||||
sourceMap: shouldUseSourceMap,
|
||||
},
|
||||
},
|
||||
{
|
||||
loader: require.resolve('sass-loader'),
|
||||
options: {
|
||||
sourceMap: shouldUseSourceMap,
|
||||
}
|
||||
},
|
||||
{
|
||||
loader: require.resolve('postcss-loader'),
|
||||
options: {
|
||||
// Necessary for external CSS imports to work
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2677
|
||||
ident: 'postcss',
|
||||
plugins: () => [
|
||||
require('postcss-flexbugs-fixes'),
|
||||
autoprefixer({
|
||||
browsers: [
|
||||
'>1%',
|
||||
'last 4 versions',
|
||||
'Firefox ESR',
|
||||
'not ie < 9', // React doesn't support IE8 anyway
|
||||
],
|
||||
flexbox: 'no-2009',
|
||||
}),
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
extractTextPluginOptions
|
||||
)
|
||||
),
|
||||
// Note: this won't work without `new ExtractTextPlugin()` in `plugins`.
|
||||
},
|
||||
// "file" loader makes sure assets end up in the `build` folder.
|
||||
// When you `import` an asset, you get its filename.
|
||||
// This loader doesn't use a "test" so it will catch all modules
|
||||
// that fall through the other loaders.
|
||||
{
|
||||
loader: require.resolve('file-loader'),
|
||||
// Exclude `js` files to keep "css" loader working as it injects
|
||||
// it's runtime that would otherwise processed through "file" loader.
|
||||
// Also exclude `html` and `json` extensions so they get processed
|
||||
// by webpacks internal loaders.
|
||||
exclude: [/\.(js|jsx|mjs)$/, /\.html$/, /\.json$/],
|
||||
options: {
|
||||
name: 'static/media/[name].[hash:8].[ext]',
|
||||
},
|
||||
},
|
||||
// ** STOP ** Are you adding a new loader?
|
||||
// Make sure to add the new loader(s) before the "file" loader.
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
plugins: [
|
||||
// Makes some environment variables available in index.html.
|
||||
// The public URL is available as %PUBLIC_URL% in index.html, e.g.:
|
||||
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||
// In production, it will be an empty string unless you specify "homepage"
|
||||
// in `package.json`, in which case it will be the pathname of that URL.
|
||||
new InterpolateHtmlPlugin(env.raw),
|
||||
// Generates an `index.html` file with the <script> injected.
|
||||
new HtmlWebpackPlugin({
|
||||
inject: true,
|
||||
template: paths.appHtml,
|
||||
minify: {
|
||||
removeComments: true,
|
||||
collapseWhitespace: true,
|
||||
removeRedundantAttributes: true,
|
||||
useShortDoctype: true,
|
||||
removeEmptyAttributes: true,
|
||||
removeStyleLinkTypeAttributes: true,
|
||||
keepClosingSlash: true,
|
||||
minifyJS: true,
|
||||
minifyCSS: true,
|
||||
minifyURLs: true,
|
||||
},
|
||||
}),
|
||||
// Makes some environment variables available to the JS code, for example:
|
||||
// if (process.env.NODE_ENV === 'production') { ... }. See `./env.js`.
|
||||
// It is absolutely essential that NODE_ENV was set to production here.
|
||||
// Otherwise React will be compiled in the very slow development mode.
|
||||
new webpack.DefinePlugin(env.stringified),
|
||||
// Minify the code.
|
||||
new webpack.optimize.UglifyJsPlugin({
|
||||
compress: {
|
||||
warnings: false,
|
||||
// Disabled because of an issue with Uglify breaking seemingly valid code:
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2376
|
||||
// Pending further investigation:
|
||||
// https://github.com/mishoo/UglifyJS2/issues/2011
|
||||
comparisons: false,
|
||||
},
|
||||
mangle: {
|
||||
safari10: true,
|
||||
},
|
||||
output: {
|
||||
comments: false,
|
||||
// Turned on because emoji and regex is not minified properly using default
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2488
|
||||
ascii_only: true,
|
||||
},
|
||||
sourceMap: shouldUseSourceMap,
|
||||
}),
|
||||
// Note: this won't work without ExtractTextPlugin.extract(..) in `loaders`.
|
||||
new ExtractTextPlugin({
|
||||
filename: cssFilename,
|
||||
}),
|
||||
// Generate a manifest file which contains a mapping of all asset filenames
|
||||
// to their corresponding output file so that tools can pick it up without
|
||||
// having to parse `index.html`.
|
||||
new ManifestPlugin({
|
||||
fileName: 'asset-manifest.json',
|
||||
}),
|
||||
// Generate a service worker script that will precache, and keep up to date,
|
||||
// the HTML & assets that are part of the Webpack build.
|
||||
new SWPrecacheWebpackPlugin({
|
||||
// By default, a cache-busting query parameter is appended to requests
|
||||
// used to populate the caches, to ensure the responses are fresh.
|
||||
// If a URL is already hashed by Webpack, then there is no concern
|
||||
// about it being stale, and the cache-busting can be skipped.
|
||||
dontCacheBustUrlsMatching: /\.\w{8}\./,
|
||||
filename: 'service-worker.js',
|
||||
logger(message) {
|
||||
if (message.indexOf('Total precache size is') === 0) {
|
||||
// This message occurs for every build and is a bit too noisy.
|
||||
return;
|
||||
}
|
||||
if (message.indexOf('Skipping static resource') === 0) {
|
||||
// This message obscures real errors so we ignore it.
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2612
|
||||
return;
|
||||
}
|
||||
console.log(message);
|
||||
},
|
||||
minify: true,
|
||||
// For unknown URLs, fallback to the index page
|
||||
navigateFallback: publicUrl + '/index.html',
|
||||
// Ignores URLs starting from /__ (useful for Firebase):
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2237#issuecomment-302693219
|
||||
navigateFallbackWhitelist: [/^(?!\/__).*/],
|
||||
// Don't precache sourcemaps (they're large) and build asset manifest:
|
||||
staticFileGlobsIgnorePatterns: [/\.map$/, /asset-manifest\.json$/],
|
||||
}),
|
||||
// Moment.js is an extremely popular library that bundles large locale files
|
||||
// by default due to how Webpack interprets its code. This is a practical
|
||||
// solution that requires the user to opt into importing specific locales.
|
||||
// https://github.com/jmblog/how-to-optimize-momentjs-with-webpack
|
||||
// You can remove this if you don't use Moment.js:
|
||||
new webpack.IgnorePlugin(/^\.\/locale$/, /moment$/),
|
||||
],
|
||||
// Some libraries import Node modules but don't use them in the browser.
|
||||
// Tell Webpack to provide empty mocks for them so importing them works.
|
||||
node: {
|
||||
dgram: 'empty',
|
||||
fs: 'empty',
|
||||
net: 'empty',
|
||||
tls: 'empty',
|
||||
child_process: 'empty',
|
||||
},
|
||||
};
|
||||
95
website/config/webpackDevServer.config.js
Normal file
@@ -0,0 +1,95 @@
|
||||
'use strict';
|
||||
|
||||
const errorOverlayMiddleware = require('react-dev-utils/errorOverlayMiddleware');
|
||||
const noopServiceWorkerMiddleware = require('react-dev-utils/noopServiceWorkerMiddleware');
|
||||
const ignoredFiles = require('react-dev-utils/ignoredFiles');
|
||||
const config = require('./webpack.config.dev');
|
||||
const paths = require('./paths');
|
||||
|
||||
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
||||
const host = process.env.HOST || '0.0.0.0';
|
||||
|
||||
module.exports = function(proxy, allowedHost) {
|
||||
return {
|
||||
// WebpackDevServer 2.4.3 introduced a security fix that prevents remote
|
||||
// websites from potentially accessing local content through DNS rebinding:
|
||||
// https://github.com/webpack/webpack-dev-server/issues/887
|
||||
// https://medium.com/webpack/webpack-dev-server-middleware-security-issues-1489d950874a
|
||||
// However, it made several existing use cases such as development in cloud
|
||||
// environment or subdomains in development significantly more complicated:
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2271
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2233
|
||||
// While we're investigating better solutions, for now we will take a
|
||||
// compromise. Since our WDS configuration only serves files in the `public`
|
||||
// folder we won't consider accessing them a vulnerability. However, if you
|
||||
// use the `proxy` feature, it gets more dangerous because it can expose
|
||||
// remote code execution vulnerabilities in backends like Django and Rails.
|
||||
// So we will disable the host check normally, but enable it if you have
|
||||
// specified the `proxy` setting. Finally, we let you override it if you
|
||||
// really know what you're doing with a special environment variable.
|
||||
disableHostCheck:
|
||||
!proxy || process.env.DANGEROUSLY_DISABLE_HOST_CHECK === 'true',
|
||||
// Enable gzip compression of generated files.
|
||||
compress: true,
|
||||
// Silence WebpackDevServer's own logs since they're generally not useful.
|
||||
// It will still show compile warnings and errors with this setting.
|
||||
clientLogLevel: 'none',
|
||||
// By default WebpackDevServer serves physical files from current directory
|
||||
// in addition to all the virtual build products that it serves from memory.
|
||||
// This is confusing because those files won’t automatically be available in
|
||||
// production build folder unless we copy them. However, copying the whole
|
||||
// project directory is dangerous because we may expose sensitive files.
|
||||
// Instead, we establish a convention that only files in `public` directory
|
||||
// get served. Our build script will copy `public` into the `build` folder.
|
||||
// In `index.html`, you can get URL of `public` folder with %PUBLIC_URL%:
|
||||
// <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
|
||||
// In JavaScript code, you can access it with `process.env.PUBLIC_URL`.
|
||||
// Note that we only recommend to use `public` folder as an escape hatch
|
||||
// for files like `favicon.ico`, `manifest.json`, and libraries that are
|
||||
// for some reason broken when imported through Webpack. If you just want to
|
||||
// use an image, put it in `src` and `import` it from JavaScript instead.
|
||||
contentBase: paths.appPublic,
|
||||
// By default files from `contentBase` will not trigger a page reload.
|
||||
watchContentBase: true,
|
||||
// Enable hot reloading server. It will provide /sockjs-node/ endpoint
|
||||
// for the WebpackDevServer client so it can learn when the files were
|
||||
// updated. The WebpackDevServer client is included as an entry point
|
||||
// in the Webpack development configuration. Note that only changes
|
||||
// to CSS are currently hot reloaded. JS changes will refresh the browser.
|
||||
hot: true,
|
||||
// It is important to tell WebpackDevServer to use the same "root" path
|
||||
// as we specified in the config. In development, we always serve from /.
|
||||
publicPath: config.output.publicPath,
|
||||
// WebpackDevServer is noisy by default so we emit custom message instead
|
||||
// by listening to the compiler events with `compiler.plugin` calls above.
|
||||
quiet: true,
|
||||
// Reportedly, this avoids CPU overload on some systems.
|
||||
// https://github.com/facebookincubator/create-react-app/issues/293
|
||||
// src/node_modules is not ignored to support absolute imports
|
||||
// https://github.com/facebookincubator/create-react-app/issues/1065
|
||||
watchOptions: {
|
||||
ignored: ignoredFiles(paths.appSrc),
|
||||
},
|
||||
// Enable HTTPS if the HTTPS environment variable is set to 'true'
|
||||
https: protocol === 'https',
|
||||
host: host,
|
||||
overlay: false,
|
||||
historyApiFallback: {
|
||||
// Paths with dots should still use the history fallback.
|
||||
// See https://github.com/facebookincubator/create-react-app/issues/387.
|
||||
disableDotRule: true,
|
||||
},
|
||||
public: allowedHost,
|
||||
proxy,
|
||||
before(app) {
|
||||
// This lets us open files from the runtime error overlay.
|
||||
app.use(errorOverlayMiddleware());
|
||||
// This service worker file is effectively a 'no-op' that will reset any
|
||||
// previous service worker registered for the same host:port combination.
|
||||
// We do this in development to avoid hitting the production cache if
|
||||
// it used the same host and port.
|
||||
// https://github.com/facebookincubator/create-react-app/issues/2272#issuecomment-302832432
|
||||
app.use(noopServiceWorkerMiddleware());
|
||||
},
|
||||
};
|
||||
};
|
||||
14508
website/package-lock.json
generated
Normal file
120
website/package.json
Normal file
@@ -0,0 +1,120 @@
|
||||
{
|
||||
"name": "dar-website",
|
||||
"version": "1.0.0",
|
||||
"private": true,
|
||||
"dependencies": {
|
||||
"auto-bind2": "^1.0.2",
|
||||
"eventemitter3": "^2.0.3",
|
||||
"immutability-helper": "^2.3.0",
|
||||
"moment": "^2.18.1",
|
||||
"papaparse": "^4.3.3",
|
||||
"prop-types": "^15.5.10",
|
||||
"rc-datepicker": "^5.0.7",
|
||||
"react": "^16.2.0",
|
||||
"react-data-grid": "^2.0.51",
|
||||
"react-data-grid-addons": "^2.0.55",
|
||||
"react-dom": "^16.2.0",
|
||||
"react-router-dom": "^4.1.1",
|
||||
"regexp-pattern": "^1.0.4",
|
||||
"semantic-ui-css": "^2.2.10",
|
||||
"semantic-ui-react": "^0.70.0",
|
||||
"socket.io-client": "^2.0.3",
|
||||
"xlsx": "^0.11.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"autoprefixer": "7.1.0",
|
||||
"babel-core": "6.24.1",
|
||||
"babel-eslint": "7.2.3",
|
||||
"babel-jest": "20.0.3",
|
||||
"babel-loader": "7.0.0",
|
||||
"babel-preset-react-app": "^3.0.1",
|
||||
"babel-runtime": "6.23.0",
|
||||
"case-sensitive-paths-webpack-plugin": "1.1.4",
|
||||
"chalk": "1.1.3",
|
||||
"css-loader": "0.28.1",
|
||||
"dotenv": "4.0.0",
|
||||
"dotenv-expand": "^4.2.0",
|
||||
"eslint": "3.19.0",
|
||||
"eslint-config-react-app": "^1.0.5",
|
||||
"eslint-config-standard": "^10.2.1",
|
||||
"eslint-config-standard-react": "^5.0.0",
|
||||
"eslint-loader": "1.7.1",
|
||||
"eslint-plugin-babel": "^4.1.1",
|
||||
"eslint-plugin-flowtype": "2.33.0",
|
||||
"eslint-plugin-import": "2.2.0",
|
||||
"eslint-plugin-jsx-a11y": "5.0.3",
|
||||
"eslint-plugin-node": "^5.1.0",
|
||||
"eslint-plugin-promise": "^3.5.0",
|
||||
"eslint-plugin-react": "7.0.1",
|
||||
"eslint-plugin-standard": "^3.0.1",
|
||||
"extract-text-webpack-plugin": "2.1.0",
|
||||
"file-loader": "0.11.1",
|
||||
"fs-extra": "3.0.1",
|
||||
"html-webpack-plugin": "2.28.0",
|
||||
"jest": "20.0.3",
|
||||
"node-sass": "^4.7.2",
|
||||
"object-assign": "4.1.1",
|
||||
"postcss-flexbugs-fixes": "3.0.0",
|
||||
"postcss-loader": "2.0.5",
|
||||
"promise": "7.1.1",
|
||||
"raf": "^3.4.0",
|
||||
"react-dev-utils": "^5.0.0",
|
||||
"react-error-overlay": "^1.0.9",
|
||||
"sass-loader": "^6.0.6",
|
||||
"style-loader": "^0.17.0",
|
||||
"sw-precache-webpack-plugin": "0.9.1",
|
||||
"url-loader": "0.5.8",
|
||||
"webpack": "^2.7.0",
|
||||
"webpack-dev-server": "^2.11.1",
|
||||
"webpack-manifest-plugin": "1.1.0",
|
||||
"whatwg-fetch": "2.0.3"
|
||||
},
|
||||
"scripts": {
|
||||
"start": "node scripts/start.js",
|
||||
"build": "node scripts/build.js",
|
||||
"lint": "eslint --ext .js --ext .jsx src/",
|
||||
"lint:fix": "eslint --ext .js --ext .jsx --fix src/"
|
||||
},
|
||||
"proxy": {
|
||||
"/api": {
|
||||
"target": "http://localhost:3001",
|
||||
"ws": true,
|
||||
"pathRewrite": {
|
||||
"^/api": ""
|
||||
}
|
||||
}
|
||||
},
|
||||
"jest": {
|
||||
"collectCoverageFrom": [
|
||||
"src/**/*.{js,jsx}"
|
||||
],
|
||||
"setupFiles": [
|
||||
"<rootDir>/config/polyfills.js"
|
||||
],
|
||||
"testMatch": [
|
||||
"<rootDir>/src/**/__tests__/**/*.js?(x)",
|
||||
"<rootDir>/src/**/?(*.)(spec|test).js?(x)"
|
||||
],
|
||||
"testEnvironment": "node",
|
||||
"testURL": "http://localhost",
|
||||
"transform": {
|
||||
"^.+\\.(js|jsx)$": "<rootDir>/node_modules/babel-jest",
|
||||
"^.+\\.css$": "<rootDir>/config/jest/cssTransform.js",
|
||||
"^(?!.*\\.(js|jsx|css|json)$)": "<rootDir>/config/jest/fileTransform.js"
|
||||
},
|
||||
"transformIgnorePatterns": [
|
||||
"[/\\\\]node_modules[/\\\\].+\\.(js|jsx)$"
|
||||
],
|
||||
"moduleNameMapper": {
|
||||
"^react-native$": "react-native-web"
|
||||
}
|
||||
},
|
||||
"babel": {
|
||||
"presets": [
|
||||
"react-app"
|
||||
]
|
||||
},
|
||||
"eslintConfig": {
|
||||
"extends": "react-app"
|
||||
}
|
||||
}
|
||||
BIN
website/public/favicon.ico
Normal file
|
After Width: | Height: | Size: 24 KiB |
BIN
website/public/favicon.png
Normal file
|
After Width: | Height: | Size: 910 B |
22
website/public/index.html
Normal file
@@ -0,0 +1,22 @@
|
||||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<title>Transition Management Resources</title>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.png">
|
||||
<!--<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.2.9/semantic.min.css">-->
|
||||
<!--
|
||||
Notice the use of %PUBLIC_URL% in the tag above.
|
||||
It will be replaced with the URL of the `public` folder during the build.
|
||||
Only files inside the `public` folder can be referenced from the HTML.
|
||||
|
||||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||
work correctly both with client-side routing and a non-root public URL.
|
||||
Learn how to configure a non-root public URL by running `npm run build`.
|
||||
-->
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
</body>
|
||||
</html>
|
||||
150
website/scripts/build.js
Normal file
@@ -0,0 +1,150 @@
|
||||
'use strict';
|
||||
|
||||
// Do this as the first thing so that any code reading it knows the right env.
|
||||
process.env.BABEL_ENV = 'production';
|
||||
process.env.NODE_ENV = 'production';
|
||||
|
||||
// Makes the script crash on unhandled rejections instead of silently
|
||||
// ignoring them. In the future, promise rejections that are not handled will
|
||||
// terminate the Node.js process with a non-zero exit code.
|
||||
process.on('unhandledRejection', err => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
// Ensure environment variables are read.
|
||||
require('../config/env');
|
||||
|
||||
const path = require('path');
|
||||
const chalk = require('chalk');
|
||||
const fs = require('fs-extra');
|
||||
const webpack = require('webpack');
|
||||
const config = require('../config/webpack.config.prod');
|
||||
const paths = require('../config/paths');
|
||||
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
||||
const formatWebpackMessages = require('react-dev-utils/formatWebpackMessages');
|
||||
const printHostingInstructions = require('react-dev-utils/printHostingInstructions');
|
||||
const FileSizeReporter = require('react-dev-utils/FileSizeReporter');
|
||||
const printBuildError = require('react-dev-utils/printBuildError');
|
||||
|
||||
const measureFileSizesBeforeBuild =
|
||||
FileSizeReporter.measureFileSizesBeforeBuild;
|
||||
const printFileSizesAfterBuild = FileSizeReporter.printFileSizesAfterBuild;
|
||||
const useYarn = fs.existsSync(paths.yarnLockFile);
|
||||
|
||||
// These sizes are pretty large. We'll warn for bundles exceeding them.
|
||||
const WARN_AFTER_BUNDLE_GZIP_SIZE = 512 * 1024;
|
||||
const WARN_AFTER_CHUNK_GZIP_SIZE = 1024 * 1024;
|
||||
|
||||
// Warn and crash if required files are missing
|
||||
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// First, read the current file sizes in build directory.
|
||||
// This lets us display how much they changed later.
|
||||
measureFileSizesBeforeBuild(paths.appBuild)
|
||||
.then(previousFileSizes => {
|
||||
// Remove all content but keep the directory so that
|
||||
// if you're in it, you don't end up in Trash
|
||||
fs.emptyDirSync(paths.appBuild);
|
||||
// Merge with the public folder
|
||||
copyPublicFolder();
|
||||
// Start the webpack build
|
||||
return build(previousFileSizes);
|
||||
})
|
||||
.then(
|
||||
({ stats, previousFileSizes, warnings }) => {
|
||||
if (warnings.length) {
|
||||
console.log(chalk.yellow('Compiled with warnings.\n'));
|
||||
console.log(warnings.join('\n\n'));
|
||||
console.log(
|
||||
'\nSearch for the ' +
|
||||
chalk.underline(chalk.yellow('keywords')) +
|
||||
' to learn more about each warning.'
|
||||
);
|
||||
console.log(
|
||||
'To ignore, add ' +
|
||||
chalk.cyan('// eslint-disable-next-line') +
|
||||
' to the line before.\n'
|
||||
);
|
||||
} else {
|
||||
console.log(chalk.green('Compiled successfully.\n'));
|
||||
}
|
||||
|
||||
console.log('File sizes after gzip:\n');
|
||||
printFileSizesAfterBuild(
|
||||
stats,
|
||||
previousFileSizes,
|
||||
paths.appBuild,
|
||||
WARN_AFTER_BUNDLE_GZIP_SIZE,
|
||||
WARN_AFTER_CHUNK_GZIP_SIZE
|
||||
);
|
||||
console.log();
|
||||
|
||||
const appPackage = require(paths.appPackageJson);
|
||||
const publicUrl = paths.publicUrl;
|
||||
const publicPath = config.output.publicPath;
|
||||
const buildFolder = path.relative(process.cwd(), paths.appBuild);
|
||||
printHostingInstructions(
|
||||
appPackage,
|
||||
publicUrl,
|
||||
publicPath,
|
||||
buildFolder,
|
||||
useYarn
|
||||
);
|
||||
},
|
||||
err => {
|
||||
console.log(chalk.red('Failed to compile.\n'));
|
||||
printBuildError(err);
|
||||
process.exit(1);
|
||||
}
|
||||
);
|
||||
|
||||
// Create the production build and print the deployment instructions.
|
||||
function build(previousFileSizes) {
|
||||
console.log('Creating an optimized production build...');
|
||||
|
||||
let compiler = webpack(config);
|
||||
return new Promise((resolve, reject) => {
|
||||
compiler.run((err, stats) => {
|
||||
if (err) {
|
||||
return reject(err);
|
||||
}
|
||||
const messages = formatWebpackMessages(stats.toJson({}, true));
|
||||
if (messages.errors.length) {
|
||||
// Only keep the first error. Others are often indicative
|
||||
// of the same problem, but confuse the reader with noise.
|
||||
if (messages.errors.length > 1) {
|
||||
messages.errors.length = 1;
|
||||
}
|
||||
return reject(new Error(messages.errors.join('\n\n')));
|
||||
}
|
||||
if (
|
||||
process.env.CI &&
|
||||
(typeof process.env.CI !== 'string' ||
|
||||
process.env.CI.toLowerCase() !== 'false') &&
|
||||
messages.warnings.length
|
||||
) {
|
||||
console.log(
|
||||
chalk.yellow(
|
||||
'\nTreating warnings as errors because process.env.CI = true.\n' +
|
||||
'Most CI servers set it automatically.\n'
|
||||
)
|
||||
);
|
||||
return reject(new Error(messages.warnings.join('\n\n')));
|
||||
}
|
||||
return resolve({
|
||||
stats,
|
||||
previousFileSizes,
|
||||
warnings: messages.warnings,
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function copyPublicFolder() {
|
||||
fs.copySync(paths.appPublic, paths.appBuild, {
|
||||
dereference: true,
|
||||
filter: file => file !== paths.appHtml,
|
||||
});
|
||||
}
|
||||
107
website/scripts/start.js
Normal file
@@ -0,0 +1,107 @@
|
||||
'use strict';
|
||||
|
||||
// Do this as the first thing so that any code reading it knows the right env.
|
||||
process.env.BABEL_ENV = 'development';
|
||||
process.env.NODE_ENV = 'development';
|
||||
|
||||
// Makes the script crash on unhandled rejections instead of silently
|
||||
// ignoring them. In the future, promise rejections that are not handled will
|
||||
// terminate the Node.js process with a non-zero exit code.
|
||||
process.on('unhandledRejection', err => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
// Ensure environment variables are read.
|
||||
require('../config/env');
|
||||
|
||||
const fs = require('fs');
|
||||
const chalk = require('chalk');
|
||||
const webpack = require('webpack');
|
||||
const WebpackDevServer = require('webpack-dev-server');
|
||||
const clearConsole = require('react-dev-utils/clearConsole');
|
||||
const checkRequiredFiles = require('react-dev-utils/checkRequiredFiles');
|
||||
const {
|
||||
choosePort,
|
||||
createCompiler,
|
||||
prepareProxy,
|
||||
prepareUrls,
|
||||
} = require('react-dev-utils/WebpackDevServerUtils');
|
||||
const openBrowser = require('react-dev-utils/openBrowser');
|
||||
const paths = require('../config/paths');
|
||||
const config = require('../config/webpack.config.dev');
|
||||
const createDevServerConfig = require('../config/webpackDevServer.config');
|
||||
|
||||
const useYarn = fs.existsSync(paths.yarnLockFile);
|
||||
const isInteractive = process.stdout.isTTY;
|
||||
|
||||
// Warn and crash if required files are missing
|
||||
if (!checkRequiredFiles([paths.appHtml, paths.appIndexJs])) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Tools like Cloud9 rely on this.
|
||||
const DEFAULT_PORT = parseInt(process.env.PORT, 10) || 3000;
|
||||
const HOST = process.env.HOST || '0.0.0.0';
|
||||
|
||||
if (process.env.HOST) {
|
||||
console.log(
|
||||
chalk.cyan(
|
||||
`Attempting to bind to HOST environment variable: ${chalk.yellow(
|
||||
chalk.bold(process.env.HOST)
|
||||
)}`
|
||||
)
|
||||
);
|
||||
console.log(
|
||||
`If this was unintentional, check that you haven't mistakenly set it in your shell.`
|
||||
);
|
||||
console.log(`Learn more here: ${chalk.yellow('http://bit.ly/2mwWSwH')}`);
|
||||
console.log();
|
||||
}
|
||||
|
||||
// We attempt to use the default port but if it is busy, we offer the user to
|
||||
// run on a different port. `choosePort()` Promise resolves to the next free port.
|
||||
choosePort(HOST, DEFAULT_PORT)
|
||||
.then(port => {
|
||||
if (port == null) {
|
||||
// We have not found a port.
|
||||
return;
|
||||
}
|
||||
const protocol = process.env.HTTPS === 'true' ? 'https' : 'http';
|
||||
const appName = require(paths.appPackageJson).name;
|
||||
const urls = prepareUrls(protocol, HOST, port);
|
||||
// Create a webpack compiler that is configured with custom messages.
|
||||
const compiler = createCompiler(webpack, config, appName, urls, useYarn);
|
||||
// Load proxy config
|
||||
const proxySetting = require(paths.appPackageJson).proxy;
|
||||
const proxyConfig = prepareProxy(proxySetting, paths.appPublic);
|
||||
// Serve webpack assets generated by the compiler over a web sever.
|
||||
const serverConfig = createDevServerConfig(
|
||||
proxyConfig,
|
||||
urls.lanUrlForConfig
|
||||
);
|
||||
const devServer = new WebpackDevServer(compiler, serverConfig);
|
||||
// Launch WebpackDevServer.
|
||||
devServer.listen(port, HOST, err => {
|
||||
if (err) {
|
||||
return console.log(err);
|
||||
}
|
||||
if (isInteractive) {
|
||||
clearConsole();
|
||||
}
|
||||
console.log(chalk.cyan('Starting the development server...\n'));
|
||||
openBrowser(urls.localUrlForBrowser);
|
||||
});
|
||||
|
||||
['SIGINT', 'SIGTERM'].forEach(function(sig) {
|
||||
process.on(sig, function() {
|
||||
devServer.close();
|
||||
process.exit();
|
||||
});
|
||||
});
|
||||
})
|
||||
.catch(err => {
|
||||
if (err && err.message) {
|
||||
console.log(err.message);
|
||||
}
|
||||
process.exit(1);
|
||||
});
|
||||
27
website/scripts/test.js
Normal file
@@ -0,0 +1,27 @@
|
||||
'use strict';
|
||||
|
||||
// Do this as the first thing so that any code reading it knows the right env.
|
||||
process.env.BABEL_ENV = 'test';
|
||||
process.env.NODE_ENV = 'test';
|
||||
process.env.PUBLIC_URL = '';
|
||||
|
||||
// Makes the script crash on unhandled rejections instead of silently
|
||||
// ignoring them. In the future, promise rejections that are not handled will
|
||||
// terminate the Node.js process with a non-zero exit code.
|
||||
process.on('unhandledRejection', err => {
|
||||
throw err;
|
||||
});
|
||||
|
||||
// Ensure environment variables are read.
|
||||
require('../config/env');
|
||||
|
||||
const jest = require('jest');
|
||||
const argv = process.argv.slice(2);
|
||||
|
||||
// Watch unless on CI or in coverage mode
|
||||
if (!process.env.CI && argv.indexOf('--coverage') < 0) {
|
||||
argv.push('--watch');
|
||||
}
|
||||
|
||||
|
||||
jest.run(argv);
|
||||
35
website/src/App.js
Normal file
@@ -0,0 +1,35 @@
|
||||
import React from 'react'
|
||||
import './App.scss'
|
||||
import { NavBar } from './Navigation'
|
||||
import { Home } from './Home'
|
||||
import { Login, Logout, ResetPassword, ForgotPassword, ConfirmEmail, ProtectedRoute } from './Auth'
|
||||
import { Dashboard } from './Dashboard'
|
||||
import { Profile } from './Profile'
|
||||
import { Users } from './Users'
|
||||
import { Footer } from './Footer'
|
||||
import { BrowserRouter as Router, Route, Switch } from 'react-router-dom'
|
||||
|
||||
export class App extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<Router basename='/'>
|
||||
<div className='App'>
|
||||
<NavBar />
|
||||
<Switch>
|
||||
<Route exact path='/' component={Home} />
|
||||
<Route path='/login' component={Login} />
|
||||
<Route path='/confirm-email' component={ConfirmEmail} />
|
||||
<Route path='/reset-password' component={ResetPassword} />
|
||||
<Route path='/forgot-password' component={ForgotPassword} />
|
||||
<ProtectedRoute path='/logout' component={Logout} />
|
||||
<ProtectedRoute path='/profile' component={Profile} />
|
||||
<ProtectedRoute roles={['administrator', 'normal']} path='/dashboard' component={Dashboard} />
|
||||
<ProtectedRoute roles={['administrator']} path='/users' component={Users} />
|
||||
<Route component={Home} />{/* No Match Route */}
|
||||
</Switch>
|
||||
<Footer />
|
||||
</div>
|
||||
</Router>
|
||||
)
|
||||
}
|
||||
}
|
||||
9
website/src/App.scss
Normal file
@@ -0,0 +1,9 @@
|
||||
.App {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 768px) {
|
||||
html, body {
|
||||
padding-top: 4em;
|
||||
}
|
||||
}
|
||||
70
website/src/Auth/ConfirmEmail.js
Normal file
@@ -0,0 +1,70 @@
|
||||
import React from 'react'
|
||||
import { api } from '../helpers'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Container } from 'semantic-ui-react'
|
||||
import { MessageDialog, WaitDialog } from '../Dialog'
|
||||
import './ConfirmEmail.scss'
|
||||
|
||||
export class ConfirmEmail extends React.Component {
|
||||
static propTypes = {
|
||||
history: PropTypes.oneOfType([PropTypes.array, PropTypes.object])
|
||||
}
|
||||
constructor() {
|
||||
super()
|
||||
this.state = {
|
||||
waitDialog: null,
|
||||
messageDialog: null
|
||||
}
|
||||
this.handleMessageDialogDismiss = this.handleMessageDialogDismiss.bind(this)
|
||||
}
|
||||
|
||||
componentDidMount(props) {
|
||||
let emailToken = new URLSearchParams(decodeURIComponent(window.location.search)).get('email-token')
|
||||
this.setState({ waitDialog: { message: 'Validating Email...' } })
|
||||
if (emailToken) {
|
||||
api.confirmEmail(emailToken).then((response) => {
|
||||
this.setState({ waitDialog: null })
|
||||
if (response && response.passwordToken) {
|
||||
// API will send a password reset token if this is the first time loggin on
|
||||
this.props.history.replace(`/reset-password?password-token=${response.passwordToken}`)
|
||||
} else {
|
||||
this.props.history.replace('/login')
|
||||
}
|
||||
}).catch((err) => {
|
||||
console.error(err)
|
||||
const supportEmail = 'support@kingstonsoftware.solutions' // TODO: From configuration
|
||||
const message = err.message.includes('The token was not found')
|
||||
? 'This email address may have already been confirmed.'
|
||||
: `Please contact ${supportEmail} to request a new user invitation`
|
||||
this.setState({
|
||||
waitDialog: null,
|
||||
messageDialog: {
|
||||
title: 'Error Verifying Email...',
|
||||
message: `We couldn't complete that request. ${message}`
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
this.props.history.replace('/login')
|
||||
}
|
||||
}
|
||||
|
||||
handleMessageDialogDismiss() {
|
||||
this.setState({ messageDialog: null })
|
||||
this.props.history.replace('/login')
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Container className='email-confirm-container'>
|
||||
<WaitDialog active={!!this.state.waitDialog}
|
||||
message={this.state.waitDialog ? this.state.waitDialog.message : ''} />
|
||||
|
||||
<MessageDialog error open={!!this.state.messageDialog}
|
||||
title={this.state.messageDialog ? this.state.messageDialog.title : ''}
|
||||
message={this.state.messageDialog ? this.state.messageDialog.message : ''}
|
||||
onDismiss={this.handleMessageDialogDismiss} />
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
11
website/src/Auth/ConfirmEmail.scss
Normal file
@@ -0,0 +1,11 @@
|
||||
.ui.container.email-confirm-container {
|
||||
display: flex;
|
||||
height: 80vh;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.ui.container.email-confirm-container button {
|
||||
margin-top: 1em;
|
||||
}
|
||||
93
website/src/Auth/ForgotPassword.js
Normal file
@@ -0,0 +1,93 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { regExpPattern } from 'regexp-pattern'
|
||||
import { Container, Header, Form, Message } from 'semantic-ui-react'
|
||||
import './ForgotPassword.scss'
|
||||
import { MessageDialog, WaitDialog } from '../Dialog'
|
||||
import { Validator, ValidatedInput, ValidatedButton } from '../Validated'
|
||||
import { api } from '../helpers'
|
||||
|
||||
export class ForgotPassword extends React.Component {
|
||||
static propTypes = {
|
||||
history: PropTypes.oneOfType([PropTypes.array, PropTypes.object])
|
||||
}
|
||||
|
||||
static validations = {
|
||||
email: {
|
||||
alwaysGet: true,
|
||||
isValid: (r, v) => (regExpPattern.email.test(v))
|
||||
},
|
||||
submit: {
|
||||
nonValue: true,
|
||||
isDisabled: (r) => (!r.anyModified || !r.allValid)
|
||||
}
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
validator: new Validator({}, ForgotPassword.validations),
|
||||
messageDialog: null,
|
||||
waitDialog: null
|
||||
}
|
||||
this.handleSubmit = this.handleSubmit.bind(this)
|
||||
this.handleMessageDialogDismiss = this.handleMessageDialogDismiss.bind(this)
|
||||
}
|
||||
|
||||
handleSubmit() {
|
||||
const obj = this.state.validator.getValues()
|
||||
|
||||
this.setState({ waitDialog: { message: 'Requesting Reset Email' } })
|
||||
api.sendResetPassword(obj.email).then((res) => {
|
||||
const email = this.state.validator.getField('email').value
|
||||
this.setState({
|
||||
waitDialog: null,
|
||||
messageDialog: {
|
||||
error: false,
|
||||
title: 'Password Reset Requested',
|
||||
message: `An email will be sent to '${email}' with a reset link. Please click on it to finish resetting the password.`
|
||||
}
|
||||
})
|
||||
}).catch((error) => {
|
||||
this.setState({
|
||||
validator: new Validator({}, ForgotPassword.validations), // Reset to avoid rapid retries
|
||||
waitDialog: null,
|
||||
messageDialog: {
|
||||
error: true,
|
||||
title: 'Password Reset Failed',
|
||||
message: `There was a problem requesting the password reset. ${error ? error.message : ''}`
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
handleMessageDialogDismiss() {
|
||||
this.props.history.replace('/')
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Container className='forgot-password-container'>
|
||||
<Header content='Forgotten Password' size='large' />
|
||||
<Form size='large' onSubmit={this.handleSubmit}>
|
||||
<ValidatedInput label='Email' name='email'
|
||||
placeholder='example@xyz.com' validator={this.state.validator}
|
||||
message='A valid email address' />
|
||||
<Message info content='The email address of an existing user to send the password reset link to.' />
|
||||
<ValidatedButton className='submit' name='submit' content='Submit'
|
||||
primary submit validator={this.state.validator}>Submit</ValidatedButton>
|
||||
</Form>
|
||||
|
||||
<WaitDialog active={!!this.state.waitDialog}
|
||||
message={this.state.waitDialog ? this.state.waitDialog.message : ''} />
|
||||
|
||||
<MessageDialog
|
||||
open={!!this.state.messageDialog}
|
||||
error={this.state.messageDialog ? this.state.messageDialog.error : true}
|
||||
title={this.state.messageDialog ? this.state.messageDialog.title : ''}
|
||||
message={this.state.messageDialog ? this.state.messageDialog.message : ''}
|
||||
onDismiss={this.handleMessageDialogDismiss} />
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
23
website/src/Auth/ForgotPassword.scss
Normal file
@@ -0,0 +1,23 @@
|
||||
.ui.container.forgot-password-container {
|
||||
height: 80vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.ui.container.forgot-password-container .header {
|
||||
border-bottom: 1px solid #d4d4d5;
|
||||
width: 40%;
|
||||
padding-bottom: 0.5em;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.ui.container.forgot-password-container form {
|
||||
width: 40%;
|
||||
}
|
||||
|
||||
.ui.container.forgot-password-container .message {
|
||||
margin: 2em 0;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
125
website/src/Auth/Login.js
Normal file
@@ -0,0 +1,125 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Container, Header, Form, Message } from 'semantic-ui-react'
|
||||
import './Login.scss'
|
||||
import { regExpPattern } from 'regexp-pattern'
|
||||
import { api } from '../helpers'
|
||||
import { Validator, ValidatedInput, ValidatedCheckbox, ValidatedButton } from '../Validated'
|
||||
import { WaitDialog, MessageDialog } from '../Dialog'
|
||||
import { Link } from 'react-router-dom'
|
||||
|
||||
export class Login extends React.Component {
|
||||
static propTypes = {
|
||||
history: PropTypes.oneOfType([PropTypes.array, PropTypes.object])
|
||||
}
|
||||
|
||||
static validations = {
|
||||
email: {
|
||||
alwaysGet: true,
|
||||
isValid: (r, v) => (regExpPattern.email.test(v))
|
||||
},
|
||||
password: {
|
||||
alwaysGet: true,
|
||||
isValid: (r, v) => (v !== '')
|
||||
},
|
||||
rememberMe: {
|
||||
alwaysGet: true,
|
||||
initValue: true
|
||||
},
|
||||
submit: {
|
||||
nonValue: true,
|
||||
isDisabled: (r) => (!r.anyModified || !r.allValid)
|
||||
}
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.handleSubmit = this.handleSubmit.bind(this)
|
||||
this.handleMessageDialogDismiss = this.handleMessageDialogDismiss.bind(this)
|
||||
this.state = {
|
||||
waitDialog: false,
|
||||
messageDialog: null,
|
||||
validator: new Validator({}, Login.validations)
|
||||
}
|
||||
}
|
||||
|
||||
handleSubmit(e) {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
|
||||
if (this.state.messageDialog) {
|
||||
this.setState({ messageDialog: null })
|
||||
return
|
||||
} else if (this.state.waitDialog) {
|
||||
return
|
||||
}
|
||||
|
||||
let obj = this.state.validator.getValues()
|
||||
|
||||
if (obj) {
|
||||
this.setState({ waitDialog: true })
|
||||
api.login(obj.email, obj.password, obj.rememberMe).then((user) => {
|
||||
this.setState({ waitDialog: false })
|
||||
if (this.props.history) {
|
||||
const landing = user.role === 'broker' ? '/broker-dashboard' : 'dashboard'
|
||||
let url = new URLSearchParams(window.location.search).get('redirect') || landing
|
||||
try {
|
||||
this.props.history.replace(url)
|
||||
} catch (error) {
|
||||
this.props.history.replace('/')
|
||||
}
|
||||
}
|
||||
}).catch((error) => {
|
||||
const elems = document.getElementsByName('email')
|
||||
if (elems) {
|
||||
elems[0].focus()
|
||||
}
|
||||
this.setState({
|
||||
validator: new Validator({ email: this.state.validator.getField('email').value }, Login.validations),
|
||||
waitDialog: false,
|
||||
messageDialog: { title: 'Login Error...', message: `Unable to login. ${error.message}` }
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
handleMessageDialogDismiss() {
|
||||
this.setState({ messageDialog: null })
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Container id='login' className='password-reset-container'>
|
||||
<Header size='large'>Login Portal</Header>
|
||||
<Form onSubmit={this.handleSubmit}>
|
||||
{/* Add in 'Username' field pass */}
|
||||
<ValidatedInput label='Email' name='email'
|
||||
placeholder='example@xyz.com' validator={this.state.validator}
|
||||
message='Enter the email address associated with your account.' width={16} />
|
||||
<ValidatedInput password label='Password' name='password'
|
||||
validator={this.state.validator} message='Enter your password.' width={16} />
|
||||
<Form.Group widths='equal' className='login-options'>
|
||||
<Form.Field className='login-password'>
|
||||
<Link to='/forgot-password'>Forgot your password?</Link>
|
||||
</Form.Field>
|
||||
<ValidatedCheckbox label='Remember Me'
|
||||
name='rememberMe' onChange={this.handleChange} validator={this.state.validator}
|
||||
message='Should we keep you logged in on this computer?' className='login-checkbox' />
|
||||
</Form.Group>
|
||||
<ValidatedButton className='submit' name='submit' content='Submit'
|
||||
primary submit validator={this.state.validator} />
|
||||
<Message info>
|
||||
Please contact <a href='mailto:support@jamoki.com'>support@jamoki.com</a> to request login credentials.
|
||||
</Message>
|
||||
</Form>
|
||||
|
||||
<WaitDialog active={this.state.waitDialog} message='Logging In' />
|
||||
|
||||
<MessageDialog error open={!!this.state.messageDialog}
|
||||
title={this.state.messageDialog ? this.state.messageDialog.title : ''}
|
||||
message={this.state.messageDialog ? this.state.messageDialog.message : ''}
|
||||
onDismiss={this.handleMessageDialogDismiss} />
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
3
website/src/Auth/Login.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
#login .login-options { margin: 1.5em 0 3em 0; }
|
||||
#login .login-password { text-align: left; }
|
||||
#login .login-checkbox { text-align: right; }
|
||||
20
website/src/Auth/Logout.js
Normal file
@@ -0,0 +1,20 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { api } from '../helpers'
|
||||
|
||||
export class Logout extends React.Component {
|
||||
static propTypes = {
|
||||
history: PropTypes.oneOfType([PropTypes.array, PropTypes.object])
|
||||
}
|
||||
componentDidMount(event) {
|
||||
api.logout().then(() => {
|
||||
if (this.props.history) {
|
||||
this.props.history.push('/')
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
return null
|
||||
}
|
||||
}
|
||||
53
website/src/Auth/ProtectedRoute.js
Normal file
@@ -0,0 +1,53 @@
|
||||
import React from 'react'
|
||||
import { Route, Redirect } from 'react-router-dom'
|
||||
import { PropTypes } from 'prop-types'
|
||||
import { api } from '../helpers'
|
||||
|
||||
export class ProtectedRoute extends React.Component {
|
||||
static propTypes = {
|
||||
roles: PropTypes.array,
|
||||
location: PropTypes.shape({
|
||||
pathname: PropTypes.string,
|
||||
search: PropTypes.string
|
||||
})
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.updateComponent = this.updateComponent.bind(this)
|
||||
}
|
||||
|
||||
updateComponent() {
|
||||
this.forceUpdate()
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
api.addListener('login', this.updateComponent)
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
api.removeListener('login', this.updateComponent)
|
||||
}
|
||||
|
||||
render(props) {
|
||||
let user = api.loggedInUser
|
||||
|
||||
if (user) {
|
||||
if (user.pending) {
|
||||
// The Api might be in the middle of fetching the user information
|
||||
return <div />
|
||||
}
|
||||
let roles = this.props.roles
|
||||
|
||||
if (!roles || roles.includes(user.role)) {
|
||||
return <Route {...this.props} />
|
||||
} else if (!!user.role && user.role === 'broker') {
|
||||
return <Redirect to='/broker-dashboard' />
|
||||
} else if (!!user.role && (user.role === 'employee' || 'administrator' || 'executive')) {
|
||||
return <Redirect to='/dashboard' />
|
||||
}
|
||||
} else {
|
||||
return <Redirect to={`/login?redirect=${this.props.location.pathname}${this.props.location.search}`} />
|
||||
}
|
||||
}
|
||||
}
|
||||
93
website/src/Auth/ResetPassword.js
Normal file
@@ -0,0 +1,93 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Container, Header, Form, Message } from 'semantic-ui-react'
|
||||
import './ResetPassword.scss'
|
||||
import { Validator, ValidatedInput, ValidatedButton } from '../Validated'
|
||||
import { MessageDialog, WaitDialog } from '../Dialog'
|
||||
import { api } from '../helpers'
|
||||
|
||||
export class ResetPassword extends React.Component {
|
||||
static propTypes = {
|
||||
history: PropTypes.oneOfType([PropTypes.array, PropTypes.object])
|
||||
}
|
||||
|
||||
static validations = {
|
||||
newPassword: {
|
||||
alwaysGet: true,
|
||||
isValid: (r, v) => (v.length >= 6)
|
||||
},
|
||||
reenteredNewPassword: {
|
||||
isValid: (r, v) => (v !== '' && v === r.getField('newPassword').value)
|
||||
},
|
||||
submit: {
|
||||
nonValue: true,
|
||||
isDisabled: (r) => (!r.anyModified && !r.allValid)
|
||||
}
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
validator: new Validator({}, ResetPassword.validations),
|
||||
messageDialog: null,
|
||||
waitDialog: null
|
||||
}
|
||||
this.handleSubmit = this.handleSubmit.bind(this)
|
||||
this.handleMessageDialogDismiss = this.handleMessageDialogDismiss.bind(this)
|
||||
}
|
||||
|
||||
handleSubmit() {
|
||||
const obj = this.state.validator.getValues()
|
||||
const passwordToken = new URLSearchParams(decodeURIComponent(window.location.search)).get('password-token')
|
||||
|
||||
this.setState({ waitDialog: { message: 'Setting Password...' } })
|
||||
api.resetPassword({ newPassword: obj.newPassword, passwordToken }).then(() => {
|
||||
this.setState({ waitDialog: null })
|
||||
this.props.history.replace('/login')
|
||||
}).catch((error) => {
|
||||
this.setState({
|
||||
validator: new Validator({}, ResetPassword.validations), // Reset to avoid accidental rapid retries
|
||||
waitDialog: null,
|
||||
messageDialog: {
|
||||
title: 'We had a problem changing your password',
|
||||
message: error.message
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
handleMessageDialogDismiss() {
|
||||
this.setState({ messageDialog: null })
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Container className='password-reset-container'>
|
||||
<Header content='Reset Password' size='large' />
|
||||
<Form size='large' onSubmit={this.handleSubmit}>
|
||||
<ValidatedInput label='New Password' password name='newPassword'
|
||||
message='A new password, cannot be blank or the same as your old password'
|
||||
width={16} validator={this.state.validator} />
|
||||
<ValidatedInput label='Re-entered New Password' password name='reenteredNewPassword'
|
||||
message='The new password again, must match and cannot be blank'
|
||||
width={16} validator={this.state.validator} />
|
||||
<Message info>
|
||||
Passwords can contain special characters and are discouraged from being simple or reused from other sites or applications.
|
||||
<br /><br />
|
||||
Passwords must be at least 6 characters long.
|
||||
</Message>
|
||||
<ValidatedButton className='submit' name='submit' content='Submit'
|
||||
primary submit validator={this.state.validator} />
|
||||
</Form>
|
||||
|
||||
<MessageDialog error open={!!this.state.messageDialog}
|
||||
title={this.state.messageDialog ? this.state.messageDialog.title : ''}
|
||||
message={this.state.messageDialog ? this.state.messageDialog.message : ''}
|
||||
onDismiss={this.handleMessageDialogDismiss} />
|
||||
|
||||
<WaitDialog active={!!this.state.waitDialog}
|
||||
message={this.state.waitDialog ? this.state.waitDialog.message : ''} />
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
23
website/src/Auth/ResetPassword.scss
Normal file
@@ -0,0 +1,23 @@
|
||||
.ui.container.password-reset-container {
|
||||
height: 80vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.ui.container.password-reset-container .header {
|
||||
border-bottom: 1px solid #d4d4d5;
|
||||
width: 40%;
|
||||
padding-bottom: 0.5em;
|
||||
margin-bottom: 1em;
|
||||
}
|
||||
|
||||
.ui.container.password-reset-container form {
|
||||
width: 40%;
|
||||
}
|
||||
|
||||
.ui.container.password-reset-container .message {
|
||||
margin: 2em 0;
|
||||
font-size: 0.8em;
|
||||
}
|
||||
6
website/src/Auth/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export { Login } from './Login'
|
||||
export { Logout } from './Logout'
|
||||
export { ResetPassword } from './ResetPassword'
|
||||
export { ForgotPassword } from './ForgotPassword'
|
||||
export { ConfirmEmail } from './ConfirmEmail'
|
||||
export { ProtectedRoute } from './ProtectedRoute'
|
||||
31
website/src/Dashboard/Dashboard.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import React from 'react'
|
||||
import { Container } from 'semantic-ui-react'
|
||||
import { ProjectList } from './ProjectList'
|
||||
import { api } from '../helpers'
|
||||
|
||||
export class Dashboard extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
projects: []
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
api.listDashboardProjects().then((list) => {
|
||||
this.setState({
|
||||
projects: list.items
|
||||
})
|
||||
}).catch((error) => {
|
||||
console.error(error)
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Container>
|
||||
<ProjectList projects={this.state.projects} />
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
60
website/src/Dashboard/ProjectCard.js
Normal file
@@ -0,0 +1,60 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Card, Image, Button, Icon, Popup } from 'semantic-ui-react'
|
||||
import { Link } from 'react-router-dom'
|
||||
import { Constants, api } from '../helpers'
|
||||
import './ProjectCard.scss'
|
||||
|
||||
export class ProjectCard extends React.Component {
|
||||
static propTypes = {
|
||||
project: PropTypes.object.isRequired // TODO: Add required fields
|
||||
}
|
||||
|
||||
render() {
|
||||
let { project } = this.props
|
||||
const corporationLink = `/corporations/${project.branch.corporation.fingerprint}`
|
||||
const branchLink = corporationLink + `/branches/${project.branch.fingerprint}`
|
||||
const projectLink = branchLink + `/projects/${project.fingerprint}`
|
||||
return (
|
||||
<Card className='project-card' fluid>
|
||||
{/* Project/Corp Logo Link Section */}
|
||||
<Card.Content>
|
||||
<Image as={Link} to={corporationLink}
|
||||
src={api.makeImageUrl(project.branch.corporation.imageId, Constants.logoImageSize)}
|
||||
alt={project.branch.corporation.name} />
|
||||
</Card.Content>
|
||||
|
||||
{/* Project Info Section */}
|
||||
<Card.Content className='project-info'>
|
||||
<Card.Header as={Link}
|
||||
to={projectLink}
|
||||
className='project-name' content={project.name} />
|
||||
<Card.Description>
|
||||
<Link to={branchLink}>{project.branch.name}</Link>
|
||||
@
|
||||
<Link to={corporationLink}>{project.branch.corporation.name}</Link>
|
||||
</Card.Description>
|
||||
</Card.Content>
|
||||
|
||||
{/* Project Link and Status Icon */}
|
||||
<Card.Content className='project-links'>
|
||||
<Button fluid as={Link} to={projectLink}
|
||||
className='project-link' content='View Project' />
|
||||
{ project.error
|
||||
? <Popup trigger={<Icon name='check' size='large' />}
|
||||
content='This project is underway with no errors!'
|
||||
position='bottom left' />
|
||||
: <Popup trigger={<Icon name='table' size='large' color='red' />}
|
||||
content='The Client Data Sheet for this project has not been completed.'
|
||||
position='bottom left' />
|
||||
}
|
||||
</Card.Content>
|
||||
|
||||
{/* Project Status Bar */}
|
||||
<div className={`status in-progress`}>
|
||||
In-Progress
|
||||
</div>
|
||||
</Card>
|
||||
)
|
||||
}
|
||||
}
|
||||
55
website/src/Dashboard/ProjectCard.scss
Normal file
@@ -0,0 +1,55 @@
|
||||
.ui.card.project-card {
|
||||
border-top: 2px solid #D4D4D5;
|
||||
}
|
||||
|
||||
.status {
|
||||
color: WhiteSmoke;
|
||||
padding: 0.25em 1em;
|
||||
text-align: right;
|
||||
font-size: 0.85em;
|
||||
text-transform: capitalize;
|
||||
}
|
||||
|
||||
.in-progress { background-color: #CF414A; }
|
||||
.sending { background-color: #D66C0A; }
|
||||
.receiving { background-color: #0062AF; }
|
||||
|
||||
.project-card img {
|
||||
height: 2.5em !important;
|
||||
width: auto !important;
|
||||
margin: 0.25em auto;
|
||||
}
|
||||
|
||||
.project-info {
|
||||
height: 7em !important;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.project-info a {
|
||||
padding: 0.25em;
|
||||
color: black;
|
||||
border-radius: 5px;
|
||||
|
||||
}
|
||||
|
||||
.project-name.header { font-size: 1em !important; }
|
||||
|
||||
.project-links {
|
||||
padding: 0 !important;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.project-links a {
|
||||
background-color: transparent !important;
|
||||
}
|
||||
|
||||
.project-links i.icon {
|
||||
position: absolute;
|
||||
right: 0.25em;
|
||||
color: LightSlateGrey;
|
||||
}
|
||||
32
website/src/Dashboard/ProjectList.js
Normal file
@@ -0,0 +1,32 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Grid } from 'semantic-ui-react'
|
||||
import { ProjectCard } from './ProjectCard'
|
||||
import './ProjectList.scss'
|
||||
|
||||
export class ProjectList extends React.Component {
|
||||
static propTypes = {
|
||||
projects: PropTypes.arrayOf(PropTypes.object)
|
||||
}
|
||||
|
||||
render() {
|
||||
let { projects } = this.props
|
||||
|
||||
return (
|
||||
<div className='project-list'>
|
||||
<Grid centered={(window.innerWidth <= 768)}>
|
||||
<Grid.Column width={16} textAlign='left' className='project-list-heading'>
|
||||
{projects.length} Projects Underway
|
||||
</Grid.Column>
|
||||
{this.props.projects
|
||||
? projects.map((project, index) => (
|
||||
<Grid.Column mobile={12} tablet={8} computer={4} textAlign='center' key={index}>
|
||||
<ProjectCard project={project} />
|
||||
</Grid.Column>))
|
||||
: null
|
||||
}
|
||||
</Grid>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
11
website/src/Dashboard/ProjectList.scss
Normal file
@@ -0,0 +1,11 @@
|
||||
.project-list {
|
||||
margin: 3em 0 2em 0;
|
||||
padding-bottom: 2em;
|
||||
border-bottom: 1px solid Silver;
|
||||
}
|
||||
|
||||
.project-list-heading {
|
||||
font-size: 1.5em;
|
||||
border-bottom: 1px solid Silver;
|
||||
margin-bottom: 1em !important;
|
||||
}
|
||||
1
website/src/Dashboard/index.js
Normal file
@@ -0,0 +1 @@
|
||||
export { Dashboard } from './Dashboard'
|
||||
85
website/src/Dialog/ChangeEmailDialog.js
Normal file
@@ -0,0 +1,85 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { autoBind } from 'auto-bind2'
|
||||
import { Modal, Button, Icon, Header, Grid, Form } from 'semantic-ui-react'
|
||||
import { ValidatedInput, ValidatedActionsButton, Validator } from '../Validated'
|
||||
import { regExpPattern } from 'regexp-pattern'
|
||||
|
||||
export class ChangeEmailDialog extends React.Component {
|
||||
static propTypes = {
|
||||
open: PropTypes.bool,
|
||||
onDismiss: PropTypes.func
|
||||
}
|
||||
|
||||
static validations = {
|
||||
newEmail: {
|
||||
isValid: (r, v) => (v !== '' && regExpPattern.email.test(v))
|
||||
},
|
||||
submit: {
|
||||
isDisabled: (r) => (!r.allValid),
|
||||
nonValue: true
|
||||
}
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
autoBind(this, (name) => (name.startsWith('handle')))
|
||||
this.state = {
|
||||
validator: new Validator({}, ChangeEmailDialog.validations)
|
||||
}
|
||||
}
|
||||
|
||||
close(newEmail) {
|
||||
this.state.validator = new Validator({}, ChangeEmailDialog.validations)
|
||||
this.props.onDismiss(newEmail)
|
||||
}
|
||||
|
||||
handleClose() {
|
||||
this.close(null)
|
||||
}
|
||||
|
||||
handleSubmit(e) {
|
||||
e.preventDefault()
|
||||
let newEmail = null
|
||||
|
||||
if (this.state.validator.anyModified && this.state.validator.allValid) {
|
||||
newEmail = this.state.validator.getField('newEmail').value
|
||||
}
|
||||
|
||||
this.close(newEmail)
|
||||
}
|
||||
|
||||
handleClick(e) {
|
||||
this.close(null)
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Modal dimmer='inverted' open={this.props.open} onClose={this.handleClose}
|
||||
closeOnDimmerClick={false}>
|
||||
<Header color='black' icon='edit' content='Change Email' />
|
||||
<Modal.Content>
|
||||
<Form className='user-form' id='emailForm' onSubmit={this.handleSubmit}>
|
||||
<Grid>
|
||||
<Grid.Column width={16}>
|
||||
<Form.Group>
|
||||
<ValidatedInput label='New Email' name='newEmail' width={16}
|
||||
message='Your new email address, e.g. xyz@abc.com, cannot be blank'
|
||||
validator={this.state.validator} />
|
||||
</Form.Group>
|
||||
</Grid.Column>
|
||||
</Grid>
|
||||
</Form>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<ValidatedActionsButton primary submit form='emailForm' name='submit' validator={this.state.validator}>
|
||||
<Icon name='checkmark' /> OK
|
||||
</ValidatedActionsButton>
|
||||
<Button color='red' onClick={this.handleClick}>
|
||||
<Icon name='close' /> Cancel
|
||||
</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
}
|
||||
102
website/src/Dialog/ChangePasswordDialog.js
Normal file
@@ -0,0 +1,102 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { autoBind } from 'auto-bind2'
|
||||
import { Modal, Button, Icon, Header, Grid, Form } from 'semantic-ui-react'
|
||||
import { ValidatedInput, ValidatedActionsButton, Validator } from '../Validated'
|
||||
|
||||
export class ChangePasswordDialog extends React.Component {
|
||||
static propTypes = {
|
||||
open: PropTypes.bool,
|
||||
onDismiss: PropTypes.func
|
||||
}
|
||||
|
||||
static validations = {
|
||||
oldPassword: {
|
||||
alwaysGet: true,
|
||||
isValid: (r, v) => (v !== '')
|
||||
},
|
||||
newPassword: {
|
||||
alwaysGet: true,
|
||||
isValid: (r, v) => (v !== '' && v !== r.fields.oldPassword.value)
|
||||
},
|
||||
reenteredNewPassword: {
|
||||
alwaysGet: true,
|
||||
isValid: (r, v) => (v !== '' && v === r.fields.newPassword.value)
|
||||
},
|
||||
submit: {
|
||||
isDisabled: (r) => (!r.allValid),
|
||||
nonValue: true
|
||||
}
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
autoBind(this, (name) => (name.startsWith('handle')))
|
||||
this.state = {
|
||||
validator: new Validator({}, ChangePasswordDialog.validations)
|
||||
}
|
||||
}
|
||||
|
||||
close(passwords) {
|
||||
this.state.validator = new Validator({}, ChangePasswordDialog.validations)
|
||||
this.props.onDismiss(passwords)
|
||||
}
|
||||
|
||||
handleClose() {
|
||||
close(null)
|
||||
}
|
||||
|
||||
handleSubmit(e) {
|
||||
e.preventDefault()
|
||||
let passwords = null
|
||||
|
||||
if (this.state.validator.allValid) {
|
||||
const oldPassword = this.state.validator.getField('oldPassword').value
|
||||
const newPassword = this.state.validator.getField('newPassword').value
|
||||
passwords = { oldPassword, newPassword }
|
||||
}
|
||||
this.close(passwords)
|
||||
}
|
||||
|
||||
handleClick(e) {
|
||||
this.close(null)
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Modal dimmer='inverted' open={this.props.open} onClose={this.handleClose}
|
||||
closeOnDimmerClick={false}>
|
||||
<Header color='black' icon='edit' content='Change Password' />
|
||||
<Modal.Content>
|
||||
<Form className='user-form' id='passwordForm' onSubmit={this.handleSubmit}>
|
||||
<Grid stackable>
|
||||
<Grid.Column width={16}>
|
||||
<Form.Group>
|
||||
<ValidatedInput label='Current Password' password name='oldPassword'
|
||||
message='Your existing password, cannot be blank'
|
||||
width={8} validator={this.state.validator} />
|
||||
</Form.Group>
|
||||
<Form.Group>
|
||||
<ValidatedInput label='New Password' password name='newPassword'
|
||||
message='A new password, cannot be blank or the same as your old password'
|
||||
width={8} validator={this.state.validator} />
|
||||
<ValidatedInput label='Re-entered New Password' password name='reenteredNewPassword'
|
||||
message='The new password again, must match and cannot be blank'
|
||||
width={8} validator={this.state.validator} />
|
||||
</Form.Group>
|
||||
</Grid.Column>
|
||||
</Grid>
|
||||
</Form>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<ValidatedActionsButton primary submit form='passwordForm' name='submit' validator={this.state.validator}>
|
||||
<Icon name='checkmark' /> OK
|
||||
</ValidatedActionsButton>
|
||||
<Button color='red' onClick={this.handleClick}>
|
||||
<Icon name='close' /> Cancel
|
||||
</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
}
|
||||
33
website/src/Dialog/MessageDialog.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Modal, Button, Icon, Header } from 'semantic-ui-react'
|
||||
|
||||
export class MessageDialog extends React.Component {
|
||||
static propTypes = {
|
||||
open: PropTypes.bool,
|
||||
error: PropTypes.bool,
|
||||
title: PropTypes.string.isRequired,
|
||||
message: PropTypes.string.isRequired,
|
||||
onDismiss: PropTypes.func
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Modal dimmer='inverted' open={this.props.open} onClose={this.props.onDismiss}
|
||||
closeOnDimmerClick={false}>
|
||||
<Header
|
||||
color={this.props.error ? 'red' : 'blue'}
|
||||
icon={this.props.error ? 'warning circle' : 'info circle'}
|
||||
content={this.props.title} />
|
||||
<Modal.Content>
|
||||
<h3>{this.props.message}</h3>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button onClick={this.props.onDismiss}>
|
||||
<Icon name='checkmark' /> OK
|
||||
</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
}
|
||||
26
website/src/Dialog/ProgressDialog.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Dimmer, Button, Progress } from 'semantic-ui-react'
|
||||
import './ProgressDialog.scss'
|
||||
|
||||
export class ProgressDialog extends React.Component {
|
||||
static propTypes = {
|
||||
open: PropTypes.bool.isRequired,
|
||||
message: PropTypes.string.isRequired,
|
||||
percent: PropTypes.number.isRequired,
|
||||
onCancel: PropTypes.func
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Dimmer inverted page active={this.props.open}>
|
||||
<div className='progress-dialog'>
|
||||
<Progress id='progress' percent={this.props.percent}
|
||||
size='large' progress indicating autoSuccess>{this.props.message}
|
||||
</Progress>
|
||||
<Button name='cancel' primary onClick={this.props.onCancel}>Cancel</Button>
|
||||
</div>
|
||||
</Dimmer>
|
||||
)
|
||||
}
|
||||
}
|
||||
11
website/src/Dialog/ProgressDialog.scss
Normal file
@@ -0,0 +1,11 @@
|
||||
.progress-dialog {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#progress {
|
||||
width: 60%;
|
||||
}
|
||||
18
website/src/Dialog/WaitDialog.js
Normal file
@@ -0,0 +1,18 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Dimmer, Loader } from 'semantic-ui-react'
|
||||
|
||||
export class WaitDialog extends React.Component {
|
||||
static propTypes = {
|
||||
active: PropTypes.bool.isRequired,
|
||||
message: PropTypes.string.isRequired
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Dimmer inverted page active={this.props.active}>
|
||||
<Loader inverted size='massive'>{this.props.message}...</Loader>
|
||||
</Dimmer>
|
||||
)
|
||||
}
|
||||
}
|
||||
37
website/src/Dialog/YesNoMessageDialog.js
Normal file
@@ -0,0 +1,37 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import './YesNoMessageDialog.scss'
|
||||
import { Modal, Button, Icon, Header } from 'semantic-ui-react'
|
||||
|
||||
export class YesNoMessageDialog extends React.Component {
|
||||
static propTypes = {
|
||||
open: PropTypes.bool,
|
||||
title: PropTypes.string.isRequired,
|
||||
message: PropTypes.string.isRequired,
|
||||
onDismiss: PropTypes.func
|
||||
}
|
||||
|
||||
onDismiss(yes) {
|
||||
return () => (this.props.onDismiss ? this.props.onDismiss(yes) : null)
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Modal dimmer='inverted' open={this.props.open} onClose={this.onDismiss(false)}
|
||||
closeOnDimmerClick={false} className='yes-no-modal'>
|
||||
<Header color='orange' size='large' icon='warning circle' content={this.props.title} />
|
||||
<Modal.Content>
|
||||
<p>{this.props.message}</p>
|
||||
</Modal.Content>
|
||||
<Modal.Actions>
|
||||
<Button negative onClick={this.onDismiss(false)}>
|
||||
<Icon name='remove' /> No
|
||||
</Button>
|
||||
<Button positive onClick={this.onDismiss(true)}>
|
||||
<Icon name='checkmark' /> Yes
|
||||
</Button>
|
||||
</Modal.Actions>
|
||||
</Modal>
|
||||
)
|
||||
}
|
||||
}
|
||||
6
website/src/Dialog/YesNoMessageDialog.scss
Normal file
@@ -0,0 +1,6 @@
|
||||
.yes-no-modal p {
|
||||
font-size: 1.125em;
|
||||
line-height: 1.6em;
|
||||
width: 90%;
|
||||
margin: auto;
|
||||
}
|
||||
6
website/src/Dialog/index.js
Normal file
@@ -0,0 +1,6 @@
|
||||
export { WaitDialog } from './WaitDialog'
|
||||
export { ProgressDialog } from './ProgressDialog'
|
||||
export { YesNoMessageDialog } from './YesNoMessageDialog'
|
||||
export { MessageDialog } from './MessageDialog'
|
||||
export { ChangePasswordDialog } from './ChangePasswordDialog'
|
||||
export { ChangeEmailDialog } from './ChangeEmailDialog'
|
||||
106
website/src/FilePicker/FilePicker.js
Normal file
@@ -0,0 +1,106 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Button, Header, Icon } from 'semantic-ui-react'
|
||||
import { autoBind } from 'auto-bind2'
|
||||
import './FilePicker.scss'
|
||||
|
||||
export class FilePicker extends React.Component {
|
||||
static propTypes = {
|
||||
validExtensions: PropTypes.arrayOf(PropTypes.string).isRequired, // Make sure these are lowercase
|
||||
onFileSelect: PropTypes.func,
|
||||
content: PropTypes.string,
|
||||
horizontal: PropTypes.bool
|
||||
}
|
||||
constructor(props) {
|
||||
super(props)
|
||||
autoBind(this, (name) => (name.startsWith('handle')))
|
||||
|
||||
this.state = {
|
||||
icon: 'none',
|
||||
value: ''
|
||||
}
|
||||
this.counter = 0
|
||||
}
|
||||
|
||||
handleDragEnter(e) {
|
||||
this.counter++
|
||||
this.setState({ icon: 'pending' })
|
||||
}
|
||||
|
||||
handleDragLeave(e) {
|
||||
this.counter--
|
||||
|
||||
if (this.counter === 0) {
|
||||
this.setState({ icon: 'none' })
|
||||
}
|
||||
}
|
||||
|
||||
handleDragOver(e) {
|
||||
e.preventDefault()
|
||||
e.stopPropagation()
|
||||
}
|
||||
|
||||
handleDragDrop(e) {
|
||||
e.preventDefault()
|
||||
|
||||
const files = e.dataTransfer.files
|
||||
|
||||
if (files.length > 0) {
|
||||
const file = files[0]
|
||||
|
||||
if (file) {
|
||||
const fileName = file.name.toLowerCase()
|
||||
const isValidFile = this.props.validExtensions.some((ext) => (fileName.endsWith(ext)))
|
||||
|
||||
this.setState({ icon: isValidFile ? 'valid' : 'invalid' })
|
||||
this.counter = 0
|
||||
if (isValidFile && this.props.onFileSelect) {
|
||||
this.props.onFileSelect(file)
|
||||
window.setTimeout(function() {
|
||||
this.setState({ icon: 'none' })
|
||||
}.bind(this), 1000)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
handleOnFileChange(e) {
|
||||
let file = e.currentTarget.files[0]
|
||||
|
||||
this.setState({ value: '' })
|
||||
if (this.props.onFileSelect) {
|
||||
this.props.onFileSelect(file)
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div draggable id={this.props.horizontal ? 'holderHorizontal' : 'holderVertical'}
|
||||
onDragOver={this.handleDragOver}
|
||||
onDragEnter={this.handleDragEnter} onDragLeave={this.handleDragLeave}
|
||||
onDrop={this.handleDragDrop}>
|
||||
<input id='fileInput' type='file' onChange={this.handleOnFileChange} value={this.state.value} />
|
||||
<Button as='label' htmlFor='fileInput' size={'medium'} type='browse' name='selectFile'
|
||||
id='selectFile' content={this.props.content} icon='upload' primary />
|
||||
{ this.props.horizontal
|
||||
? (<Icon id='fileIconHorizontal'
|
||||
name={'file' + ((this.state.icon === 'none' || this.state.icon === 'pending') ? ' outline' : '')}
|
||||
size='huge'
|
||||
color={this.state.icon === 'valid' ? 'green' : this.state.icon === 'invalid' ? 'red' : 'grey'}
|
||||
style={this.state.icon === 'pending' ? { transform: 'scale(1.5)' } : {}} />)
|
||||
: (<Header as='h3' color='grey' icon>
|
||||
OR
|
||||
<Header.Subheader>
|
||||
Drag-and-drop the file here
|
||||
</Header.Subheader>
|
||||
<Icon id='fileIconVertical' className=''
|
||||
name={'file' + ((this.state.icon === 'none' || this.state.icon === 'pending') ? ' outline' : '')}
|
||||
size='huge'
|
||||
color={this.state.icon === 'valid' ? 'green' : this.state.icon === 'invalid' ? 'red' : 'grey'}
|
||||
style={this.state.icon === 'pending' ? { transform: 'scale(1.5)' } : {}} />
|
||||
</Header>)
|
||||
}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
51
website/src/FilePicker/FilePicker.scss
Normal file
@@ -0,0 +1,51 @@
|
||||
#holderVertical {
|
||||
border: 3px dashed lightgray;
|
||||
text-align: center;
|
||||
border-radius: 0.5em;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding: 0.25em 1.25em;
|
||||
width: auto;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
#holderHorizontal {
|
||||
border: 3px dashed lightgray;
|
||||
text-align: center;
|
||||
border-radius: 0.5em;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0.25em 1.25em;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
#helpText {
|
||||
height: 2em;
|
||||
margin-top: 2em;
|
||||
margin-bottom: 2em;
|
||||
color: lightgray;
|
||||
}
|
||||
|
||||
#fileIconVertical {
|
||||
margin-top: 0.5em;
|
||||
margin-bottom: 0.5em;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
#fileIconHorizontal {
|
||||
margin-left: 0.3em;
|
||||
transition: all 0.3s ease;
|
||||
}
|
||||
|
||||
#selectFile {
|
||||
margin-top: 1.5em;
|
||||
margin-bottom: 1.5em;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
#fileInput {
|
||||
display: none;
|
||||
}
|
||||
1
website/src/FilePicker/index.js
Normal file
@@ -0,0 +1 @@
|
||||
export { FilePicker } from './FilePicker'
|
||||
9
website/src/Footer/Footer.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import React from 'react'
|
||||
import './Footer.scss'
|
||||
import { VersionInfo } from '../version'
|
||||
|
||||
export const Footer = () => (
|
||||
<footer>
|
||||
v{VersionInfo.fullVersion}. © {VersionInfo.startYear} Deighton. All rights reserved.
|
||||
</footer>
|
||||
)
|
||||
14
website/src/Footer/Footer.scss
Normal file
@@ -0,0 +1,14 @@
|
||||
footer {
|
||||
background-color: #0b0b0b;
|
||||
color: grey;
|
||||
height: 3em;
|
||||
line-height: 3em;
|
||||
padding: 0 2em;
|
||||
font-size: 1em;
|
||||
margin-top: 3em;
|
||||
position: absolute;
|
||||
right: 0;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
text-align: left;
|
||||
}
|
||||
1
website/src/Footer/index.js
Normal file
@@ -0,0 +1 @@
|
||||
export { Footer } from './Footer'
|
||||
9
website/src/Home/Home.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import React from 'react'
|
||||
|
||||
export class Home extends React.Component {
|
||||
render() {
|
||||
return (
|
||||
<div />
|
||||
)
|
||||
}
|
||||
}
|
||||
1
website/src/Home/index.js
Normal file
@@ -0,0 +1 @@
|
||||
export { Home } from './Home'
|
||||
169
website/src/Navigation/NavBar.js
Normal file
@@ -0,0 +1,169 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { autoBind } from 'auto-bind2'
|
||||
import { Menu, Image, Button, Dropdown } from 'semantic-ui-react'
|
||||
import { Link, NavLink } from 'react-router-dom'
|
||||
import logoImg from 'images/logo.png'
|
||||
import { Constants, api } from '../helpers'
|
||||
import './NavBar.scss'
|
||||
|
||||
export class NavBar extends React.Component {
|
||||
static propTypes = {
|
||||
activeItem: PropTypes.string
|
||||
}
|
||||
|
||||
constructor() {
|
||||
super()
|
||||
autoBind(this, (name) => (name.startsWith('handle')))
|
||||
this.state = {
|
||||
activeItem: null
|
||||
}
|
||||
}
|
||||
|
||||
handleItemClick = (event, { name }) => this.setState({ activeItem: name })
|
||||
|
||||
handleUpdate() {
|
||||
this.forceUpdate()
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
api.addListener('login', this.handleUpdate)
|
||||
api.addListener('logout', this.handleUpdate)
|
||||
api.addListener('newThumbnailImage', this.handleUpdate)
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
api.removeListener('login', this.handleUpdate)
|
||||
api.removeListener('logout', this.handleUpdate)
|
||||
api.addListener('newThumbnailImage', this.handleUpdate)
|
||||
}
|
||||
|
||||
render() {
|
||||
const { activeItem } = this.state
|
||||
const user = api.loggedInUser
|
||||
|
||||
if (!user) {
|
||||
if (window.innerWidth <= 768) {
|
||||
return (
|
||||
<Menu fluid inverted borderless fixed='top' size='large' id='MobileNavMenu'>
|
||||
<Menu.Item>
|
||||
<Image as={Link} to='/' src={logoImg} alt='Deighton Logo' size='tiny' centered />
|
||||
</Menu.Item>
|
||||
<Menu.Menu position='right'>
|
||||
<Menu.Item>
|
||||
<Button as={Link} to='/login' color='facebook' content='Login' />
|
||||
</Menu.Item>
|
||||
</Menu.Menu>
|
||||
</Menu>
|
||||
)
|
||||
} else {
|
||||
return (<Menu pointing stackable secondary id='NavMenu'>
|
||||
<Menu.Item link href='/' active={activeItem === 'logo'} onClick={this.handleItemClick}>
|
||||
<Image className='menu-logo' src={logoImg} alt='Deighton Logo' />
|
||||
</Menu.Item>
|
||||
<Menu.Item id='nav-item1' name='meetTheTeam' active={activeItem === 'meetTheTeam'} onClick={this.handleItemClick} />
|
||||
<Menu.Item id='nav-item2' name='testimonials' active={activeItem === 'testimonials'} onClick={this.handleItemClick} />
|
||||
<Menu.Item id='nav-item3' name='contactUs' active={activeItem === 'contactUs'} onClick={this.handleItemClick} />
|
||||
<Menu.Menu position='right'>
|
||||
<Button as={Link} to='/login' primary content='Login' id='login-button' />
|
||||
</Menu.Menu>
|
||||
</Menu>)
|
||||
}
|
||||
}
|
||||
|
||||
if (user.pending) {
|
||||
return <div />
|
||||
}
|
||||
|
||||
const userImageUrl = api.makeImageUrl(user.thumbnailImageId, Constants.smallUserImageSize)
|
||||
const userName = user.firstName + ' ' + user.lastName
|
||||
|
||||
if (window.innerWidth <= 768) {
|
||||
return (
|
||||
user.role === 'broker'
|
||||
? <Menu fluid inverted borderless fixed='top' size='large' id='MobileNavMenu'>
|
||||
<Menu.Item>
|
||||
<Image as={Link} to='/' src={logoImg} alt='Deighton Logo' size='tiny' centered />
|
||||
</Menu.Item>
|
||||
<Menu.Menu position='right'>
|
||||
<Dropdown icon='content' item>
|
||||
<Dropdown.Menu>
|
||||
<Dropdown.Item as={Link} exact to='/'>Home</Dropdown.Item>
|
||||
<Dropdown.Item as={Link} to='/broker-dashboard'>Dashboard</Dropdown.Item>
|
||||
<Dropdown.Divider />
|
||||
<Dropdown.Item as={Link} to='/profile'>Profile</Dropdown.Item>
|
||||
<Dropdown.Divider />
|
||||
<Dropdown.Item as={Link} to='/logout'>Logout</Dropdown.Item>
|
||||
</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
</Menu.Menu>
|
||||
</Menu>
|
||||
: <Menu fluid inverted borderless fixed='top' size='large' id='MobileNavMenu'>
|
||||
<Menu.Item>
|
||||
<Image as={Link} to='/' src={logoImg} alt='Deighton Logo' size='tiny' centered />
|
||||
</Menu.Item>
|
||||
<Menu.Menu position='right'>
|
||||
<Dropdown icon='content' item>
|
||||
<Dropdown.Menu>
|
||||
<Dropdown.Item as={Link} exact to='/'>Home</Dropdown.Item>
|
||||
<Dropdown.Item as={Link} to='/dashboard'>Dashboard</Dropdown.Item>
|
||||
<Dropdown.Item as={Link} to='/corporations'>Corporations</Dropdown.Item>
|
||||
{ api.loggedInUser.role === 'administrator' || api.loggedInUser.role === 'executive'
|
||||
? <Dropdown.Item as={Link} to='/forms'>Forms</Dropdown.Item>
|
||||
: null
|
||||
}
|
||||
{ api.loggedInUser.role === 'administrator' || api.loggedInUser.role === 'executive'
|
||||
? <Dropdown.Item as={Link} to='/users'>Users</Dropdown.Item>
|
||||
: null
|
||||
}
|
||||
<Dropdown.Divider />
|
||||
<Dropdown.Item as={Link} to='/profile'>Profile</Dropdown.Item>
|
||||
<Dropdown.Divider />
|
||||
<Dropdown.Item as={Link} to='/logout'>Logout</Dropdown.Item>
|
||||
</Dropdown.Menu>
|
||||
</Dropdown>
|
||||
</Menu.Menu>
|
||||
</Menu>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
user.role === 'broker'
|
||||
? <Menu pointing secondary stackable id='NavMenu'>
|
||||
<Menu.Item as={NavLink} activeClassName='nav-menu-active' exact to='/' name='home' active={activeItem === 'home'} onClick={this.handleItemClick} />
|
||||
<Menu.Item as={NavLink} activeClassName='nav-menu-active' to='/broker-dashboard' name='dashboard' active={activeItem === 'dashboard'} onClick={this.handleItemClick} />
|
||||
<Menu.Menu position='right'>
|
||||
<div className='logged-in-user'>
|
||||
<NavLink to='/profile' activeClassName='nav-menu-active'>
|
||||
<Image avatar src={this.userImage} />
|
||||
<span className='user-name'>{userName}</span>
|
||||
</NavLink>
|
||||
<Button as={Link} to='/logout' content='Logout' id='logout-button' />
|
||||
</div>
|
||||
</Menu.Menu>
|
||||
</Menu>
|
||||
: <Menu pointing secondary stackable id='NavMenu'>
|
||||
<Menu.Item as={NavLink} activeClassName='nav-menu-active' exact to='/' name='home' active={activeItem === 'home'} onClick={this.handleItemClick} />
|
||||
<Menu.Item as={NavLink} activeClassName='nav-menu-active' to='/dashboard' name='dashboard' active={activeItem === 'dashboard'} onClick={this.handleItemClick} />
|
||||
<Menu.Item as={NavLink} activeClassName='nav-menu-active' to='/corporations' name='corporations' active={activeItem === 'corporations'} onClick={this.handleItemClick} />
|
||||
{ api.loggedInUser.role === 'administrator' || api.loggedInUser.role === 'executive'
|
||||
? <Menu.Item as={NavLink} activeClassName='nav-menu-active' to='/forms' name='forms' active={activeItem === 'forms'} onClick={this.handleItemClick} />
|
||||
: null
|
||||
}
|
||||
{ api.loggedInUser.role === 'administrator' || api.loggedInUser.role === 'executive'
|
||||
? <Menu.Item as={NavLink} activeClassName='nav-menu-active' to='/users' name='users' active={activeItem === 'users'} onClick={this.handleItemClick} />
|
||||
: null
|
||||
}
|
||||
<Menu.Menu position='right'>
|
||||
<div className='logged-in-user'>
|
||||
<NavLink to='/profile' activeClassName='nav-menu-active'>
|
||||
<Image avatar src={userImageUrl} />
|
||||
<span className='user-name'>{userName}</span>
|
||||
</NavLink>
|
||||
<Button as={Link} to='/logout' content='Logout' id='logout-button' />
|
||||
</div>
|
||||
</Menu.Menu>
|
||||
</Menu>
|
||||
)
|
||||
}
|
||||
}
|
||||
116
website/src/Navigation/NavBar.scss
Normal file
@@ -0,0 +1,116 @@
|
||||
/* === Nav Menu Stylesheet === */
|
||||
|
||||
#NavMenu {
|
||||
background-color: #1b1b1b;
|
||||
box-shadow: 0 0 20px 2px Grey;
|
||||
}
|
||||
|
||||
#NavMenu a.item {
|
||||
color: white;
|
||||
align-self: flex-end;
|
||||
}
|
||||
|
||||
#NavMenu a.item.nav-menu-active {
|
||||
background-color: #2d2b2b;
|
||||
height: 100%;
|
||||
}
|
||||
|
||||
#NavMenu a.item.nav-menu-active:nth-child(n) { border-bottom: 0.25em solid #CF414A; }
|
||||
#NavMenu a.item.nav-menu-active:nth-child(2n) { border-bottom: 0.25em solid #2185D0; }
|
||||
#NavMenu a.item.nav-menu-active:nth-child(3n) { border-bottom: 0.25em solid #DB822E; }
|
||||
|
||||
#NavMenu a.item:hover { background-color: #444344; }
|
||||
|
||||
#NavMenu img.menu-logo {
|
||||
height: 1em;
|
||||
}
|
||||
|
||||
#login-button {
|
||||
height: 60%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 1em;
|
||||
margin: auto 1em;
|
||||
background-color: #3f62ab;
|
||||
}
|
||||
|
||||
#logout-button {
|
||||
height: 60%;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 1em;
|
||||
margin: auto 1em;
|
||||
background-color: silver;
|
||||
}
|
||||
|
||||
.logged-in-user {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.logged-in-user a {
|
||||
color: Silver;
|
||||
margin-right: 1em;
|
||||
}
|
||||
|
||||
.logged-in-user a:hover {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.logged-in-user .user-name {
|
||||
margin-left: 0.25em;
|
||||
}
|
||||
|
||||
#nav-item1 { border-bottom: 5px solid #2e4d9a; }
|
||||
#nav-item2 { border-bottom: 5px solid #db822e; }
|
||||
#nav-item3 { border-bottom: 5px solid #cf414a; }
|
||||
|
||||
/* === Tablet-Specific Menu Styles === */
|
||||
|
||||
#MobileNavMenu {
|
||||
border-radius: 0 !important;
|
||||
border-bottom: 5px solid #db822e !important;
|
||||
}
|
||||
|
||||
@media screen and (max-width: 992px) {
|
||||
.user-name {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* === Mobile-Specific Menu Styles === */
|
||||
|
||||
@media screen and (max-width: 767px) {
|
||||
#NavMenu {
|
||||
font-size: 1em;
|
||||
}
|
||||
|
||||
#NavMenu a.item {
|
||||
text-align: center !important;
|
||||
}
|
||||
|
||||
.logged-in-user {
|
||||
width: 100%;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
|
||||
}
|
||||
|
||||
.user-name {
|
||||
display: inline;
|
||||
}
|
||||
|
||||
.logged-in-user a {
|
||||
width: 30%;
|
||||
}
|
||||
|
||||
#logout-button {
|
||||
width: 30%;
|
||||
margin: 1.5em 0.5em 0.5em 0;
|
||||
}
|
||||
}
|
||||
1
website/src/Navigation/index.js
Normal file
@@ -0,0 +1 @@
|
||||
export { NavBar } from './NavBar'
|
||||
177
website/src/Profile/Profile.js
Normal file
@@ -0,0 +1,177 @@
|
||||
import React from 'react'
|
||||
import { Container } from 'semantic-ui-react'
|
||||
import { ProfileForm } from './ProfileForm'
|
||||
import { Constants, api } from '../helpers'
|
||||
import { WaitDialog, MessageDialog, ChangePasswordDialog, ProgressDialog, ChangeEmailDialog } from '../Dialog'
|
||||
import { autoBind } from 'auto-bind2'
|
||||
|
||||
export class Profile extends React.Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
autoBind(this, (name) => (name.startsWith('handle')))
|
||||
|
||||
const user = api.loggedInUser
|
||||
this.state = {
|
||||
messageDialog: null,
|
||||
waitDialog: null,
|
||||
changePasswordDialog: null,
|
||||
changeEmailDialog: null,
|
||||
progressDialog: null,
|
||||
uploadPercent: 0,
|
||||
user,
|
||||
userImageUrl: api.makeImageUrl(user.imageId, Constants.bigUserImageSize)
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
api.addListener('newProfileImage', this.handleNewProfileImage)
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
api.removeListener('newProfileImage', this.handleNewProfileImage)
|
||||
}
|
||||
|
||||
handleNewProfileImage(data) {
|
||||
this.setState({ userImageUrl: api.makeImageUrl(data.imageId, Constants.bigUserImageSize) })
|
||||
}
|
||||
|
||||
handleSaved(user) {
|
||||
this.setState({ waitDialog: { message: 'Updating Profile' } })
|
||||
api.updateUser(user).then((updatedUser) => {
|
||||
this.setState({
|
||||
waitDialog: null,
|
||||
user: updatedUser
|
||||
})
|
||||
}).catch((error) => {
|
||||
this.setState({
|
||||
waitDialog: null,
|
||||
messageDialog: { title: 'Update Error...', message: `Unable to save the profile changes. ${error.message}` }
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
handleMessageDialogDismiss() {
|
||||
this.setState({ messageDialog: null })
|
||||
}
|
||||
|
||||
handleChangePassword() {
|
||||
this.setState({ changePasswordDialog: true })
|
||||
}
|
||||
|
||||
handleSelectImage(file) {
|
||||
this.setState({ progressDialog: { message: `Uploading image '${file.name}'...`, file }, uploadPercent: 0 })
|
||||
api.upload(file, this.handleProgress).then((uploadData) => {
|
||||
this.setState({ progressDialog: null })
|
||||
return api.setUserImage({
|
||||
_id: api.loggedInUser._id,
|
||||
imageId: uploadData.assetId,
|
||||
bigSize: Profile.bigUserImageSize,
|
||||
smallSize: Constants.smallUserImageSize
|
||||
})
|
||||
}).catch((error) => {
|
||||
// TODO: if the upload succeeds but the setUserImage fails, delete the uploaded image
|
||||
this.setState({
|
||||
progressDialog: null,
|
||||
messageDialog: { title: 'Upload Error...', message: `Unable to upload the file. ${error.message}` }
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
handleProgress(uploadData) {
|
||||
if (this.state.progressDialog) {
|
||||
this.setState({ uploadPercent: Math.round(uploadData.uploadedChunks / uploadData.numberOfChunks * 100) })
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
handleUploadCancel(result) {
|
||||
this.setState({ progressDialog: null })
|
||||
}
|
||||
|
||||
handleChangePasswordDismiss(passwords) {
|
||||
this.setState({ changePasswordDialog: false })
|
||||
|
||||
if (passwords) {
|
||||
this.setState({
|
||||
waitDialog: { message: 'Changing Password' }
|
||||
})
|
||||
api.changePassword(passwords).then(() => {
|
||||
this.setState({ waitDialog: false })
|
||||
}).catch((error) => {
|
||||
this.setState({
|
||||
waitDialog: false,
|
||||
messageDialog: {
|
||||
title: 'Changing Password Error',
|
||||
message: `Unable to change password. ${error.message}.`
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
handleChangeEmail() {
|
||||
this.setState({ changeEmailDialog: {} })
|
||||
}
|
||||
|
||||
handleChangeEmailDismiss(newEmail) {
|
||||
this.setState({ changeEmailDialog: null })
|
||||
if (!newEmail) {
|
||||
return
|
||||
}
|
||||
this.setState({
|
||||
waitDialog: { message: 'Requesting Email Change...' }
|
||||
})
|
||||
api.sendConfirmEmail({ newEmail }).then(() => {
|
||||
this.setState({
|
||||
waitDialog: null,
|
||||
messageDialog: {
|
||||
error: false,
|
||||
title: 'Email Change Requested...',
|
||||
message: `An email has been sent to '${newEmail}' with a link that you need to click on to finish changing your email.`
|
||||
}
|
||||
})
|
||||
}).catch((error) => {
|
||||
this.setState({
|
||||
error: true,
|
||||
waitDialog: null,
|
||||
messageDialog: {
|
||||
error: true,
|
||||
title: 'Email Change Error...',
|
||||
message: `Unable to request email change. ${error ? error.message : ''}`
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Container>
|
||||
<ProfileForm
|
||||
user={this.state.user}
|
||||
onSaved={this.handleSaved}
|
||||
onSelectImage={this.handleSelectImage}
|
||||
onChangePassword={this.handleChangePassword}
|
||||
onChangeEmail={this.handleChangeEmail}
|
||||
userImageUrl={this.state.userImageUrl} />
|
||||
|
||||
<MessageDialog error open={!!this.state.messageDialog}
|
||||
title={this.state.messageDialog ? this.state.messageDialog.title : ''}
|
||||
message={this.state.messageDialog ? this.state.messageDialog.message : ''}
|
||||
onDismiss={this.handleMessageDialogDismiss} />
|
||||
|
||||
<ChangeEmailDialog open={!!this.state.changeEmailDialog} onDismiss={this.handleChangeEmailDismiss} />
|
||||
|
||||
<WaitDialog active={!!this.state.waitDialog} message={this.state.waitDialog ? this.state.waitDialog.message : ''} />
|
||||
|
||||
<ChangePasswordDialog open={!!this.state.changePasswordDialog} onDismiss={this.handleChangePasswordDismiss} />
|
||||
|
||||
<ProgressDialog open={!!this.state.progressDialog}
|
||||
message={this.state.progressDialog ? this.state.progressDialog.message : ''}
|
||||
percent={this.state.uploadPercent}
|
||||
onCancel={this.handleUploadCancel} />
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
170
website/src/Profile/ProfileForm.js
Normal file
@@ -0,0 +1,170 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Grid, Form, Image } from 'semantic-ui-react'
|
||||
import { regExpPattern } from 'regexp-pattern'
|
||||
import './ProfileForm.scss'
|
||||
import { Constants } from '../helpers'
|
||||
import { FilePicker } from '../FilePicker'
|
||||
import { Validator, ValidatedInput, ValidatedDropdown, ValidatedButton, ValidatedDatePicker } from '../Validated'
|
||||
|
||||
export class ProfileForm extends React.Component {
|
||||
static propTypes = {
|
||||
user: PropTypes.object.isRequired,
|
||||
onSaved: PropTypes.func.isRequired,
|
||||
onModifiedChanged: PropTypes.func,
|
||||
onChangePassword: PropTypes.func,
|
||||
onChangeEmail: PropTypes.func,
|
||||
onSelectImage: PropTypes.func,
|
||||
userImageUrl: PropTypes.string
|
||||
}
|
||||
|
||||
static validations = {
|
||||
email: {
|
||||
isValid: (r, v) => (v !== ''),
|
||||
isDisabled: (r) => (!!r._id)
|
||||
},
|
||||
firstName: {
|
||||
isValid: (r, v) => (v !== '')
|
||||
},
|
||||
lastName: {
|
||||
isValid: (r, v) => (v !== '')
|
||||
},
|
||||
zip: {
|
||||
isValid: (r, v) => (v === '' || regExpPattern.zip.test(v))
|
||||
},
|
||||
state: {
|
||||
isValid: (r, v) => (v === '' || regExpPattern.state.test(v))
|
||||
},
|
||||
city: {
|
||||
isValid: true
|
||||
},
|
||||
address1: {
|
||||
isValid: true
|
||||
},
|
||||
address2: {
|
||||
isValid: true
|
||||
},
|
||||
homePhone: {
|
||||
isValid: (r, v) => (v === '' || regExpPattern.phone.test(v))
|
||||
},
|
||||
cellPhone: {
|
||||
isValid: (r, v) => (v === '' || regExpPattern.phone.test(v))
|
||||
},
|
||||
dateOfBirth: {
|
||||
isValid: true
|
||||
},
|
||||
dateOfHire: {
|
||||
isValid: true
|
||||
},
|
||||
ssn: {
|
||||
isValid: (r, v) => (v === '' || regExpPattern.ssn.test(v))
|
||||
},
|
||||
role: {
|
||||
isDisabled: true
|
||||
},
|
||||
save: {
|
||||
nonValue: true,
|
||||
isDisabled: (r) => (!r.anyModified || !r.allValid)
|
||||
}
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.handleSubmit = this.handleSubmit.bind(this)
|
||||
this.state = {
|
||||
validator: new Validator(
|
||||
this.props.user, ProfileForm.validations, this.props.onModifiedChanged)
|
||||
}
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.user !== this.props.user) {
|
||||
this.setState({
|
||||
validator: new Validator(
|
||||
nextProps.user, ProfileForm.validations, nextProps.onModifiedChanged)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
handleSubmit(e) {
|
||||
e.preventDefault()
|
||||
|
||||
let obj = this.state.validator.getValues()
|
||||
|
||||
if (obj && this.props.onSaved) {
|
||||
this.props.onSaved(obj)
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Form className='profile-form' onSubmit={this.handleSubmit}>
|
||||
<Grid stackable>
|
||||
<Grid.Column width={3}>
|
||||
<Image id='userImage' shape='circular' size='medium' src={this.props.userImageUrl} centered />
|
||||
<FilePicker validExtensions={['.jpg', '.jpeg', '.png']} content='Select Image' onFileSelect={this.props.onSelectImage} />
|
||||
</Grid.Column>
|
||||
|
||||
<Grid.Column width={13}>
|
||||
<Form.Group>
|
||||
<ValidatedInput label='First Name' name='firstName' width={8}
|
||||
validator={this.state.validator} />
|
||||
<ValidatedInput label='Last Name' name='lastName' width={8}
|
||||
validator={this.state.validator} />
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group>
|
||||
<ValidatedInput label='Email' name='email' width={8} message='Required. Must be a valid email address.'
|
||||
validator={this.state.validator} />
|
||||
<Form.Button fluid content={'Change Email'} label=' '
|
||||
width={4} onClick={this.props.onChangeEmail} />
|
||||
<Form.Button fluid content={'Change Password'} label=' '
|
||||
width={4} onClick={this.props.onChangePassword} />
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group>
|
||||
<ValidatedInput label='Zip' name='zip' width={4}
|
||||
validator={this.state.validator} message='5 Character U.S. Zip Code. Optional.' />
|
||||
<ValidatedDropdown label='State' name='state' width={6} message='Type or select a U.S. State or Province.'
|
||||
placeholder='Select State' options={Constants.stateOptions}
|
||||
validator={this.state.validator} searchable />
|
||||
<ValidatedInput label='City' name='city' width={6}
|
||||
validator={this.state.validator} message='U.S. City. Optional.' />
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group>
|
||||
<ValidatedInput label='Address' name='address1' width={12}
|
||||
validator={this.state.validator} message='Primary Street Address. Optional.' />
|
||||
<ValidatedInput label='Apt. #' name='address2' width={4}
|
||||
validator={this.state.validator} message='Apartment/Unit number. Optional.' />
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group>
|
||||
<ValidatedInput label='Home Phone' name='homePhone' width={8}
|
||||
validator={this.state.validator} message='A valid U.S. phone number. IE: (555)123-4567. Optional.' />
|
||||
<ValidatedInput label='Cell Phone' name='cellPhone' width={8}
|
||||
validator={this.state.validator} message='A valid U.S. phone number. IE: (555)123-4567. Optional.' />
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group>
|
||||
<ValidatedDatePicker label='Date of Birth' name='dateOfBirth' width={5}
|
||||
validator={this.state.validator} message='Select a date.' />
|
||||
<ValidatedInput label='SSN' name='ssn' width={6}
|
||||
validator={this.state.validator} message='U.S. Social Security Number. IE: 123-45-6789' />
|
||||
<ValidatedDatePicker label='Hire Date' name='dateOfHire' width={5}
|
||||
validator={this.state.validator} message='Select a date.' />
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group>
|
||||
<Form.Field width={12} />
|
||||
<ValidatedButton submit primary width={4} size='medium' content='Save' label=' ' name='save'
|
||||
validator={this.state.validator} />
|
||||
</Form.Group>
|
||||
|
||||
</Grid.Column>
|
||||
</Grid>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
}
|
||||
12
website/src/Profile/ProfileForm.scss
Normal file
@@ -0,0 +1,12 @@
|
||||
.profile-form {
|
||||
text-align: left;
|
||||
margin: 3em auto 4em auto;
|
||||
}
|
||||
|
||||
.profile-form > .fields {
|
||||
margin-bottom: 1.5em !important;
|
||||
}
|
||||
|
||||
#userImage {
|
||||
margin-bottom: 2em;
|
||||
}
|
||||
1
website/src/Profile/index.js
Normal file
@@ -0,0 +1 @@
|
||||
export { Profile } from './Profile'
|
||||
230
website/src/Users/UserForm.js
Normal file
@@ -0,0 +1,230 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { autoBind } from 'auto-bind2'
|
||||
import { regExpPattern } from 'regexp-pattern'
|
||||
import { Grid, Form } from 'semantic-ui-react'
|
||||
import './UserForm.scss'
|
||||
import { ValidatedEmailIcon } from './ValidatedEmailIcon'
|
||||
import { Constants, api } from '../helpers'
|
||||
import { Validator, ValidatedInput, ValidatedButton, ValidatedDropdown, ValidatedDatePicker, ValidatedContainer } from '../Validated'
|
||||
|
||||
export class UserForm extends React.Component {
|
||||
static propTypes = {
|
||||
user: PropTypes.object,
|
||||
onSave: PropTypes.func,
|
||||
onRemove: PropTypes.func,
|
||||
onModifiedChanged: PropTypes.func,
|
||||
onChangeEmail: PropTypes.func,
|
||||
onResendEmail: PropTypes.func
|
||||
}
|
||||
|
||||
static validations = {
|
||||
email: {
|
||||
isValid: (r, v) => (regExpPattern.email.test(v)),
|
||||
isDisabled: (r) => (!!r._id)
|
||||
},
|
||||
emailValidated: {
|
||||
isDisabled: (r) => (!!r._id === false)
|
||||
},
|
||||
changeEmail: {
|
||||
nonValue: true,
|
||||
isDisabled: (r) => (!!r._id === false)
|
||||
},
|
||||
firstName: {
|
||||
isValid: (r, v) => (v !== '')
|
||||
},
|
||||
lastName: {
|
||||
isValid: (r, v) => (v !== '')
|
||||
},
|
||||
zip: {
|
||||
isValid: (r, v) => (v === '' || regExpPattern.zip.test(v))
|
||||
},
|
||||
state: {
|
||||
isValid: (r, v) => (v === '' || regExpPattern.state.test(v))
|
||||
},
|
||||
city: {
|
||||
isValid: true
|
||||
},
|
||||
address1: {
|
||||
isValid: true
|
||||
},
|
||||
address2: {
|
||||
isValid: true
|
||||
},
|
||||
homePhone: {
|
||||
isValid: (r, v) => (v === '' || regExpPattern.phone.test(v))
|
||||
},
|
||||
cellPhone: {
|
||||
isValid: (r, v) => (v === '' || regExpPattern.phone.test(v))
|
||||
},
|
||||
dateOfBirth: {
|
||||
isValid: true
|
||||
},
|
||||
dateOfHire: {
|
||||
isValid: true
|
||||
},
|
||||
ssn: {
|
||||
isValid: (r, v) => (v === '' || regExpPattern.ssn.test(v))
|
||||
},
|
||||
numHouseholds: {
|
||||
isValid: true
|
||||
},
|
||||
t12: {
|
||||
isValid: true
|
||||
},
|
||||
aum: {
|
||||
isValid: true
|
||||
},
|
||||
role: {
|
||||
isValid: (r, v) => (v !== ''),
|
||||
isDisabled: (r) => (api.loggedInUser._id === r._id)
|
||||
},
|
||||
project: {
|
||||
isValid: (r, v) => (v !== '' || v === '')
|
||||
},
|
||||
remove: {
|
||||
nonValue: true,
|
||||
isVisible: (r) => (!!r._id),
|
||||
isDisabled: (r) => (api.loggedInUser._id === r._id)
|
||||
},
|
||||
reset: {
|
||||
nonValue: true,
|
||||
isDisabled: (r) => (!r.anyModified)
|
||||
},
|
||||
submit: {
|
||||
nonValue: true,
|
||||
isDisabled: (r) => (!r.anyModified && !r.allValid)
|
||||
},
|
||||
'broker-fields': {
|
||||
nonValue: true,
|
||||
isVisible: (r, v) => (r.getField('role').value === 'broker')
|
||||
},
|
||||
'standard-fields': {
|
||||
nonValue: true,
|
||||
isVisible: (r, v) => (r.getField('role').value !== 'broker')
|
||||
}
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
autoBind(this, (name) => (name.startsWith('handle')))
|
||||
this.state = {
|
||||
validator: new Validator(this.props.user, UserForm.validations, this.props.onModifiedChanged)
|
||||
}
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.user !== this.props.user) {
|
||||
this.setState({
|
||||
validator: new Validator(nextProps.user, UserForm.validations, nextProps.onModifiedChanged)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
handleSubmit(e) {
|
||||
e.preventDefault()
|
||||
let obj = this.state.validator.getValues()
|
||||
if (obj) {
|
||||
this.props.onSave(obj)
|
||||
}
|
||||
}
|
||||
|
||||
handleReset() {
|
||||
this.setState({ validator: new Validator(this.props.user, UserForm.validations, this.props.onModifiedChanged) })
|
||||
this.props.onModifiedChanged(false)
|
||||
}
|
||||
|
||||
handleChangeEmail() {
|
||||
this.props.onChangeEmail()
|
||||
}
|
||||
|
||||
handleResendEmail() {
|
||||
this.props.onResendEmail()
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Form className='user-form' onSubmit={this.handleSubmit}>
|
||||
<Grid stackable>
|
||||
<Grid.Column width={16}>
|
||||
<Form.Group>
|
||||
<ValidatedDropdown label={'Deighton Access & Security Level'} width={6} selection
|
||||
options={Constants.accessLevels} name='role' message='The user role and security level'
|
||||
placeholder='' validator={this.state.validator} />
|
||||
</Form.Group>
|
||||
<Form.Group>
|
||||
<ValidatedInput label='First Name' name='firstName'
|
||||
width={8} validator={this.state.validator} />
|
||||
<ValidatedInput label='Last Name' name='lastName'
|
||||
width={8} validator={this.state.validator} />
|
||||
</Form.Group>
|
||||
<Form.Group>
|
||||
<ValidatedInput label='Email' name='email' width={8} message='Must be a valid email address. Required.'
|
||||
validator={this.state.validator} />
|
||||
<ValidatedEmailIcon name='emailValidated' validator={this.state.validator} width={4}
|
||||
onClick={this.handleResendEmail} />
|
||||
<ValidatedButton width={4} size='medium' content='Change Email' label=' ' name='changeEmail'
|
||||
validator={this.state.validator} onClick={this.handleChangeEmail} />
|
||||
</Form.Group>
|
||||
|
||||
<ValidatedContainer name='standard-fields' validator={this.state.validator}>
|
||||
<Form.Group>
|
||||
<ValidatedInput label='Zip' width={4} name='zip' message='5 Character U.S. Zip Code. Optional.'
|
||||
position='bottom center' validator={this.state.validator} />
|
||||
<ValidatedDropdown label='State' name='state' width={4}
|
||||
placeholder='Select State' options={Constants.stateOptions} validator={this.state.validator} searchable />
|
||||
<ValidatedInput label='City' width={8} type='text' name='city' message='U.S. City. Optional.'
|
||||
validator={this.state.validator} />
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group>
|
||||
<ValidatedInput label='Address' width={12} name='address1'
|
||||
validator={this.state.validator} message='Primary Street Address. Optional.' />
|
||||
<ValidatedInput label='Apt. #' width={4} name='address2'
|
||||
validator={this.state.validator} message='Apartment/Unit number. Optional.' />
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group>
|
||||
<ValidatedInput label='Home Phone' width={8} name='homePhone'
|
||||
validator={this.state.validator} message='A valid U.S. phone number. IE: (555)123-4567. Optional.' />
|
||||
<ValidatedInput label='Cell Phone' width={8} name='cellPhone'
|
||||
validator={this.state.validator} message='A valid U.S. phone number. IE: (555)123-4567. Optional.' />
|
||||
</Form.Group>
|
||||
|
||||
<Form.Group>
|
||||
<ValidatedDatePicker label='Date of Birth' width={5} name='dateOfBirth'
|
||||
validator={this.state.validator} />
|
||||
<ValidatedInput label='SSN' width={6} name='ssn'
|
||||
validator={this.state.validator} message='U.S. Social Security Number. IE: 123-45-6789' />
|
||||
<ValidatedDatePicker label='Hire Date' width={5} name='dateOfHire'
|
||||
validator={this.state.validator} />
|
||||
</Form.Group>
|
||||
</ValidatedContainer>
|
||||
|
||||
<ValidatedContainer name='broker-fields' validator={this.state.validator}>
|
||||
<Form.Group>
|
||||
<ValidatedInput label='# Households' width={5} name='numHouseholds'
|
||||
message='Number of households in this brokers account' validator={this.state.validator} />
|
||||
<ValidatedInput label='T-12' width={6} name='t12' message='This brokers T-12 info.'
|
||||
validator={this.state.validator} />
|
||||
<ValidatedInput label='AUM' width={5} name='aum'
|
||||
message='This brokers AUM information.' validator={this.state.validator} />
|
||||
</Form.Group>
|
||||
</ValidatedContainer>
|
||||
|
||||
<Form.Group>
|
||||
<ValidatedButton color='red' width={4} size='medium' content='Remove' label=' ' name='remove'
|
||||
validator={this.state.validator} onClick={this.props.onRemove} />
|
||||
<ValidatedButton width={4} size='medium' content='Reset' label=' ' name='reset'
|
||||
validator={this.state.validator} onClick={this.handleReset} />
|
||||
<Form.Field width={this.state.validator._id ? 8 : 12} />
|
||||
<ValidatedButton primary submit width={4} size='medium'
|
||||
content={this.state.validator._id ? 'Save' : 'Add'} label=' ' name='submit'
|
||||
validator={this.state.validator} />
|
||||
</Form.Group>
|
||||
</Grid.Column>
|
||||
</Grid>
|
||||
</Form>
|
||||
)
|
||||
}
|
||||
}
|
||||
8
website/src/Users/UserForm.scss
Normal file
@@ -0,0 +1,8 @@
|
||||
.user-form {
|
||||
text-align: left;
|
||||
margin: 3em auto 4em auto;
|
||||
}
|
||||
|
||||
.user-form > .fields {
|
||||
margin-bottom: 1.5em !important;
|
||||
}
|
||||
9
website/src/Users/UserFormPlaceholder.js
Normal file
@@ -0,0 +1,9 @@
|
||||
import React from 'react'
|
||||
import './UserFormPlaceholder.scss'
|
||||
|
||||
export const UserFormPlaceholder = () => (
|
||||
<div className='user-form-placeholder'>
|
||||
<h3>Select a registered user to view details here</h3>
|
||||
<h5>Or 'Add New User'</h5>
|
||||
</div>
|
||||
)
|
||||
7
website/src/Users/UserFormPlaceholder.scss
Normal file
@@ -0,0 +1,7 @@
|
||||
.user-form-placeholder {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
}
|
||||
69
website/src/Users/UserList.js
Normal file
@@ -0,0 +1,69 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Dropdown, List, Icon, Button, Image } from 'semantic-ui-react'
|
||||
import { Constants, api } from '../helpers'
|
||||
import './UserList.scss'
|
||||
|
||||
const selectionOptions = Constants.accessLevels.concat([{ value: 'all', text: 'All Levels' }])
|
||||
|
||||
export class UserList extends React.Component {
|
||||
static propTypes = {
|
||||
users: PropTypes.array,
|
||||
onUserListClick: PropTypes.func,
|
||||
selectedUser: PropTypes.object,
|
||||
selectionModified: PropTypes.bool,
|
||||
onAddNewUser: PropTypes.func
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {
|
||||
users: null
|
||||
}
|
||||
this.filterUsers = this.filterUsers.bind(this)
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
// This ensures that the original list is populated with 'all' by default,
|
||||
// due to the component mounting before users are returned (by api)
|
||||
if (nextProps.users !== this.props.users) {
|
||||
this.setState({ users: nextProps.users })
|
||||
}
|
||||
}
|
||||
|
||||
filterUsers(e, data) {
|
||||
e.preventDefault()
|
||||
let users = this.props.users
|
||||
if (data.value !== 'all') {
|
||||
users = users.filter(user => data.value === user.role)
|
||||
}
|
||||
this.setState({ users })
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<div>
|
||||
<Dropdown placeholder='All Registered Users' selection fluid
|
||||
options={selectionOptions} onChange={this.filterUsers} />
|
||||
<List className='user-list' size='big' selection verticalAlign='middle'>
|
||||
{
|
||||
this.state.users
|
||||
? this.state.users.map((user, index) =>
|
||||
(<List.Item className='user-list-item' key={user._id || '0'} onClick={this.props.onUserListClick}
|
||||
active={user === this.props.selectedUser} data-index={index}>
|
||||
<Image avatar src={api.makeImageUrl(user.thumbnailImageId, Constants.smallUserImageSize)} />
|
||||
<List.Content>
|
||||
{ user._id ? user.firstName + ' ' + user.lastName : '[New User]' }
|
||||
{ user === this.props.selectedUser && this.props.selectionModified ? <Icon className='user-update'
|
||||
name='edit' /> : null }
|
||||
</List.Content>
|
||||
</List.Item>)
|
||||
)
|
||||
: null
|
||||
}
|
||||
</List>
|
||||
<Button className='add-new-user' content='Add New User' primary onClick={this.props.onAddNewUser} />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
}
|
||||
21
website/src/Users/UserList.scss
Normal file
@@ -0,0 +1,21 @@
|
||||
.user-list {
|
||||
text-align: left;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
padding: 0.25em !important;
|
||||
border-radius: 5px;
|
||||
box-shadow: 0 0 0.25em 2px Silver;
|
||||
-webkit-box-shadow: 0 0 0.25em 2px Silver;
|
||||
max-height: 60vh;
|
||||
min-height: 60vh;
|
||||
overflow-y: scroll;
|
||||
}
|
||||
|
||||
.user-list > .item {
|
||||
margin: 5em 0;
|
||||
}
|
||||
|
||||
i.user-update {
|
||||
position: absolute;
|
||||
right: 7.5%;
|
||||
}
|
||||
281
website/src/Users/Users.js
Normal file
@@ -0,0 +1,281 @@
|
||||
import React from 'react'
|
||||
import { Container, Grid } from 'semantic-ui-react'
|
||||
import { autoBind } from 'auto-bind2'
|
||||
import { UserList } from './UserList'
|
||||
import { UserForm } from './UserForm'
|
||||
import { UserFormPlaceholder } from './UserFormPlaceholder'
|
||||
import { api } from '../helpers'
|
||||
import { YesNoMessageDialog, MessageDialog, ChangeEmailDialog, WaitDialog } from '../Dialog'
|
||||
|
||||
export class Users extends React.Component {
|
||||
constructor() {
|
||||
super()
|
||||
autoBind(this, (name) => (name.startsWith('handle')))
|
||||
this.state = {
|
||||
selectedUser: null,
|
||||
users: [],
|
||||
yesNoDialog: null,
|
||||
messageDialog: null,
|
||||
waitDialog: null,
|
||||
changeEmailDialog: null
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
api.listUsers().then((list) => {
|
||||
list.items.sort((userA, userB) => (userA.lastName.localeCompare(userB.lastName)))
|
||||
this.setState({ users: list.items })
|
||||
}).catch((error) => {
|
||||
this.setState({
|
||||
messageDialog: {
|
||||
error: true,
|
||||
title: 'User List Error',
|
||||
message: `Unable to get the list of users. ${error.message}`
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
removeUnfinishedNewUser() {
|
||||
let users = this.state.users
|
||||
|
||||
if (users.length > 0 && !users[0]._id) {
|
||||
this.setState({ users: this.state.users.slice(1) })
|
||||
}
|
||||
}
|
||||
|
||||
handleUserListClick(e) {
|
||||
let user = this.state.users[Number(e.currentTarget.getAttribute('data-index'))]
|
||||
|
||||
if (this.state.modified) {
|
||||
this.nextSelectedUser = user
|
||||
this.setState({
|
||||
yesNoDialog: {
|
||||
title: 'User Modified',
|
||||
message: 'This user has been modified. Are you sure you would like to navigate away?',
|
||||
onDismiss: this.handleModifiedDialogDismiss
|
||||
}
|
||||
})
|
||||
} else {
|
||||
this.setState({ selectedUser: user })
|
||||
this.removeUnfinishedNewUser()
|
||||
}
|
||||
}
|
||||
|
||||
handleSave(user) {
|
||||
if (user._id) {
|
||||
this.setState({ waitDialog: { message: 'Updating User' } })
|
||||
api.updateUser(user).then((updatedUser) => {
|
||||
this.setState({
|
||||
waitDialog: null,
|
||||
users: this.state.users.map((user) => (user._id === updatedUser._id ? updatedUser : user)),
|
||||
modified: false,
|
||||
selectedUser: updatedUser
|
||||
})
|
||||
}).catch((error) => {
|
||||
this.setState({
|
||||
waitDialog: null,
|
||||
messageDialog: {
|
||||
error: true,
|
||||
title: 'Update Error',
|
||||
message: `Unable to save the user changes. ${error.message}`
|
||||
}
|
||||
})
|
||||
})
|
||||
} else {
|
||||
this.setState({ waitDialog: { message: 'Creating User' } })
|
||||
api.createUser(user).then((createdUser) => {
|
||||
this.setState({
|
||||
waitDialog: false,
|
||||
users: this.state.users.map((user) => (!user._id ? createdUser : user)),
|
||||
modified: false,
|
||||
selectedUser: createdUser
|
||||
})
|
||||
}).catch((error) => {
|
||||
this.setState({
|
||||
waitDialog: null,
|
||||
messageDialog: {
|
||||
error: true,
|
||||
title: 'Create Error',
|
||||
message: `Unable to create the user. ${error.message}`
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
handleChangeEmail() {
|
||||
this.setState({ changeEmailDialog: {} })
|
||||
}
|
||||
|
||||
handleResendEmail() {
|
||||
this.setState({
|
||||
waitDialog: { message: 'Resending Email...' }
|
||||
})
|
||||
api.sendConfirmEmail({ existingEmail: this.state.selectedUser.email }).then(() => {
|
||||
this.setState({
|
||||
waitDialog: null,
|
||||
messageDialog: {
|
||||
error: false,
|
||||
title: "We've Re-Sent the Email...",
|
||||
message: `An email has been sent to '${this.state.selectedUser.email}'. This user will need to follow that email's included link to verify their account.`
|
||||
}
|
||||
})
|
||||
}).catch((error) => {
|
||||
this.setState({
|
||||
error: true,
|
||||
waitDialog: null,
|
||||
messageDialog: {
|
||||
error: true,
|
||||
title: 'Email Change Error...',
|
||||
message: `Unable to request email change. ${error ? error.message : ''}`
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
handleChangeEmailDismiss(newEmail) {
|
||||
this.setState({ changeEmailDialog: null })
|
||||
if (!newEmail) {
|
||||
return
|
||||
}
|
||||
this.setState({
|
||||
waitDialog: { message: 'Requesting Email Change...' }
|
||||
})
|
||||
api.sendConfirmEmail({ existingEmail: this.state.selectedUser.email, newEmail }).then(() => {
|
||||
this.setState({
|
||||
waitDialog: null,
|
||||
messageDialog: {
|
||||
error: false,
|
||||
title: 'Email Change Requested...',
|
||||
message: `An email has been sent to '${newEmail}'. This user will need to follow that email's included link to finish changing their email.`
|
||||
}
|
||||
})
|
||||
}).catch((error) => {
|
||||
this.setState({
|
||||
error: true,
|
||||
waitDialog: null,
|
||||
messageDialog: {
|
||||
error: true,
|
||||
title: 'Email Change Error...',
|
||||
message: `Unable to request email change. ${error ? error.message : ''}`
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
handleRemove() {
|
||||
this.setState({
|
||||
yesNoDialog: {
|
||||
title: 'Permanently Delete User?',
|
||||
message: 'You are about to delete this user from the system. This includes references to this user in Projects, Packages, and so on. Are you sure you want to remove this user?',
|
||||
onDismiss: this.handleRemoveDialogDismiss
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
handleRemoveDialogDismiss(yes) {
|
||||
if (yes) {
|
||||
// TODO: Pass the _id back from the dialog input data
|
||||
const selectedUserId = this.state.selectedUser._id
|
||||
const selectedIndex = this.state.users.findIndex((user) => (user._id === selectedUserId))
|
||||
|
||||
if (selectedIndex >= 0) {
|
||||
this.setState({ waitDialog: { message: 'Removing User' } })
|
||||
api.deleteUser(selectedUserId).then(() => {
|
||||
this.setState({
|
||||
waitDialog: null,
|
||||
users: [...this.state.users.slice(0, selectedIndex), ...this.state.users.slice(selectedIndex + 1)],
|
||||
selectedUser: null
|
||||
})
|
||||
}).catch((error) => {
|
||||
this.setState({
|
||||
waitDialog: null,
|
||||
messageDialog: {
|
||||
error: true,
|
||||
title: 'Remove Error',
|
||||
message: `Unable to remove the user. ${error.message}`
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
this.setState({
|
||||
yesNoDialog: null
|
||||
})
|
||||
}
|
||||
|
||||
handleModifiedDialogDismiss(yes) {
|
||||
if (yes) {
|
||||
this.setState({
|
||||
selectedUser: this.nextSelectedUser,
|
||||
modified: false
|
||||
})
|
||||
this.removeUnfinishedNewUser()
|
||||
delete this.nextSelectedUser
|
||||
}
|
||||
|
||||
this.setState({
|
||||
yesNoDialog: null
|
||||
})
|
||||
}
|
||||
|
||||
handleMessageDialogDismiss() {
|
||||
this.setState({ messageDialog: null })
|
||||
}
|
||||
|
||||
handleModifiedChanged(modified) {
|
||||
this.setState({ modified: modified })
|
||||
}
|
||||
|
||||
handleAddNewUser() {
|
||||
let newUser = {}
|
||||
let newUsers = [newUser].concat(this.state.users)
|
||||
this.setState({ users: newUsers, selectedUser: newUser })
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Container>
|
||||
<div>Users</div>
|
||||
|
||||
<Grid stackable>
|
||||
{/* User List - Displayed on left hand side. */}
|
||||
<Grid.Column width={5}>
|
||||
<UserList users={this.state.users} selectedUser={this.state.selectedUser}
|
||||
selectionModified={this.state.modified} onUserListClick={this.handleUserListClick}
|
||||
onAddNewUser={this.handleAddNewUser} />
|
||||
</Grid.Column>
|
||||
|
||||
{/* User Info - Displayed on right hand side. */}
|
||||
<Grid.Column width={11}>
|
||||
{
|
||||
this.state.selectedUser
|
||||
? <UserForm user={this.state.selectedUser} onSave={this.handleSave}
|
||||
onRemove={this.handleRemove} onModifiedChanged={this.handleModifiedChanged}
|
||||
onChangeEmail={this.handleChangeEmail} onResendEmail={this.handleResendEmail} />
|
||||
: <UserFormPlaceholder />
|
||||
}
|
||||
</Grid.Column>
|
||||
</Grid>
|
||||
|
||||
<ChangeEmailDialog open={!!this.state.changeEmailDialog} onDismiss={this.handleChangeEmailDismiss} />
|
||||
|
||||
<YesNoMessageDialog open={!!this.state.yesNoDialog}
|
||||
title={this.state.yesNoDialog ? this.state.yesNoDialog.title : ''}
|
||||
message={this.state.yesNoDialog ? this.state.yesNoDialog.message : ''}
|
||||
onDismiss={this.state.yesNoDialog ? this.state.yesNoDialog.onDismiss : null} />
|
||||
|
||||
<MessageDialog
|
||||
open={!!this.state.messageDialog}
|
||||
error={this.state.messageDialog ? this.state.messageDialog.error : false}
|
||||
title={this.state.messageDialog ? this.state.messageDialog.title : ''}
|
||||
message={this.state.messageDialog ? this.state.messageDialog.message : ''}
|
||||
onDismiss={this.handleMessageDialogDismiss} />
|
||||
|
||||
<WaitDialog active={!!this.state.waitDialog} message={this.state.waitDialog ? this.state.waitDialog.message : ''} />
|
||||
</Container>
|
||||
)
|
||||
}
|
||||
}
|
||||
47
website/src/Users/ValidatedEmailIcon.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Form, Icon, Popup, Button } from 'semantic-ui-react'
|
||||
import './ValidatedEmailIcon.scss'
|
||||
|
||||
// This is a validated component with a value that cannot change itself and is specialized
|
||||
|
||||
export class ValidatedEmailIcon extends React.Component {
|
||||
static propTypes = {
|
||||
name: PropTypes.string,
|
||||
validator: PropTypes.object,
|
||||
width: PropTypes.number,
|
||||
onClick: PropTypes.func
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = props.validator.getField('emailValidated')
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.validator !== this.props.validator) {
|
||||
this.setState(nextProps.validator.getField(nextProps.name))
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.value) {
|
||||
return (
|
||||
<Form.Field width={this.props.width}>
|
||||
<label> </label>
|
||||
<Popup content='Email Validated' position='bottom center' hoverable trigger={
|
||||
<Icon name='mail' color='green' size='big' className='mail-validated-icon' />
|
||||
} />
|
||||
</Form.Field>
|
||||
)
|
||||
} else {
|
||||
return (
|
||||
<Form.Field width={this.props.width}>
|
||||
<label> </label>
|
||||
<Button fluid icon='mail outline' color='red' labelPosition='left'
|
||||
content='Resend Email' onClick={this.props.onClick} disabled={this.state.disabled} />
|
||||
</Form.Field>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
3
website/src/Users/ValidatedEmailIcon.scss
Normal file
@@ -0,0 +1,3 @@
|
||||
.mail-validated-icon {
|
||||
padding-top: 4px;
|
||||
}
|
||||
1
website/src/Users/index.js
Normal file
@@ -0,0 +1 @@
|
||||
export { Users } from './Users'
|
||||
59
website/src/Validated/ValidatedActionsButton.js
Normal file
@@ -0,0 +1,59 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Button } from 'semantic-ui-react'
|
||||
|
||||
export class ValidatedActionsButton extends React.Component {
|
||||
static propTypes = {
|
||||
name: PropTypes.string.isRequired,
|
||||
size: PropTypes.string,
|
||||
validator: PropTypes.object.isRequired,
|
||||
primary: PropTypes.bool,
|
||||
submit: PropTypes.bool,
|
||||
color: PropTypes.string,
|
||||
form: PropTypes.string,
|
||||
children: PropTypes.node
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.updateValue = this.updateValue.bind(this)
|
||||
|
||||
let { name, validator } = this.props
|
||||
|
||||
validator.addListener(name, this.updateValue)
|
||||
this.state = validator.getField(name)
|
||||
}
|
||||
|
||||
updateValue(name) {
|
||||
this.setState(this.props.validator.getField(name))
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.props.validator.removeListener(this.props.name, this.updateValue)
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.validator !== this.props.validator) {
|
||||
this.props.validator.removeListener(this.props.name, this.updateValue)
|
||||
nextProps.validator.addListener(nextProps.name, this.updateValue)
|
||||
this.setState(nextProps.validator.getField(nextProps.name))
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
const { children, size, color, primary, submit, name, form } = this.props
|
||||
|
||||
if (this.state.visible) {
|
||||
return (
|
||||
<Button color={color} primary={primary}
|
||||
disabled={this.state.disabled}
|
||||
type={submit ? 'submit' : 'button'}
|
||||
size={size} name={name} form={form}>
|
||||
{children}
|
||||
</Button>
|
||||
)
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
61
website/src/Validated/ValidatedButton.js
Normal file
@@ -0,0 +1,61 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Form, Button } from 'semantic-ui-react'
|
||||
|
||||
export class ValidatedButton extends React.Component {
|
||||
static propTypes = {
|
||||
name: PropTypes.string.isRequired,
|
||||
label: PropTypes.string,
|
||||
width: PropTypes.number,
|
||||
size: PropTypes.string,
|
||||
content: PropTypes.string,
|
||||
validator: PropTypes.object.isRequired,
|
||||
primary: PropTypes.bool,
|
||||
submit: PropTypes.bool,
|
||||
color: PropTypes.string,
|
||||
floated: PropTypes.string,
|
||||
onClick: PropTypes.func
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.updateValue = this.updateValue.bind(this)
|
||||
|
||||
let { name, validator } = this.props
|
||||
|
||||
validator.addListener(name, this.updateValue)
|
||||
this.state = validator.getField(name)
|
||||
}
|
||||
|
||||
updateValue(name) {
|
||||
this.setState(this.props.validator.getField(name))
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.props.validator.removeListener(this.props.name, this.updateValue)
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.validator !== this.props.validator) {
|
||||
this.props.validator.removeListener(this.props.name, this.updateValue)
|
||||
nextProps.validator.addListener(nextProps.name, this.updateValue)
|
||||
this.setState(nextProps.validator.getField(nextProps.name))
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.visible) {
|
||||
return (
|
||||
<Form.Field width={this.props.width} disabled={this.state.disabled}>
|
||||
<label>{this.props.label}</label>
|
||||
<Button fluid color={this.props.color} primary={this.props.primary}
|
||||
type={this.props.submit ? 'submit' : 'button'} onClick={this.props.onClick}
|
||||
content={this.props.content} size={this.props.size} name={this.props.name}
|
||||
floated={this.props.floated} />
|
||||
</Form.Field>
|
||||
)
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
48
website/src/Validated/ValidatedCheckbox.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Form, Popup, Checkbox } from 'semantic-ui-react'
|
||||
|
||||
// This is an example of a validated component with a value that can change itself, that cannot ever be invalid.
|
||||
|
||||
export class ValidatedCheckbox extends React.Component {
|
||||
static propTypes = {
|
||||
name: PropTypes.string.isRequired,
|
||||
message: PropTypes.string.isRequired,
|
||||
label: PropTypes.string,
|
||||
width: PropTypes.number,
|
||||
validator: PropTypes.object.isRequired,
|
||||
className: PropTypes.string
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = props.validator.getField(props.name)
|
||||
this.handleChange = this.handleChange.bind(this)
|
||||
}
|
||||
|
||||
handleChange(e, data) {
|
||||
const { validator, name } = this.props
|
||||
const state = validator.getField(name)
|
||||
|
||||
if (!state.readOnly && !state.disabled) {
|
||||
this.setState(validator.updateValue(name, data.checked))
|
||||
}
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.validator !== this.props.validator) {
|
||||
this.setState(nextProps.validator.getField(nextProps.name))
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Form.Field width={this.props.width} disabled={this.state.disabled} className={this.props.className}>
|
||||
<Popup content={this.props.message} position='bottom center' hoverable trigger={
|
||||
<Checkbox checked={!!this.state.value} name={this.props.name} label={this.props.label}
|
||||
onChange={this.handleChange} />} />
|
||||
</Form.Field>
|
||||
)
|
||||
}
|
||||
}
|
||||
52
website/src/Validated/ValidatedContainer.js
Normal file
@@ -0,0 +1,52 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Container } from 'semantic-ui-react'
|
||||
|
||||
export class ValidatedContainer extends React.Component {
|
||||
static propTypes = {
|
||||
name: PropTypes.string.isRequired,
|
||||
validator: PropTypes.object.isRequired,
|
||||
children: PropTypes.oneOfType([
|
||||
PropTypes.array,
|
||||
PropTypes.object
|
||||
])
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.updateValue = this.updateValue.bind(this)
|
||||
|
||||
let { name, validator } = this.props
|
||||
|
||||
validator.addListener(name, this.updateValue)
|
||||
this.state = validator.getField(name)
|
||||
}
|
||||
|
||||
updateValue(name) {
|
||||
this.setState(this.props.validator.getField(name))
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.props.validator.removeListener(this.props.name, this.updateValue)
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.validator !== this.props.validator) {
|
||||
this.props.validator.removeListener(this.props.name, this.updateValue)
|
||||
nextProps.validator.addListener(nextProps.name, this.updateValue)
|
||||
this.setState(nextProps.validator.getField(nextProps.name))
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
if (this.state.visible) {
|
||||
return (
|
||||
<Container>
|
||||
{this.props.children}
|
||||
</Container>
|
||||
)
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
}
|
||||
}
|
||||
56
website/src/Validated/ValidatedDatePicker.js
Normal file
@@ -0,0 +1,56 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Form, Popup } from 'semantic-ui-react'
|
||||
import 'moment'
|
||||
import { DatePickerInput } from 'rc-datepicker'
|
||||
import 'rc-datepicker/lib/style.css'
|
||||
|
||||
export class ValidatedDatePicker extends React.Component {
|
||||
static propTypes = {
|
||||
name: PropTypes.string.isRequired,
|
||||
message: PropTypes.string.isRequired,
|
||||
label: PropTypes.string,
|
||||
width: PropTypes.number,
|
||||
validator: PropTypes.object.isRequired
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = props.validator.getField(props.name)
|
||||
this.handleChange = this.handleChange.bind(this)
|
||||
this.handleClear = this.handleClear.bind(this)
|
||||
}
|
||||
|
||||
handleChange(e, data) {
|
||||
const { validator, name } = this.props
|
||||
const state = validator.getField(name)
|
||||
|
||||
if (!state.readOnly && !state.disabled) {
|
||||
// NOTE: data is a little different for this control - no value property
|
||||
this.setState(validator.updateValue(name, data))
|
||||
}
|
||||
}
|
||||
|
||||
handleClear(e) {
|
||||
this.props.validator.updateValue(this.props.name, '')
|
||||
this.setState(this.props.validator.getField(this.props.name))
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.validator !== this.props.validator) {
|
||||
this.setState(nextProps.validator.getField(nextProps.name))
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Form.Field error={!this.state.valid} width={this.props.width} disabled={this.state.disabled}>
|
||||
<label>{this.props.label}</label>
|
||||
<Popup content={this.props.message} position='right center' hoverable trigger={
|
||||
<DatePickerInput value={this.state.value} name={this.props.name} onChange={this.handleChange}
|
||||
showOnInputClick onClear={this.handleClear} />} />
|
||||
</Form.Field>
|
||||
)
|
||||
}
|
||||
}
|
||||
47
website/src/Validated/ValidatedDropdown.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Form, Dropdown, Popup } from 'semantic-ui-react'
|
||||
|
||||
export class ValidatedDropdown extends React.Component {
|
||||
static propTypes = {
|
||||
name: PropTypes.string.isRequired,
|
||||
label: PropTypes.string,
|
||||
width: PropTypes.number,
|
||||
placeholder: PropTypes.string,
|
||||
options: PropTypes.array,
|
||||
message: PropTypes.string.isRequired,
|
||||
validator: PropTypes.object.isRequired,
|
||||
searchable: PropTypes.bool
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = props.validator.getField(props.name)
|
||||
this.handleChange = this.handleChange.bind(this)
|
||||
}
|
||||
|
||||
handleChange(e, data) {
|
||||
const { validator, name } = this.props
|
||||
|
||||
this.setState(validator.updateValue(name, data.value))
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.validator !== this.props.validator) {
|
||||
this.setState(nextProps.validator.getField(nextProps.name))
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Form.Field error={!this.state.valid} width={this.props.width}>
|
||||
<label>{this.props.label}</label>
|
||||
<Popup content={this.props.message} position='right center' hoverable trigger={
|
||||
<Dropdown selection fluid disabled={this.state.disabled} readOnly={this.state.readOnly}
|
||||
placeholder={this.props.placeholder} options={this.props.options}
|
||||
value={this.state.value} onChange={this.handleChange} search={this.props.searchable} />} />
|
||||
</Form.Field>
|
||||
)
|
||||
}
|
||||
}
|
||||
63
website/src/Validated/ValidatedInput.js
Normal file
@@ -0,0 +1,63 @@
|
||||
import React from 'react'
|
||||
import PropTypes from 'prop-types'
|
||||
import { Form, Popup, Input } from 'semantic-ui-react'
|
||||
|
||||
// This is an example of a validated component with a value that changes itself
|
||||
|
||||
export class ValidatedInput extends React.Component {
|
||||
static propTypes = {
|
||||
name: PropTypes.string.isRequired,
|
||||
message: PropTypes.string,
|
||||
label: PropTypes.string,
|
||||
width: PropTypes.number,
|
||||
validator: PropTypes.object.isRequired,
|
||||
password: PropTypes.bool,
|
||||
className: PropTypes.string,
|
||||
placeholder: PropTypes.string,
|
||||
icon: PropTypes.string,
|
||||
iconPosition: PropTypes.string
|
||||
}
|
||||
|
||||
constructor(props) {
|
||||
super(props)
|
||||
|
||||
this.state = props.validator.getField(props.name)
|
||||
this.handleChange = this.handleChange.bind(this)
|
||||
}
|
||||
|
||||
handleChange(e, data) {
|
||||
const { validator, name } = this.props
|
||||
const state = validator.getField(name)
|
||||
|
||||
if (!state.readOnly && !state.disabled) {
|
||||
this.setState(validator.updateValue(name, data.value))
|
||||
}
|
||||
}
|
||||
|
||||
componentWillReceiveProps(nextProps) {
|
||||
if (nextProps.validator !== this.props.validator) {
|
||||
this.setState(nextProps.validator.getField(nextProps.name))
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<Form.Field error={!this.state.valid} width={this.props.width} disabled={this.state.disabled} className={this.props.className}>
|
||||
<label>{this.props.label}</label>
|
||||
{this.props.message
|
||||
? <Popup content={this.props.message} position='bottom center' hoverable trigger={
|
||||
<Input value={this.state.value} type={this.props.password ? 'password' : 'text'}
|
||||
name={this.props.name} onChange={this.handleChange} placeholder={this.props.placeholder}
|
||||
className={this.props.className} icon={this.props.icon} iconPosition={this.props.iconPosition} />}
|
||||
/>
|
||||
: <Input value={this.state.value}
|
||||
type={this.props.password ? 'password' : 'text'}
|
||||
name={this.props.name} onChange={this.handleChange}
|
||||
placeholder={this.props.placeholder}
|
||||
className={this.props.className} icon={this.props.icon}
|
||||
iconPosition={this.props.iconPosition} />
|
||||
}
|
||||
</Form.Field>
|
||||
)
|
||||
}
|
||||
}
|
||||