Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(workspace): i#0453 workspace name empty error #538

Merged
merged 1 commit into from
Oct 30, 2023
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
Expand Up @@ -41,4 +41,10 @@ Copyright (c) 2023-present Kaleidos INC
& .workspace-input-project-name {
inline-size: 278px;
}

&::ng-deep {
& .input-container {
flex-direction: column;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
(keydown.esc)="close()"
(ngSubmit)="onSubmit()"
[attr.aria-invalid]="createProjectForm.invalid"
[showFormErrors]="submitted"
class="workspace-create-padding">
<tg-ui-avatar
class="workspace-image"
Expand All @@ -28,16 +29,19 @@
class="input-project"
(keyup)="setName($event)"
data-test="workspace-name-input"
formControlName="projectName"
formControlName="workspaceName"
#firstInput
tuiAutoFocus
maxlength="40"
[maxlength]="maxLength"
[placeholder]="t('workspace.workspace_name')" />
<tg-ui-error
inputError
error="required">
{{ t('workspace.error_name_empty') }}
</tg-ui-error>
<tg-ui-error error="pattern">{{
t('workspace.error_name_empty')
}}</tg-ui-error>
</tg-ui-input>
<button
data-test="workspace-project-form-submit"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,7 @@ import {
Output,
ViewChild,
} from '@angular/core';
import {
FormBuilder,
FormGroup,
Validators,
ReactiveFormsModule,
} from '@angular/forms';
import { FormBuilder, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { Store } from '@ngrx/store';
import { RxState } from '@rx-angular/state';
import { RandomColorService } from '@taiga/ui/services/random-color/random-color.service';
Expand All @@ -35,6 +30,10 @@ import { CommonModule } from '@angular/common';
import { InputsModule } from '@taiga/ui/inputs';
import { AvatarComponent } from '@taiga/ui/avatar/avatar.component';
import { FormDirective } from '@taiga/ui/inputs/form/form.directive';
import {
WorkspaceNameMaxLength,
WorkspaceNameValidation,
} from '~/app/shared/workspace/workspace-name-validation';

@Component({
selector: 'tg-workspace-create',
Expand Down Expand Up @@ -66,6 +65,8 @@ export class WorkspaceCreateComponent implements OnInit {
public color = 0;
public createProjectForm!: FormGroup;
public name = '';
public maxLength = WorkspaceNameMaxLength;
public submitted = false;

public close() {
this.store.dispatch(createFormHasError({ hasError: false }));
Expand All @@ -76,24 +77,26 @@ export class WorkspaceCreateComponent implements OnInit {
this.color = RandomColorService.randomColorPicker();
this.createProjectForm = this.fb.group(
{
projectName: ['', [Validators.required]],
workspaceName: ['', WorkspaceNameValidation],
},
{ updateOn: 'submit' }
);
}

public setName(event: Event) {
this.submitted = false;
this.name = (<HTMLInputElement>event.target).value;
}

public onSubmit() {
if (this.createProjectForm.invalid) {
this.submitted = true;
(this.firstInput.nativeElement as HTMLElement).focus();
this.store.dispatch(createFormHasError({ hasError: true }));
} else {
this.store.dispatch(
createWorkspace({
name: this.createProjectForm.get('projectName')!.value as string,
name: this.createProjectForm.get('workspaceName')!.value as string,
color: this.color,
})
);
Expand Down