From d6f1a03501086030f25f3be43f49b06f357c93c2 Mon Sep 17 00:00:00 2001 From: Ruslan Bakiev <572431+veikab@users.noreply.github.com> Date: Thu, 9 Apr 2026 16:36:43 +0700 Subject: [PATCH] Simplify catalog settings layout --- app/pages/catalog-settings.vue | 175 ++++++++++++--------------------- 1 file changed, 64 insertions(+), 111 deletions(-) diff --git a/app/pages/catalog-settings.vue b/app/pages/catalog-settings.vue index bd77720..3ec7fe4 100644 --- a/app/pages/catalog-settings.vue +++ b/app/pages/catalog-settings.vue @@ -27,9 +27,9 @@ const settingsQuery = useQuery(CatalogProductTypeSettingsDocument); const saveSettingMutation = useMutation(UpsertCatalogProductTypeSettingDocument, { throws: 'never' }); const forms = reactive>({}); -const savingState = reactive>({}); -const successMessage = reactive>({}); -const errorMessage = reactive>({}); +const isSavingAll = ref(false); +const saveSuccess = ref(''); +const saveError = ref(''); const settings = computed(() => settingsQuery.result.value?.catalogProductTypeSettings ?? []); @@ -61,9 +61,6 @@ function parseOptionalInteger(value: string) { function formFor(item: CatalogSettingItem) { forms[item.productType] ??= createForm(item); - savingState[item.productType] ??= false; - successMessage[item.productType] ??= ''; - errorMessage[item.productType] ??= ''; return forms[item.productType]; } @@ -75,65 +72,53 @@ watch( for (const productType of Object.keys(forms)) { if (!activeTypes.has(productType)) { Reflect.deleteProperty(forms, productType); - Reflect.deleteProperty(savingState, productType); - Reflect.deleteProperty(successMessage, productType); - Reflect.deleteProperty(errorMessage, productType); } } for (const item of items) { forms[item.productType] = createForm(item); - savingState[item.productType] ??= false; - successMessage[item.productType] ??= ''; - errorMessage[item.productType] ??= ''; } }, { immediate: true }, ); -async function saveProductTypeSetting(productType: string) { - const form = forms[productType]; - if (!form) { - return; +async function saveAllSettings() { + saveSuccess.value = ''; + saveError.value = ''; + isSavingAll.value = true; + + for (const item of settings.value) { + const form = formFor(item); + const result = await saveSettingMutation.mutate({ + input: { + productType: form.productType, + showQuantityPerBox: form.showQuantityPerBox, + allowCustomLength: form.allowCustomLength, + customLengthMinM: form.allowCustomLength ? parseOptionalInteger(form.customLengthMinM) : null, + customLengthMaxM: form.allowCustomLength ? parseOptionalInteger(form.customLengthMaxM) : null, + customLengthStepM: form.allowCustomLength ? parseOptionalInteger(form.customLengthStepM) : null, + allowCustomSleeveBrand: form.allowCustomSleeveBrand, + allowCustomLabel: form.allowCustomLabel, + }, + }); + + if (!result?.data?.upsertCatalogProductTypeSetting) { + saveError.value = saveSettingMutation.error.value?.message || `Не удалось сохранить настройки для "${form.productType}".`; + isSavingAll.value = false; + return; + } + + forms[item.productType] = createForm(result.data.upsertCatalogProductTypeSetting); } - successMessage[productType] = ''; - errorMessage[productType] = ''; - savingState[productType] = true; - - const result = await saveSettingMutation.mutate({ - input: { - productType: form.productType, - showQuantityPerBox: form.showQuantityPerBox, - allowCustomLength: form.allowCustomLength, - customLengthMinM: form.allowCustomLength ? parseOptionalInteger(form.customLengthMinM) : null, - customLengthMaxM: form.allowCustomLength ? parseOptionalInteger(form.customLengthMaxM) : null, - customLengthStepM: form.allowCustomLength ? parseOptionalInteger(form.customLengthStepM) : null, - allowCustomSleeveBrand: form.allowCustomSleeveBrand, - allowCustomLabel: form.allowCustomLabel, - }, - }); - - savingState[productType] = false; - - if (!result?.data?.upsertCatalogProductTypeSetting) { - errorMessage[productType] = saveSettingMutation.error.value?.message || 'Не удалось сохранить настройки.'; - return; - } - - forms[productType] = createForm(result.data.upsertCatalogProductTypeSetting); - successMessage[productType] = 'Настройки сохранены.'; + isSavingAll.value = false; + saveSuccess.value = 'Настройки сохранены.'; }