added setting check
This commit is contained in:
@@ -76,6 +76,7 @@
|
|||||||
step="1"
|
step="1"
|
||||||
inputmode="numeric"
|
inputmode="numeric"
|
||||||
placeholder="0"
|
placeholder="0"
|
||||||
|
[disabled]="isAmountLocked()"
|
||||||
autofocus
|
autofocus
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -22,6 +22,8 @@ interface SettingsResponse {
|
|||||||
minAmount?: number;
|
minAmount?: number;
|
||||||
maxAmount?: number;
|
maxAmount?: number;
|
||||||
qrTTL?: number;
|
qrTTL?: number;
|
||||||
|
defaultAmount?: number;
|
||||||
|
enableAmount?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface CreateQrResponse {
|
interface CreateQrResponse {
|
||||||
@@ -58,6 +60,7 @@ export class CreatePage {
|
|||||||
maxAmount = signal<number>(200_000);
|
maxAmount = signal<number>(200_000);
|
||||||
|
|
||||||
amount = signal<number | null>(null);
|
amount = signal<number | null>(null);
|
||||||
|
private lockedAmount = signal<number | null>(null);
|
||||||
note = signal<string>('');
|
note = signal<string>('');
|
||||||
error = signal<string>('');
|
error = signal<string>('');
|
||||||
loading = signal<boolean>(false);
|
loading = signal<boolean>(false);
|
||||||
@@ -109,17 +112,26 @@ export class CreatePage {
|
|||||||
|
|
||||||
private loadSettings(): void {
|
private loadSettings(): void {
|
||||||
// Fetch limits from /qr/settings. If the call fails, keep defaults.
|
// Fetch limits from /qr/settings. If the call fails, keep defaults.
|
||||||
const url = `${QR_VITANOVA_API}/qr/settings`;
|
const partnerqrID = this.partnerqrID;
|
||||||
|
const url = `${QR_VITANOVA_API}/qr/settings${partnerqrID ? `?id=${encodeURIComponent(partnerqrID)}` : ''}`;
|
||||||
this.http.get<SettingsResponse>(url).subscribe({
|
this.http.get<SettingsResponse>(url).subscribe({
|
||||||
next: (s) => {
|
next: (s) => {
|
||||||
if (typeof s?.minAmount === 'number') this.minAmount.set(s.minAmount);
|
if (typeof s?.minAmount === 'number') this.minAmount.set(s.minAmount);
|
||||||
if (typeof s?.maxAmount === 'number') this.maxAmount.set(s.maxAmount);
|
if (typeof s?.maxAmount === 'number') this.maxAmount.set(s.maxAmount);
|
||||||
|
|
||||||
|
const defaultAmount = typeof s?.defaultAmount === 'number' ? s.defaultAmount : 0;
|
||||||
|
if (s?.enableAmount === true && defaultAmount > 0) {
|
||||||
|
this.lockedAmount.set(defaultAmount);
|
||||||
|
this.amount.set(defaultAmount);
|
||||||
|
} else {
|
||||||
|
this.lockedAmount.set(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
createCheck(): void {
|
createCheck(): void {
|
||||||
const val = this.amount();
|
const val = this.lockedAmount() ?? this.amount();
|
||||||
if (val !== null && val < this.minAmount()) {
|
if (val !== null && val < this.minAmount()) {
|
||||||
this.error.set(`${this.t('errors.invalid_amount')} (мин. ${this.minAmount()} ₽)`);
|
this.error.set(`${this.t('errors.invalid_amount')} (мин. ${this.minAmount()} ₽)`);
|
||||||
return;
|
return;
|
||||||
@@ -223,10 +235,19 @@ export class CreatePage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onAmountChange(value: number | null): void {
|
onAmountChange(value: number | null): void {
|
||||||
|
if (this.lockedAmount() !== null) {
|
||||||
|
this.amount.set(this.lockedAmount());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.amount.set(value || null);
|
this.amount.set(value || null);
|
||||||
if (value && value > 0) this.error.set('');
|
if (value && value > 0) this.error.set('');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isAmountLocked(): boolean {
|
||||||
|
return this.lockedAmount() !== null;
|
||||||
|
}
|
||||||
|
|
||||||
onNoteChange(value: string): void {
|
onNoteChange(value: string): void {
|
||||||
this.note.set(value);
|
this.note.set(value);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user