diff --git a/README.md b/README.md index 7d58994..9561105 100644 --- a/README.md +++ b/README.md @@ -53,6 +53,10 @@ If you need to update `npm`, you can make it using `npm`! cd NotificationCenter npm install --force + Note: + Make sure that you have correct endpoint set inside `config/.env` file: + You case this URL for dev notifications: https://d2xm4bcf3at21r.cloudfront.net/dynNotifications.json + ## Running the project npm run start diff --git a/config/.env b/config/.env new file mode 100644 index 0000000..2a76f8c --- /dev/null +++ b/config/.env @@ -0,0 +1 @@ +NOTIFICATION_URL="" \ No newline at end of file diff --git a/config/.env.dev b/config/.env.dev new file mode 100644 index 0000000..2a76f8c --- /dev/null +++ b/config/.env.dev @@ -0,0 +1 @@ +NOTIFICATION_URL="" \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 72467e0..8a109d5 100644 --- a/package-lock.json +++ b/package-lock.json @@ -22,6 +22,7 @@ "babel-loader": "^8.2.5", "compression-webpack-plugin": "^10.0.0", "css-loader": "^6.7.1", + "dotenv-webpack": "^8.0.0", "enzyme": "^3.11.0", "enzyme-adapter-react-16": "^1.15.6", "eslint": "^8.21.0", @@ -5245,6 +5246,39 @@ "tslib": "^2.0.3" } }, + "node_modules/dotenv": { + "version": "8.6.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz", + "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==", + "dev": true, + "engines": { + "node": ">=10" + } + }, + "node_modules/dotenv-defaults": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/dotenv-defaults/-/dotenv-defaults-2.0.2.tgz", + "integrity": "sha512-iOIzovWfsUHU91L5i8bJce3NYK5JXeAwH50Jh6+ARUdLiiGlYWfGw6UkzsYqaXZH/hjE/eCd/PlfM/qqyK0AMg==", + "dev": true, + "dependencies": { + "dotenv": "^8.2.0" + } + }, + "node_modules/dotenv-webpack": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/dotenv-webpack/-/dotenv-webpack-8.0.0.tgz", + "integrity": "sha512-vsWj11yWbIxLUPcQDbifCGW1+Mp03XfApFHJTC+/Ag9g3D/AnxoaVZcp76LpuBmReRwIJ+YO1fVdhmpzh+LL1A==", + "dev": true, + "dependencies": { + "dotenv-defaults": "^2.0.2" + }, + "engines": { + "node": ">=10" + }, + "peerDependencies": { + "webpack": "^4 || ^5" + } + }, "node_modules/ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", @@ -16487,6 +16521,30 @@ "tslib": "^2.0.3" } }, + "dotenv": { + "version": "8.6.0", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-8.6.0.tgz", + "integrity": "sha512-IrPdXQsk2BbzvCBGBOTmmSH5SodmqZNt4ERAZDmW4CT+tL8VtvinqywuANaFu4bOMWki16nqf0e4oC0QIaDr/g==", + "dev": true + }, + "dotenv-defaults": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/dotenv-defaults/-/dotenv-defaults-2.0.2.tgz", + "integrity": "sha512-iOIzovWfsUHU91L5i8bJce3NYK5JXeAwH50Jh6+ARUdLiiGlYWfGw6UkzsYqaXZH/hjE/eCd/PlfM/qqyK0AMg==", + "dev": true, + "requires": { + "dotenv": "^8.2.0" + } + }, + "dotenv-webpack": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/dotenv-webpack/-/dotenv-webpack-8.0.0.tgz", + "integrity": "sha512-vsWj11yWbIxLUPcQDbifCGW1+Mp03XfApFHJTC+/Ag9g3D/AnxoaVZcp76LpuBmReRwIJ+YO1fVdhmpzh+LL1A==", + "dev": true, + "requires": { + "dotenv-defaults": "^2.0.2" + } + }, "ee-first": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/ee-first/-/ee-first-1.1.1.tgz", diff --git a/package.json b/package.json index a01e001..d42f787 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dynamods/notifications-center", - "version": "0.0.10", + "version": "0.0.11", "description": "Notification center maintained by Dynamo Team@Autodesk", "author": "Autodesk Inc.", "license": "MIT", @@ -18,7 +18,7 @@ "lint:fix": "eslint src/ tests/ --fix", "test": "npm run lint:fix && jest", "start": "webpack serve", - "build": "webpack --config webpack.config.js --mode=development", + "build": "webpack --config webpack.config.js --env dev --mode=development", "bundle": "webpack --config webpack.config.js --mode=production", "copy": "cp package.json dist/ && cp README.md dist/", "production": "npm run bundle && npm run copy" @@ -29,15 +29,16 @@ "react-dom": "^18.2.0" }, "devDependencies": { - "@filipeop/notifications-panel": "^0.0.2", "@babel/core": "^7.18.6", "@babel/preset-env": "^7.18.6", "@babel/preset-react": "^7.18.6", + "@filipeop/notifications-panel": "^0.0.2", "@hig/timestamp": "^2.1.0", "axios": "^0.27.2", "babel-loader": "^8.2.5", "compression-webpack-plugin": "^10.0.0", "css-loader": "^6.7.1", + "dotenv-webpack": "^8.0.0", "enzyme": "^3.11.0", "enzyme-adapter-react-16": "^1.15.6", "eslint": "^8.21.0", diff --git a/src/App.js b/src/App.js index 0f3e52a..ab112ee 100644 --- a/src/App.js +++ b/src/App.js @@ -7,33 +7,34 @@ import Timestamp from '@hig/timestamp'; function App() { const [APIData, setAPIData] = useState(false); useEffect(() => { - axios.get('http://demo9540080.mockable.io/notifications') - .then((response) => { - const notifications = response.data.notifications; - let notificationData = []; - - for (let i = 0; i < notifications.length; i++) { - var notificationItem = { - id: notifications[i].id, - featured: true, - unread: true, - image: , - message: notifications[i].title, - href: notifications[i].linkTitle, - timestamp: , - content:
- {notifications[i].title} -

