AURORA-1671: добавленна отображения ошибки crm_id_exists напрямую в форму
This commit is contained in:
parent
633c4d3fed
commit
daec128fc3
@ -1,7 +1,6 @@
|
|||||||
import { PlusOutlined } from '@ant-design/icons';
|
import { PlusOutlined } from '@ant-design/icons';
|
||||||
import { Button, Space } from 'antd';
|
import { Button, Space } from 'antd';
|
||||||
import { useEffect, useState } from 'react';
|
import { useEffect, useState } from 'react';
|
||||||
import { ApiError } from '../api/client';
|
|
||||||
import PageTitle from '../components/PageTitle';
|
import PageTitle from '../components/PageTitle';
|
||||||
import { createCatalogueJur } from '../services/api/directories/catalogue_jur';
|
import { createCatalogueJur } from '../services/api/directories/catalogue_jur';
|
||||||
import { createCompanyGroup, fetchRelatedGroups } from '../services/api/directories/company_groups';
|
import { createCompanyGroup, fetchRelatedGroups } from '../services/api/directories/company_groups';
|
||||||
@ -13,7 +12,6 @@ import type { RelatedGroupOut } from '../types/api';
|
|||||||
import type { CatalogueJurFormProps } from '../types/catalogueJur/catalogueJur';
|
import type { CatalogueJurFormProps } from '../types/catalogueJur/catalogueJur';
|
||||||
import type { CreateCompanyGroupProps } from '../types/companyGroups/companyGroups';
|
import type { CreateCompanyGroupProps } from '../types/companyGroups/companyGroups';
|
||||||
import type { CreateEntityKind, RelatedGroupFormType } from '../types/relatedGroup/relatedGroup';
|
import type { CreateEntityKind, RelatedGroupFormType } from '../types/relatedGroup/relatedGroup';
|
||||||
import { useNotificationApi } from '../utils/useNotification';
|
|
||||||
import { CataloguGroupTabs, type CatalogueGroupTabKey } from '../widgets/CataloguGroupTabs/CataloguGroupTabs';
|
import { CataloguGroupTabs, type CatalogueGroupTabKey } from '../widgets/CataloguGroupTabs/CataloguGroupTabs';
|
||||||
import { CompanyGroupHeader } from '../widgets/CatalogueGroupHeader/CatalogueGroupHeader';
|
import { CompanyGroupHeader } from '../widgets/CatalogueGroupHeader/CatalogueGroupHeader';
|
||||||
import { CatalogueJurForm } from '../widgets/CatalogueJurForm/CatalogueJurForm';
|
import { CatalogueJurForm } from '../widgets/CatalogueJurForm/CatalogueJurForm';
|
||||||
@ -26,7 +24,6 @@ import { RelatedGroupTable } from '../widgets/RelatedGroupTable/RelatedGroupTabl
|
|||||||
|
|
||||||
export function CatalogueGroup() {
|
export function CatalogueGroup() {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const notification = useNotificationApi();
|
|
||||||
|
|
||||||
const isGettingArchive = useAppSelector((state) => state.catalogue_jur.isGettingArchive);
|
const isGettingArchive = useAppSelector((state) => state.catalogue_jur.isGettingArchive);
|
||||||
|
|
||||||
@ -53,55 +50,30 @@ export function CatalogueGroup() {
|
|||||||
}
|
}
|
||||||
async function createRelatedGroupHandler(values: RelatedGroupFormType) {
|
async function createRelatedGroupHandler(values: RelatedGroupFormType) {
|
||||||
if (values.company_group_id) {
|
if (values.company_group_id) {
|
||||||
try {
|
await createRelatedGroup(values.company_group_id, {
|
||||||
await createRelatedGroup(values.company_group_id, {
|
...values,
|
||||||
...values,
|
company_group_id: undefined,
|
||||||
company_group_id: undefined,
|
});
|
||||||
});
|
getRelatedGroupsHandler();
|
||||||
getRelatedGroupsHandler();
|
setKindForm(null);
|
||||||
setKindForm(null);
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof ApiError) {
|
|
||||||
notification.error({
|
|
||||||
description: e.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async function createCompanyGroupHandler(values: CreateCompanyGroupProps) {
|
async function createCompanyGroupHandler(values: CreateCompanyGroupProps) {
|
||||||
try {
|
await createCompanyGroup(values);
|
||||||
await createCompanyGroup(values);
|
dispatch(getCompanyGroupsThunk());
|
||||||
dispatch(getCompanyGroupsThunk());
|
getRelatedGroupsHandler();
|
||||||
getRelatedGroupsHandler();
|
setKindForm(null);
|
||||||
setKindForm(null);
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof ApiError) {
|
|
||||||
notification.error({
|
|
||||||
description: e.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getRelatedGroupsHandler() {
|
async function getRelatedGroupsHandler() {
|
||||||
if (activeCompanyGroup?.id) {
|
if (activeCompanyGroup?.id) {
|
||||||
setRelatedGroupLoading(true);
|
setRelatedGroupLoading(true);
|
||||||
try {
|
const res = await fetchRelatedGroups(activeCompanyGroup?.id);
|
||||||
const res = await fetchRelatedGroups(activeCompanyGroup?.id);
|
const gsks = res.filter((elem) => elem.kind === 'gsk');
|
||||||
const gsks = res.filter((elem) => elem.kind === 'gsk');
|
const gszs = res.filter((elem) => elem.kind === 'gsz');
|
||||||
const gszs = res.filter((elem) => elem.kind === 'gsz');
|
setGskData(gsks);
|
||||||
setGskData(gsks);
|
setGszData(gszs);
|
||||||
setGszData(gszs);
|
setRelatedGroupLoading(false);
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof ApiError) {
|
|
||||||
notification.error({
|
|
||||||
description: e.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
setRelatedGroupLoading(false);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -197,9 +169,7 @@ export function CatalogueGroup() {
|
|||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
setKindForm(null);
|
setKindForm(null);
|
||||||
}}
|
}}
|
||||||
onOk={async (values) => {
|
onOk={createRelatedGroupHandler}
|
||||||
await createRelatedGroupHandler(values);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{kindForm === 'gk' && (
|
{kindForm === 'gk' && (
|
||||||
@ -208,9 +178,7 @@ export function CatalogueGroup() {
|
|||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
setKindForm(null);
|
setKindForm(null);
|
||||||
}}
|
}}
|
||||||
onOk={async (values) => {
|
onOk={createCompanyGroupHandler}
|
||||||
await createCompanyGroupHandler(values);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,41 +1,30 @@
|
|||||||
import { PlusOutlined } from '@ant-design/icons';
|
import { PlusOutlined } from '@ant-design/icons';
|
||||||
import { Button, Space } from 'antd';
|
import { Button, Space } from 'antd';
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { ApiError } from '../api/client';
|
|
||||||
import PageTitle from '../components/PageTitle';
|
import PageTitle from '../components/PageTitle';
|
||||||
import { createCatalogueJur } from '../services/api/directories/catalogue_jur';
|
import { createCatalogueJur } from '../services/api/directories/catalogue_jur';
|
||||||
import { getCatalogueJurThunk } from '../store/slices/catalogueJurSlice/thunks';
|
import { getCatalogueJurThunk } from '../store/slices/catalogueJurSlice/thunks';
|
||||||
import { useAppDispatch, useAppSelector } from '../store/store';
|
import { useAppDispatch, useAppSelector } from '../store/store';
|
||||||
import type { CatalogueJurFormProps } from '../types/catalogueJur/catalogueJur';
|
import type { CatalogueJurFormProps } from '../types/catalogueJur/catalogueJur';
|
||||||
import { useNotificationApi } from '../utils/useNotification';
|
|
||||||
import { CatalogueJurForm } from '../widgets/CatalogueJurForm/CatalogueJurForm';
|
import { CatalogueJurForm } from '../widgets/CatalogueJurForm/CatalogueJurForm';
|
||||||
import { CatalogueJurTable } from '../widgets/CatalogueJurTable/CatalogueJurTable';
|
import { CatalogueJurTable } from '../widgets/CatalogueJurTable/CatalogueJurTable';
|
||||||
|
|
||||||
export function CatalogueJur() {
|
export function CatalogueJur() {
|
||||||
const dispatch = useAppDispatch();
|
const dispatch = useAppDispatch();
|
||||||
const notification = useNotificationApi();
|
|
||||||
|
|
||||||
const isGettingArchive = useAppSelector((state) => state.catalogue_jur.isGettingArchive);
|
const isGettingArchive = useAppSelector((state) => state.catalogue_jur.isGettingArchive);
|
||||||
|
|
||||||
const [createFormOpen, setCreateFormOpen] = useState(false);
|
const [createFormOpen, setCreateFormOpen] = useState(false);
|
||||||
const outside_group = true;
|
const outside_group = true;
|
||||||
async function createJurHandler(values: CatalogueJurFormProps) {
|
async function createJurHandler(values: CatalogueJurFormProps) {
|
||||||
try {
|
await createCatalogueJur(values);
|
||||||
await createCatalogueJur(values);
|
dispatch(
|
||||||
dispatch(
|
getCatalogueJurThunk({
|
||||||
getCatalogueJurThunk({
|
closed: isGettingArchive,
|
||||||
closed: isGettingArchive,
|
outside_group: outside_group,
|
||||||
outside_group: outside_group,
|
}),
|
||||||
}),
|
);
|
||||||
);
|
setCreateFormOpen(false);
|
||||||
setCreateFormOpen(false);
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof ApiError) {
|
|
||||||
notification.error({
|
|
||||||
description: e.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -59,9 +48,7 @@ export function CatalogueJur() {
|
|||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
setCreateFormOpen(false);
|
setCreateFormOpen(false);
|
||||||
}}
|
}}
|
||||||
onOk={async (values) => {
|
onOk={createJurHandler}
|
||||||
await createJurHandler(values);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -124,6 +124,14 @@ export const CatalogueJurForm: React.FC<Props> = ({ open, onCancel, onOk, jurId
|
|||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
if (e.code === 'CRM_ID_EXISTS') {
|
||||||
|
form.setFields([
|
||||||
|
{
|
||||||
|
name: 'crm_id',
|
||||||
|
errors: [e.message],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
notification.error({ description: e.message });
|
notification.error({ description: e.message });
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@ -122,21 +122,13 @@ export function CatalogueJurTable({ outside_group, tabsComponent }: CatalogueJur
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function editJurHandler(values: CatalogueJurFormProps) {
|
async function editJurHandler(values: CatalogueJurFormProps) {
|
||||||
try {
|
await editCatalogueJur(jurId, values);
|
||||||
await editCatalogueJur(jurId, values);
|
getCatalogueJur();
|
||||||
getCatalogueJur();
|
closeEditCatalogueJurHandler();
|
||||||
closeEditCatalogueJurHandler();
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof ApiError) {
|
|
||||||
notification.error({
|
|
||||||
description: e.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getCatalogueJur();
|
getCatalogueJur();
|
||||||
}, [isGettingArchive, activeCompanyGroup, outside_group]);
|
}, [isGettingArchive, activeCompanyGroup, outside_group]);
|
||||||
|
|
||||||
const extraColumns: ColumnsType<ICatalogueJur> = useMemo(
|
const extraColumns: ColumnsType<ICatalogueJur> = useMemo(
|
||||||
@ -327,9 +319,7 @@ export function CatalogueJurTable({ outside_group, tabsComponent }: CatalogueJur
|
|||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
closeEditCatalogueJurHandler();
|
closeEditCatalogueJurHandler();
|
||||||
}}
|
}}
|
||||||
onOk={async (values) => {
|
onOk={editJurHandler}
|
||||||
await editJurHandler(values);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -49,6 +49,14 @@ export const CompanyGroupForm: React.FC<Props> = ({ open, onCancel, onOk }) => {
|
|||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof ApiError) {
|
if (e instanceof ApiError) {
|
||||||
|
if (e.code === 'CRM_ID_EXISTS') {
|
||||||
|
form.setFields([
|
||||||
|
{
|
||||||
|
name: 'crm_id',
|
||||||
|
errors: [e.message],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
notification.error({
|
notification.error({
|
||||||
description: e.message,
|
description: e.message,
|
||||||
});
|
});
|
||||||
|
|||||||
@ -59,7 +59,7 @@ export const RelatedGroupForm: React.FC<Props> = ({ open, onCancel, onOk, relate
|
|||||||
try {
|
try {
|
||||||
const { created_date, name, crm_id, company_group_id } = await form.validateFields();
|
const { created_date, name, crm_id, company_group_id } = await form.validateFields();
|
||||||
await onOk({
|
await onOk({
|
||||||
created_date: created_date ?? (relatedGroupId ? null : dayjs().format('YYYY-MM-DD') ),
|
created_date: created_date ?? (relatedGroupId ? null : dayjs().format('YYYY-MM-DD')),
|
||||||
name,
|
name,
|
||||||
crm_id,
|
crm_id,
|
||||||
company_group_id: relatedGroupId ? undefined : company_group_id,
|
company_group_id: relatedGroupId ? undefined : company_group_id,
|
||||||
@ -67,6 +67,14 @@ export const RelatedGroupForm: React.FC<Props> = ({ open, onCancel, onOk, relate
|
|||||||
});
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (e instanceof ApiError) {
|
if (e instanceof ApiError) {
|
||||||
|
if (e.code === 'CRM_ID_EXISTS') {
|
||||||
|
form.setFields([
|
||||||
|
{
|
||||||
|
name: 'crm_id',
|
||||||
|
errors: [e.message],
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
}
|
||||||
notification.error({
|
notification.error({
|
||||||
description: e.message,
|
description: e.message,
|
||||||
});
|
});
|
||||||
@ -101,8 +109,8 @@ export const RelatedGroupForm: React.FC<Props> = ({ open, onCancel, onOk, relate
|
|||||||
loading={initialDataLoading}
|
loading={initialDataLoading}
|
||||||
confirmLoading={confirmLoading}>
|
confirmLoading={confirmLoading}>
|
||||||
<Form form={form} layout='vertical'>
|
<Form form={form} layout='vertical'>
|
||||||
<FormItem name='crm_id' label='ID в CRM'>
|
<FormItem name='crm_id' label='ID в CRM' >
|
||||||
<Input />
|
<Input />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
<FormItem name='name' label='Наименование' rules={[{ required: true, message: 'Укажите наименование' }]}>
|
<FormItem name='name' label='Наименование' rules={[{ required: true, message: 'Укажите наименование' }]}>
|
||||||
<Input />
|
<Input />
|
||||||
|
|||||||
@ -62,17 +62,9 @@ export function RelatedGroupTable({ tabsComponent, data, loading, getData, activ
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function editRelatedGroupHandler(values: RelatedGroupFormType) {
|
async function editRelatedGroupHandler(values: RelatedGroupFormType) {
|
||||||
try {
|
await editRelatedGroup(groupId, values);
|
||||||
await editRelatedGroup(groupId, values);
|
getData();
|
||||||
getData();
|
closeEditRelatedGroupHandler();
|
||||||
closeEditRelatedGroupHandler();
|
|
||||||
} catch (e) {
|
|
||||||
if (e instanceof ApiError) {
|
|
||||||
notification.error({
|
|
||||||
description: e.message,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const extraColumns: ColumnsType<RelatedGroupOut> = useMemo(
|
const extraColumns: ColumnsType<RelatedGroupOut> = useMemo(
|
||||||
@ -167,9 +159,7 @@ export function RelatedGroupTable({ tabsComponent, data, loading, getData, activ
|
|||||||
onCancel={() => {
|
onCancel={() => {
|
||||||
closeEditRelatedGroupHandler();
|
closeEditRelatedGroupHandler();
|
||||||
}}
|
}}
|
||||||
onOk={async (values) => {
|
onOk={editRelatedGroupHandler}
|
||||||
await editRelatedGroupHandler(values);
|
|
||||||
}}
|
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{deleteModalOpen && (
|
{deleteModalOpen && (
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user