ConceptPortal-public/rsconcept/frontend/src/features/oss/dialogs/dlg-delete-operation.tsx
Ivan a69a26bb7b
Some checks are pending
Backend CI / build (3.12) (push) Waiting to run
Backend CI / notify-failure (push) Blocked by required conditions
Frontend CI / build (22.x) (push) Waiting to run
Frontend CI / notify-failure (push) Blocked by required conditions
F: Implementing block UI pt1
2025-04-21 20:37:11 +03:00

84 lines
2.7 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use client';
import { Controller, useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import { HelpTopic } from '@/features/help';
import { Checkbox, TextInput } from '@/components/input';
import { ModalForm } from '@/components/modal';
import { useDialogsStore } from '@/stores/dialogs';
import { type IDeleteOperationDTO, type IOssLayout, schemaDeleteOperation } from '../backend/types';
import { useDeleteOperation } from '../backend/use-delete-operation';
import { type IOperation, type IOperationSchema } from '../models/oss';
export interface DlgDeleteOperationProps {
oss: IOperationSchema;
target: IOperation;
layout: IOssLayout;
}
export function DlgDeleteOperation() {
const { oss, target, layout } = useDialogsStore(state => state.props as DlgDeleteOperationProps);
const { deleteOperation } = useDeleteOperation();
const { handleSubmit, control } = useForm<IDeleteOperationDTO>({
resolver: zodResolver(schemaDeleteOperation),
defaultValues: {
target: target.id,
layout: layout,
keep_constituents: false,
delete_schema: false
}
});
function onSubmit(data: IDeleteOperationDTO) {
return deleteOperation({ itemID: oss.id, data: data });
}
return (
<ModalForm
overflowVisible
header='Удаление операции'
submitText='Подтвердить удаление'
onSubmit={event => void handleSubmit(onSubmit)(event)}
className='w-140 pb-3 px-6 cc-column select-none'
helpTopic={HelpTopic.CC_PROPAGATION}
>
<TextInput disabled dense noBorder id='operation_alias' label='Операция' value={target.alias} />
<Controller
control={control}
name='keep_constituents'
render={({ field }) => (
<Checkbox
label='Сохранить наследованные конституенты'
titleHtml='Наследованные конституенты <br/>превратятся в дописанные'
value={field.value}
onChange={field.onChange}
disabled={target.result === null}
/>
)}
/>
<Controller
control={control}
name='delete_schema'
render={({ field }) => (
<Checkbox
label='Удалить схему'
titleHtml={
!target.is_owned || target.result === null
? 'Привязанную схему нельзя удалить'
: 'Удалить схему вместе с операцией'
}
value={field.value}
onChange={field.onChange}
disabled={!target.is_owned || target.result === null}
/>
)}
/>
</ModalForm>
);
}