Fix catalog settings SSR form initialization

This commit is contained in:
Ruslan Bakiev
2026-04-09 16:23:13 +07:00
parent 7ed5fbd66d
commit a5fd0a7d5e

View File

@@ -59,6 +59,14 @@ function parseOptionalInteger(value: string) {
return Number(normalized); return Number(normalized);
} }
function formFor(item: CatalogSettingItem) {
forms[item.productType] ??= createForm(item);
savingState[item.productType] ??= false;
successMessage[item.productType] ??= '';
errorMessage[item.productType] ??= '';
return forms[item.productType];
}
watch( watch(
settings, settings,
(items) => { (items) => {
@@ -151,7 +159,7 @@ async function saveProductTypeSetting(productType: string) {
<div class="grid gap-3 md:grid-cols-2"> <div class="grid gap-3 md:grid-cols-2">
<label class="surface-card flex items-start gap-3 rounded-[22px] p-4"> <label class="surface-card flex items-start gap-3 rounded-[22px] p-4">
<input v-model="forms[item.productType].allowCustomLength" type="checkbox" class="toggle toggle-success mt-1"> <input v-model="formFor(item).allowCustomLength" type="checkbox" class="toggle toggle-success mt-1">
<span> <span>
<span class="block font-semibold text-[#123824]">Своя длина</span> <span class="block font-semibold text-[#123824]">Своя длина</span>
<span class="mt-1 block text-sm text-[#557562]">Разрешить длину вне стандартного списка.</span> <span class="mt-1 block text-sm text-[#557562]">Разрешить длину вне стандартного списка.</span>
@@ -159,7 +167,7 @@ async function saveProductTypeSetting(productType: string) {
</label> </label>
<label class="surface-card flex items-start gap-3 rounded-[22px] p-4"> <label class="surface-card flex items-start gap-3 rounded-[22px] p-4">
<input v-model="forms[item.productType].allowCustomSleeveBrand" type="checkbox" class="toggle toggle-success mt-1"> <input v-model="formFor(item).allowCustomSleeveBrand" type="checkbox" class="toggle toggle-success mt-1">
<span> <span>
<span class="block font-semibold text-[#123824]">Своя втулка</span> <span class="block font-semibold text-[#123824]">Своя втулка</span>
<span class="mt-1 block text-sm text-[#557562]">Клиент сможет запросить втулку со своим вариантом.</span> <span class="mt-1 block text-sm text-[#557562]">Клиент сможет запросить втулку со своим вариантом.</span>
@@ -167,7 +175,7 @@ async function saveProductTypeSetting(productType: string) {
</label> </label>
<label class="surface-card flex items-start gap-3 rounded-[22px] p-4"> <label class="surface-card flex items-start gap-3 rounded-[22px] p-4">
<input v-model="forms[item.productType].allowCustomLabel" type="checkbox" class="toggle toggle-success mt-1"> <input v-model="formFor(item).allowCustomLabel" type="checkbox" class="toggle toggle-success mt-1">
<span> <span>
<span class="block font-semibold text-[#123824]">Своя надпись</span> <span class="block font-semibold text-[#123824]">Своя надпись</span>
<span class="mt-1 block text-sm text-[#557562]">Разрешить индивидуальную надпись или маркировку.</span> <span class="mt-1 block text-sm text-[#557562]">Разрешить индивидуальную надпись или маркировку.</span>
@@ -175,7 +183,7 @@ async function saveProductTypeSetting(productType: string) {
</label> </label>
<label class="surface-card flex items-start gap-3 rounded-[22px] p-4"> <label class="surface-card flex items-start gap-3 rounded-[22px] p-4">
<input v-model="forms[item.productType].showQuantityPerBox" type="checkbox" class="toggle toggle-success mt-1"> <input v-model="formFor(item).showQuantityPerBox" type="checkbox" class="toggle toggle-success mt-1">
<span> <span>
<span class="block font-semibold text-[#123824]">Показывать короб</span> <span class="block font-semibold text-[#123824]">Показывать короб</span>
<span class="mt-1 block text-sm text-[#557562]">Если выключено, параметр короба скрывается из клиентского каталога.</span> <span class="mt-1 block text-sm text-[#557562]">Если выключено, параметр короба скрывается из клиентского каталога.</span>
@@ -191,9 +199,9 @@ async function saveProductTypeSetting(productType: string) {
</div> </div>
<span <span
class="rounded-full px-3 py-1 text-xs font-bold uppercase tracking-[0.12em]" class="rounded-full px-3 py-1 text-xs font-bold uppercase tracking-[0.12em]"
:class="forms[item.productType].allowCustomLength ? 'bg-[#e8f5ec] text-[#1c6b45]' : 'bg-[#eef2ef] text-[#6b7f71]'" :class="formFor(item).allowCustomLength ? 'bg-[#e8f5ec] text-[#1c6b45]' : 'bg-[#eef2ef] text-[#6b7f71]'"
> >
{{ forms[item.productType].allowCustomLength ? 'Включено' : 'Выключено' }} {{ formFor(item).allowCustomLength ? 'Включено' : 'Выключено' }}
</span> </span>
</div> </div>
@@ -201,36 +209,36 @@ async function saveProductTypeSetting(productType: string) {
<label class="space-y-2"> <label class="space-y-2">
<span class="text-sm font-semibold text-[#123824]">Мин. длина, м</span> <span class="text-sm font-semibold text-[#123824]">Мин. длина, м</span>
<input <input
v-model="forms[item.productType].customLengthMinM" v-model="formFor(item).customLengthMinM"
type="number" type="number"
min="1" min="1"
step="1" step="1"
class="input manager-field w-full" class="input manager-field w-full"
:disabled="!forms[item.productType].allowCustomLength" :disabled="!formFor(item).allowCustomLength"
> >
</label> </label>
<label class="space-y-2"> <label class="space-y-2">
<span class="text-sm font-semibold text-[#123824]">Макс. длина, м</span> <span class="text-sm font-semibold text-[#123824]">Макс. длина, м</span>
<input <input
v-model="forms[item.productType].customLengthMaxM" v-model="formFor(item).customLengthMaxM"
type="number" type="number"
min="1" min="1"
step="1" step="1"
class="input manager-field w-full" class="input manager-field w-full"
:disabled="!forms[item.productType].allowCustomLength" :disabled="!formFor(item).allowCustomLength"
> >
</label> </label>
<label class="space-y-2"> <label class="space-y-2">
<span class="text-sm font-semibold text-[#123824]">Шаг, м</span> <span class="text-sm font-semibold text-[#123824]">Шаг, м</span>
<input <input
v-model="forms[item.productType].customLengthStepM" v-model="formFor(item).customLengthStepM"
type="number" type="number"
min="1" min="1"
step="1" step="1"
class="input manager-field w-full" class="input manager-field w-full"
:disabled="!forms[item.productType].allowCustomLength" :disabled="!formFor(item).allowCustomLength"
> >
</label> </label>
</div> </div>