Compare commits

..

2 Commits

Author SHA1 Message Date
e218d3aa1e Merge pull request 'fix update project' (#103) from stage-project into test
Reviewed-on: #103
2026-08-19 12:55:39 +03:00
PotapovaA
7e3846d64e fix update project 2026-08-19 12:55:13 +03:00
2 changed files with 45 additions and 16 deletions

View File

@ -4,7 +4,7 @@ import React from 'react';
import { useAuth } from '../../../../app/context/AuthProvider';
import { DangerOutlinedButton, PrimaryButton } from '../../../../components/common/Buttons/Buttons';
import { DEVELOMENT_BLOCK, FUNDING_BY_DECISION } from '../../constants';
import { canEditFirstTableField } from '../../constants/fieldAccess';
import { canEditFirstTableField, isFirstTableFieldDependencySatisfied } from '../../constants/fieldAccess';
const EditModal = ({ open, onClose, rowData, onSave, isSaving = false, orgUnitNames = {} }) => {
const { user } = useAuth();
@ -20,10 +20,21 @@ const EditModal = ({ open, onClose, rowData, onSave, isSaving = false, orgUnitNa
let value = event.target.value;
if (field.valueType === 'boolean') value = value === '' ? null : value === 'true';
if (field.valueType === 'number') value = value === '' ? '' : Number(value);
setFormData({
const nextFormData = {
...formData,
[field.key]: value,
});
};
if (!value && field.key === 'krf_decision_date') {
nextFormData.fk_decision_date = '';
nextFormData.board_decision_date = '';
}
if (!value && field.key === 'fk_decision_date') {
nextFormData.board_decision_date = '';
}
setFormData(nextFormData);
};
const handleSave = async () => {
@ -69,7 +80,10 @@ const EditModal = ({ open, onClose, rowData, onSave, isSaving = false, orgUnitNa
// Компонент для поля ввода
const renderField = (field) => {
const rawValue = formData[field.key];
const isFieldDisabled = field.disabled || !canEditFirstTableField(field.key, user?.role_id);
const isFieldDisabled =
field.disabled ||
!canEditFirstTableField(field.key, user?.role_id) ||
!isFirstTableFieldDependencySatisfied(field.key, formData);
const fieldValue = field.valueType === 'boolean' && rawValue !== null && rawValue !== undefined
? String(rawValue)
: (rawValue ?? '');

View File

@ -1,26 +1,29 @@
import { ROLES_NAME_ID } from '../../../constants/constants';
import { ROLES_NAME_ID } from "../../../constants/constants";
const ADMIN_ROLES = [ROLES_NAME_ID.admin];
const DFIP_ROLES = [ROLES_NAME_ID.admin, ROLES_NAME_ID.executor_dfip];
const RF_ROLES = [ROLES_NAME_ID.admin, ROLES_NAME_ID.executor_rf];
const ALL_ROLES = [
ROLES_NAME_ID.admin,
ROLES_NAME_ID.executor_rf,
ROLES_NAME_ID.executor_dfip,
];
// Матрица доступа к полям первой таблицы.
// Поля «авто» доступны для ручного редактирования только администратору.
export const FIRST_TABLE_FIELD_ACCESS = {
name: ADMIN_ROLES,
org_unit_id: ADMIN_ROLES,
status: DFIP_ROLES,
technical_number: ADMIN_ROLES,
object_address: ADMIN_ROLES,
vsp_format: ADMIN_ROLES,
technical_number: [],
object_address: ALL_ROLES,
vsp_format: ALL_ROLES,
placement_type: ADMIN_ROLES,
staff_count: ADMIN_ROLES,
total_area: ADMIN_ROLES,
project_type: ADMIN_ROLES,
krf_decision_date: RF_ROLES,
fk_decision_date: RF_ROLES,
board_decision_date: RF_ROLES,
open_relocate_close_date: RF_ROLES,
project_type: ALL_ROLES,
krf_decision_date: ALL_ROLES,
fk_decision_date: ALL_ROLES,
board_decision_date: ALL_ROLES,
open_relocate_close_date: ALL_ROLES,
funding_by_ko_decision: DFIP_ROLES,
year: ADMIN_ROLES,
is_in_plan: DFIP_ROLES,
@ -32,4 +35,16 @@ export const FIRST_TABLE_FIELD_ACCESS = {
reserve_to_prrs_kv: DFIP_ROLES,
};
export const canEditFirstTableField = (fieldKey, roleId) => FIRST_TABLE_FIELD_ACCESS[fieldKey]?.includes(roleId) ?? false;
// Поле становится доступным после заполнения предыдущего этапа согласования.
export const FIRST_TABLE_FIELD_DEPENDENCIES = {
fk_decision_date: "krf_decision_date",
board_decision_date: "fk_decision_date",
};
export const canEditFirstTableField = (fieldKey, roleId) =>
FIRST_TABLE_FIELD_ACCESS[fieldKey]?.includes(roleId) ?? false;
export const isFirstTableFieldDependencySatisfied = (fieldKey, rowData) => {
const dependencyKey = FIRST_TABLE_FIELD_DEPENDENCIES[fieldKey];
return !dependencyKey || Boolean(rowData?.[dependencyKey]);
};