fix атрибутов создания шаблона

This commit is contained in:
2025-07-27 08:25:21 +03:00
parent 4752b2dedc
commit de5b60907b
3 changed files with 57 additions and 19 deletions

View File

@@ -118,7 +118,7 @@ interface TemplateFormProps {
attributeValues: AttributeValue[]
onAttributeValuesChange: (values: AttributeValue[]) => void
attributesLoading: boolean
onSubmit: () => void
onSubmit: () => void | Promise<void>
onCancel: () => void
submitText: string
submitIcon: React.ReactNode
@@ -229,7 +229,14 @@ const TemplateForm: React.FC<TemplateFormProps> = ({
<Button variant="outline">Отмена</Button>
</DialogClose>
<Button
onClick={onSubmit}
onClick={() => {
const result = onSubmit()
if (result instanceof Promise) {
result.catch(error => {
console.error('Ошибка при выполнении операции:', error)
})
}
}}
disabled={isSubmitDisabled}
className="min-w-[130px]"
>
@@ -319,18 +326,27 @@ export const TemplatesOverviewPage = () => {
setSelectionMode(false)
}
const handleCreate = () => {
const handleCreate = async () => {
if (newName.trim()) {
addTemplate({
name: newName,
elements: [],
description: newDescription,
mergedCells: [],
})
setNewName('')
setNewDescription('')
setNewAttributeValues([])
setIsDialogOpen(false)
try {
// Создаем шаблон с атрибутами сразу
await addTemplate(
{
name: newName,
elements: [],
description: newDescription,
mergedCells: [],
},
newAttributeValues.length > 0 ? newAttributeValues : undefined
)
setNewName('')
setNewDescription('')
setNewAttributeValues([])
setIsDialogOpen(false)
} catch (error) {
console.error('Ошибка при создании шаблона:', error)
}
}
}