ConceptPortal-public/rsconcept/frontend/src/dialogs/DlgCreateVersion.tsx

76 lines
2.2 KiB
TypeScript
Raw Normal View History

'use client';
import clsx from 'clsx';
import { useState } from 'react';
2024-08-24 12:29:38 +03:00
import Checkbox from '@/components/ui/Checkbox';
import Modal from '@/components/ui/Modal';
import TextArea from '@/components/ui/TextArea';
import TextInput from '@/components/ui/TextInput';
2024-08-24 12:29:38 +03:00
import { IVersionCreateData, IVersionInfo } from '@/models/library';
import { nextVersion } from '@/models/libraryAPI';
2024-08-24 12:29:38 +03:00
import { ConstituentaID } from '@/models/rsform';
import { useDialogsStore } from '@/stores/dialogs';
export interface DlgCreateVersionProps {
versions: IVersionInfo[];
2024-08-24 12:29:38 +03:00
onCreate: (data: IVersionCreateData) => void;
selected: ConstituentaID[];
totalCount: number;
}
function DlgCreateVersion() {
const { versions, selected, totalCount, onCreate } = useDialogsStore(state => state.props as DlgCreateVersionProps);
const [version, setVersion] = useState(versions.length > 0 ? nextVersion(versions[0].version) : '1.0.0');
const [description, setDescription] = useState('');
2024-08-24 12:29:38 +03:00
const [onlySelected, setOnlySelected] = useState(false);
const canSubmit = !versions.find(ver => ver.version === version);
function handleSubmit() {
2024-08-24 12:29:38 +03:00
const data: IVersionCreateData = {
version: version,
description: description
};
2024-08-24 12:29:38 +03:00
if (onlySelected) {
data.items = selected;
}
onCreate(data);
}
return (
<Modal
header='Создание версии'
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:38 +03:00
<Checkbox
id='dlg_only_selected'
label={`Только выбранные конституенты [${selected.length} из ${totalCount}]`}
value={onlySelected}
setValue={value => setOnlySelected(value)}
/>
</Modal>
);
}
export default DlgCreateVersion;