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