Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<h2 matDialogTitle>Create workspace</h2>
<mat-dialog-content>
<p class="text-sm m-0 mb-3">
A workspace holds its own applications, team, API keys and billing. You become its Owner and the dashboard
switches to it right away. You can switch back any time from the workspace menu.
</p>
<form id="create-workspace-form" [formGroup]="form" (ngSubmit)="submit()">
<mat-form-field appearance="outline" class="w-full">
<mat-label>Workspace name</mat-label>
<input matInput formControlName="name" autocomplete="off" [attr.maxlength]="nameMax" />
<mat-hint>{{ nameMin }}–{{ nameMax }} letters, numbers, spaces or underscores</mat-hint>
@if (form.controls.name.touched && form.controls.name.invalid) {
<mat-error>
@if (form.controls.name.hasError('required')) {
Name is required
} @else if (form.controls.name.hasError('minlength')) {
Use at least {{ nameMin }} characters
} @else {
Start with a letter or number; use only letters, numbers, spaces and underscores
}
</mat-error>
}
</mat-form-field>
</form>
@if (error(); as message) {
<p class="text-sm mt-2 mb-0" role="alert" style="color: var(--mat-sys-error, #b91c1c)">{{ message }}</p>
}
</mat-dialog-content>
<mat-dialog-actions align="end">
<button type="button" mat-button [disabled]="saving()" (click)="cancel()">Cancel</button>
<button type="submit" form="create-workspace-form" mat-flat-button [disabled]="saving()">
@if (saving()) {
<mat-spinner diameter="18" class="mr-2"></mat-spinner>
Creating…
} @else {
Create workspace
}
</button>
</mat-dialog-actions>
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { ChangeDetectionStrategy, Component, inject, signal } from '@angular/core';
import { FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatDialogModule, MatDialogRef } from '@angular/material/dialog';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner';
import { IClient } from '@proxy/models/root-models';
import { RootService } from '@proxy/services/proxy/root';
import {
WORKSPACE_NAME_MAX,
WORKSPACE_NAME_MIN,
WORKSPACE_NAME_PATTERN,
errorMessages,
isForbidden,
} from '../../team/team.models';

