handle duplicate company name
parent
a3a63b8d84
commit
19adacfcf6
|
@ -31,6 +31,12 @@
|
||||||
"show": "Anzeigen",
|
"show": "Anzeigen",
|
||||||
"hide": "Verbergen",
|
"hide": "Verbergen",
|
||||||
"reload": "Neu laden"
|
"reload": "Neu laden"
|
||||||
|
},
|
||||||
|
"request": {
|
||||||
|
"unknownError": {
|
||||||
|
"title": "Ein unbekannter Fehler ist aufgetreten",
|
||||||
|
"description": "Bitte versuchen Sie es erneut."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sideMenu": {
|
"sideMenu": {
|
||||||
|
|
|
@ -31,6 +31,12 @@
|
||||||
"show": "Show",
|
"show": "Show",
|
||||||
"hide": "Hide",
|
"hide": "Hide",
|
||||||
"reload": "Reload"
|
"reload": "Reload"
|
||||||
|
},
|
||||||
|
"request": {
|
||||||
|
"unknownError": {
|
||||||
|
"title": "An unknown error has occurred",
|
||||||
|
"description": "The request failed. Please try again."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"sideMenu": {
|
"sideMenu": {
|
||||||
|
@ -284,6 +290,12 @@
|
||||||
"notes": "Notes"
|
"notes": "Notes"
|
||||||
},
|
},
|
||||||
"tabContent": {
|
"tabContent": {
|
||||||
|
"request": {
|
||||||
|
"duplicateCompanyError": {
|
||||||
|
"message": "Company already exists",
|
||||||
|
"description": "Choose another company name"
|
||||||
|
}
|
||||||
|
},
|
||||||
"dealInfo": {
|
"dealInfo": {
|
||||||
"collapseDealStatus": {
|
"collapseDealStatus": {
|
||||||
"label": "Deal Status",
|
"label": "Deal Status",
|
||||||
|
|
|
@ -12,6 +12,7 @@ import {
|
||||||
Table,
|
Table,
|
||||||
Tabs,
|
Tabs,
|
||||||
Typography,
|
Typography,
|
||||||
|
notification,
|
||||||
} from "antd";
|
} from "antd";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useNavigate, useParams } from "react-router-dom";
|
import { useNavigate, useParams } from "react-router-dom";
|
||||||
|
@ -50,6 +51,8 @@ export default function Crm() {
|
||||||
const crmContext = useCrmContext();
|
const crmContext = useCrmContext();
|
||||||
const { paramType, paramDealPhase } = useParams();
|
const { paramType, paramDealPhase } = useParams();
|
||||||
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
|
const [isDrawerOpen, setIsDrawerOpen] = useState(false);
|
||||||
|
const [notificationApi, notificationContextHolder] =
|
||||||
|
notification.useNotification();
|
||||||
|
|
||||||
const title =
|
const title =
|
||||||
paramType === Constants.CRM_TYPE.CUSTOMERS
|
paramType === Constants.CRM_TYPE.CUSTOMERS
|
||||||
|
@ -146,7 +149,7 @@ export default function Crm() {
|
||||||
`/crm/pipeline/${paramType}/${paramDealPhase}?page=${crmContext.paginationPage}`,
|
`/crm/pipeline/${paramType}/${paramDealPhase}?page=${crmContext.paginationPage}`,
|
||||||
"GET"
|
"GET"
|
||||||
).then((data) => {
|
).then((data) => {
|
||||||
if (data.Customers !== undefined) {
|
if (data.Customers !== undefined && data.Customers !== null) {
|
||||||
crmContext.setCustomers(data.Customers);
|
crmContext.setCustomers(data.Customers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -177,6 +180,8 @@ export default function Crm() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
{notificationContextHolder}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
|
@ -243,13 +248,15 @@ export default function Crm() {
|
||||||
|
|
||||||
<CustomerDrawer
|
<CustomerDrawer
|
||||||
isOpen={isDrawerOpen}
|
isOpen={isDrawerOpen}
|
||||||
|
setIsOpen={setIsDrawerOpen}
|
||||||
onClose={() => setIsDrawerOpen(false)}
|
onClose={() => setIsDrawerOpen(false)}
|
||||||
|
notificationApi={notificationApi}
|
||||||
/>
|
/>
|
||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
function CustomerDrawer({ isOpen, onClose }) {
|
function CustomerDrawer({ isOpen, setIsOpen, onClose, notificationApi }) {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const crmContext = useCrmContext();
|
const crmContext = useCrmContext();
|
||||||
|
|
||||||
|
@ -282,19 +289,6 @@ function CustomerDrawer({ isOpen, onClose }) {
|
||||||
|
|
||||||
const [activeTab, setActiveTab] = useState(tabItems[0].key);
|
const [activeTab, setActiveTab] = useState(tabItems[0].key);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
if (crmContext.openDrawerCustomerId.current === null) return;
|
|
||||||
|
|
||||||
if (crmContext.openDrawerCustomerId.current === "new") {
|
|
||||||
if (isOpen) return;
|
|
||||||
|
|
||||||
// check if something has changed
|
|
||||||
if (crmContext.currentDrawerCustomer === null) return;
|
|
||||||
|
|
||||||
myFetch(`/crm/customer/create`, "POST", crmContext.currentDrawerCustomer);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const customerRequest = () => {
|
const customerRequest = () => {
|
||||||
if (!isOpen) return;
|
if (!isOpen) return;
|
||||||
|
|
||||||
|
@ -307,6 +301,42 @@ function CustomerDrawer({ isOpen, onClose }) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (crmContext.openDrawerCustomerId.current === null) return;
|
||||||
|
|
||||||
|
if (crmContext.openDrawerCustomerId.current === "new") {
|
||||||
|
if (isOpen) return;
|
||||||
|
|
||||||
|
// check if something has changed
|
||||||
|
if (crmContext.currentDrawerCustomer === null) return;
|
||||||
|
|
||||||
|
myFetch(`/crm/customer/create`, "POST", crmContext.currentDrawerCustomer)
|
||||||
|
.then(() => {
|
||||||
|
crmContext.openDrawerCustomerId.current = false;
|
||||||
|
handleCloseDrawer();
|
||||||
|
})
|
||||||
|
.catch((status) => {
|
||||||
|
if (status === 409) {
|
||||||
|
notificationApi["error"]({
|
||||||
|
message: t(
|
||||||
|
"crm.tabContent.request.duplicateCompanyError.message"
|
||||||
|
),
|
||||||
|
description: t(
|
||||||
|
"crm.tabContent.request.duplicateCompanyError.description"
|
||||||
|
),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
notificationApi["error"]({
|
||||||
|
message: "test",
|
||||||
|
description: "here",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsOpen(true);
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (isOpen) {
|
if (isOpen) {
|
||||||
customerRequest();
|
customerRequest();
|
||||||
} else {
|
} else {
|
||||||
|
@ -331,10 +361,32 @@ function CustomerDrawer({ isOpen, onClose }) {
|
||||||
`/crm/customer/update/${crmContext.openDrawerCustomerId.current}`,
|
`/crm/customer/update/${crmContext.openDrawerCustomerId.current}`,
|
||||||
"POST",
|
"POST",
|
||||||
updatedCustomer
|
updatedCustomer
|
||||||
);
|
)
|
||||||
|
.then(() => {
|
||||||
|
handleCloseDrawer();
|
||||||
|
})
|
||||||
|
.catch((status) => {
|
||||||
|
if (status === 409) {
|
||||||
|
notificationApi["error"]({
|
||||||
|
message: t(
|
||||||
|
"crm.tabContent.request.duplicateCompanyError.message"
|
||||||
|
),
|
||||||
|
description: t(
|
||||||
|
"crm.tabContent.request.duplicateCompanyError.description"
|
||||||
|
),
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
notificationApi["error"]({
|
||||||
|
message: "test",
|
||||||
|
description: "here",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
handleCloseDrawer();
|
setIsOpen(true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
//handleCloseDrawer();
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleCustomerRequest = () => customerRequest();
|
const handleCustomerRequest = () => customerRequest();
|
||||||
|
|
|
@ -1469,3 +1469,10 @@ export function myFetch(
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function showUnkownErrorNotification(notificationApi, t) {
|
||||||
|
notificationApi["error"]({
|
||||||
|
message: t("common.request.unknownError.title"),
|
||||||
|
description: t("common.request.unknownError.description"),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue