diff --git a/src/views/settings/SettingsView.vue b/src/views/settings/SettingsView.vue index 505e001..18d3852 100644 --- a/src/views/settings/SettingsView.vue +++ b/src/views/settings/SettingsView.vue @@ -320,6 +320,9 @@ const getSlotDefaultName = (templateKey, slotKey) => { return found?.defaultName || ''; }; +let varIdCounter = 0; +const nextVarId = () => `var_${++varIdCounter}_${Date.now()}`; + const lockedAtLabel = computed(() => { if (!lockedAt.value) return ''; const date = new Date(lockedAt.value); @@ -332,9 +335,7 @@ const onSlotChange = (templateKey, vIdx) => { if (!form || !form.variables[vIdx]) return; const currentVar = form.variables[vIdx]; const defaultName = getSlotDefaultName(templateKey, currentVar.slot); - if (!currentVar.name || currentVar.name === 'param') { - currentVar.name = defaultName; - } + currentVar.name = defaultName; }; const addVariable = (templateKey) => { @@ -347,7 +348,7 @@ const addVariable = (templateKey) => { const selectedSlot = unusedSlot || availableSlots[0] || { slot: 'amount', defaultName: 'PAYMENT_PRICE' }; form.variables.push({ - id: `var_${Date.now()}_${Math.random().toString(36).substring(2, 7)}`, + id: nextVarId(), slot: selectedSlot.slot, name: selectedSlot.defaultName || '' }); @@ -449,13 +450,13 @@ const emptyFormEntry = (template) => { let vars = []; if (Array.isArray(template?.variables) && template.variables.length > 0) { vars = template.variables.map((variable) => ({ - id: `var_${Date.now()}_${Math.random().toString(36).substring(2, 7)}`, + id: nextVarId(), slot: variable.slot || slots[0]?.slot || 'amount', name: variable.name || getSlotDefaultName(template?.key, variable.slot) || '' })); } else if (!template?.variables) { vars = slots.map((s) => ({ - id: `var_${Date.now()}_${Math.random().toString(36).substring(2, 7)}`, + id: nextVarId(), slot: s.slot, name: s.defaultName })); @@ -499,11 +500,15 @@ const saveSmsTemplates = async () => { smsTemplatesPayload[template.key] = { templateId: String(entry.templateId || '').trim(), variables: (entry.variables || []) - .filter((v) => v.slot && String(v.name || '').trim()) - .map((v) => ({ - slot: v.slot, - name: String(v.name).trim().replace(/^#+|#+$/g, '') - })) + .filter((v) => v && v.slot) + .map((v) => { + const raw = String(v.name || '').trim().replace(/^#+|#+$/g, ''); + const fallback = getSlotDefaultName(template.key, v.slot) || v.slot; + return { + slot: v.slot, + name: raw || fallback + }; + }) }; }); const response = await settingsApi.save({ smsTemplates: smsTemplatesPayload });