|
1 | | -import { logError } from '@codesandbox/common/lib/utils/analytics'; |
| 1 | +import track, { logError } from '@codesandbox/common/lib/utils/analytics'; |
| 2 | +import { notificationState } from '@codesandbox/common/lib/utils/notifications'; |
| 3 | +import { NotificationStatus } from '@codesandbox/notifications'; |
| 4 | +import { patronUrl } from '@codesandbox/common/lib/utils/url-generator'; |
2 | 5 | import { values } from 'lodash-es'; |
3 | 6 |
|
4 | 7 | import { camelizeKeys, decamelizeKeys } from 'humps'; |
@@ -44,13 +47,53 @@ const getMessage = (error: Error & { response: ?Object }) => { |
44 | 47 | return error.message; |
45 | 48 | }; |
46 | 49 |
|
| 50 | +function showNotification(controller, errorMessage: string) { |
| 51 | + if (errorMessage.startsWith('You need to sign in to create more than')) { |
| 52 | + // Error for "You need to sign in to create more than 10 sandboxes" |
| 53 | + track('Anonymous Sandbox Limit Reached', { errorMessage }); |
| 54 | + |
| 55 | + notificationState.addNotification({ |
| 56 | + title: errorMessage, |
| 57 | + status: NotificationStatus.ERROR, |
| 58 | + actions: { |
| 59 | + primary: [ |
| 60 | + { |
| 61 | + label: 'Sign in', |
| 62 | + run: () => { |
| 63 | + controller.getSignal('signInClicked')({}); |
| 64 | + }, |
| 65 | + }, |
| 66 | + ], |
| 67 | + }, |
| 68 | + }); |
| 69 | + } else if (errorMessage.startsWith('You reached the maximum of')) { |
| 70 | + track('Non-Patron Sandbox Limit Reached', { errorMessage }); |
| 71 | + |
| 72 | + notificationState.addNotification({ |
| 73 | + title: errorMessage, |
| 74 | + status: NotificationStatus.ERROR, |
| 75 | + actions: { |
| 76 | + primary: [ |
| 77 | + { |
| 78 | + label: 'Open Patron Page', |
| 79 | + run: () => { |
| 80 | + window.open(patronUrl(), '_blank'); |
| 81 | + }, |
| 82 | + }, |
| 83 | + ], |
| 84 | + }, |
| 85 | + }); |
| 86 | + } else { |
| 87 | + controller.runSignal( |
| 88 | + 'notificationAdded', |
| 89 | + addNotification(errorMessage, 'error') |
| 90 | + ); |
| 91 | + } |
| 92 | +} |
| 93 | + |
47 | 94 | const showError = (error, controller) => { |
48 | 95 | const errorMessage = getMessage(error); |
49 | | - |
50 | | - controller.runSignal( |
51 | | - 'notificationAdded', |
52 | | - addNotification(errorMessage, 'error') |
53 | | - ); |
| 96 | + showNotification(controller, errorMessage); |
54 | 97 |
|
55 | 98 | error.apiMessage = errorMessage; // eslint-disable-line no-param-reassign |
56 | 99 | }; |
|
0 commit comments