diff --git a/ngsw-config.json b/ngsw-config.json index 28333b9..e9c4674 100644 --- a/ngsw-config.json +++ b/ngsw-config.json @@ -1,9 +1,9 @@ { "$schema": "./node_modules/@angular/service-worker/config/schema.json", "appData": { - "appVersion": "0.0.14", - "buildDate": "2026-05-16T13:47:08.720Z", - "buildNumber": 14 + "appVersion": "0.0.17", + "buildDate": "2026-05-16T16:43:54.103Z", + "buildNumber": 17 }, "assetGroups": [ { @@ -12,9 +12,7 @@ "resources": { "files": [ "/favicon.ico", - "/index.html", - "/*.css", - "/*.js" + "/index.html" ] }, "updateMode": "prefetch" @@ -42,11 +40,5 @@ } ], "dataGroups": [], - "index": "/index.html", - "navigationUrls": [ - "/**", - "!/**/*.*", - "!/**/*__*", - "!/**/*__*/**" - ] + "index": "/index.html" } diff --git a/src/app/domains/pos/layouts/pagesLayout/layout.component.ts b/src/app/domains/pos/layouts/pagesLayout/layout.component.ts index f946955..58a119c 100644 --- a/src/app/domains/pos/layouts/pagesLayout/layout.component.ts +++ b/src/app/domains/pos/layouts/pagesLayout/layout.component.ts @@ -119,6 +119,15 @@ export class PosPagesLayoutComponent { this.layoutService.setTopbarEndSlot(this.topbarEnd); } + // ngAfterViewInit() { + // // @ts-ignore + // window.WebV = { + // onPaymentResult: (payload: unknown) => { + // console.log('payload', payload); + // }, + // }; + // } + ngOnDestroy() { this.layoutService.changeIsFullPage(false); this.layoutService.setTopbarStartSlot(null); diff --git a/src/app/domains/pos/modules/landing/components/payloads/gold/form.component.ts b/src/app/domains/pos/modules/landing/components/payloads/gold/form.component.ts index dbb92ef..cb1ef98 100644 --- a/src/app/domains/pos/modules/landing/components/payloads/gold/form.component.ts +++ b/src/app/domains/pos/modules/landing/components/payloads/gold/form.component.ts @@ -31,16 +31,16 @@ export class PosGoldPayloadFormComponent extends AbstractForm< IPosOrderItem, IPosOrderItem > { - // override defaultValues: Partial> = { - // unit_price: 200_000_000, - // quantity: 2, - // payload: { - // commission: 10_000, - // wages: 10_000, - // profit: 10_000, - // karat: '18' as TGoldKarat, - // } as any, - // }; + override defaultValues: Partial> = { + unit_price: 200_000_000, + quantity: 2, + payload: { + // commission: 10_000, + // wages: 10_000, + // profit: 10_000, + karat: 'KARAT_18' as TGoldKarat, + } as any, + }; @Output() onSubmitForm = new EventEmitter(); @Output() onChangeTotalAmount = new EventEmitter(); diff --git a/src/app/domains/pos/modules/landing/components/payloads/standard/form.component.html b/src/app/domains/pos/modules/landing/components/payloads/standard/form.component.html index 79d063b..5e1ac58 100644 --- a/src/app/domains/pos/modules/landing/components/payloads/standard/form.component.html +++ b/src/app/domains/pos/modules/landing/components/payloads/standard/form.component.html @@ -27,6 +27,6 @@ [discountAmount]="discountAmount()" [taxAmount]="taxAmount()" /> - {{ preparedCTAText() }} + diff --git a/src/app/domains/pos/modules/landing/components/payloads/standard/form.component.ts b/src/app/domains/pos/modules/landing/components/payloads/standard/form.component.ts index 6094183..0c3bd2f 100644 --- a/src/app/domains/pos/modules/landing/components/payloads/standard/form.component.ts +++ b/src/app/domains/pos/modules/landing/components/payloads/standard/form.component.ts @@ -6,7 +6,7 @@ import { formatWithCurrency } from '@/utils'; import { Component, computed, EventEmitter, Input, Output, signal } from '@angular/core'; import { takeUntilDestroyed } from '@angular/core/rxjs-interop'; import { ReactiveFormsModule, Validators } from '@angular/forms'; -import { Button } from 'primeng/button'; +import { ButtonDirective } from 'primeng/button'; import { IPosOrderItem, IStandardPayload } from '../../../models'; import { PosFormDialogAmountCardTemplateComponent } from '../form-dialog-amount-card-template.component'; @@ -16,9 +16,9 @@ import { PosFormDialogAmountCardTemplateComponent } from '../form-dialog-amount- imports: [ ReactiveFormsModule, InputComponent, - Button, PosFormDialogAmountCardTemplateComponent, AmountPercentageInputComponent, + ButtonDirective, ], }) export class PosStandardPayloadFormComponent extends AbstractForm< diff --git a/src/app/domains/pos/modules/landing/components/payment/form-dialog.component.ts b/src/app/domains/pos/modules/landing/components/payment/form-dialog.component.ts index 9968874..69e89e6 100644 --- a/src/app/domains/pos/modules/landing/components/payment/form-dialog.component.ts +++ b/src/app/domains/pos/modules/landing/components/payment/form-dialog.component.ts @@ -57,12 +57,16 @@ export class PosPaymentFormDialogComponent extends AbstractFormDialog>([]); private restorePaymentCallback: Maybe<() => void> = null; + private readonly injectedPaymentResultHandler = (payload: unknown) => { + alert('پرداخت با موفقیت انجام شد'); this.toastServices.success({ text: 'شد شد شد شد شد' }); // this.handlePaymentResult(payload); }; - ngOnViewInit() { + ngAfterViewInit() { + console.log('ngOnViewInit'); + this.restorePaymentCallback = this.paymentBridge.registerPaymentResultListener( this.injectedPaymentResultHandler, ); diff --git a/src/app/domains/pos/modules/landing/services/payment-bridge.service.ts b/src/app/domains/pos/modules/landing/services/payment-bridge.service.ts index a39bae3..0d7da81 100644 --- a/src/app/domains/pos/modules/landing/services/payment-bridge.service.ts +++ b/src/app/domains/pos/modules/landing/services/payment-bridge.service.ts @@ -1,36 +1,33 @@ -import { Injectable } from '@angular/core'; +import { ToastService } from '@/core/services/toast.service'; +import { inject, Injectable } from '@angular/core'; import { PosPaymentBridgeAbstract } from './payment-bridge.abstract'; @Injectable({ providedIn: 'root' }) export class PosPaymentBridgeService extends PosPaymentBridgeAbstract { + private readonly toastServices = inject(ToastService); registerPaymentResultListener(handler: (payload: unknown) => void): () => void { - const w = window as unknown as { - WebV: { - onPaymentResult?: (payload: unknown) => void; - AndroidBridge?: { - onPaymentResult?: (payload: unknown) => void; - }; - }; + // const w = window as unknown as { + // WebV?: { + // onPaymentResult?: (payload: unknown) => void; + // AndroidBridge?: { + // onPaymentResult?: (payload: unknown) => void; + // }; + // }; + // }; + this.toastServices.error({ text: '@@@@@@@@@@@@@' }); + + // @ts-ignore + window.webV = { + onPaymentResult: () => { + this.toastServices.error({ text: 'asdasdsadassadasdas' }); + }, }; - const previousGlobal = w.WebV.onPaymentResult; - const previousBridge = w.WebV.AndroidBridge?.onPaymentResult; - - w.WebV.onPaymentResult = handler; - if (w.WebV.AndroidBridge) { - w.WebV.AndroidBridge.onPaymentResult = handler; - } - - return () => { - w.WebV.onPaymentResult = previousGlobal; - if (w.WebV.AndroidBridge) { - w.WebV.AndroidBridge.onPaymentResult = previousBridge; - } - }; + return () => {}; } emitPaymentResultForTest(payload: unknown): void { - const w = window as unknown as { WebV: { onPaymentResult?: (payload: unknown) => void } }; - w.WebV.onPaymentResult?.(payload); + const w = window as unknown as { WebV?: { onPaymentResult?: (payload: unknown) => void } }; + w.WebV?.onPaymentResult?.(payload); } } diff --git a/src/app/shared/components/input/input.component.ts b/src/app/shared/components/input/input.component.ts index 21caa59..e8ff507 100644 --- a/src/app/shared/components/input/input.component.ts +++ b/src/app/shared/components/input/input.component.ts @@ -41,6 +41,7 @@ import { ToggleSwitch } from 'primeng/toggleswitch'; templateUrl: './input.component.html', }) export class InputComponent { + private lastValidNumericValue = ''; @Input() type: | 'simple' | 'postalCode' @@ -226,6 +227,21 @@ export class InputComponent { return `${normalizedInteger}.${fixedDecimal}`; } + private normalizeLeadingZeros(value: string, allowDecimal: boolean): string { + if (!value) return value; + if (!allowDecimal) { + return value.replace(/^0+(?=\d)/, ''); + } + + if (value.includes('.')) { + const [integerPart = '0', decimalPart = ''] = value.split('.'); + const normalizedInteger = integerPart.replace(/^0+(?=\d)/, '') || '0'; + return `${normalizedInteger}.${decimalPart}`; + } + + return value.replace(/^0+(?=\d)/, ''); + } + onInput($event: Event, isPriceFormat?: boolean) { const target = $event.target as HTMLInputElement | null; if (!target) return; @@ -236,6 +252,7 @@ export class InputComponent { if (this.inputMode === 'numeric' || this.inputMode === 'decimal' || isPriceFormat) { value = this.sanitizeNumericValue(value, allowDecimal); value = this.applyFixed(value); + value = this.normalizeLeadingZeros(value, allowDecimal); } if (this.preparedMaxLength && value.length > this.preparedMaxLength) { @@ -260,12 +277,23 @@ export class InputComponent { text: `مقدار ${this.label} نمی‌تواند کمتر از ${this.min} باشد.`, }); } - value = value.slice(0, -1); + value = this.lastValidNumericValue; numericValue = Number.isNaN(parseFloat(value)) ? 0 : parseFloat(value); + + const isIdentifierField = ['mobile', 'phone', 'postalCode', 'nationalId'].includes(this.type); + const restoredControlValue = isIdentifierField ? value : value === '' ? '' : numericValue; + + this.control.setValue(restoredControlValue); + target.value = isPriceFormat && value !== '' ? numericValue.toLocaleString('en-US') : value; + return; + } else if (this.inputMode === 'numeric' || this.inputMode === 'decimal') { + this.lastValidNumericValue = value; } - const isIdentifierField = !this.numericValue; - this.control.setValue(isIdentifierField ? value : value === '' ? '' : numericValue); + const isIdentifierField = ['mobile', 'phone', 'postalCode', 'nationalId'].includes(this.type); + const controlValue = isIdentifierField ? value : value === '' ? '' : numericValue; + + this.control.setValue(controlValue); const viewValue = isPriceFormat && value !== '' ? numericValue.toLocaleString('en-US') : value; @@ -277,4 +305,10 @@ export class InputComponent { this.valueChange.emit(isIdentifierField ? value : numericValue); } } + + ngOnInit() { + const allowDecimal = this.type === 'price' || this.type === 'number'; + const initial = this.sanitizeNumericValue(`${this.control?.value ?? ''}`, allowDecimal); + this.lastValidNumericValue = initial; + } }