Add installment calculator and Latin digits in English product text.
Wire the product CTA to store-loan-methods calculate so shoppers can pick a term and see the plan, and render English model runs under Montserrat so fanum fonts stop painting 0-9 as Persian digits. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
co-authored by
Cursor
parent
7b8b5fd723
commit
e625354dc9
@@ -0,0 +1,53 @@
|
||||
import { API_BASE, SITE_DOMAIN } from "./config";
|
||||
import type { StoreLoanCalculateResponse, StoreLoanMethodsResponse } from "./types";
|
||||
|
||||
const base = `${API_BASE}/tenants/${SITE_DOMAIN}/store-loan-methods`;
|
||||
|
||||
/** Browser-side list — same contract as GET .../store-loan-methods. */
|
||||
export async function fetchStoreLoanMethods(
|
||||
signal?: AbortSignal,
|
||||
): Promise<StoreLoanMethodsResponse> {
|
||||
const res = await fetch(base, { signal });
|
||||
if (!res.ok) throw new Error(`loan methods failed (${res.status})`);
|
||||
return res.json() as Promise<StoreLoanMethodsResponse>;
|
||||
}
|
||||
|
||||
/** Browser-side calculate — POST .../store-loan-methods/calculate. */
|
||||
export async function fetchStoreLoanPlan(
|
||||
input: {
|
||||
methodId: string;
|
||||
totalValue: number;
|
||||
creditAmount: number;
|
||||
months: number;
|
||||
},
|
||||
signal?: AbortSignal,
|
||||
): Promise<StoreLoanCalculateResponse> {
|
||||
const res = await fetch(`${base}/calculate`, {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify(input),
|
||||
signal,
|
||||
});
|
||||
if (!res.ok) {
|
||||
let message = `calculate failed (${res.status})`;
|
||||
try {
|
||||
const body = (await res.json()) as { message?: string };
|
||||
if (body.message) message = body.message;
|
||||
} catch {
|
||||
/* ignore */
|
||||
}
|
||||
throw new Error(message);
|
||||
}
|
||||
return res.json() as Promise<StoreLoanCalculateResponse>;
|
||||
}
|
||||
|
||||
export function clampCreditAmount(
|
||||
value: number,
|
||||
totalValue: number,
|
||||
minAmount: number,
|
||||
maxAmount: number,
|
||||
): number {
|
||||
const upper = Math.min(Math.round(maxAmount), Math.round(totalValue));
|
||||
const lower = Math.min(Math.round(minAmount), upper);
|
||||
return Math.min(upper, Math.max(lower, Math.round(value)));
|
||||
}
|
||||
Reference in New Issue
Block a user