/**
* Creates a new workspace (a "client") owned by the signed-in user. On success the dialog closes with the created
* workspace; the API has already switched the session into it, so the caller reloads the panel.
*/
@Component({
selector: 'proxy-create-workspace-dialog',
changeDetection: ChangeDetectionStrategy.OnPush,
imports: [
ReactiveFormsModule,
MatButtonModule,
MatDialogModule,
MatFormFieldModule,
MatInputModule,
MatProgressSpinnerModule,
],
templateUrl: './create-workspace-dialog.component.html',
})
export class CreateWorkspaceDialogComponent {
private readonly dialogRef = inject<MatDialogRef<CreateWorkspaceDialogComponent, IClient>>(MatDialogRef);
private readonly rootService = inject(RootService);

protected readonly nameMin = WORKSPACE_NAME_MIN;
protected readonly nameMax = WORKSPACE_NAME_MAX;
readonly saving = signal(false);
readonly error = signal<string | null>(null);

readonly form = new FormGroup({
name: new FormControl('', [
Validators.required,
Validators.minLength(WORKSPACE_NAME_MIN),
Validators.maxLength(WORKSPACE_NAME_MAX),
Validators.pattern(WORKSPACE_NAME_PATTERN),
]),
});

submit(): void {
if (this.saving()) return;
if (this.form.invalid) {
this.form.markAllAsTouched();
return;
}
const failure = 'The workspace could not be created. Check the name and retry.';
this.saving.set(true);
this.error.set(null);
this.dialogRef.disableClose = true;
this.rootService.createClient({ name: this.form.getRawValue().name!.trim() }).subscribe({
next: (response) => {
if (response.hasError || !response.data) {
this.fail(errorMessages(response, failure));
return;
}
this.saving.set(false);
this.dialogRef.close(response.data);
},
error: (error: unknown) =>
this.fail(
isForbidden(error)
? 'You do not have permission to create a workspace.'
: errorMessages(error, failure)
),
});
}

cancel(): void {
if (!this.saving()) this.dialogRef.close();
}

private fail(message: string): void {
this.saving.set(false);
this.dialogRef.disableClose = false;
this.error.set(message);
}
}
18 changes: 10 additions & 8 deletions apps/36-blocks/src/app/panel/layout/layout.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
}
</a>
@let clientSettings = clientSettings$ | async; @let clientList = clients$ | async;
@let isMultipleClients = (clientList?.data?.length ?? 0) > 1;
<div
class="flex items-center pt-2"
[class.flex-col]="!sideNavService.isSideNavOpen()"
Expand All @@ -26,11 +25,11 @@
class="flex items-center grow gap-2 mat-drawer-header-title pr-2"
role="button"
tabindex="0"
aria-label="Switch workspace"
aria-label="Switch or create workspace"
(keydown.enter)="clientsMenuTrigger.openMenu()"
(keydown.space)="$event.preventDefault(); clientsMenuTrigger.openMenu()"
#clientsMenuTrigger="matMenuTrigger"
[matMenuTriggerFor]="isMultipleClients ? clientsMenu : null"
[matMenuTriggerFor]="clientsMenu"
[class.pl-2]="!sideNavService.isSideNavOpen()"
[class.pl-4]="sideNavService.isSideNavOpen()"
>
Expand All @@ -41,11 +40,9 @@
>
{{ clientSettings?.client?.name }}
</span>
@if (isMultipleClients) {
<mat-icon>{{
clientsMenuTrigger?.menuOpen ? 'keyboard_arrow_up' : 'keyboard_arrow_down'
}}</mat-icon>
}
<mat-icon>{{
clientsMenuTrigger?.menuOpen ? 'keyboard_arrow_up' : 'keyboard_arrow_down'
}}</mat-icon>
</div>
} @else {
<mat-icon class="mat-icon-22" [matTooltip]="clientSettings?.client?.name" matTooltipPosition="right"
Expand All @@ -72,6 +69,11 @@
</span>
</button>
}
<mat-divider></mat-divider>
<button mat-menu-item type="button" (click)="createWorkspace()">
<mat-icon>add</mat-icon>
<span>Create workspace</span>
</button>
</mat-menu>
<button
matIconButton
Expand Down
21 changes: 21 additions & 0 deletions apps/36-blocks/src/app/panel/layout/layout.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import { rootActions } from '../../core/ngrx/actions';
import { selectAllClient, selectClientSettings, selectSwitchClientSuccess } from '../../core/ngrx';
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import { RootService } from '@proxy/services/proxy/root';
import { MatDialog } from '@angular/material/dialog';
import { CreateWorkspaceDialogComponent } from './create-workspace-dialog/create-workspace-dialog.component';
import { environment } from '../../../environments/environment';
import { AuthService } from '@proxy/services/proxy/auth';
import { SideNavService } from './side-nav.service';
Expand Down Expand Up @@ -88,6 +90,7 @@ export class LayoutComponent extends BaseComponent implements OnInit, OnDestroy
dashboard: 'Overview',
features: 'Applications & blocks',
users: 'People',
team: 'Team & access',
logs: 'Request logs',
activity: 'Operator activity',
chatbot: 'Assistant',
Expand All @@ -111,6 +114,7 @@ export class LayoutComponent extends BaseComponent implements OnInit, OnDestroy
public sideNavService = inject(SideNavService);
private uiSettings = inject(UiSettingsService);
private featuresService = inject(FeaturesService);
private dialog = inject(MatDialog);

constructor() {
super();
Expand Down Expand Up @@ -268,6 +272,23 @@ export class LayoutComponent extends BaseComponent implements OnInit, OnDestroy
this.store.dispatch(rootActions.getClientSettings());
}

/** Opens the create-workspace dialog. The API switches the session into the new workspace, so reload like a switch. */
public createWorkspace(): void {
this.dialog
.open(CreateWorkspaceDialogComponent, {
panelClass: ['mat-dialog'],
autoFocus: 'input',
restoreFocus: true,
})
.afterClosed()
.pipe(takeUntil(this.destroy$))
.subscribe((client) => {
if (client) {
location.href = '/app';
}
});
}

public switchClient(clientId: number): void {
this.store.dispatch(rootActions.switchClient({ request: { client_id: clientId } }));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export class MainLeftSideNavComponent extends BaseComponent {
{ route: 'dashboard', icon: 'dashboard', label: 'Overview' },
{ route: 'features', icon: 'featured_play_list', label: 'Applications & blocks' },
{ route: 'users', icon: 'person', label: 'People' },
{ route: 'team', icon: 'admin_panel_settings', label: 'Team & access' },
{ route: 'logs', icon: 'description', label: 'Request logs' },
{ route: 'activity', icon: 'history', label: 'Operator activity' },
{ route: 'chatbot', icon: 'face', label: 'Assistant' },
Expand Down
4 changes: 4 additions & 0 deletions apps/36-blocks/src/app/panel/panel.routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ export const panelRoutes: Route[] = [
path: 'logs',
loadChildren: () => import('./logs/logs.routes').then((r) => r.logsRoutes),
},
{
path: 'team',
loadChildren: () => import('./team/team.routes').then((r) => r.teamRoutes),
},
{
path: 'activity',
loadComponent: () => import('./activity/activity.component').then((c) => c.ActivityComponent),
Expand Down
Loading
Loading