2024-06-07 20:17:03 +03:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
import clsx from 'clsx';
|
2024-12-13 21:30:49 +03:00
|
|
|
import { useState } from 'react';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
2024-08-24 12:29:09 +03:00
|
|
|
import Checkbox from '@/components/ui/Checkbox';
|
2024-06-07 20:17:03 +03:00
|
|
|
import Modal, { ModalProps } from '@/components/ui/Modal';
|
|
|
|
import TextArea from '@/components/ui/TextArea';
|
|
|
|
import TextInput from '@/components/ui/TextInput';
|
2024-08-24 12:29:09 +03:00
|
|
|
import { IVersionCreateData, IVersionInfo } from '@/models/library';
|
2024-06-07 20:17:03 +03:00
|
|
|
import { nextVersion } from '@/models/libraryAPI';
|
2024-08-24 12:29:09 +03:00
|
|
|
import { ConstituentaID } from '@/models/rsform';
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
interface DlgCreateVersionProps extends Pick<ModalProps, 'hideWindow'> {
|
|
|
|
versions: IVersionInfo[];
|
2024-08-24 12:29:09 +03:00
|
|
|
onCreate: (data: IVersionCreateData) => void;
|
|
|
|
selected: ConstituentaID[];
|
|
|
|
totalCount: number;
|
2024-06-07 20:17:03 +03:00
|
|
|
}
|
|
|
|
|
2024-08-24 12:29:09 +03:00
|
|
|
function DlgCreateVersion({ hideWindow, versions, selected, totalCount, onCreate }: DlgCreateVersionProps) {
|
2024-06-07 20:17:03 +03:00
|
|
|
const [version, setVersion] = useState(versions.length > 0 ? nextVersion(versions[0].version) : '1.0.0');
|
|
|
|
const [description, setDescription] = useState('');
|
2024-08-24 12:29:09 +03:00
|
|
|
const [onlySelected, setOnlySelected] = useState(false);
|
2024-06-07 20:17:03 +03:00
|
|
|
|
2024-12-13 21:30:49 +03:00
|
|
|
const canSubmit = !versions.find(ver => ver.version === version);
|
2024-06-07 20:17:03 +03:00
|
|
|
|
|
|
|
function handleSubmit() {
|
2024-08-24 12:29:09 +03:00
|
|
|
const data: IVersionCreateData = {
|
2024-06-07 20:17:03 +03:00
|
|
|
version: version,
|
|
|
|
description: description
|
|
|
|
};
|
2024-08-24 12:29:09 +03:00
|
|
|
if (onlySelected) {
|
|
|
|
data.items = selected;
|
|
|
|
}
|
2024-06-07 20:17:03 +03:00
|
|
|
onCreate(data);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Modal
|
|
|
|
header='Создание версии'
|
|
|
|
hideWindow={hideWindow}
|
|
|
|
canSubmit={canSubmit}
|
|
|
|
onSubmit={handleSubmit}
|
|
|
|
submitText='Создать'
|
|
|
|
className={clsx('cc-column', 'w-[30rem]', 'py-2 px-6')}
|
|
|
|
>
|
|
|
|
<TextInput
|
|
|
|
id='dlg_version'
|
|
|
|
dense
|
|
|
|
label='Версия'
|
|
|
|
className='w-[16rem]'
|
|
|
|
value={version}
|
|
|
|
onChange={event => setVersion(event.target.value)}
|
|
|
|
/>
|
|
|
|
<TextArea
|
|
|
|
id='dlg_description'
|
|
|
|
spellCheck
|
|
|
|
label='Описание'
|
|
|
|
rows={3}
|
|
|
|
value={description}
|
|
|
|
onChange={event => setDescription(event.target.value)}
|
|
|
|
/>
|
2024-08-24 12:29:09 +03:00
|
|
|
<Checkbox
|
|
|
|
id='dlg_only_selected'
|
|
|
|
label={`Только выбранные конституенты [${selected.length} из ${totalCount}]`}
|
|
|
|
value={onlySelected}
|
|
|
|
setValue={value => setOnlySelected(value)}
|
|
|
|
/>
|
2024-06-07 20:17:03 +03:00
|
|
|
</Modal>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export default DlgCreateVersion;
|