public submit()

in desktop/src/app/components/account/action/create/batch-account-create.component.ts [97:143]


    public submit(): Observable<any> {
        const formData = this.form.value;
        const subscription = formData.subscription;

        let resourceGroup = formData.resourceGroup;
        if (!this.isNewResourceGroup) {
            if (typeof resourceGroup !== "string") {
                resourceGroup = resourceGroup.name;
            }
        }

        const accountName = formData.name;
        const body = createAccountFormToJsonData(formData);

        let observable: Observable<any> = null;
        if (this.isNewResourceGroup) {
            observable = this.accountService.putResourceGroup(subscription, resourceGroup, {
                location: formData.location,
            }).pipe(
                flatMap(() => this.accountService.create(subscription, resourceGroup, accountName, body)),
            );
        } else {
            observable = this.accountService.create(subscription, resourceGroup, accountName, body);
        }
        observable.subscribe({
            next: () => {
                const accountUri = this.accountService.getAccountId(subscription, resourceGroup, accountName);
                // poll account every 1.5 sec to check whether it has been created
                const sub = interval(1500).pipe(
                    flatMap(() => this.accountService.get(accountUri)),
                    retry(),
                ).subscribe(response => {
                    const message = `Batch account '${accountName}' was successfully created!`;
                    this.notificationService.success("Create batch account", message, { persist: true });
                    sub.unsubscribe();
                });
            },
            error: (response: Response) => {
                log.error("Failed to create batch account:: ", response);
                this.notificationService.error(
                    "Creating batch account failed",
                    `Failed to create batch account ${accountName} for resource group ${resourceGroup}`,
                );
            },
        });
        return observable;
    }