Skip to content

Commit

Permalink
Add bugsnag config to DS and handle toast arg error
Browse files Browse the repository at this point in the history
  • Loading branch information
gretahayes19 committed Feb 18, 2023
1 parent 89f38ba commit 0ed5e30
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 12 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ lib
.env.test.local
.env.production.local
.npmrc
.env

# Ignore Jetbrains IDE settings
/.idea
Expand Down
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ module.exports = {
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga|mdx)$": "<rootDir>/spec/__mocks__/fileMock.js",
'\\.(?:(?!variables).)+.(css|less|scss)$': '<rootDir>/spec/__mocks__/styleMock.js',
'^src/([^\\.]*)$': "<rootDir>/src/$1",
'@bugsnag/js': '@bugsnag/browser',
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"name": "@user-interviews/ui-design-system",
"version": "1.40.0",
"dependencies": {
"@bugsnag/js": "^6.0.0",
"@bugsnag/plugin-react": "^6.0.0",
"dotenv": "^16.0.3",
"react-bootstrap": "^2.5.0",
"react-loading-skeleton": "^3.1.0",
"react-router-dom": "^5.2.0",
Expand Down
31 changes: 19 additions & 12 deletions src/Toast/useToast.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { useCallback, useReducer } from 'react';
import { v4 as generateUUID } from 'uuid';
import { bugsnagClient } from '../bugsnag';

const createMessage = (
type,
Expand Down Expand Up @@ -48,18 +49,24 @@ const useToast = (initialMessages = []) => {
dispatch({ type: ACTIONS.CLEAR_MESSAGES });
}, []);

const setMessage = useCallback(({
action,
type,
message,
title,
}) => {
dispatch({
type: ACTIONS.SET_MESSAGE,
payload: {
action, type, message, title,
},
});
const setMessage = useCallback((options) => {
if ((options && typeof options === 'string')) {
bugsnagClient.notify(new Error('Toast component argument error, expecting single formatted object'));
} else {
const {
action,
type,
message,
title,
} = options;

dispatch({
type: ACTIONS.SET_MESSAGE,
payload: {
action, type, message, title,
},
});
}
}, []);

const dismissMessage = useCallback((messageId) => {
Expand Down
15 changes: 15 additions & 0 deletions src/bugsnag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import bugsnag from '@bugsnag/js';
import bugsnagReact from '@bugsnag/plugin-react';
import react from 'react';

import * as dotenv from 'dotenv';

dotenv.config();

const bugsnagClient = bugsnag({
apiKey: process.env.BUGSNAG_API_KEY_JS,
});

bugsnagClient.use(bugsnagReact, react);

export { bugsnagClient };
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ import {
} from 'src/Toast';
import { ToggleInput } from 'src/ToggleInput';
import Tooltip from 'src/Tooltip';
import { bugsnagClient } from './bugsnag';

export {
Accordion,
Expand All @@ -92,6 +93,7 @@ export {
Avatar,
AsyncSelect,
AsyncCreatableSelect,
bugsnagClient,
Button,
BUTTON_GROUP_ORIENTATIONS,
Card,
Expand Down
63 changes: 63 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,35 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==

"@bugsnag/browser@^6.5.2":
version "6.5.2"
resolved "https://registry.yarnpkg.com/@bugsnag/browser/-/browser-6.5.2.tgz#3f8f911dd739d2ace056fd5a38d5d25283ca4bfc"
integrity sha512-XFKKorJc92ivLnlHHhLiPvkP03tZ5y7n0Z2xO6lOU7t+jWF5YapgwqQAda/TWvyYO38B/baWdnOpWMB3QmjhkA==

"@bugsnag/js@^6.0.0":
version "6.5.2"
resolved "https://registry.yarnpkg.com/@bugsnag/js/-/js-6.5.2.tgz#810383aa7a2246639041bb9031ab316432959527"
integrity sha512-4ibw624fM5+Y/WSuo3T/MsJVtslsPV8X0MxFuRxdvpKVUXX216d8hN8E/bG4hr7aipqQOGhBYDqSzeL2wgmh0Q==
dependencies:
"@bugsnag/browser" "^6.5.2"
"@bugsnag/node" "^6.5.2"

"@bugsnag/node@^6.5.2":
version "6.5.2"
resolved "https://registry.yarnpkg.com/@bugsnag/node/-/node-6.5.2.tgz#7bc2d0d1c7a682784be388404ab728a80b7ae2b9"
integrity sha512-KQ1twKoOttMCYsHv7OXUVsommVcrk6RGQ5YoZGlTbREhccbzsvjbiXPKiY31Qc7OXKvaJwSXhnOKrQTpRleFUg==
dependencies:
byline "^5.0.0"
error-stack-parser "^2.0.2"
iserror "^0.0.2"
pump "^3.0.0"
stack-generator "^2.0.3"

"@bugsnag/plugin-react@^6.0.0":
version "6.5.0"
resolved "https://registry.yarnpkg.com/@bugsnag/plugin-react/-/plugin-react-6.5.0.tgz#93eec6bd167dab007ca588e69daa544124c3107a"
integrity sha512-kbyFSnQ4QLGjN04t9MbuD5KLWI2qQpjrgKrJvJNKM8xyeVIJYpkjx//TsDzG4ujNFVkwaP3bT48j85rf4EJNqA==

"@cnakazawa/watch@^1.0.3":
version "1.0.4"
resolved "https://registry.yarnpkg.com/@cnakazawa/watch/-/watch-1.0.4.tgz#f864ae85004d0fcab6f50be9141c4da368d1656a"
Expand Down Expand Up @@ -4470,6 +4499,11 @@ builtin-status-codes@^3.0.0:
resolved "https://registry.yarnpkg.com/builtin-status-codes/-/builtin-status-codes-3.0.0.tgz#85982878e21b98e1c66425e03d0174788f569ee8"
integrity sha1-hZgoeOIbmOHGZCXgPQF0eI9Wnug=

byline@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/byline/-/byline-5.0.0.tgz#741c5216468eadc457b03410118ad77de8c1ddb1"
integrity sha512-s6webAy+R4SR8XVuJWt2V2rGvhnrhxN+9S15GNuTK3wKPOXFF6RNc+8ug2XhH+2s4f+uudG4kUVYmYOQWL2g0Q==

bytes@3.1.2:
version "3.1.2"
resolved "https://registry.yarnpkg.com/bytes/-/bytes-3.1.2.tgz#8b0beeb98605adf1b128fa4386403c009e0221a5"
Expand Down Expand Up @@ -5731,6 +5765,11 @@ dotenv-webpack@^1.8.0:
dependencies:
dotenv-defaults "^1.0.2"

dotenv@^16.0.3:
version "16.0.3"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-16.0.3.tgz#115aec42bac5053db3c456db30cc243a5a836a07"
integrity sha512-7GO6HghkA5fYG9TYnNxi14/7K9f5occMlp3zXAuSxn7CKCxt9xbNWG7yF8hTCSUchlfWSe3uLmlPfigevRItzQ==

dotenv@^6.2.0:
version "6.2.0"
resolved "https://registry.yarnpkg.com/dotenv/-/dotenv-6.2.0.tgz#941c0410535d942c8becf28d3f357dbd9d476064"
Expand Down Expand Up @@ -5916,6 +5955,13 @@ error-ex@^1.2.0, error-ex@^1.3.1:
dependencies:
is-arrayish "^0.2.1"

error-stack-parser@^2.0.2:
version "2.1.4"
resolved "https://registry.yarnpkg.com/error-stack-parser/-/error-stack-parser-2.1.4.tgz#229cb01cdbfa84440bfa91876285b94680188286"
integrity sha512-Sk5V6wVazPhq5MhpO+AUxJn5x7XSXGl1R93Vn7i+zS15KDVxQijejNCrz8340/2bgLBjR9GtEG8ZVKONDjcqGQ==
dependencies:
stackframe "^1.3.4"

error-stack-parser@^2.0.6:
version "2.0.6"
resolved "https://registry.yarnpkg.com/error-stack-parser/-/error-stack-parser-2.0.6.tgz#5a99a707bd7a4c58a797902d48d82803ede6aad8"
Expand Down Expand Up @@ -8161,6 +8207,11 @@ isarray@^2.0.5:
resolved "https://registry.yarnpkg.com/isarray/-/isarray-2.0.5.tgz#8af1e4c1221244cc62459faf38940d4e644a5723"
integrity sha512-xHjhDr3cNBK0BzdUJSPXZntQUx/mwMS5Rw4A7lPJ90XGAO6ISP/ePDNuo0vhqOZU+UD5JoodwCAAoZQd3FeAKw==

iserror@^0.0.2:
version "0.0.2"
resolved "https://registry.yarnpkg.com/iserror/-/iserror-0.0.2.tgz#bd53451fe2f668b9f2402c1966787aaa2c7c0bf5"
integrity sha512-oKGGrFVaWwETimP3SiWwjDeY27ovZoyZPHtxblC4hCq9fXxed/jasx+ATWFFjCVSRZng8VTMsN1nDnGo6zMBSw==

isexe@^2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/isexe/-/isexe-2.0.0.tgz#e8fbf374dc556ff8947a10dcb0572d633f2cfa10"
Expand Down Expand Up @@ -12420,6 +12471,13 @@ stable@^0.1.8:
resolved "https://registry.yarnpkg.com/stable/-/stable-0.1.8.tgz#836eb3c8382fe2936feaf544631017ce7d47a3cf"
integrity sha512-ji9qxRnOVfcuLDySj9qzhGSEFVobyt1kIOSkj1qZzYLzq7Tos/oUUWvotUPQLlrsidqsK6tBH89Bc9kL5zHA6w==

stack-generator@^2.0.3:
version "2.0.10"
resolved "https://registry.yarnpkg.com/stack-generator/-/stack-generator-2.0.10.tgz#8ae171e985ed62287d4f1ed55a1633b3fb53bb4d"
integrity sha512-mwnua/hkqM6pF4k8SnmZ2zfETsRUpWXREfA/goT8SLCV4iOFa4bzOX2nDipWAZFPTjLvQB82f5yaodMVhK0yJQ==
dependencies:
stackframe "^1.3.4"

stack-utils@^2.0.2:
version "2.0.3"
resolved "https://registry.yarnpkg.com/stack-utils/-/stack-utils-2.0.3.tgz#cd5f030126ff116b78ccb3c027fe302713b61277"
Expand All @@ -12439,6 +12497,11 @@ stackframe@^1.1.1:
resolved "https://registry.yarnpkg.com/stackframe/-/stackframe-1.2.0.tgz#52429492d63c62eb989804c11552e3d22e779303"
integrity sha512-GrdeshiRmS1YLMYgzF16olf2jJ/IzxXY9lhKOskuVziubpTYcYqyOwYeJKzQkwy7uN0fYSsbsC4RQaXf9LCrYA==

stackframe@^1.3.4:
version "1.3.4"
resolved "https://registry.yarnpkg.com/stackframe/-/stackframe-1.3.4.tgz#b881a004c8c149a5e8efef37d51b16e412943310"
integrity sha512-oeVtt7eWQS+Na6F//S4kJ2K2VbRlS9D43mAlMyVpVWovy9o+jfgH8O9agzANzaiLjclA0oYzUXEM4PurhSUChw==

state-toggle@^1.0.0:
version "1.0.3"
resolved "https://registry.yarnpkg.com/state-toggle/-/state-toggle-1.0.3.tgz#e123b16a88e143139b09c6852221bc9815917dfe"
Expand Down

0 comments on commit 0ed5e30

Please sign in to comment.