Skip to content

💡 [Feature]: Improve code base to move some of the window prompts logic to separate util methods #443

@Adam-it

Description

@Adam-it

🎯 Aim of the feature

Since we started adding more and more advanced functionalities to SPFx Toolkit I noticed our code base have some duplicated logic we could try to move to some util methods and reuse. I think a good candidate to refactor are the window.showInputBox parts were we prompt the user for additional info to run a CLI command. In this case we usually provide context to select data and validate if it was provided and if not we cancel.
Some good candidates to refactor

const owner: string | undefined = await window.showInputBox({
      prompt: 'Enter the email address of the tenant admin (owner)',
      ignoreFocusOut: true,
      validateInput: (value) => value ? undefined : 'Owner email is required',
    });
    if (!owner) {
      Notifications.error('Owner email is required to create a Tenant App Catalog.');
      return;
    }

or for sure this one

const relativeUrl = await window.showInputBox({
      prompt: 'Enter the relative URL of the site',
      ignoreFocusOut: true,
      placeHolder: 'e.g., sites/sales',
      validateInput: (input) => {
        if (!input) {
          return 'site URL is required';
        }
        const trimmedInput = input.trim();
        if (trimmedInput.startsWith('https://')) {
          return 'Please provide a relative URL, not an absolute URL.';
        }
        if (trimmedInput.startsWith('/')) {
          return 'Please provide a relative URL without a leading slash.';
        }
        return undefined;
      }
    });
    if (relativeUrl === undefined) {
      Notifications.warning('No site URL provided. Setting form customizer aborted.');
      return;
    }

📷 Images (if possible) with expected result

No response

🤔 Additional remarks or comments

lets leave this on hold until we merge this PR #440

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions