funky-framadate-front/src/app/features/administration/form/base-config/base-config.component.ts

50 lines
1.7 KiB
TypeScript
Raw Normal View History

2021-04-25 12:05:17 +02:00
import { ChangeDetectorRef, Component, Inject, Input } from '@angular/core';
2021-02-04 16:14:07 +01:00
import { ToastService } from '../../../../core/services/toast.service';
import { UntypedFormBuilder, UntypedFormGroup } from '@angular/forms';
2021-02-04 16:14:07 +01:00
import { UuidService } from '../../../../core/services/uuid.service';
import { PollService } from '../../../../core/services/poll.service';
import { ApiService } from '../../../../core/services/api.service';
import { Router } from '@angular/router';
import { DOCUMENT } from '@angular/common';
import { Poll } from '../../../../core/models/poll.model';
2021-04-25 12:05:17 +02:00
import { environment } from '../../../../../environments/environment';
import { PollUtilitiesService } from '../../../../core/services/poll.utilities.service';
2021-02-04 16:14:07 +01:00
@Component({
selector: 'app-base-config',
templateUrl: './base-config.component.html',
styleUrls: ['./base-config.component.scss'],
})
2021-02-05 17:02:52 +01:00
export class BaseConfigComponent {
2021-02-04 16:14:07 +01:00
@Input()
public poll?: Poll;
@Input()
public form: UntypedFormGroup;
2021-02-04 16:14:07 +01:00
constructor(
private fb: UntypedFormBuilder,
2021-02-04 16:14:07 +01:00
private cd: ChangeDetectorRef,
private uuidService: UuidService,
private toastService: ToastService,
private pollService: PollService,
private utilitiesService: PollUtilitiesService,
2021-02-04 16:14:07 +01:00
private apiService: ApiService,
private router: Router,
@Inject(DOCUMENT) private document: Document
) {}
public updateSlug(): void {
2021-11-07 15:21:27 +01:00
const newValueFormatted = this.pollService.makeSlug(this.pollService.form);
console.log('newValueFormatted', newValueFormatted);
2021-04-30 11:27:54 +02:00
this.form.patchValue({ custom_url: newValueFormatted });
2021-02-04 16:14:07 +01:00
}
2021-05-04 09:33:28 +02:00
getErrorMessage(fieldControl) {
return fieldControl.hasError('required')
? 'You must enter a value'
: fieldControl.hasError('email')
? 'Not a valid email'
: '';
}
2021-02-04 16:14:07 +01:00
}