2025-02-23 16:53:23 +03:00
|
|
|
import { useAuthSuspense } from '@/features/auth';
|
|
|
|
|
2025-03-12 12:04:23 +03:00
|
|
|
import { Button } from '@/components/control';
|
|
|
|
import { Dropdown, DropdownButton, useDropdown } from '@/components/dropdown';
|
|
|
|
import { IconChild, IconEdit2 } from '@/components/icons';
|
2025-02-26 12:54:51 +03:00
|
|
|
import { useDialogsStore } from '@/stores/dialogs';
|
2025-02-23 16:53:23 +03:00
|
|
|
|
2025-03-12 11:54:32 +03:00
|
|
|
import { useMutatingOss } from '../../backend/use-mutating-oss';
|
2025-02-23 16:53:23 +03:00
|
|
|
|
2025-03-12 11:54:32 +03:00
|
|
|
import { useOssEdit } from './oss-edit-context';
|
2025-02-23 16:53:23 +03:00
|
|
|
|
|
|
|
export function MenuEditOss() {
|
|
|
|
const { isAnonymous } = useAuthSuspense();
|
|
|
|
const editMenu = useDropdown();
|
2025-02-26 12:54:51 +03:00
|
|
|
const { schema, isMutable } = useOssEdit();
|
2025-02-23 16:53:23 +03:00
|
|
|
const isProcessing = useMutatingOss();
|
|
|
|
|
2025-02-26 12:54:51 +03:00
|
|
|
const showRelocateConstituents = useDialogsStore(state => state.showRelocateConstituents);
|
|
|
|
|
2025-02-23 16:53:23 +03:00
|
|
|
function handleRelocate() {
|
|
|
|
editMenu.hide();
|
2025-02-26 12:54:51 +03:00
|
|
|
showRelocateConstituents({
|
|
|
|
oss: schema,
|
|
|
|
initialTarget: undefined,
|
|
|
|
positions: []
|
|
|
|
});
|
2025-02-23 16:53:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (isAnonymous) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
2025-03-07 02:45:37 +03:00
|
|
|
<div ref={editMenu.ref} className='relative'>
|
2025-02-23 16:53:23 +03:00
|
|
|
<Button
|
|
|
|
dense
|
|
|
|
noBorder
|
|
|
|
noOutline
|
|
|
|
tabIndex={-1}
|
|
|
|
title='Редактирование'
|
|
|
|
hideTitle={editMenu.isOpen}
|
|
|
|
className='h-full px-2'
|
|
|
|
icon={<IconEdit2 size='1.25rem' className={isMutable ? 'icon-green' : 'icon-red'} />}
|
|
|
|
onClick={editMenu.toggle}
|
|
|
|
/>
|
2025-03-07 02:45:37 +03:00
|
|
|
<Dropdown isOpen={editMenu.isOpen} margin='mt-3'>
|
2025-02-23 16:53:23 +03:00
|
|
|
<DropdownButton
|
|
|
|
text='Конституенты'
|
|
|
|
titleHtml='Перенос конституент</br>между схемами'
|
|
|
|
icon={<IconChild size='1rem' className='icon-green' />}
|
|
|
|
disabled={isProcessing}
|
|
|
|
onClick={handleRelocate}
|
|
|
|
/>
|
|
|
|
</Dropdown>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|