Refactor code structure for improved readability and maintainability
This commit is contained in:
+1
-1
@@ -4,7 +4,7 @@
|
||||
emptyPlaceholderTitle="حساب کاربریای یافت نشد."
|
||||
[items]="items()"
|
||||
[loading]="loading()"
|
||||
[showDetails]="true"
|
||||
[showIndex]="false"
|
||||
(onRefresh)="refresh()"
|
||||
>
|
||||
</app-page-data-list>
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
[pageTitle]="'مدیریت دستهبندیهای کالا'"
|
||||
[addNewCtaLabel]="'افزودن دستهبندی'"
|
||||
[columns]="columns"
|
||||
[showAdd]="true"
|
||||
emptyPlaceholderTitle="دستهبندی یافت نشد"
|
||||
emptyPlaceholderDescription="برای افزودن دستهبندی، روی دکمهٔ بالا کلیک کنید."
|
||||
[items]="items()"
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
<shared-dialog header="فرم صنف" [(visible)]="visible" [modal]="true" [style]="{ width: '500px' }" [closable]="true" ()>
|
||||
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||
<app-input label="عنوان" [control]="form.controls.name" name="name" />
|
||||
<app-input label="کد" [control]="form.controls.code" name="code" />
|
||||
<field-name [control]="form.controls.name" />
|
||||
<field-code [control]="form.controls.code" />
|
||||
<field-invoice-templates [control]="form.controls.invoice_template" />
|
||||
|
||||
<app-form-footer-actions [submitLabel]="'ذخیره'" [loading]="submitLoading()" (onCancel)="close()" />
|
||||
</form>
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||
import { InputComponent } from '@/shared/components';
|
||||
import { CodeComponent, FieldInvoiceTemplatesComponent, NameComponent } from '@/shared/components';
|
||||
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { fieldControl } from '@/shared/constants';
|
||||
import { Component, inject, Input } from '@angular/core';
|
||||
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { ReactiveFormsModule } from '@angular/forms';
|
||||
import { IGuildRequest, IGuildResponse } from '../models';
|
||||
import { GuildsService } from '../services/main.service';
|
||||
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';
|
||||
|
||||
interface T {
|
||||
name: string;
|
||||
@@ -15,21 +16,23 @@ interface T {
|
||||
@Component({
|
||||
selector: 'admin-guild-form',
|
||||
templateUrl: './form.component.html',
|
||||
imports: [ReactiveFormsModule, SharedDialogComponent, InputComponent, FormFooterActionsComponent],
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
SharedDialogComponent,
|
||||
FormFooterActionsComponent,
|
||||
NameComponent,
|
||||
CodeComponent,
|
||||
FieldInvoiceTemplatesComponent,
|
||||
],
|
||||
})
|
||||
export class GuildFormComponent extends AbstractFormDialog<IGuildRequest, IGuildResponse> {
|
||||
@Input() guildId?: string;
|
||||
private service = inject(GuildsService);
|
||||
|
||||
form = this.fb.group({
|
||||
name: [
|
||||
{ value: this.initialValues?.name, disabled: this.submitLoading() },
|
||||
Validators.required,
|
||||
],
|
||||
code: [
|
||||
{ value: this.initialValues?.code, disabled: this.submitLoading() },
|
||||
Validators.required,
|
||||
],
|
||||
name: fieldControl.name(this.initialValues?.name, true),
|
||||
code: fieldControl.code(this.initialValues?.code, true),
|
||||
invoice_template: fieldControl.invoice_template(this.initialValues?.invoice_template.id, true),
|
||||
});
|
||||
|
||||
override ngOnChanges() {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<app-page-data-list
|
||||
pageTitle="مدیریت کالاها"
|
||||
[addNewCtaLabel]="'افزودن کالای'"
|
||||
[addNewCtaLabel]="'افزودن کالا'"
|
||||
[columns]="columns"
|
||||
[showAdd]="true"
|
||||
emptyPlaceholderTitle="کالایی یافت نشد"
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
import ISummary from '@/core/models/summary';
|
||||
|
||||
export interface IGuildRawResponse {
|
||||
id: string;
|
||||
name: string;
|
||||
code: string;
|
||||
invoice_template: ISummary;
|
||||
created_at: string;
|
||||
}
|
||||
export interface IGuildResponse extends IGuildRawResponse {}
|
||||
@@ -9,7 +12,7 @@ export interface IGuildResponse extends IGuildRawResponse {}
|
||||
export interface IGuildRequest {
|
||||
name: string;
|
||||
code: string;
|
||||
invoice_template_type: string;
|
||||
invoice_template: string;
|
||||
}
|
||||
|
||||
export interface IGoodCategoriesRawResponse {
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
[pageTitle]="'مدیریت اصناف'"
|
||||
[addNewCtaLabel]="'افزودن صنف'"
|
||||
[columns]="columns"
|
||||
[showAdd]="true"
|
||||
emptyPlaceholderTitle="صنفی یافت نشد"
|
||||
emptyPlaceholderDescription="برای افزودن صنف، روی دکمهٔ بالا کلیک کنید."
|
||||
[items]="items()"
|
||||
[loading]="loading()"
|
||||
[showDetails]="true"
|
||||
[showAdd]="true"
|
||||
[showEdit]="true"
|
||||
(onAdd)="openAddForm()"
|
||||
(onDetails)="toSinglePage($event)"
|
||||
(onRefresh)="refresh()"
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
emptyPlaceholderDescription="برای افزودن حساب کاربری، روی دکمهٔ بالا کلیک کنید."
|
||||
[items]="items()"
|
||||
[loading]="loading()"
|
||||
[showIndex]="false"
|
||||
(onAdd)="openAddForm()"
|
||||
(onRefresh)="refresh()"
|
||||
>
|
||||
|
||||
@@ -8,12 +8,11 @@
|
||||
>
|
||||
<form [formGroup]="form" (submit)="submit()" class="flex flex-col gap-4">
|
||||
<app-shared-upload-file accept="image/*" name="image" (onSelect)="changeFile($event)" />
|
||||
<app-input label="عنوان" [control]="form.controls.name" name="name" />
|
||||
<app-input label="کد" [control]="form.controls.code" name="code" />
|
||||
<field-name [control]="form.controls.name" />
|
||||
<field-code [control]="form.controls.code" />
|
||||
@if (!editMode) {
|
||||
<p-divider align="center"> اطلاعات ورود </p-divider>
|
||||
<!-- @ts-ignore -->
|
||||
<app-input label="نام کاربری" [control]="form.controls.username" name="username" [isLtrInput]="true" />
|
||||
<field-username [control]="form.controls.username" />
|
||||
<shared-password-input
|
||||
[passwordControl]="form.controls.password"
|
||||
[confirmPasswordControl]="form.controls.confirmPassword"
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import { Maybe } from '@/core';
|
||||
import { MustMatch } from '@/core/validators';
|
||||
import { MustMatch, usernameValidator } from '@/core/validators';
|
||||
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||
import { InputComponent, SharedPasswordInputComponent } from '@/shared/components';
|
||||
import {
|
||||
CodeComponent,
|
||||
NameComponent,
|
||||
SharedPasswordInputComponent,
|
||||
UsernameComponent,
|
||||
} from '@/shared/components';
|
||||
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { onSelectFileArgs } from '@/shared/components/uploadFile/model';
|
||||
import { SharedUploadFileComponent } from '@/shared/components/uploadFile/upload-file.component';
|
||||
import { fieldControl } from '@/shared/constants';
|
||||
import { buildFormData } from '@/utils';
|
||||
import { Component, computed, inject, Input, signal } from '@angular/core';
|
||||
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
@@ -19,11 +25,13 @@ import { PartnersService } from '../services/main.service';
|
||||
imports: [
|
||||
ReactiveFormsModule,
|
||||
SharedDialogComponent,
|
||||
InputComponent,
|
||||
FormFooterActionsComponent,
|
||||
Divider,
|
||||
SharedPasswordInputComponent,
|
||||
SharedUploadFileComponent,
|
||||
UsernameComponent,
|
||||
NameComponent,
|
||||
CodeComponent,
|
||||
],
|
||||
})
|
||||
export class GuildFormComponent extends AbstractFormDialog<IPartnerRequest, IPartnerResponse> {
|
||||
@@ -32,35 +40,16 @@ export class GuildFormComponent extends AbstractFormDialog<IPartnerRequest, IPar
|
||||
|
||||
private initForm() {
|
||||
const form = this.fb.group({
|
||||
name: [this.initialValues?.name, [Validators.required]],
|
||||
code: [this.initialValues?.code, [Validators.required]],
|
||||
username: [''],
|
||||
password: [''],
|
||||
confirmPassword: [''],
|
||||
name: fieldControl.name(this.initialValues?.name || ''),
|
||||
code: fieldControl.code(this.initialValues?.code || ''),
|
||||
username: fieldControl.username(),
|
||||
password: fieldControl.password(),
|
||||
confirmPassword: fieldControl.confirmPassword(),
|
||||
});
|
||||
|
||||
if (!this.editMode) {
|
||||
form.addControl(
|
||||
'username',
|
||||
this.fb.control<string>('', {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
);
|
||||
form.addControl(
|
||||
'password',
|
||||
this.fb.control<string>('', {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
);
|
||||
form.addControl(
|
||||
'confirmPassword',
|
||||
this.fb.control<string>('', {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
);
|
||||
form.controls.username.setValidators([Validators.required, usernameValidator()]);
|
||||
form.controls.username.updateValueAndValidity({ emitEvent: false });
|
||||
form.addValidators([MustMatch('password', 'confirmPassword')]);
|
||||
} else {
|
||||
// @ts-ignore
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<p-avatar
|
||||
[image]="item.logo_url"
|
||||
[title]="item.name"
|
||||
[label]="item.logo_url ? '' : item.code.slice(0, 2)"
|
||||
[label]="item.logo_url ? '' : item.name.slice(0, 2)"
|
||||
shape="square"
|
||||
size="large"
|
||||
></p-avatar>
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { MustMatch } from '@/core/validators';
|
||||
import { MustMatch, usernameValidator } from '@/core/validators';
|
||||
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||
import { InputComponent, SharedPasswordInputComponent } from '@/shared/components';
|
||||
import { SharedDialogComponent } from '@/shared/components/dialog/dialog.component';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { fieldControl } from '@/shared/constants';
|
||||
import { Component, computed, inject, Input } from '@angular/core';
|
||||
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Divider } from 'primeng/divider';
|
||||
@@ -27,35 +28,16 @@ export class ProviderFormComponent extends AbstractFormDialog<IProviderRequest,
|
||||
|
||||
private initForm() {
|
||||
const form = this.fb.group({
|
||||
name: [this.initialValues?.name, [Validators.required]],
|
||||
code: [this.initialValues?.code, [Validators.required]],
|
||||
username: [''],
|
||||
password: [''],
|
||||
confirmPassword: [''],
|
||||
name: fieldControl.name(this.initialValues?.name || ''),
|
||||
code: fieldControl.code(this.initialValues?.code || ''),
|
||||
username: fieldControl.username(),
|
||||
password: fieldControl.password(),
|
||||
confirmPassword: fieldControl.confirmPassword(),
|
||||
});
|
||||
|
||||
if (!this.editMode) {
|
||||
form.addControl(
|
||||
'username',
|
||||
this.fb.control<string>('', {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
);
|
||||
form.addControl(
|
||||
'password',
|
||||
this.fb.control<string>('', {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
);
|
||||
form.addControl(
|
||||
'confirmPassword',
|
||||
this.fb.control<string>('', {
|
||||
nonNullable: true,
|
||||
validators: [Validators.required],
|
||||
}),
|
||||
);
|
||||
form.controls.username.setValidators([Validators.required, usernameValidator()]);
|
||||
form.controls.username.updateValueAndValidity({ emitEvent: false });
|
||||
form.addValidators([MustMatch('password', 'confirmPassword')]);
|
||||
} else {
|
||||
// @ts-ignore
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
pageTitle="مدیریت حسابهای کاربری"
|
||||
[addNewCtaLabel]="'افزودن حساب کاربری'"
|
||||
[columns]="columns"
|
||||
[showAdd]="true"
|
||||
emptyPlaceholderTitle="حساب کاربریای یافت نشد."
|
||||
emptyPlaceholderDescription="برای افزودن حساب کاربری، روی دکمهٔ بالا کلیک کنید."
|
||||
[items]="items()"
|
||||
[loading]="loading()"
|
||||
[showDetails]="true"
|
||||
[showAdd]="true"
|
||||
[showIndex]="false"
|
||||
(onAdd)="openAddForm()"
|
||||
(onRefresh)="refresh()"
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user