{notifications[i].longDescription}

- {notifications[i].linkTitle} -
- }; - notificationData.push(notificationItem); - } - - setAPIData(notificationData); - }); + window.RequestNotifications = RequestNotifications; }, []); - + + const RequestNotifications = (url) => { + axios.get(url) + .then((response) => { + const notifications = response.data.notifications; + let notificationData = []; + for (let i = 0; i < notifications.length; i++) { + var notificationItem = { + id: notifications[i].id, + featured: true, + unread: true, + image: , + message: notifications[i].title, + href: notifications[i].linkTitle, + timestamp: , + content:
+ {notifications[i].title} +

{notifications[i].longDescription}

+ {notifications[i].linkTitle} +
+ }; + notificationData.push(notificationItem); + } + setAPIData(notificationData); + }); + } return APIData ? : null; } - -export default App; +export default App; \ No newline at end of file diff --git a/webpack.config.js b/webpack.config.js index ea21922..c542ba1 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,44 +1,52 @@ const path = require('path'); const TerserPlugin = require('terser-webpack-plugin'); +const Dotenv = require('dotenv-webpack'); -module.exports = { - mode: 'development', - entry: { - app: './src/index.js', - }, - output: { - path: path.join(__dirname, '/dist/build'), - filename: 'index.bundle.js', - publicPath: '', - clean: true, - }, - module: { - rules: [ - { - test: /\.(js|jsx)$/, - exclude: /node_modules/, - use: { - loader: 'babel-loader' - } - }, - { - test: /\.(scss|css)$/, - exclude: /node_modules/, - use: [ - 'style-loader', - 'css-loader', - 'sass-loader' - ] - } - ] - }, - optimization: { - minimizer: [ - new TerserPlugin({ - parallel: true, - terserOptions: { +module.exports = env => { + return { + mode: 'development', + entry: { + app: './src/index.js', + }, + output: { + path: path.join(__dirname, '/dist/build'), + filename: 'index.bundle.js', + publicPath: '', + clean: true, + }, + module: { + rules: [ + { + test: /\.(js|jsx)$/, + exclude: /node_modules/, + use: { + loader: 'babel-loader' + } + }, + { + test: /\.(scss|css)$/, + exclude: /node_modules/, + use: [ + 'style-loader', + 'css-loader', + 'sass-loader' + ] + } + ] }, - }), - ], - } + optimization: { + minimizer: [ + new TerserPlugin({ + parallel: true, + terserOptions: { + }, + }), + ], + }, + plugins: [ + new Dotenv({ + path: `./config/.env${env.dev ? `.dev` : ''}` + }) + ] + } };