fix ui issues and upload image for guild good
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { BreadcrumbService } from '@/core/services';
|
||||
import { AppCardComponent, KeyValueComponent } from '@/shared/components';
|
||||
import { JalaliDateDirective } from '@/shared/directives';
|
||||
import { licenseStatus } from '@/shared/localEnum/constants/licenseStatus';
|
||||
import { getLicenseStatus } from '@/utils';
|
||||
import { Component, computed, effect, inject, signal } from '@angular/core';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Button } from 'primeng/button';
|
||||
@@ -38,19 +38,9 @@ export class ConsumerComponent {
|
||||
readonly loading = computed(() => this.store.loading());
|
||||
readonly consumer = computed(() => this.store.entity());
|
||||
readonly license = computed(() => this.store.entity()?.license_info);
|
||||
readonly licenseStatus = computed(() => {
|
||||
console.log(this.store.entity()?.license_info?.expires_at);
|
||||
|
||||
if (!this.store.entity()?.license_info?.expires_at) {
|
||||
return null;
|
||||
}
|
||||
if (
|
||||
new Date().getTime() > new Date(this.store.entity()?.license_info?.expires_at || '').getTime()
|
||||
) {
|
||||
return licenseStatus.EXPIRED;
|
||||
}
|
||||
return licenseStatus.ACTIVE;
|
||||
});
|
||||
readonly licenseStatus = computed(() =>
|
||||
getLicenseStatus(this.store.entity()?.license_info?.expires_at),
|
||||
);
|
||||
|
||||
constructor() {
|
||||
effect(() => {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<p-dialog [header]="preparedTitle" [(visible)]="visible" [modal]="true" [style]="{ width: '500px' }" [closable]="true">
|
||||
<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.sku" name="sku" />
|
||||
<admin-guild-categories-select
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
import { AbstractFormDialog } from '@/shared/abstractClasses';
|
||||
import { InputComponent } from '@/shared/components';
|
||||
import { FormFooterActionsComponent } from '@/shared/components/formFooterActions/form-footer-actions.component';
|
||||
import { Component, inject, Input } from '@angular/core';
|
||||
import { Component, inject, Input, signal } from '@angular/core';
|
||||
import { ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { Dialog } from 'primeng/dialog';
|
||||
|
||||
import { Maybe } from '@/core';
|
||||
import { EnumSelectComponent } from '@/shared/apiEnum/select.component';
|
||||
import { onSelectFileArgs } from '@/shared/components/uploadFile/model';
|
||||
import { SharedUploadFileComponent } from '@/shared/components/uploadFile/upload-file.component';
|
||||
import { buildFormData } from '@/utils';
|
||||
import { IGuildGoodRequest, IGuildGoodsResponse } from '../../models';
|
||||
import { GuildGoodsService } from '../../services/goods.service';
|
||||
import { GuildCategoriesSelectComponent } from '../categories/select.component';
|
||||
@@ -20,6 +24,7 @@ import { GuildCategoriesSelectComponent } from '../categories/select.component';
|
||||
FormFooterActionsComponent,
|
||||
EnumSelectComponent,
|
||||
GuildCategoriesSelectComponent,
|
||||
SharedUploadFileComponent,
|
||||
],
|
||||
})
|
||||
export class GuildGoodFormComponent extends AbstractFormDialog<
|
||||
@@ -31,6 +36,8 @@ export class GuildGoodFormComponent extends AbstractFormDialog<
|
||||
|
||||
private service = inject(GuildGoodsService);
|
||||
|
||||
goodImage = signal<Maybe<File>>(null);
|
||||
|
||||
form = this.fb.group({
|
||||
name: [this.initialValues?.name || '', [Validators.required]],
|
||||
sku: [this.initialValues?.sku || '', [Validators.required]],
|
||||
@@ -44,10 +51,20 @@ export class GuildGoodFormComponent extends AbstractFormDialog<
|
||||
return `${this.editMode ? 'ویرایش' : 'ایجاد'} کالا`;
|
||||
}
|
||||
|
||||
changeFile(payload: onSelectFileArgs) {
|
||||
this.goodImage.set(payload.file);
|
||||
}
|
||||
|
||||
override ngOnChanges(): void {
|
||||
this.form.patchValue(this.initialValues || {});
|
||||
this.form.controls.category_id.setValue(this.initialValues?.category.id || '');
|
||||
}
|
||||
|
||||
override submitForm(payload: IGuildGoodRequest) {
|
||||
const formData = buildFormData(this.form, { image: this.goodImage() });
|
||||
if (this.editMode) {
|
||||
return this.service.update(this.guildId, this.categoryId!, payload);
|
||||
return this.service.update(this.guildId, this.categoryId!, formData);
|
||||
}
|
||||
return this.service.create(this.guildId, payload);
|
||||
return this.service.create(this.guildId, formData);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { HttpClient } from '@angular/common/http';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs';
|
||||
import { GUILD_GOODS_API_ROUTES } from '../constants/apiRoutes/goods';
|
||||
import { IGuildGoodRequest, IGuildGoodsRawResponse, IGuildGoodsResponse } from '../models';
|
||||
import { IGuildGoodsRawResponse, IGuildGoodsResponse } from '../models';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class GuildGoodsService {
|
||||
@@ -18,11 +18,11 @@ export class GuildGoodsService {
|
||||
return this.http.get<IGuildGoodsRawResponse>(this.apiRoutes.single(guildId, id));
|
||||
}
|
||||
|
||||
create(guildId: string, data: IGuildGoodRequest): Observable<IGuildGoodsResponse> {
|
||||
create(guildId: string, data: FormData): Observable<IGuildGoodsResponse> {
|
||||
return this.http.post<IGuildGoodsResponse>(this.apiRoutes.list(guildId), data);
|
||||
}
|
||||
|
||||
update(guildId: string, id: string, data: IGuildGoodRequest): Observable<IGuildGoodsResponse> {
|
||||
update(guildId: string, id: string, data: FormData): Observable<IGuildGoodsResponse> {
|
||||
return this.http.patch<IGuildGoodsResponse>(this.apiRoutes.single(guildId, id), data);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user