funky-framadate-front/src/app/features/administration/poll-edit/poll-edit.component.ts

42 lines
1.2 KiB
TypeScript

import { Component, Input, OnInit } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { Poll } from '../../../core/models/poll.model';
import { PollUtilsService } from '../../../core/utils/poll-utils.service';
@Component({
selector: 'app-poll-edit',
templateUrl: './poll-edit.component.html',
styleUrls: ['./poll-edit.component.scss'],
})
export class PollEditComponent implements OnInit {
@Input()
public poll?: Poll;
public pollForm: FormGroup;
constructor(private fb: FormBuilder, private pollUtilsService: PollUtilsService) {}
ngOnInit(): void {
this.pollForm = this.fb.group({
type: [this.poll ? this.poll.configuration.isAboutDate : false, [Validators.required]],
title: [this.poll ? this.poll.question.label : '', [Validators.required]],
description: [this.poll ? this.poll.question.description : ''],
slug: [this.poll ? this.poll.configuration.slug : this.generateRandomSlug(), [Validators.required]],
address: this.fb.group({
street: [''],
city: [''],
state: [''],
zip: [''],
}),
});
}
public onSubmit(): void {
console.log(this.pollForm);
}
private generateRandomSlug(): string {
return this.pollUtilsService.makeUuid();
}
}