Skip to content

Commit ac6e730

Browse files
fix: improve init onboarding UX for app add step (#562)
- Merge two redundant confirm prompts ("Is this the correct app ID?" + "Add in Capgo?") into a single select with emoji labels - Fix duplicate app ID error not being caught (Supabase returns "duplicate key" / code 23505, not "already exist") - Skip checkAlerts() in addAppInternal when called silently from init to avoid flashing clack output during Ink session
1 parent c497367 commit ac6e730

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

src/app/add.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ export async function addAppInternal(
8080
if (!silent)
8181
intro('Adding')
8282

83-
await checkAlerts()
83+
if (!silent)
84+
await checkAlerts()
8485

8586
options.apikey = options.apikey || findSavedKey()
8687
const extConfig = await getConfig()

src/init/command.ts

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,27 +1056,21 @@ async function addAppStep(organization: Organization, apikey: string, appId: str
10561056
let currentAppId = appId
10571057

10581058
while (true) {
1059-
const appIdCorrect = await pConfirm({
1060-
message: `Is ${currentAppId} the correct app ID?`,
1061-
initialValue: true,
1059+
const addChoice = await pSelect({
1060+
message: `Add ${currentAppId} to Capgo?`,
1061+
options: [
1062+
{ value: 'yes', label: '✅ Yes, add it' },
1063+
{ value: 'change', label: '❌ No, use a different app ID' },
1064+
],
10621065
})
1063-
await cancelCommand(appIdCorrect, organization.gid, apikey)
1066+
await cancelCommand(addChoice, organization.gid, apikey)
10641067

1065-
if (!appIdCorrect) {
1068+
if (addChoice === 'change') {
10661069
currentAppId = await askForAppId('Enter the correct app ID (e.g., com.example.app):')
10671070
await saveAppIdToCapacitorConfig(currentAppId)
10681071
continue
10691072
}
10701073

1071-
const doAdd = await pConfirm({ message: `Add ${currentAppId} in Capgo?` })
1072-
await cancelCommand(doAdd, organization.gid, apikey)
1073-
1074-
if (!doAdd) {
1075-
pLog.info(`If you change your mind, run it for yourself with: "${pm.runner} @capgo/cli@latest app add ${currentAppId}"`)
1076-
await markStep(organization.gid, apikey, 'add-app', currentAppId)
1077-
return currentAppId
1078-
}
1079-
10801074
try {
10811075
const s = pSpinner()
10821076
s.start(`Running: ${pm.runner} @capgo/cli@latest app add ${currentAppId}`)
@@ -1097,7 +1091,7 @@ async function addAppStep(organization: Organization, apikey: string, appId: str
10971091
const errorMessage = error instanceof Error ? error.message : String(error)
10981092

10991093
// Check if the error is about app already existing
1100-
if (errorMessage.includes('already exist')) {
1094+
if (errorMessage.includes('already exist') || errorMessage.includes('duplicate key') || errorMessage.includes('23505')) {
11011095
pLog.error(`❌ App ID "${currentAppId}" is already taken`)
11021096

11031097
// Generate alternative suggestions with validation

0 commit comments

Comments
 (0)