Fix invoice preview i18n release gate (#255)
Use a statically discoverable invoice-preview translation key while preserving the off-period fallback.
This commit is contained in:
+64
-46
@@ -38,9 +38,8 @@ export const normalizeInvoiceCollectionActionPreview = (
|
||||
): InvoiceCollectionActionPreview => {
|
||||
const preview = value && typeof value === "object" ? (value as Record<string, any>) : {};
|
||||
const summary = preview.summary && typeof preview.summary === "object" ? preview.summary : {};
|
||||
const impact = preview.off_period_impact && typeof preview.off_period_impact === "object"
|
||||
? preview.off_period_impact
|
||||
: {};
|
||||
const impact =
|
||||
preview.off_period_impact && typeof preview.off_period_impact === "object" ? preview.off_period_impact : {};
|
||||
const options = preview.options && typeof preview.options === "object" ? preview.options : {};
|
||||
const changes = [
|
||||
...asArray(preview.changes),
|
||||
@@ -53,26 +52,25 @@ export const normalizeInvoiceCollectionActionPreview = (
|
||||
return {
|
||||
previewId: String(preview.preview_id ?? ""),
|
||||
confirmationPhrase: String(preview.confirmation_phrase ?? ""),
|
||||
collectionCount: finiteNumber(
|
||||
summary.collection_count ?? summary.collections ?? asArray(preview.invoice_collection_ids).length ?? fallbackCollectionCount
|
||||
) || fallbackCollectionCount,
|
||||
collectionCount:
|
||||
finiteNumber(
|
||||
summary.collection_count ??
|
||||
summary.collections ??
|
||||
asArray(preview.invoice_collection_ids).length ??
|
||||
fallbackCollectionCount
|
||||
) || fallbackCollectionCount,
|
||||
changedCount: finiteNumber(summary.changed_count ?? summary.order_items ?? summary.orders_to_move),
|
||||
skippedCount: finiteNumber(summary.skipped_count),
|
||||
targetInvoiceCollectionId: positiveInteger(
|
||||
preview.target_invoice_collection_id
|
||||
?? options.target_invoice_collection_id
|
||||
?? summary.target_invoice_collection_id
|
||||
preview.target_invoice_collection_id ??
|
||||
options.target_invoice_collection_id ??
|
||||
summary.target_invoice_collection_id
|
||||
),
|
||||
offPeriodOrderCount: finiteNumber(
|
||||
impact.order_count
|
||||
?? impact.orders
|
||||
?? summary.off_period_order_count
|
||||
?? asArray(preview.off_period_orders).length
|
||||
impact.order_count ?? impact.orders ?? summary.off_period_order_count ?? asArray(preview.off_period_orders).length
|
||||
),
|
||||
offPeriodTotalNetAmount: finiteNumber(
|
||||
impact.total_net_amount
|
||||
?? impact.amount
|
||||
?? summary.off_period_total_net_amount
|
||||
impact.total_net_amount ?? impact.amount ?? summary.off_period_total_net_amount
|
||||
),
|
||||
blockers: asArray(preview.blockers),
|
||||
changes,
|
||||
@@ -80,11 +78,6 @@ export const normalizeInvoiceCollectionActionPreview = (
|
||||
};
|
||||
};
|
||||
|
||||
const translated = (t: Translate, key: string, params: Record<string, unknown>, fallback: string) => {
|
||||
const value = t(key, params);
|
||||
return value === key ? fallback : value;
|
||||
};
|
||||
|
||||
const concreteChangeLabel = (change: Record<string, any>, t: Translate) => {
|
||||
if (change.message) {
|
||||
return String(change.message);
|
||||
@@ -125,6 +118,18 @@ export const renderInvoiceCollectionActionPreviewHtml = ({
|
||||
t: Translate;
|
||||
formatCurrency?: (value: number) => string;
|
||||
}) => {
|
||||
const translateOffPeriodImpact = () => {
|
||||
const key = "invoicing_period.invoice_collection_actions.preview.off_period_impact";
|
||||
const value = t("invoicing_period.invoice_collection_actions.preview.off_period_impact", {
|
||||
count: preview.offPeriodOrderCount,
|
||||
amount: formatCurrency(preview.offPeriodTotalNetAmount),
|
||||
});
|
||||
return value === key
|
||||
? `${preview.offPeriodOrderCount} orders outside the selected period · ${formatCurrency(
|
||||
preview.offPeriodTotalNetAmount
|
||||
)}`
|
||||
: value;
|
||||
};
|
||||
const lines = [
|
||||
t("invoicing_period.invoice_collection_actions.preview.collections", { count: preview.collectionCount }),
|
||||
t("invoicing_period.invoice_collection_actions.preview.changed", { count: preview.changedCount }),
|
||||
@@ -132,38 +137,51 @@ export const renderInvoiceCollectionActionPreviewHtml = ({
|
||||
? [t("invoicing_period.invoice_collection_actions.preview.skipped", { count: preview.skippedCount })]
|
||||
: []),
|
||||
...(preview.targetInvoiceCollectionId
|
||||
? [t("invoicing_period.invoice_collection_actions.preview.merge_target", { id: preview.targetInvoiceCollectionId })]
|
||||
: []),
|
||||
...(preview.offPeriodOrderCount > 0
|
||||
? [translated(
|
||||
t,
|
||||
"invoicing_period.invoice_collection_actions.preview.off_period_impact",
|
||||
{ count: preview.offPeriodOrderCount, amount: formatCurrency(preview.offPeriodTotalNetAmount) },
|
||||
`${preview.offPeriodOrderCount} orders outside the selected period · ${formatCurrency(preview.offPeriodTotalNetAmount)}`
|
||||
)]
|
||||
? [
|
||||
t("invoicing_period.invoice_collection_actions.preview.merge_target", {
|
||||
id: preview.targetInvoiceCollectionId,
|
||||
}),
|
||||
]
|
||||
: []),
|
||||
...(preview.offPeriodOrderCount > 0 ? [translateOffPeriodImpact()] : []),
|
||||
];
|
||||
const html = [
|
||||
`<p>${escapeInvoiceCollectionPreviewHtml(t(
|
||||
"invoicing_period.invoice_collection_actions.preview.requires_confirmation",
|
||||
{ phrase: preview.confirmationPhrase }
|
||||
))}</p>`,
|
||||
`<ul class="has-text-left">${lines.map((line) => `<li>${escapeInvoiceCollectionPreviewHtml(line)}</li>`).join("")}</ul>`,
|
||||
`<p>${escapeInvoiceCollectionPreviewHtml(
|
||||
t("invoicing_period.invoice_collection_actions.preview.requires_confirmation", {
|
||||
phrase: preview.confirmationPhrase,
|
||||
})
|
||||
)}</p>`,
|
||||
`<ul class="has-text-left">${lines
|
||||
.map((line) => `<li>${escapeInvoiceCollectionPreviewHtml(line)}</li>`)
|
||||
.join("")}</ul>`,
|
||||
];
|
||||
const changes = preview.changes.map((change) => concreteChangeLabel(change, t)).filter(Boolean).slice(0, 10);
|
||||
const changes = preview.changes
|
||||
.map((change) => concreteChangeLabel(change, t))
|
||||
.filter(Boolean)
|
||||
.slice(0, 10);
|
||||
if (changes.length > 0) {
|
||||
html.push(`<hr><p class="has-text-left has-text-weight-bold">${escapeInvoiceCollectionPreviewHtml(
|
||||
t("invoicing_period.invoice_collection_actions.preview.affected_examples")
|
||||
)}</p>`);
|
||||
html.push(`<ul class="has-text-left">${changes.map((line) => `<li>${escapeInvoiceCollectionPreviewHtml(line)}</li>`).join("")}</ul>`);
|
||||
html.push(
|
||||
`<hr><p class="has-text-left has-text-weight-bold">${escapeInvoiceCollectionPreviewHtml(
|
||||
t("invoicing_period.invoice_collection_actions.preview.affected_examples")
|
||||
)}</p>`
|
||||
);
|
||||
html.push(
|
||||
`<ul class="has-text-left">${changes
|
||||
.map((line) => `<li>${escapeInvoiceCollectionPreviewHtml(line)}</li>`)
|
||||
.join("")}</ul>`
|
||||
);
|
||||
}
|
||||
if (preview.blockers.length > 0) {
|
||||
html.push(`<hr><p class="has-text-left has-text-weight-bold has-text-danger">${escapeInvoiceCollectionPreviewHtml(
|
||||
t("invoicing_period.invoice_collection_actions.preview.blockers")
|
||||
)}</p>`);
|
||||
html.push(`<ul class="has-text-left">${preview.blockers.map((blocker) => `<li>${escapeInvoiceCollectionPreviewHtml(
|
||||
blocker.message || blocker.code
|
||||
)}</li>`).join("")}</ul>`);
|
||||
html.push(
|
||||
`<hr><p class="has-text-left has-text-weight-bold has-text-danger">${escapeInvoiceCollectionPreviewHtml(
|
||||
t("invoicing_period.invoice_collection_actions.preview.blockers")
|
||||
)}</p>`
|
||||
);
|
||||
html.push(
|
||||
`<ul class="has-text-left">${preview.blockers
|
||||
.map((blocker) => `<li>${escapeInvoiceCollectionPreviewHtml(blocker.message || blocker.code)}</li>`)
|
||||
.join("")}</ul>`
|
||||
);
|
||||
}
|
||||
return html.join("");
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user