|
32 | 32 | let userInfo = null |
33 | 33 | let organizationInfo = null |
34 | 34 | let repositoryInfo = null |
| 35 | + let orgError = null |
35 | 36 | /** |
36 | 37 | * Escapes HTML special characters to prevent XSS attacks. |
37 | 38 | * @param {string | undefined | null} str - The string to escape |
|
50 | 51 | /** |
51 | 52 | * Safely sets cloud description with highlighted text using DOM methods. |
52 | 53 | * @param {HTMLElement} element - The element to update |
53 | | - * @param {{type: 'organization' | 'repository' | 'user', params: {organization?: string, provider?: string, repository?: string, user?: string}}} context - The context to use |
| 54 | + * @param {{type: 'organization' | 'repository' | 'user' | 'organizationNotFound', params: {organization?: string, provider?: string, repository?: string, user?: string}}} context - The context to use |
54 | 55 | */ |
55 | 56 | function setCloudDescription(element, { type, params }) { |
56 | 57 | element.textContent = '' |
|
61 | 62 | <p class="loading-text">Connecting to Codacy...</p> |
62 | 63 | </div>` |
63 | 64 | switch (type) { |
| 65 | + case 'organizationNotFound': |
| 66 | + textNode.textContent = 'The organization you\'re trying to connect to is not found in Codacy. ' |
| 67 | + linkNode.textContent = `Check your available organizations` |
| 68 | + linkNode.href = `https://app.codacy.com/organizations` |
| 69 | + break |
64 | 70 | case 'organization': |
65 | 71 | if (!params.provider || !params.organization) { |
66 | 72 | element.innerHTML = loadingHtml |
|
134 | 140 | userInfo = message.userInfo |
135 | 141 | organizationInfo = message.organizationInfo |
136 | 142 | repositoryInfo = message.repositoryInfo |
137 | | - handleLoginStateChange(isLoggedIn, isOrgInCodacy, isRepoInCodacy, userInfo, organizationInfo, repositoryInfo) |
| 143 | + orgError = message.orgError |
| 144 | + handleLoginStateChange(isLoggedIn, isOrgInCodacy, isRepoInCodacy, userInfo, organizationInfo, repositoryInfo, orgError) |
138 | 145 | break |
139 | 146 | case 'mcpStatusChanged': |
140 | 147 | isMCPInstalled = message.isMCPInstalled |
|
236 | 243 | } = elements |
237 | 244 | const { organizationName, organizationProvider, repositoryName, userName, billing } = connectionInfo |
238 | 245 | switch (state) { |
| 246 | + case 'organizationNotFound': |
| 247 | + cloudIcon.src = iconUris.warning |
| 248 | + addOrgButton.style.display = 'none' |
| 249 | + addRepoButton.style.display = 'none' |
| 250 | + noOrgDescription.style.display = 'none' |
| 251 | + upgradeBox.style.display = 'none' |
| 252 | + setCloudDescription(cloudDescription, { type: 'organizationNotFound', params: { } }) |
| 253 | + break |
239 | 254 | case 'needsToAddOrganization': |
240 | 255 | addOrgButton.style.display = 'inline-block' |
241 | 256 | noOrgDescription.style.display = 'inline-block' |
|
293 | 308 | * @param {Object|null} userInfo |
294 | 309 | * @param {Object|null} organizationInfo |
295 | 310 | * @param {Object|null} repositoryInfo |
| 311 | + * @param {string|null} orgError |
296 | 312 | */ |
297 | | - function handleLoginStateChange(loggedIn, isOrgInCodacy, isRepoInCodacy, userInfo, organizationInfo, repositoryInfo) { |
| 313 | + function handleLoginStateChange(loggedIn, isOrgInCodacy, isRepoInCodacy, userInfo, organizationInfo, repositoryInfo, orgError) { |
298 | 314 | const upgradeBox = document.getElementById('upgrade-box') |
299 | 315 | const upgradeButton = document.getElementById('upgrade-button') |
300 | 316 | /** @type {HTMLImageElement | null} */ |
|
335 | 351 | } else { |
336 | 352 | handleLoginOrgStates(elements, connectionInfo, 'needsToAddOrganization') |
337 | 353 | } |
| 354 | + if (orgError) { |
| 355 | + handleLoginOrgStates(elements, connectionInfo, 'organizationNotFound') |
| 356 | + } |
338 | 357 | } else { |
339 | 358 | showLoggedOutState(elements) |
340 | 359 | } |
|
0 commit comments