diff --git a/src/const/ApiConst.js b/src/const/ApiConst.js
index 99d1c34..b0aecf4 100644
--- a/src/const/ApiConst.js
+++ b/src/const/ApiConst.js
@@ -741,6 +741,9 @@ export const COMPANY_MANAGEMENT_SEARCH = `${BASE_SIMPRO_LUMEN}/company-managemen
export const COMPANY_MANAGEMENT_EDIT = (id) => {
return `${BASE_SIMPRO_LUMEN}/company-management/update/${id}`;
};
+export const COMPANY_MANAGEMENT_GET_ID = (id) => {
+ return `${BASE_SIMPRO_LUMEN}/company-management/edit/${id}`;
+};
export const COMPANY_MANAGEMENT_DELETE = (id) => {
return `${BASE_SIMPRO_LUMEN}/company-management/delete/${id}`;
};
diff --git a/src/views/Master/MasterCompany/DialogForm.js b/src/views/Master/MasterCompany/DialogForm.js
index 936a6c2..e0fd9a8 100644
--- a/src/views/Master/MasterCompany/DialogForm.js
+++ b/src/views/Master/MasterCompany/DialogForm.js
@@ -3,7 +3,7 @@ import {
Modal, ModalHeader, ModalBody, ModalFooter,
Button, Form, FormGroup, Row, Col, Label, Input,
} from 'reactstrap';
-import { Pagination, Table, Tooltip, Select } from 'antd';
+import { Pagination, Table, Tooltip, Select, Spin } from 'antd';
import SweetAlert from 'react-bootstrap-sweetalert';
import { NotificationContainer, NotificationManager } from 'react-notifications';
import DialogFormUser from './FormUser';
@@ -12,7 +12,7 @@ import 'antd/dist/antd.css';
import { useTranslation } from 'react-i18next';
import axios from "../../../const/interceptorApi"
import {
- USER_SEARCH, USER_EDIT, USER_DELETE, ROLE_SEARCH, DIVISI_SEARCH, MENU_COMPANY_SEARCH
+ USER_SEARCH, MENU_COMPANY_DELETE, USER_DELETE, ROLE_SEARCH, COMPANY_MANAGEMENT_GET_ID, MENU_COMPANY_SEARCH
} from '../../../const/ApiConst';
const token = window.localStorage.getItem('token');
const config = {
@@ -22,7 +22,7 @@ const config = {
"Content-type": `application/json`
}
};
-const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, companyID, companyNameProp }) => {
+const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, companyID, companyNameProp, dataEditCompany, imageHeader, imageFavIcon, imageLogin, lastIdCompany }) => {
const { Option } = Select
const { t } = useTranslation()
const [registrationnumber, setRegistrationNumber] = useState('')
@@ -31,9 +31,9 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
const [phoneNumber, setPhoneNumber] = useState('')
const [emailCompany, setEmailCompany] = useState('')
const [description, setDescription] = useState('')
- const [logoLogin, setLogoLogin] = useState([])
- const [logoHeader, setLogoHeader] = useState([])
- const [favIcon, setFavIcon] = useState([])
+ const [logoLogin, setLogoLogin] = useState(null)
+ const [logoHeader, setLogoHeader] = useState(null)
+ const [favIcon, setFavIcon] = useState(null)
const [loginInstruction, setLoginInstruction] = useState('')
const [about, setAbout] = useState('')
const [htmlTitle, setHtmlTitle] = useState('')
@@ -42,7 +42,8 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
const [statusCompany, setStatusCompany] = useState(true)
const [template, setTemplate] = useState('')
const [lastIdxURL, setLastIdxURL] = useState(0);
-
+ const [availableUrl, setAvailableBaseUrl] = useState(false);
+ const [id, setId] = useState(0)
const [dataTable, setDatatable] = useState([])
const [openDialogUser, setOpenDialogUser] = useState(false)
@@ -63,15 +64,57 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
const [totalPageMenu, setTotalPageMenu] = useState(0)
const [openDialogMenu, setOpenDialogMenu] = useState(false)
const [typeDialogMenu, setTypeDialogMenu] = useState("add")
+ const [loading, setLoading] = useState(true);
useEffect(() => {
if (companyID && typeDialog === 'Set') {
- getDataUser()
- getRoleList()
+ setLoading(true)
+ getDataUser()
+ getRoleList()
+ } else if(typeDialog === 'Set-Menu') {
+ setLoading(true)
+ getDataMenu()
+ } else if(lastIdCompany && typeDialog === 'Save'){
+ getLastCompany()
+ }
+ },[typeDialog, companyID, lastIdCompany, rowsPerPage, currentPage, rowsPerPageMenu, currentPageMenu])
+
+ useEffect(()=> {
+ if(typeDialog==="Edit"){
+ setId(dataEditCompany.id)
+ setRegistrationNumber(dataEditCompany.registration_no)
+ setCompanyName(dataEditCompany.company_name)
+ setEmailCompany(dataEditCompany.email)
+ setPhoneNumber(dataEditCompany.phone_no)
+ setAddressCompany(dataEditCompany.address)
+ setAbout(dataEditCompany.about)
+ setAppName(dataEditCompany.app_name)
+ setHtmlTitle(dataEditCompany.html_title)
+ setStatusCompany(dataEditCompany.is_active)
+ setTemplate(dataEditCompany.template_id)
+ setBaseUrl(dataEditCompany.base_url ? dataEditCompany.base_url : [])
+ if(dataEditCompany.base_url)
+ {
+ setAvailableBaseUrl(true)
} else {
- getDataMenu()
+ setAvailableBaseUrl(false)
}
- }, [typeDialog, companyID, rowsPerPage, currentPage, rowsPerPageMenu, currentPageMenu])
-
+ } else {
+ setId(0)
+ setCompanyName('')
+ setEmailCompany('')
+ setPhoneNumber('')
+ setAddressCompany('')
+ setAbout('')
+ setAppName('')
+ setHtmlTitle('')
+ setStatusCompany('')
+ setTemplate('')
+ setLogoLogin(null)
+ setLogoHeader(null)
+ setFavIcon(null)
+ setBaseUrl([])
+ }
+ },[dataEditCompany,openDialog])
const onShowSizeChange = (current, pageSize) => {
setRowsPerPage(pageSize)
@@ -94,14 +137,13 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
"orders": { "columns": ["id"], "ascending": false }
}
-
const result = await axios
- .post(ROLE_SEARCH, formData, config)
- .then(res => res)
- .catch((error) => error.response);
-
+ .post(ROLE_SEARCH, formData, config)
+ .then(res => res)
+ .catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
- setRoleList(result.data.data);
+ setLoading(false)
+ setRoleList(result.data.data);
}
}
@@ -202,24 +244,26 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
- setDatatable(result.data.data);
- setTotalPage(result.data.totalRecord);
+ setDatatable(result.data.data);
+ setTotalPage(result.data.totalRecord);
+ setLoading(false)
} else {
- NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
+ setLoading(false)
+ NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
}
}
const getDataMenu = async () => {
let start = 0;
- if (currentPage !== 1 && currentPage > 1) {
- start = (currentPage * rowsPerPage) - rowsPerPage
+ if (currentPageMenu !== 1 && currentPageMenu > 1) {
+ start = (currentPageMenu * rowsPerPageMenu) - rowsPerPageMenu
}
const payload = {
"paging": {
"start": start,
- "length": rowsPerPage
+ "length": rowsPerPageMenu
},
"columns": [{
"name": "company_id",
@@ -243,13 +287,26 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
- setDatatableMenu(result.data.data);
- setTotalPageMenu(result.data.totalRecord);
+ setDatatableMenu(result.data.data);
+ setTotalPageMenu(result.data.totalRecord);
+ setLoading(false)
} else {
+ setLoading(false)
NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
}
}
+ const getLastCompany = async () => {
+ const result = await axios
+ .get(`${COMPANY_MANAGEMENT_GET_ID(lastIdCompany)}`, config)
+ .then((res) => res)
+ .catch((err) => err.response);
+ const lastRegistrationNumber = result.data.data.registration_no;
+ const lastNumber = parseInt(lastRegistrationNumber.match(/\d+$/)[0]);
+ const newNumber = lastNumber + 1;
+ const newRegistrationNumber = `RG-${newNumber}`;
+ setRegistrationNumber(newRegistrationNumber);
+ }
const handleAddUser = async () => {
await setTypeDialogUser("Save")
@@ -271,7 +328,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
if (type == 'success') {
NotificationManager.success(`${message}`, "Success!!");
getDataUser()
- } else if (type == 'Failed') {
+ } else if (type == 'failed') {
NotificationManager.error(`${message}`, "Failed!!");
}
};
@@ -282,7 +339,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
}
const handleEditMenu = async (data) => {
- setDataEdit(data)
+ setDataEdit(data)
await setTypeDialogMenu('Edit')
setOpenDialogMenu(true)
}
@@ -297,7 +354,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
if (type == 'success') {
NotificationManager.success(`${message}`, "Success!!");
getDataMenu()
- } else if (type == 'Failed') {
+ } else if (type == 'failed') {
NotificationManager.error(`${message}`, "Failed!!");
}
@@ -323,68 +380,41 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
phone_no: phoneNumber,
email: emailCompany,
description: description,
- logo_login: logoLogin,
- logo_header: logoHeader,
- favicon_image: favIcon,
login_instruction: loginInstruction,
about: about,
html_title: htmlTitle,
app_name: appName,
- base_url: baseUrl,
+ base_url: baseUrl.length == 0 ? null : baseUrl,
is_active: statusCompany,
- template_id: template
+ template_id: parseInt(template)
}
- console.log(data)
-
+ data.imageLogin = logoLogin ? logoLogin : null;
+ data.imageHeader = logoHeader ? logoHeader : null;
+ data.imageFavicon = favIcon ? favIcon : null;
closeDialog('save', data);
- } else if (typeDialog === "Set") {
- // if (!password && password === "") {
- // alert("Please fill password");
- // return;
- // }
- // if (password !== retryPassword) {
- // alert("Password doesn't match");
- // return;
- // }
- // if (password.length < 8) {
- // alert("Password minimum 8 character");
- // return;
- // }
- // data = {
- // id,
- // username,
- // password,
- // email,
- // }
-
- closeDialog('edit', data);
- } else {
-
- // data = {
- // id,
- // name: resourceName,
- // username,
- // employee_type: employeeType,
- // phone_number: phoneNo,
- // email,
- // gender,
- // birth_place: birthPlace,
- // blood_type: bloodType,
- // ktp_number: ktpNumber,
- // biaya_per_jam: biayaPerJam.replace('.', ''),
- // role_id: roleId,
- // divisi_id: divisionId,
- // address,
- // status_resource: statusResource,
- // status_boundary: statusRestriction,
- // company_id: company_id
- // }
-
- // if (birthDate && birthDate != "") {
- // data['birth_date'] = birthDate;
- // }
-
- closeDialog('edit', data);
+ setLoading(false);
+ } else if (typeDialog === "Edit") {
+ data = {
+ id,
+ registration_no: registrationnumber,
+ company_name: companyName,
+ address: addressCompany,
+ phone_no: phoneNumber,
+ email: emailCompany,
+ description: description,
+ login_instruction: loginInstruction,
+ about: about,
+ html_title: htmlTitle,
+ app_name: appName,
+ base_url: baseUrl.length == 0 ? null : baseUrl,
+ is_active: statusCompany,
+ template_id: parseInt(template),
+ }
+ data.imageLogin = logoLogin ? logoLogin : null;
+ data.imageHeader = logoHeader ? logoHeader : null;
+ data.imageFavicon = favIcon ? favIcon : null;
+ closeDialog('edit', data);
+ setLoading(false);
}
}
@@ -395,25 +425,43 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
const handleCancel = () => {
closeDialog('cancel', 'none')
- setDatatable([])
+ setDatatable([]);
+ setBaseUrl([]);
+ setAvailableBaseUrl(false);
+ setLoading(false);
}
const onConfirmDelete = async () => {
- let url = USER_DELETE(idDelete);
-
+ let url;
+ if(typeDialog === "Set-Menu") {
+ url = MENU_COMPANY_DELETE(idDelete);
+ } else if(typeDialog === "Set") {
+ url = USER_DELETE(idDelete);
+ }
const result = await axios.delete(url, config)
.then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code === 200) {
- getDataUser()
- setIdDelete(0)
- setAlertDelete(false)
+ setIdDelete(0);
+ setAlertDelete(false);
+ setLoading(false);
+ if (typeDialog === "Set-Menu") {
+ getDataMenu();
+ NotificationManager.success(`Data menu berhasil dihapus!`, 'Success!!');
+ } else if (typeDialog === "Set") {
+ getDataUser();
NotificationManager.success(`Data user berhasil dihapus!`, 'Success!!');
+ }
} else {
- setIdDelete(0)
- setAlertDelete(false)
+ setIdDelete(0)
+ setAlertDelete(false)
+ setLoading(false);
+ if (typeDialog === "Set-Menu") {
+ NotificationManager.success(`Data menu gagal dihapus!`, 'Success!!');
+ } else if (typeDialog === "Set") {
NotificationManager.error(`Data user gagal dihapus!`, 'Failed!!');
+ }
}
}
@@ -422,63 +470,87 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
setIdDelete(0)
}
- const addBaseUrl = () => {
+ const addBaseUrl = () => {
+ if (availableUrl === true) {
+ const baseUrlArray = JSON.parse(baseUrl);
+ baseUrlArray.push({
+ id: lastIdxURL + 1,
+ base_url: "",
+ });
+ setBaseUrl(JSON.stringify(baseUrlArray));
+ setLastIdxURL(lastIdxURL + 1);
+ } else {
baseUrl.push({
id: lastIdxURL + 1,
- url: "",
+ base_url: "",
});
setBaseUrl(baseUrl);
setLastIdxURL(lastIdxURL + 1);
+ }
};
- const handleChangeBaseURL = (value, index) => {
- const newBaseURL = [...baseUrl];
- newBaseURL[index] = value;
- setBaseUrl(newBaseURL);
+ const handleChangeBaseURL = (e, index) => {
+ if (availableUrl === true) {
+ const { name, value } = e.target;
+ const newBaseURL = [...JSON.parse(baseUrl)];
+ newBaseURL[index][name] = value;
+ setBaseUrl(JSON.stringify(newBaseURL));
+ } else {
+ const { name, value } = e.target;
+ const newBaseURL = [...baseUrl];
+ newBaseURL[index][name] = value;
+ setBaseUrl(newBaseURL);
+ }
}
- const deleteBaseURL = (id) => {
- if (baseUrl && baseUrl.length > 0) {
- let checkIdx = baseUrl.findIndex((o) => o.id === id);
- if (checkIdx > -1) {
- baseUrl.splice(checkIdx, 1);
- setBaseUrl(baseUrl.filter((_, i2) => i2 !== id));
- }
+ const deleteBaseURL = (id) => {
+ if (availableUrl === true) {
+ const baseUrlArray = JSON.parse(baseUrl);
+ let checkIdx = baseUrlArray.findIndex((o) => o.id === id);
+ if (checkIdx > -1) {
+ baseUrlArray.splice(checkIdx, 1);
+ const baseFilter = baseUrlArray.filter((i2) => i2 !== id);
+ setBaseUrl(JSON.stringify(baseFilter));
}
+ } else {
+ let checkIdx = baseUrl.findIndex((o) => o.id === id);
+ if (checkIdx > -1) {
+ baseUrl.splice(checkIdx, 1);
+ setBaseUrl(baseUrl.filter((_, i2) => i2 !== id));
+ }
+ }
}
- const handleLogoHeader = (content) => {
- const newLogoHeader = [...logoHeader, {
- type: "image",
- content: content,
- }];
- setLogoHeader(newLogoHeader);
- }
-
- const RenderBaseURL = () => {
+ const RenderBaseURL = () => {
if (baseUrl.length > 0) {
- return baseUrl.map((item, index) => {
- return (
-