refactor: form submit text as input

This commit is contained in:
2025-12-15 21:43:01 -03:00
parent a41c4a7761
commit 01ac16fbdc
3 changed files with 18 additions and 7 deletions

View File

@@ -24,7 +24,7 @@
</div> </div>
<div class="footer"> <div class="footer">
<app-squared-btn <app-squared-btn
[text]="strings.add" [text]="submitText()"
></app-squared-btn> ></app-squared-btn>
</div> </div>
</form> </form>

View File

@@ -5,7 +5,7 @@ import { STRINGS_INJECTOR } from '../../app.config';
import { SquaredBtn } from '../squared-btn/squared-btn'; import { SquaredBtn } from '../squared-btn/squared-btn';
import { NameAndCompanyFieldsErrorsDictionary } from '../../errors-dictionaries/name-and-company-field'; import { NameAndCompanyFieldsErrorsDictionary } from '../../errors-dictionaries/name-and-company-field';
import { PhoneFieldErroresDictionary } from '../../errors-dictionaries/phone-field'; import { PhoneFieldErroresDictionary } from '../../errors-dictionaries/phone-field';
import { UpperfirstPipe } from "../../pipes/upperfirst-pipe"; import { UpperfirstPipe } from '../../pipes/upperfirst-pipe';
import { ContactDTO } from '../../models/ContactDTO'; import { ContactDTO } from '../../models/ContactDTO';
import { ContactFormValue } from '../../types/ContactFormValue.type'; import { ContactFormValue } from '../../types/ContactFormValue.type';
import { FormGroupContact } from '../../utils/form-group-contact'; import { FormGroupContact } from '../../utils/form-group-contact';
@@ -19,13 +19,21 @@ import { FormGroupContact } from '../../utils/form-group-contact';
export class ContactForm { export class ContactForm {
contact = output<ContactDTO>(); contact = output<ContactDTO>();
form = input(new FormGroupContact()); form = input(new FormGroupContact());
submitText = input('');
protected strings = inject(STRINGS_INJECTOR); protected strings = inject(STRINGS_INJECTOR);
protected companyAndNameErrorsDictionary = new NameAndCompanyFieldsErrorsDictionary().getDictionary(); protected companyAndNameErrorsDictionary =
new NameAndCompanyFieldsErrorsDictionary().getDictionary();
protected phoneErrorsDictionary = new PhoneFieldErroresDictionary().getDictionary(); protected phoneErrorsDictionary = new PhoneFieldErroresDictionary().getDictionary();
handleSubmit(contactForm: ContactFormValue) { handleSubmit(contactForm: ContactFormValue) {
if(contactForm.company === null || contactForm.name === null || contactForm.phone === null) return; if (contactForm.company === null || contactForm.name === null || contactForm.phone === null)
const contact = new ContactDTO(undefined, contactForm.name, contactForm.company, contactForm.phone); return;
const contact = new ContactDTO(
undefined,
contactForm.name,
contactForm.company,
contactForm.phone
);
this.contact.emit(contact); this.contact.emit(contact);
this.form().reset(); this.form().reset();
} }

View File

@@ -1,7 +1,10 @@
<app-main-header [title]="strings.contactList"/> <app-main-header [title]="strings.contactList"/>
<app-card bgColor="var(--secondary)"> <app-card bgColor="var(--secondary)">
<app-contact-form class="form" (contact)="save($event)"> <app-contact-form
<app-form-header (contact)="save($event)"
[submitText]="strings.add"
class="form"
><app-form-header
[subtitle]="strings.allFieldRequired|upperfirst" [subtitle]="strings.allFieldRequired|upperfirst"
[title]="strings.addContact|upperfirst" [title]="strings.addContact|upperfirst"
slot="header" slot="header"