diff --git a/ApiCore-Frontend/src/app/(app)/settings/automation/automation-rules-tab.tsx b/ApiCore-Frontend/src/app/(app)/settings/automation/automation-rules-tab.tsx index a5b62cb..34a8602 100644 --- a/ApiCore-Frontend/src/app/(app)/settings/automation/automation-rules-tab.tsx +++ b/ApiCore-Frontend/src/app/(app)/settings/automation/automation-rules-tab.tsx @@ -9,6 +9,7 @@ import { updateAutomationRule, } from "@/lib/automation/api"; import { AutomationRule, AutomationTriggerType } from "@/lib/automation/types"; +import { formatGeneratedNumber } from "@/lib/automation/number-format"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; @@ -130,6 +131,14 @@ function RuleCard({ rule }: { rule: AutomationRule }) {

Aktueller Zähler: {rule.sequenceValue}

+ {rule.active ? ( +

+ Beispiel für die nächste Nummer:{" "} + + {formatGeneratedNumber(format, rule.sequenceValue + 1, new Date())} + +

+ ) : null} ) : (
diff --git a/ApiCore-Frontend/src/lib/automation/number-format.ts b/ApiCore-Frontend/src/lib/automation/number-format.ts new file mode 100644 index 0000000..351da39 --- /dev/null +++ b/ApiCore-Frontend/src/lib/automation/number-format.ts @@ -0,0 +1,20 @@ +// Mirrors ApiCore-Backend/src/automation/number-format.ts exactly, so the +// settings UI can preview a live example number as the admin edits the +// format - no shared package between the two apps to import it from. +// Placeholders: {YYYY} 4-digit year, {YY} 2-digit year, {MM} month (01-12), +// {DD} day (01-31), {SEQ} running sequence unpadded, {SEQ:N} sequence +// zero-padded to N digits. +export function formatGeneratedNumber(format: string, sequence: number, date: Date): string { + const yyyy = String(date.getFullYear()); + const yy = yyyy.slice(-2); + const mm = String(date.getMonth() + 1).padStart(2, "0"); + const dd = String(date.getDate()).padStart(2, "0"); + + return format + .replace(/\{YYYY\}/g, yyyy) + .replace(/\{YY\}/g, yy) + .replace(/\{MM\}/g, mm) + .replace(/\{DD\}/g, dd) + .replace(/\{SEQ:(\d+)\}/g, (_match, width: string) => String(sequence).padStart(Number(width), "0")) + .replace(/\{SEQ\}/g, String(sequence)); +}