2025-04-21 20:37:11 +03:00
|
|
|
'use client';
|
|
|
|
|
|
2025-04-29 21:41:21 +03:00
|
|
|
import { Controller, useFormContext, useWatch } from 'react-hook-form';
|
2025-04-21 20:37:11 +03:00
|
|
|
|
|
|
|
|
import { TextArea, TextInput } from '@/components/input';
|
|
|
|
|
import { useDialogsStore } from '@/stores/dialogs';
|
|
|
|
|
|
|
|
|
|
import { type ICreateBlockDTO } from '../../backend/types';
|
2025-04-22 13:59:14 +03:00
|
|
|
import { SelectParent } from '../../components/select-parent';
|
2025-04-21 20:37:11 +03:00
|
|
|
|
|
|
|
|
import { type DlgCreateBlockProps } from './dlg-create-block';
|
|
|
|
|
|
|
|
|
|
export function TabBlockCard() {
|
2025-04-28 13:59:38 +03:00
|
|
|
const { manager } = useDialogsStore(state => state.props as DlgCreateBlockProps);
|
2025-04-21 20:37:11 +03:00
|
|
|
const {
|
|
|
|
|
register,
|
|
|
|
|
control,
|
|
|
|
|
formState: { errors }
|
|
|
|
|
} = useFormContext<ICreateBlockDTO>();
|
2025-04-29 21:41:21 +03:00
|
|
|
const children_blocks = useWatch({ control, name: 'children_blocks' });
|
|
|
|
|
const all_children = [
|
|
|
|
|
...children_blocks,
|
|
|
|
|
...manager.oss.hierarchy.expandAllOutputs(children_blocks.filter(id => id < 0).map(id => -id)).map(id => -id)
|
|
|
|
|
];
|
2025-04-21 20:37:11 +03:00
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className='cc-fade-in cc-column'>
|
|
|
|
|
<TextInput
|
|
|
|
|
id='operation_title' //
|
|
|
|
|
label='Название'
|
|
|
|
|
{...register('item_data.title')}
|
|
|
|
|
error={errors.item_data?.title}
|
|
|
|
|
/>
|
|
|
|
|
<Controller
|
|
|
|
|
name='item_data.parent'
|
|
|
|
|
control={control}
|
|
|
|
|
render={({ field }) => (
|
2025-04-22 13:59:14 +03:00
|
|
|
<SelectParent
|
2025-04-29 21:41:21 +03:00
|
|
|
items={manager.oss.blocks.filter(block => !all_children.includes(block.id))}
|
2025-04-28 13:59:38 +03:00
|
|
|
value={field.value ? manager.oss.blockByID.get(field.value) ?? null : null}
|
2025-04-21 20:37:11 +03:00
|
|
|
placeholder='Блок содержания не выбран'
|
|
|
|
|
onChange={value => field.onChange(value ? value.id : null)}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
<TextArea
|
|
|
|
|
id='operation_comment' //
|
|
|
|
|
label='Описание'
|
|
|
|
|
noResize
|
2025-04-22 13:59:14 +03:00
|
|
|
rows={5}
|
2025-04-21 20:37:11 +03:00
|
|
|
{...register('item_data.description')}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|