@@ -2,7 +2,6 @@ import { commands, window, ExtensionContext } from 'vscode';
2
2
import { updateStatusBarItems } from '../statusBar' ;
3
3
import { COMMANDS , TRACKED_EVENTS } from '../constants' ;
4
4
import { getDisplayedHubspotPortalInfo } from '../helpers' ;
5
- import { Portal } from '../types' ;
6
5
import { portalNameInvalid } from '../validation' ;
7
6
import { trackEvent } from '../tracking' ;
8
7
import { showAutoDismissedStatusBarMessage } from '../messaging' ;
@@ -13,24 +12,31 @@ import {
13
12
renameAccount ,
14
13
updateDefaultAccount ,
15
14
} from '@hubspot/local-dev-lib/config' ;
15
+ import { CLIConfig } from '@hubspot/local-dev-lib/types/Config' ;
16
+ import { CLIAccount_DEPRECATED } from '@hubspot/local-dev-lib/types/Accounts' ;
16
17
17
- const showRenameAccountPrompt = ( accountToRename : Portal ) => {
18
+ const showRenameAccountPrompt = ( accountToRename : CLIAccount_DEPRECATED ) => {
18
19
window
19
20
. showInputBox ( {
20
21
placeHolder : 'Enter a new name for the account' ,
21
22
} )
22
23
. then ( async ( newName : string | undefined ) => {
23
24
if ( newName ) {
24
25
const oldName = accountToRename . name || accountToRename . portalId ;
25
- const config = getConfig ( ) ;
26
+ const config : CLIConfig | null = getConfig ( ) ;
26
27
let invalidReason = '' ;
27
28
if ( config ) {
28
- // @ts -expect-error TODO: Fix this when updating local-dev-lib
29
29
invalidReason = portalNameInvalid ( newName , config ) ;
30
30
}
31
31
32
32
if ( ! invalidReason ) {
33
- renameAccount ( oldName , newName ) ;
33
+ if ( ! oldName ) {
34
+ window . showErrorMessage (
35
+ 'Could not determine account name to rename'
36
+ ) ;
37
+ return ;
38
+ }
39
+ renameAccount ( String ( oldName ) , newName ) ;
34
40
showAutoDismissedStatusBarMessage (
35
41
`Successfully renamed default account from ${ oldName } to ${ newName } .`
36
42
) ;
@@ -76,19 +82,16 @@ export const registerCommands = (context: ExtensionContext) => {
76
82
commands . registerCommand (
77
83
COMMANDS . CONFIG . SELECT_DEFAULT_ACCOUNT ,
78
84
async ( ) => {
79
- const config = getConfig ( ) ;
80
- // @ts -expect-error TODO: Fix this when updating local-dev-lib
81
- if ( config && config . portals ) {
85
+ const config : CLIConfig | null = getConfig ( ) ;
86
+
87
+ if ( config && 'portals' in config && config . portals ) {
82
88
window
83
89
. showQuickPick (
84
- // @ts -expect-error TODO: Fix this when updating local-dev-lib
85
- config . portals . map ( ( p : Portal ) => {
90
+ config . portals . map ( ( p : CLIAccount_DEPRECATED ) => {
86
91
return {
87
92
label : getDisplayedHubspotPortalInfo ( p ) ,
88
93
description :
89
- // @ts -expect-error TODO: Fix this when updating local-dev-lib
90
94
config . defaultPortal === p . portalId ||
91
- // @ts -expect-error TODO: Fix this when updating local-dev-lib
92
95
config . defaultPortal === p . name
93
96
? '(default)'
94
97
: '' ,
@@ -102,8 +105,13 @@ export const registerCommands = (context: ExtensionContext) => {
102
105
. then ( async ( selection ) => {
103
106
if ( selection ) {
104
107
const newDefaultAccount =
105
- // @ts -ignore selection is an object
106
108
selection . portal . name || selection . portal . portalId ;
109
+ if ( ! newDefaultAccount ) {
110
+ window . showErrorMessage (
111
+ 'No account selected; Choose an account to set as default'
112
+ ) ;
113
+ return ;
114
+ }
107
115
await trackEvent ( TRACKED_EVENTS . SELECT_DEFAULT_ACCOUNT ) ;
108
116
updateDefaultAccount ( newDefaultAccount ) ;
109
117
showAutoDismissedStatusBarMessage (
@@ -142,8 +150,11 @@ export const registerCommands = (context: ExtensionContext) => {
142
150
)
143
151
. then ( async ( answer ) => {
144
152
if ( answer === 'Yes' ) {
145
- // @ts -expect-error TODO: Fix this when updating local-dev-lib
146
- if ( config && config . portals . length === 1 ) {
153
+ if (
154
+ config &&
155
+ 'portals' in config &&
156
+ config . portals . length === 1
157
+ ) {
147
158
deleteConfigFile ( ) ;
148
159
showAutoDismissedStatusBarMessage (
149
160
`Successfully deleted account ${ accountIdentifier } . The config file has been deleted because there are no more authenticated accounts.`
0 commit comments