meta data za SMS
This commit is contained in:
@@ -250,6 +250,41 @@ const formatEu = (value, decimals = 2) => {
|
||||
}).format(isNaN(num) ? 0 : num);
|
||||
};
|
||||
|
||||
// Flatten meta structure on the client side (mirrors backend logic)
|
||||
const flattenMeta = (meta, prefix = "") => {
|
||||
if (!meta || typeof meta !== "object") return {};
|
||||
const result = {};
|
||||
for (const [key, value] of Object.entries(meta)) {
|
||||
const newKey = prefix === "" ? key : `${prefix}.${key}`;
|
||||
if (value && typeof value === "object") {
|
||||
// Check if it's a structured meta entry with 'value' field
|
||||
if ("value" in value) {
|
||||
result[newKey] = value.value;
|
||||
// If parent key is numeric, also create direct alias
|
||||
if (prefix !== "" && /^\d+$/.test(key)) {
|
||||
result[key] = value.value;
|
||||
}
|
||||
} else {
|
||||
// Recursively flatten nested objects
|
||||
const nested = flattenMeta(value, newKey);
|
||||
Object.assign(result, nested);
|
||||
// If current key is numeric, also flatten without it
|
||||
if (/^\d+$/.test(key)) {
|
||||
const directNested = flattenMeta(value, prefix);
|
||||
for (const [dk, dv] of Object.entries(directNested)) {
|
||||
if (!(dk in result)) {
|
||||
result[dk] = dv;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
result[newKey] = value;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
const renderTokens = (text, vars) => {
|
||||
if (!text) return "";
|
||||
const resolver = (obj, path) => {
|
||||
@@ -355,6 +390,7 @@ const buildVarsFromSelectedContract = () => {
|
||||
if (!uuid) return {};
|
||||
const c = (contractsForCase.value || []).find((x) => x.uuid === uuid);
|
||||
if (!c) return {};
|
||||
|
||||
const vars = {
|
||||
contract: {
|
||||
uuid: c.uuid,
|
||||
@@ -363,6 +399,15 @@ const buildVarsFromSelectedContract = () => {
|
||||
end_date: c.end_date || "",
|
||||
},
|
||||
};
|
||||
// Include contract.meta - flatten if needed (in case server returns nested structure)
|
||||
if (c.meta && typeof c.meta === "object") {
|
||||
// Check if already flattened (no nested objects with 'value' property)
|
||||
const hasStructuredMeta = Object.values(c.meta).some(
|
||||
(v) => v && typeof v === "object" && "value" in v
|
||||
);
|
||||
vars.contract.meta = hasStructuredMeta ? flattenMeta(c.meta) : c.meta;
|
||||
}
|
||||
|
||||
if (c.account) {
|
||||
vars.account = {
|
||||
reference: c.account.reference,
|
||||
|
||||
Reference in New Issue
Block a user