Browse Source

Merge pull request 'Dev-Farhan' (#10) from Dev-Farhan into master

Reviewed-on: ibnu/generic-ospro-frontend#10
pull/2/head
farhantock 1 year ago
parent
commit
3731898c9d
  1. 3
      src/const/ApiConst.js
  2. 283
      src/views/Master/MasterCompany/DialogForm.js
  3. 78
      src/views/Master/MasterCompany/FormMenu.js
  4. 4
      src/views/Master/MasterCompany/FormUser.js
  5. 283
      src/views/Master/MasterCompany/index.js
  6. 62
      src/views/Master/MasterRoles/DialogForm.js
  7. 64
      src/views/Master/MasterRoles/DialogMenuRoles.js
  8. 10
      src/views/Master/MasterRoles/index.js
  9. 5
      src/views/SimproV2/CreatedProyek/index.js

3
src/const/ApiConst.js

@ -741,6 +741,9 @@ export const COMPANY_MANAGEMENT_SEARCH = `${BASE_SIMPRO_LUMEN}/company-managemen
export const COMPANY_MANAGEMENT_EDIT = (id) => { export const COMPANY_MANAGEMENT_EDIT = (id) => {
return `${BASE_SIMPRO_LUMEN}/company-management/update/${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) => { export const COMPANY_MANAGEMENT_DELETE = (id) => {
return `${BASE_SIMPRO_LUMEN}/company-management/delete/${id}`; return `${BASE_SIMPRO_LUMEN}/company-management/delete/${id}`;
}; };

283
src/views/Master/MasterCompany/DialogForm.js

@ -3,7 +3,7 @@ import {
Modal, ModalHeader, ModalBody, ModalFooter, Modal, ModalHeader, ModalBody, ModalFooter,
Button, Form, FormGroup, Row, Col, Label, Input, Button, Form, FormGroup, Row, Col, Label, Input,
} from 'reactstrap'; } from 'reactstrap';
import { Pagination, Table, Tooltip, Select } from 'antd'; import { Pagination, Table, Tooltip, Select, Spin } from 'antd';
import SweetAlert from 'react-bootstrap-sweetalert'; import SweetAlert from 'react-bootstrap-sweetalert';
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import DialogFormUser from './FormUser'; import DialogFormUser from './FormUser';
@ -12,7 +12,7 @@ import 'antd/dist/antd.css';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import axios from "../../../const/interceptorApi" import axios from "../../../const/interceptorApi"
import { 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'; } from '../../../const/ApiConst';
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
const config = { const config = {
@ -22,7 +22,7 @@ const config = {
"Content-type": `application/json` "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 { Option } = Select
const { t } = useTranslation() const { t } = useTranslation()
const [registrationnumber, setRegistrationNumber] = useState('') const [registrationnumber, setRegistrationNumber] = useState('')
@ -31,9 +31,9 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
const [phoneNumber, setPhoneNumber] = useState('') const [phoneNumber, setPhoneNumber] = useState('')
const [emailCompany, setEmailCompany] = useState('') const [emailCompany, setEmailCompany] = useState('')
const [description, setDescription] = useState('') const [description, setDescription] = useState('')
const [logoLogin, setLogoLogin] = useState([]) const [logoLogin, setLogoLogin] = useState(null)
const [logoHeader, setLogoHeader] = useState([]) const [logoHeader, setLogoHeader] = useState(null)
const [favIcon, setFavIcon] = useState([]) const [favIcon, setFavIcon] = useState(null)
const [loginInstruction, setLoginInstruction] = useState('') const [loginInstruction, setLoginInstruction] = useState('')
const [about, setAbout] = useState('') const [about, setAbout] = useState('')
const [htmlTitle, setHtmlTitle] = useState('') const [htmlTitle, setHtmlTitle] = useState('')
@ -42,7 +42,8 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
const [statusCompany, setStatusCompany] = useState(true) const [statusCompany, setStatusCompany] = useState(true)
const [template, setTemplate] = useState('') const [template, setTemplate] = useState('')
const [lastIdxURL, setLastIdxURL] = useState(0); const [lastIdxURL, setLastIdxURL] = useState(0);
const [availableUrl, setAvailableBaseUrl] = useState(false);
const [id, setId] = useState(0)
const [dataTable, setDatatable] = useState([]) const [dataTable, setDatatable] = useState([])
const [openDialogUser, setOpenDialogUser] = useState(false) const [openDialogUser, setOpenDialogUser] = useState(false)
@ -63,15 +64,57 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
const [totalPageMenu, setTotalPageMenu] = useState(0) const [totalPageMenu, setTotalPageMenu] = useState(0)
const [openDialogMenu, setOpenDialogMenu] = useState(false) const [openDialogMenu, setOpenDialogMenu] = useState(false)
const [typeDialogMenu, setTypeDialogMenu] = useState("add") const [typeDialogMenu, setTypeDialogMenu] = useState("add")
const [loading, setLoading] = useState(true);
useEffect(() => { useEffect(() => {
if (companyID && typeDialog === 'Set') { if (companyID && typeDialog === 'Set') {
setLoading(true)
getDataUser() getDataUser()
getRoleList() getRoleList()
} else { } else if(typeDialog === 'Set-Menu') {
setLoading(true)
getDataMenu() getDataMenu()
} else if(lastIdCompany && typeDialog === 'Save'){
getLastCompany()
} }
}, [typeDialog, companyID, rowsPerPage, currentPage, rowsPerPageMenu, currentPageMenu]) },[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 {
setAvailableBaseUrl(false)
}
} 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) => { const onShowSizeChange = (current, pageSize) => {
setRowsPerPage(pageSize) setRowsPerPage(pageSize)
@ -94,13 +137,12 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
"orders": { "columns": ["id"], "ascending": false } "orders": { "columns": ["id"], "ascending": false }
} }
const result = await axios const result = await axios
.post(ROLE_SEARCH, formData, config) .post(ROLE_SEARCH, formData, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
setLoading(false)
setRoleList(result.data.data); setRoleList(result.data.data);
} }
} }
@ -204,7 +246,9 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
setDatatable(result.data.data); setDatatable(result.data.data);
setTotalPage(result.data.totalRecord); setTotalPage(result.data.totalRecord);
setLoading(false)
} else { } else {
setLoading(false)
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
} }
} }
@ -212,14 +256,14 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
const getDataMenu = async () => { const getDataMenu = async () => {
let start = 0; let start = 0;
if (currentPage !== 1 && currentPage > 1) { if (currentPageMenu !== 1 && currentPageMenu > 1) {
start = (currentPage * rowsPerPage) - rowsPerPage start = (currentPageMenu * rowsPerPageMenu) - rowsPerPageMenu
} }
const payload = { const payload = {
"paging": { "paging": {
"start": start, "start": start,
"length": rowsPerPage "length": rowsPerPageMenu
}, },
"columns": [{ "columns": [{
"name": "company_id", "name": "company_id",
@ -245,11 +289,24 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
setDatatableMenu(result.data.data); setDatatableMenu(result.data.data);
setTotalPageMenu(result.data.totalRecord); setTotalPageMenu(result.data.totalRecord);
setLoading(false)
} else { } else {
setLoading(false)
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); 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 () => { const handleAddUser = async () => {
await setTypeDialogUser("Save") await setTypeDialogUser("Save")
@ -271,7 +328,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
if (type == 'success') { if (type == 'success') {
NotificationManager.success(`${message}`, "Success!!"); NotificationManager.success(`${message}`, "Success!!");
getDataUser() getDataUser()
} else if (type == 'Failed') { } else if (type == 'failed') {
NotificationManager.error(`${message}`, "Failed!!"); NotificationManager.error(`${message}`, "Failed!!");
} }
}; };
@ -297,7 +354,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
if (type == 'success') { if (type == 'success') {
NotificationManager.success(`${message}`, "Success!!"); NotificationManager.success(`${message}`, "Success!!");
getDataMenu() getDataMenu()
} else if (type == 'Failed') { } else if (type == 'failed') {
NotificationManager.error(`${message}`, "Failed!!"); NotificationManager.error(`${message}`, "Failed!!");
} }
@ -323,68 +380,41 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
phone_no: phoneNumber, phone_no: phoneNumber,
email: emailCompany, email: emailCompany,
description: description, description: description,
logo_login: logoLogin,
logo_header: logoHeader,
favicon_image: favIcon,
login_instruction: loginInstruction, login_instruction: loginInstruction,
about: about, about: about,
html_title: htmlTitle, html_title: htmlTitle,
app_name: appName, app_name: appName,
base_url: baseUrl, base_url: baseUrl.length == 0 ? null : baseUrl,
is_active: statusCompany, 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); closeDialog('save', data);
} else if (typeDialog === "Set") { setLoading(false);
// if (!password && password === "") { } else if (typeDialog === "Edit") {
// alert("Please fill password"); data = {
// return; id,
// } registration_no: registrationnumber,
// if (password !== retryPassword) { company_name: companyName,
// alert("Password doesn't match"); address: addressCompany,
// return; phone_no: phoneNumber,
// } email: emailCompany,
// if (password.length < 8) { description: description,
// alert("Password minimum 8 character"); login_instruction: loginInstruction,
// return; about: about,
// } html_title: htmlTitle,
// data = { app_name: appName,
// id, base_url: baseUrl.length == 0 ? null : baseUrl,
// username, is_active: statusCompany,
// password, template_id: parseInt(template),
// email, }
// } data.imageLogin = logoLogin ? logoLogin : null;
data.imageHeader = logoHeader ? logoHeader : null;
closeDialog('edit', data); data.imageFavicon = favIcon ? favIcon : null;
} 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); closeDialog('edit', data);
setLoading(false);
} }
} }
@ -395,27 +425,45 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
const handleCancel = () => { const handleCancel = () => {
closeDialog('cancel', 'none') closeDialog('cancel', 'none')
setDatatable([]) setDatatable([]);
setBaseUrl([]);
setAvailableBaseUrl(false);
setLoading(false);
} }
const onConfirmDelete = async () => { 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) const result = await axios.delete(url, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code === 200) { if (result && result.data && result.data.code === 200) {
getDataUser() setIdDelete(0);
setIdDelete(0) setAlertDelete(false);
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!!'); NotificationManager.success(`Data user berhasil dihapus!`, 'Success!!');
}
} else { } else {
setIdDelete(0) setIdDelete(0)
setAlertDelete(false) 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!!'); NotificationManager.error(`Data user gagal dihapus!`, 'Failed!!');
} }
} }
}
const cancelDelete = () => { const cancelDelete = () => {
setAlertDelete(false) setAlertDelete(false)
@ -423,22 +471,48 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
} }
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({ baseUrl.push({
id: lastIdxURL + 1, id: lastIdxURL + 1,
url: "", base_url: "",
}); });
setBaseUrl(baseUrl); setBaseUrl(baseUrl);
setLastIdxURL(lastIdxURL + 1); setLastIdxURL(lastIdxURL + 1);
}
}; };
const handleChangeBaseURL = (value, index) => { 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]; const newBaseURL = [...baseUrl];
newBaseURL[index] = value; newBaseURL[index][name] = value;
setBaseUrl(newBaseURL); setBaseUrl(newBaseURL);
} }
}
const deleteBaseURL = (id) => { const deleteBaseURL = (id) => {
if (baseUrl && baseUrl.length > 0) { 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); let checkIdx = baseUrl.findIndex((o) => o.id === id);
if (checkIdx > -1) { if (checkIdx > -1) {
baseUrl.splice(checkIdx, 1); baseUrl.splice(checkIdx, 1);
@ -447,24 +521,22 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
} }
} }
const handleLogoHeader = (content) => {
const newLogoHeader = [...logoHeader, {
type: "image",
content: content,
}];
setLogoHeader(newLogoHeader);
}
const RenderBaseURL = () => { const RenderBaseURL = () => {
if (baseUrl.length > 0) { if (baseUrl.length > 0) {
return baseUrl.map((item, index) => { let baseUrlArray;
if(availableUrl === true) {
baseUrlArray = JSON.parse(baseUrl);
} else {
baseUrlArray = baseUrl;
}
return baseUrlArray.map((item, index) => {
return ( return (
<Row key={index} style={{ marginBottom: 10 }}> <Row key={index} style={{ marginBottom: 10 }}>
<Col md={8}> <Col md={8}>
<Input <Input
type="text" type="text"
value={item.url} value={availableUrl === true ? item.base_url ? item.base_url : "" : item.base_url ? item.base_url : "" }
name="item" name="base_url"
onChange={(e) => handleChangeBaseURL(e, index)} onChange={(e) => handleChangeBaseURL(e, index)}
/> />
</Col> </Col>
@ -472,7 +544,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
<Button <Button
color="danger" color="danger"
size="sm" size="sm"
onClick={() => deleteBaseURL(item.id)} onClick={() => deleteBaseURL(availableUrl === true ? item.id ? item.id : "" : item.id ? item.id : "")}
> >
<i className="fa fa-trash"></i> <i className="fa fa-trash"></i>
</Button> </Button>
@ -502,14 +574,14 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
<Form> <Form>
<Row> <Row>
<Col md={12}> <Col md={12}>
<span style={{ color: "red" }}>*</span>required. <span style={{ color: "red" }}>*</span>Is Required
</Col> </Col>
</Row> </Row>
<Row> <Row>
<Col md={6}> <Col md={6}>
<FormGroup> <FormGroup>
<Label className="capitalize">Number Registration<span style={{ color: "red" }}>*</span></Label> <Label className="capitalize">Number Registration<span style={{ color: "red" }}>*</span></Label>
<Input type="text" value={registrationnumber} onChange={(e) => setRegistrationNumber(e.target.value)} placeholder='Input Number Registration' /> <Input type="text" value={registrationnumber} readOnly disabled />
</FormGroup> </FormGroup>
</Col> </Col>
<Col md={6}> <Col md={6}>
@ -581,8 +653,8 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
<FormGroup> <FormGroup>
<Label className="capitalize">Template Application<span style={{ color: "red" }}>*</span></Label> <Label className="capitalize">Template Application<span style={{ color: "red" }}>*</span></Label>
<Select style={{ width: "100%" }} defaultValue={template} onChange={(e) => setTemplate(e)} placeholder="Select a template for application"> <Select style={{ width: "100%" }} defaultValue={template} onChange={(e) => setTemplate(e)} placeholder="Select a template for application">
<Option value={'1'}>Construction</Option> <Option value={1}>Construction</Option>
<Option value={'2'}>IT (Information AND Technology)</Option> {/* <Option value={2}>IT (Information AND Technology)</Option> */}
</Select> </Select>
</FormGroup> </FormGroup>
</Col> </Col>
@ -620,8 +692,9 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
<Input <Input
type="file" type="file"
accept="image/*" accept="image/*"
// onChange={(e) => handleLogoHeader(e.target.files[0])} onChange={(e) => setLogoLogin(e.target.files[0])}
/> />
<small>{imageLogin ? imageLogin.image : <p style={{ color: "red" }}>Not found image</p> }</small>
</FormGroup> </FormGroup>
</Row> </Row>
<Row> <Row>
@ -630,18 +703,20 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
<Input <Input
type="file" type="file"
accept="image/*" accept="image/*"
onChange={(e) => handleLogoHeader(e.target.files[0])} onChange={(e) => setLogoHeader(e.target.files[0])}
/> />
<small>{imageHeader ? imageHeader.image : <p style={{ color: "red" }}>Not found image</p> }</small>
</FormGroup> </FormGroup>
</Row> </Row>
<Row> <Row>
<FormGroup> <FormGroup>
<Label className="capitalize" style={{ fontWeight: "bold" }}>Fav Icon Logo</Label> <Label className="capitalize" style={{ fontWeight: "bold" }}>Favicon Logo</Label>
<Input <Input
type="file" type="file"
accept="image/*" accept=".ico"
// onChange={(e) => setProjectStructureOrg(e.target.files[0])} onChange={(e) => setFavIcon(e.target.files[0])}
/> />
<small>{imageFavIcon ? imageFavIcon.image : <p style={{ color: "red" }}>Not found image</p> }</small>
</FormGroup> </FormGroup>
</Row> </Row>
</Col> </Col>
@ -714,7 +789,6 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
{ title: t('icon'), dataIndex: 'icon', key: 'icon' }, { title: t('icon'), dataIndex: 'icon', key: 'icon' },
{ title: 'Alias', dataIndex: 'alias_name', key: 'alias_name' }, { title: 'Alias', dataIndex: 'alias_name', key: 'alias_name' },
{ title: t('order'), dataIndex: 'sequence', key: 'sequence' }, { title: t('order'), dataIndex: 'sequence', key: 'sequence' },
{ title: t('parentMenu'), dataIndex: 'join_first_name', key: 'join_first_name', render: (text, record) => (text ? text : "-") }
]; ];
return ( return (
<Table <Table
@ -767,6 +841,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
<Button onClick={handleAddUser} size='sm' color="primary"><i className='fa fa-plus'></i></Button> <Button onClick={handleAddUser} size='sm' color="primary"><i className='fa fa-plus'></i></Button>
</Tooltip> </Tooltip>
) : ) :
typeDialog != "Save" && typeDialog != "Edit" &&
( (
<Tooltip title="Add Menu"> <Tooltip title="Add Menu">
<Button onClick={handleAddMenu} size='sm' color="primary"><i className='fa fa-plus'></i></Button> <Button onClick={handleAddMenu} size='sm' color="primary"><i className='fa fa-plus'></i></Button>
@ -778,6 +853,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
{typeDialog !== "Set" && typeDialog !== "Set-Menu" && renderFromCompany()} {typeDialog !== "Set" && typeDialog !== "Set-Menu" && renderFromCompany()}
{typeDialog === "Set" && ( {typeDialog === "Set" && (
<> <>
<Spin tip="Loading..." spinning={loading}>
{RenderTableUser} {RenderTableUser}
<Pagination <Pagination
style={{ marginTop: "25px" }} style={{ marginTop: "25px" }}
@ -789,10 +865,12 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
pageSize={rowsPerPage} pageSize={rowsPerPage}
current={currentPage} current={currentPage}
/> />
</Spin>
</> </>
)} )}
{typeDialog === "Set-Menu" && ( {typeDialog === "Set-Menu" && (
<> <>
<Spin tip="Loading..." spinning={loading}>
{renderTableMenu} {renderTableMenu}
<Pagination <Pagination
style={{ marginTop: "25px" }} style={{ marginTop: "25px" }}
@ -804,6 +882,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
pageSize={rowsPerPageMenu} pageSize={rowsPerPageMenu}
current={currentPageMenu} current={currentPageMenu}
/> />
</Spin>
</> </>
)} )}

78
src/views/Master/MasterCompany/FormMenu.js

@ -6,7 +6,7 @@ import {
import { Transfer, Select } from 'antd'; import { Transfer, Select } from 'antd';
import 'antd/dist/antd.css'; import 'antd/dist/antd.css';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { MENU_LIST, MENU_COMPANY_ADD, MENU_COMPANY_EDIT } from '../../../const/ApiConst.js'; import { MENU_LIST, MENU_COMPANY_ADD, MENU_COMPANY_EDIT, MENU_COMPANY_SEARCH } from '../../../const/ApiConst.js';
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import axios from 'axios'; import axios from 'axios';
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
@ -39,6 +39,10 @@ const FormMenu = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit,
if (!openDialog) { if (!openDialog) {
handleCLearData() handleCLearData()
} else { } else {
if(typeDialog === "Save")
{
getMenuCompany();
}
getDataAllMenu(); getDataAllMenu();
} }
}, [openDialog]) }, [openDialog])
@ -83,7 +87,7 @@ const FormMenu = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit,
if (typeDialog === "Edit") { if (typeDialog === "Edit") {
setId(dataEdit.id) setId(dataEdit.id)
setIcon(dataEdit.icon) setIcon(dataEdit.icon)
setParentId(dataEdit.parent_id) setParentId(dataEdit.parent_menu_id)
setSequence(dataEdit.sequence) setSequence(dataEdit.sequence)
} else { } else {
setId(0) setId(0)
@ -97,12 +101,18 @@ const FormMenu = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit,
}, [dataEdit, openDialog]) }, [dataEdit, openDialog])
const validation = () => { const validation = () => {
if (!icon || icon === "") { if (!icon && icon === "") {
if(typeDialog !== "Save")
{
alert("Icon cannot be empty!"); alert("Icon cannot be empty!");
}
return true; return true;
} }
if (sequence < 0) { if (sequence < 0) {
if(typeDialog !== "Save")
{
alert("Order cannot be empty!"); alert("Order cannot be empty!");
}
return true; return true;
} }
} }
@ -119,7 +129,7 @@ const FormMenu = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit,
} }
if (parentId && parentId > 0) { if (parentId && parentId > 0) {
data['parent_id'] = parentId data['parent_menu_id'] = parentId
} }
const formData = data const formData = data
@ -143,15 +153,19 @@ const FormMenu = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit,
setAliasName('') setAliasName('')
} else { } else {
const selectedData = menuResource.filter(item => targetKeys.includes(item.key)); const selectedData = menuResource.filter(item => targetKeys.includes(item.key));
const formDatas = selectedData.map(data => ({ let formDatas = selectedData.map(data => ({
menu_id: data.key, menu_id: data.key,
parent_id: data.parent_id, parent_id: data.parent_id,
company_id: companyID,
icon: data.icon, icon: data.icon,
alias_name: data.alias_name, alias_name: data.alias_name,
url: data.url, url: data.url,
sequence: data.sequence sequence: data.sequence,
company_id: companyID
})); }));
if(targetKeys.length < 1)
{
formDatas = [{ company_id: companyID }];
}
const result = await axios const result = await axios
.post(MENU_COMPANY_ADD, formDatas, config) .post(MENU_COMPANY_ADD, formDatas, config)
.then(res => res) .then(res => res)
@ -179,6 +193,40 @@ const FormMenu = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit,
setTargetKeys(targetKeys) setTargetKeys(targetKeys)
}; };
const getMenuCompany = async () => {
const payload = {
"select": [
"id",
"menu_id",
"company_id"
],
"columns": [
{ "name": "company_id", "logic_operator": "=", "value": companyID }
],
"orders": {
"columns": [
"id"
],
"ascending": true
}
}
const result = await axios
.post(MENU_COMPANY_SEARCH, payload, config)
.then(res => res)
.catch((error) => error.response);
if(result && result.status==200){
let data = result.data.data || []
let newTargetKeys = []
if (data.length > 0) {
data.map((val,index)=> {
newTargetKeys.push(val.menu_id)
});
}
setTargetKeys(newTargetKeys)
}
}
const onChangeParent = (val) => { const onChangeParent = (val) => {
setParentId(val) setParentId(val)
} }
@ -188,7 +236,7 @@ const FormMenu = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit,
<> <>
{menuResource.map((val, index) => { {menuResource.map((val, index) => {
return ( return (
<Option key={index} value={val.id}>{val.name}</Option> <Option key={val.key} value={val.key}>{val.name}</Option>
) )
})} })}
</> </>
@ -230,14 +278,6 @@ const FormMenu = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit,
</Row> </Row>
<Row> <Row>
<Col> <Col>
{/* <FormGroup>
<Label className="capitalize">{t('name')} Menu<span style={{ color: "red" }}>*</span></Label>
<Input type="hidden" value={name} onChange={(e) => setName(e.target.value)} placeholder={t('inputName')} />
</FormGroup>
<FormGroup>
<Label className="capitalize">URL<span style={{ color: "red" }}>*</span></Label>
<Input type="hidden" value={url} onChange={(e) => setUrl(e.target.value)} placeholder={t('inputUrl')} />
</FormGroup> */}
<FormGroup> <FormGroup>
<Label className="capitalize">{t('icon')}<span style={{ color: "red" }}>*</span> </Label> <Label className="capitalize">{t('icon')}<span style={{ color: "red" }}>*</span> </Label>
<Input type="text" value={icon} onChange={(e) => setIcon(e.target.value)} placeholder={t('inputIcon')} /> <Input type="text" value={icon} onChange={(e) => setIcon(e.target.value)} placeholder={t('inputIcon')} />
@ -250,14 +290,10 @@ const FormMenu = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit,
</FormGroup> </FormGroup>
<FormGroup> <FormGroup>
<Label className="capitalize">{t('parentMenu')}</Label> <Label className="capitalize">{t('parentMenu')}</Label>
<Select showSearch defaultValue={parentId} onChange={onChangeParent} placeholder={t('inputParentMenu')} style={{ width: '100%' }}> <Select showSearch defaultValue={parentId} value={parentId} onChange={onChangeParent} placeholder={t('inputParentMenu')} style={{ width: '100%' }}>
{setupSelectParent()} {setupSelectParent()}
</Select> </Select>
</FormGroup> </FormGroup>
{/* <FormGroup>
<Label className="capitalize">Alias Menu</Label>
<Input type="hidden" value={aliasName} onChange={(e) => setAliasName(e.target.value)} placeholder={t('inputAliasMenu')} />
</FormGroup> */}
</Col> </Col>
</Row> </Row>

4
src/views/Master/MasterCompany/FormUser.js

@ -33,7 +33,6 @@ const FormUser = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit,
useEffect(() => { useEffect(() => {
if (typeDialog === "Edit") { if (typeDialog === "Edit") {
console.log(dataEdit);
setId(dataEdit.id) setId(dataEdit.id)
setResourceName(dataEdit.name) setResourceName(dataEdit.name)
setUsername(dataEdit.username) setUsername(dataEdit.username)
@ -54,6 +53,7 @@ const FormUser = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit,
setEmail('') setEmail('')
setGender('') setGender('')
setRoleId('') setRoleId('')
setKtpNumber('')
} }
}, [dataEdit, openDialog]) }, [dataEdit, openDialog])
@ -147,7 +147,7 @@ const FormUser = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdit,
<Form> <Form>
<Row> <Row>
<Col md={12}> <Col md={12}>
<span style={{ color: "red" }}>*</span>required. <span style={{ color: "red" }}>*</span>Is required
</Col> </Col>
</Row> </Row>
<Row> <Row>

283
src/views/Master/MasterCompany/index.js

@ -1,13 +1,12 @@
import * as XLSX from 'xlsx';
import React, { useState, useEffect, useMemo } from 'react'; import React, { useState, useEffect, useMemo } from 'react';
import SweetAlert from 'react-bootstrap-sweetalert'; import SweetAlert from 'react-bootstrap-sweetalert';
import axios from "../../../const/interceptorApi" import axios from "../../../const/interceptorApi"
import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap'; import { Card, CardBody, CardHeader, Col, Row, Input } from 'reactstrap';
import DialogForm from './DialogForm' import DialogForm from './DialogForm'
import { NotificationContainer, NotificationManager } from 'react-notifications'; import { NotificationContainer, NotificationManager } from 'react-notifications';
import { Pagination, Table, Button, Tooltip } from 'antd'; import { Pagination, Table, Button, Tooltip, Spin } from 'antd';
import { import {
COMPANY_MANAGEMENT_SEARCH, USER_ADD, USER_SEARCH, USER_EDIT, USER_DELETE, DIVISI_SEARCH, USER_SHIFT_ADD, USER_SYNC COMPANY_MANAGEMENT_SEARCH, COMPANY_MANAGEMENT_ADD, COMPANY_MANAGEMENT_EDIT, COMPANY_MANAGEMENT_DELETE, IMAGE_UPLOAD, IMAGE_GET_BY_ID, IMAGE_DELETE
} from '../../../const/ApiConst'; } from '../../../const/ApiConst';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
@ -28,32 +27,35 @@ const MasterCompany = ({ params }) => {
"Authorization": `Bearer ${token}` "Authorization": `Bearer ${token}`
} }
} }
const HEADER_MULTIPART = {
headers: {
"Content-Type": "multipart/form-data",
Authorization: `Bearer ${token}`,
},
};
const [alertDelete, setAlertDelete] = useState(false) const [alertDelete, setAlertDelete] = useState(false)
const [clickOpenModal, setClickOpenModal] = useState(false)
const [clickOpenModalShift, setClickOpenModalShift] = useState(false)
const [currentPage, setCurrentPage] = useState(1) const [currentPage, setCurrentPage] = useState(1)
const [dataEdit, setDataEdit] = useState([]) const [dataEdit, setDataEdit] = useState([])
const [dataExport, setDataExport] = useState([])
const [dataTable, setDatatable] = useState([]) const [dataTable, setDatatable] = useState([])
const [divisiList, setDivisiList] = useState([])
const [idDelete, setIdDelete] = useState(0) const [idDelete, setIdDelete] = useState(0)
const [openDialog, setOpenDialog] = useState(false) const [openDialog, setOpenDialog] = useState(false)
const [openDialogShift, setOpenDialogShift] = useState(false)
const [rowsPerPage, setRowsPerPage] = useState(10) const [rowsPerPage, setRowsPerPage] = useState(10)
const [search, setSearch] = useState('') const [search, setSearch] = useState('')
const [totalPage, setTotalPage] = useState(0) const [totalPage, setTotalPage] = useState(0)
const [typeDialog, setTypeDialog] = useState('Save') const [typeDialog, setTypeDialog] = useState('')
const [typeDialogShift, setTypeDialogShift] = useState('Save')
const [companyID, setCompanyID] = useState('') const [companyID, setCompanyID] = useState('')
const [companyName, setCompanyName] = useState('') const [companyName, setCompanyName] = useState('')
const [imageHeader, setProjectImageHeader] = useState(null);
const [imageLogin, setProjectImageLogin] = useState(null);
const [imageFavIcon, setProjectImageFavicon] = useState(null);
const [lastIdCompany,setLastCompanyId] = useState('');
const [loading, setLoading] = useState(true);
const pageName = params.name; const pageName = params.name;
const { t } = useTranslation(); const { t } = useTranslation();
useEffect(() => {
getDivisiList()
}, [])
useEffect(() => { useEffect(() => {
getDataUser() setLoading(true)
getDataCompany()
}, [search, rowsPerPage, currentPage]) }, [search, rowsPerPage, currentPage])
@ -66,32 +68,11 @@ const MasterCompany = ({ params }) => {
setCurrentPage(current) setCurrentPage(current)
} }
const getDivisiList = async () => { const getDataCompany = async () => {
const formData = {
"paging": { "start": 0, "length": -1 },
"orders": { "columns": ["id"], "ascending": false }
}
const result = await axios
.post(DIVISI_SEARCH, formData, config)
.then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
setDivisiList(result.data.data);
} else {
NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
}
}
const getDataUser = async () => {
let start = 0; let start = 0;
if (currentPage !== 1 && currentPage > 1) { if (currentPage !== 1 && currentPage > 1) {
start = (currentPage * rowsPerPage) - rowsPerPage start = (currentPage * rowsPerPage) - rowsPerPage
} }
const payload = { const payload = {
"paging": { "paging": {
"start": start, "start": start,
@ -103,12 +84,12 @@ const MasterCompany = ({ params }) => {
"group_operator": "OR", "group_operator": "OR",
"where": [ "where": [
{ {
"name": "name", "name": "company_name",
"logic_operator": "~*", "logic_operator": "~*",
"value": search "value": search
}, },
{ {
"name": "phone_number", "name": "registration_no",
"logic_operator": "~*", "logic_operator": "~*",
"value": search "value": search
}, },
@ -118,15 +99,12 @@ const MasterCompany = ({ params }) => {
"value": search "value": search
}, },
{ {
"name": "status_resource", "name": "phone_no",
"logic_operator": "~*", "logic_operator": "~*",
"value": search "value": search
}, },
] ]
}, },
"joins": [
],
"orders": { "orders": {
"columns": [ "columns": [
"id" "id"
@ -134,20 +112,57 @@ const MasterCompany = ({ params }) => {
"ascending": true "ascending": true
} }
} }
const result = await axios const result = await axios
.post(COMPANY_MANAGEMENT_SEARCH, payload, config) .post(COMPANY_MANAGEMENT_SEARCH, payload, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
setDatatable(result.data.data); const sourceData = result.data.data;
setDatatable(sourceData);
setTotalPage(result.data.totalRecord); setTotalPage(result.data.totalRecord);
const lastCompanyId = sourceData[sourceData.length - 1].id;
setLastCompanyId(lastCompanyId);
setLoading(false)
} else { } else {
setLoading(false)
NotificationManager.error('Gagal Mengambil Data!!', 'Failed'); NotificationManager.error('Gagal Mengambil Data!!', 'Failed');
} }
} }
const getProjectImageHeader = async (id) => {
const url = IMAGE_GET_BY_ID(id, "company_logo_header");
const result = await axios
.get(url, HEADER)
.then((res) => res)
.catch((err) => err.response);
if (result && result.data && result.data.code === 200) {
setProjectImageHeader(result.data.data);
}
}
const getProjectImageLogin = async (id) => {
const url = IMAGE_GET_BY_ID(id, "company_logo_login");
const result = await axios
.get(url, HEADER)
.then((res) => res)
.catch((err) => err.response);
if (result && result.data && result.data.code === 200) {
setProjectImageLogin(result.data.data);
}
}
const getProjectImageFavicon = async (id) => {
const url = IMAGE_GET_BY_ID(id, "company_favicon");
const result = await axios
.get(url, HEADER)
.then((res) => res)
.catch((err) => err.response);
if (result && result.data && result.data.code === 200) {
setProjectImageFavicon(result.data.data);
}
}
const handleSearch = e => { const handleSearch = e => {
const value = e.target.value const value = e.target.value
setSearch(value); setSearch(value);
@ -160,10 +175,11 @@ const MasterCompany = ({ params }) => {
} }
const handleEdit = async (data) => {
setDataEdit(data);
const handleEdit = (data) => { await getProjectImageHeader(data.id);
setDataEdit(data) await getProjectImageLogin(data.id);
await getProjectImageFavicon(data.id);
handleOpenDialog('Edit'); handleOpenDialog('Edit');
} }
@ -189,68 +205,193 @@ const MasterCompany = ({ params }) => {
const handleCloseDialog = (type, data) => { const handleCloseDialog = (type, data) => {
if (type === "save") { if (type === "save") {
saveUser(data); saveCompany(data);
} else if (type === "edit") { } else if (type === "edit") {
editUser(data); editCompany(data);
} }
setDataEdit([]) setDataEdit([])
setProjectImageHeader(null)
setProjectImageLogin(null)
setProjectImageFavicon(null)
setOpenDialog(false) setOpenDialog(false)
} }
const saveCompany = async (data) => {
const saveUser = async (data) => {
const formData = data const formData = data
const result = await axios.post(USER_ADD, formData, HEADER) const result = await axios.post(COMPANY_MANAGEMENT_ADD, formData, HEADER)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code === 200) { if (result && result.data && result.data.code === 200) {
getDataUser(); const logoHeader = data.imageHeader;
NotificationManager.success(`Data resource berhasil ditambah`, 'Success!!'); const logoLogin = data.imageLogin;
const favIcon = data.imageFavicon;
if (logoHeader) {
await saveImageHeader(
result.data.data.id,
logoHeader
);
}
if (logoLogin) {
await saveImageLogin(
result.data.data.id,
logoLogin
);
}
if (favIcon) {
await saveFavIcon(
result.data.data.id,
favIcon
);
}
getDataCompany();
setLoading(false)
NotificationManager.success(`Data company berhasil ditambah`, 'Success!!');
} else { } else {
setLoading(false)
NotificationManager.error(`${result.data.message}`, 'Failed!!'); NotificationManager.error(`${result.data.message}`, 'Failed!!');
} }
} }
const editUser = async (data) => { const editCompany = async (data) => {
let urlEdit = USER_EDIT(data.id) let urlEdit = COMPANY_MANAGEMENT_EDIT(data.id)
const logoHeader = data.imageHeader;
const logoLogin = data.imageLogin;
const favIcon = data.imageFavicon;
const formData = data const formData = data
const result = await axios.put(urlEdit, formData, HEADER) const result = await axios.put(urlEdit, formData, HEADER)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if (logoHeader) {
await deleteImageHeader(
data.id
);
await saveImageHeader(
data.id,
logoHeader
);
}
if (logoLogin) {
await deleteImageLogin(
data.id
);
await saveImageLogin(
data.id,
logoLogin
);
}
if (favIcon) {
await deleteImageFavicon(
data.id
);
await saveFavIcon(
data.id,
favIcon
);
}
if (result && result.data && result.data.code === 200) { if (result && result.data && result.data.code === 200) {
getDataUser(); getDataCompany();
NotificationManager.success(`Data resource berhasil diedit`, 'Success!!'); setLoading(false)
NotificationManager.success(`Data company berhasil diedit`, 'Success!!');
} else { } else {
setLoading(false)
NotificationManager.error(`${result.data.message}`, `Failed!!`); NotificationManager.error(`${result.data.message}`, `Failed!!`);
} }
} }
// Save Image Function
const saveImageHeader = async (id, data) => {
const formData = new FormData;
formData.append('ref_id', id);
formData.append('category', 'company_logo_header');
formData.append('files', data);
await axios
.post(IMAGE_UPLOAD, formData, HEADER_MULTIPART)
.then(res => res)
.catch((error) => error.response);
return "berhasil";
};
const saveImageLogin = async (id, data) => {
const formData = new FormData;
formData.append('ref_id', id);
formData.append('category', 'company_logo_login');
formData.append('files', data);
await axios
.post(IMAGE_UPLOAD, formData, HEADER_MULTIPART)
.then(res => res)
.catch((error) => error.response);
return "berhasil";
};
const saveFavIcon = async (id, data) => {
const formData = new FormData;
formData.append('ref_id', id);
formData.append('category', 'company_favicon');
formData.append('files', data);
await axios
.post(IMAGE_UPLOAD, formData, HEADER_MULTIPART)
.then(res => res)
.catch((error) => error.response);
return "berhasil";
};
// Delete Image Function
const deleteImageHeader = async (id) => {
const URL = IMAGE_DELETE(id, 'company_logo_header');
await axios
.delete(URL, HEADER)
.then(res => res)
.catch((error) => error.response);
return "berhasil";
};
const deleteImageLogin = async (id) => {
const URL = IMAGE_DELETE(id, 'company_logo_login');
await axios
.delete(URL, HEADER)
.then(res => res)
.catch((error) => error.response);
return "berhasil";
};
const deleteImageFavicon = async (id) => {
const URL = IMAGE_DELETE(id, 'company_favicon');
await axios
.delete(URL, HEADER)
.then(res => res)
.catch((error) => error.response);
return "berhasil";
};
const toggleAddDialog = () => { const toggleAddDialog = () => {
setOpenDialog(!openDialog) setOpenDialog(!openDialog)
} }
const onConfirmDelete = async () => { const onConfirmDelete = async () => {
let url = USER_DELETE(idDelete); let url = COMPANY_MANAGEMENT_DELETE(idDelete);
const result = await axios.delete(url, config) const result = await axios.delete(url, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code === 200) { if (result && result.data && result.data.code === 200) {
getDataUser() getDataCompany()
deleteImageHeader(idDelete)
deleteImageLogin(idDelete)
deleteImageFavicon(idDelete)
setIdDelete(0) setIdDelete(0)
setAlertDelete(false) setAlertDelete(false)
NotificationManager.success(`Data user berhasil dihapus!`, 'Success!!'); setLoading(false)
NotificationManager.success(`Data company berhasil dihapus!`, 'Success!!');
} else { } else {
setIdDelete(0) setIdDelete(0)
setAlertDelete(false) setAlertDelete(false)
NotificationManager.error(`Data user gagal dihapus!}`, 'Failed!!'); setLoading(false)
NotificationManager.error(`Data company gagal dihapus!`, 'Failed!!');
} }
} }
@ -319,11 +460,13 @@ const MasterCompany = ({ params }) => {
closeDialog={handleCloseDialog} closeDialog={handleCloseDialog}
toggleDialog={() => toggleAddDialog} toggleDialog={() => toggleAddDialog}
typeDialog={typeDialog} typeDialog={typeDialog}
dataEdit={dataEdit} dataEditCompany={dataEdit}
clickOpenModal={clickOpenModal}
divisiList={divisiList}
companyID={companyID} companyID={companyID}
companyNameProp={companyName} companyNameProp={companyName}
imageHeader={imageHeader}
imageFavIcon={imageFavIcon}
imageLogin={imageLogin}
lastIdCompany={lastIdCompany}
/> />
<Card> <Card>
@ -341,7 +484,9 @@ const MasterCompany = ({ params }) => {
</Row> </Row>
</CardHeader> </CardHeader>
<CardBody> <CardBody>
<Spin tip="Loading..." spinning={loading}>
{RenderTable} {RenderTable}
</Spin>
<Pagination <Pagination
style={{ marginTop: "25px" }} style={{ marginTop: "25px" }}
showSizeChanger showSizeChanger

62
src/views/Master/MasterRoles/DialogForm.js

@ -5,7 +5,7 @@ import 'antd/dist/antd.css';
import { withTranslation } from 'react-i18next'; import { withTranslation } from 'react-i18next';
import axios from 'axios'; import axios from 'axios';
import { Select } from 'antd'; import { Select } from 'antd';
import { MENU_SEARCH } from '../../../const/ApiConst.js'; import { MENU_COMPANY_SEARCH, MENU_SEARCH } from '../../../const/ApiConst.js';
const { Option } = Select const { Option } = Select
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
@ -18,6 +18,7 @@ const config = {
} }
}; };
class DialogForm extends Component { class DialogForm extends Component {
constructor(props) { constructor(props) {
super(props) super(props)
@ -29,7 +30,6 @@ class DialogForm extends Component {
isParentClick: false, isParentClick: false,
menu: [], menu: [],
selectedMenu: null, selectedMenu: null,
company_id
} }
} }
@ -61,12 +61,49 @@ class DialogForm extends Component {
} }
getAllMenu = async () => { getAllMenu = async () => {
const { companyID } = this.props;
const { roleName } = this.props;
if (roleName !== "Super Admin") {
const payload = { const payload = {
"paging": { "start": 0, "length": -1 }, "paging": {
"columns": [ "start": 0,
{ "name": "name", "logic_operator": "ilike", "value": "", "operator": "AND" } "length": -1
], },
"joins": [], "columns": [{
"name": "company_id",
"logic_operator": "=",
"value": companyID,
"operator": "AND"
}],
"joins": [{
"name": "m_menu",
"column_join": "menu_id",
"column_results": [
"name"
]
}],
"orders": { "columns": ["id"], "ascending": false }
}
const result = await axios
.post(MENU_COMPANY_SEARCH, payload, config)
.then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
this.setState({ menu: result.data.data });
}
} else {
const payload = {
"paging": {
"start": 0,
"length": -1
},
"columns": [{
"name": "name",
"logic_operator": "ilike",
"value": "",
"operator": "AND"
}],
"orders": { "columns": ["id"], "ascending": false } "orders": { "columns": ["id"], "ascending": false }
} }
const result = await axios const result = await axios
@ -78,6 +115,8 @@ class DialogForm extends Component {
} }
} }
}
showDialog = () => { showDialog = () => {
this.setState({ isParentClick: true }); this.setState({ isParentClick: true });
} }
@ -94,12 +133,13 @@ class DialogForm extends Component {
} }
handleSave = () => { handleSave = () => {
const { companyID } = this.props;
const { const {
id, id,
name, name,
description, description,
selectedMenu, selectedMenu,
company_id
} = this.state } = this.state
let data = ''; let data = '';
@ -111,7 +151,7 @@ class DialogForm extends Component {
name, name,
description, description,
selectedMenu, selectedMenu,
company_id company_id: companyID
} }
// console.log('data', data); // console.log('data', data);
this.props.closeDialog('save', data); this.props.closeDialog('save', data);
@ -121,7 +161,7 @@ class DialogForm extends Component {
name, name,
description, description,
selectedMenu, selectedMenu,
company_id company_id: companyID
} }
this.props.closeDialog('edit', data); this.props.closeDialog('edit', data);
} }
@ -166,7 +206,7 @@ class DialogForm extends Component {
}}> }}>
{this.state.menu.map((item) => ( {this.state.menu.map((item) => (
<option key={item.id} value={item.id}> <option key={item.id} value={item.id}>
{item.name} {item.name ?? item.join_first_name}
</option> </option>
))} ))}
</Input> </Input>

64
src/views/Master/MasterRoles/DialogMenuRoles.js

@ -3,9 +3,8 @@ import { Modal, ModalHeader, ModalBody, ModalFooter, Row, Col, Table } from 'rea
import { Button, Form, FormGroup, Label, Input } from 'reactstrap'; import { Button, Form, FormGroup, Label, Input } from 'reactstrap';
import 'antd/dist/antd.css'; import 'antd/dist/antd.css';
import axios from 'axios'; import axios from 'axios';
import { MENU_SEARCH } from '../../../const/ApiConst.js'; import { MENU_COMPANY_SEARCH, MENU_SEARCH } from '../../../const/ApiConst.js';
import { withTranslation, WithTranslation } from 'react-i18next'; import { withTranslation, WithTranslation } from 'react-i18next';
const BASE_URL = "http://siopas.co.id/custom-php/api/geohr/";
const token = window.localStorage.getItem('token'); const token = window.localStorage.getItem('token');
@ -52,30 +51,61 @@ class DialogMenuRoles extends Component {
} }
getAllMenu = async () => { getAllMenu = async () => {
const { companyID } = this.props;
const { roleName } = this.props;
if (roleName !== "Super Admin") {
const payload = { const payload = {
"paging": { "start": 0, "length": -1 }, "paging": {
"columns": [ "start": 0,
{ "name": "name", "logic_operator": "ilike", "value": "", "operator": "AND" } "length": -1
], },
"joins": [], "columns": [{
"name": "company_id",
"logic_operator": "=",
"value": companyID,
"operator": "AND"
}],
"joins": [{
"name": "m_menu",
"column_join": "menu_id",
"column_results": [
"name"
]
}],
"orders": { "columns": ["id"], "ascending": false } "orders": { "columns": ["id"], "ascending": false }
} }
const result = await axios const result = await axios
.post(MENU_SEARCH, payload, config) .post(MENU_COMPANY_SEARCH, payload, config)
.then(res => res) .then(res => res)
.catch((error) => error.response); .catch((error) => error.response);
if (result && result.data && result.data.code == 200) { if (result && result.data && result.data.code == 200) {
this.setState({ menu: result.data.data }, () => { this.setState({ menu: result.data.data }, () => {
this.setStateMenu(false); this.setStateMenu(false);
}); });
} else { } else {
} }
} else {
const payload = {
"paging": {
"start": 0,
"length": -1
},
"columns": [{
"name": "name",
"logic_operator": "ilike",
"value": "",
"operator": "AND"
}],
"orders": { "columns": ["id"], "ascending": false }
}
const result = await axios
.post(MENU_SEARCH, payload, config)
.then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
this.setState({ menu: result.data.data });
}
}
} }
setStateMenu = edit => { setStateMenu = edit => {
@ -96,13 +126,14 @@ class DialogMenuRoles extends Component {
let copyStateMenu = [...this.state.stateMenu]; let copyStateMenu = [...this.state.stateMenu];
this.props.menuRoles.map((val, indexMenu) => { this.props.menuRoles.map((val, indexMenu) => {
let index = this.getIndexDataMenu(val.menu_id); let index = this.getIndexDataMenu(val.menu_id);
console.log("index true", val.menu_id); console.log('index true', index);
if (index >= 0) { if (index >= 0) {
copyStateMenu[index] = true; copyStateMenu[index] = true;
} }
}) })
this.setState({ stateMenu: [] }, () => { this.setState({ stateMenu: [] }, () => {
let check = copyStateMenu.some(this.checkArray); let check = copyStateMenu.some(this.checkArray);
console.log('icheck', check);
if (check === false) { if (check === false) {
this.setState({ allChecked: true, stateMenu: copyStateMenu }) this.setState({ allChecked: true, stateMenu: copyStateMenu })
} else { } else {
@ -151,11 +182,12 @@ class DialogMenuRoles extends Component {
renderForm = () => { renderForm = () => {
const { menu, stateMenu } = this.state const { menu, stateMenu } = this.state
console.log('stateMenu', stateMenu);
return ( return (
menu.map((val, index) => { menu.map((val, index) => {
return ( return (
<tr key={index}> <tr key={index}>
<td>{val.name}</td> <td>{val.join_first_name ?? val.name}</td>
<td><input type="checkbox" onClick={(e) => this.handleChangeCheckbox(e.target.checked, index)} defaultChecked={stateMenu[index]} /></td> <td><input type="checkbox" onClick={(e) => this.handleChangeCheckbox(e.target.checked, index)} defaultChecked={stateMenu[index]} /></td>
</tr> </tr>
) )

10
src/views/Master/MasterRoles/index.js

@ -198,7 +198,7 @@ class index extends Component {
name: data.name, name: data.name,
description: data.description, description: data.description,
default_page: data.selectedMenu, default_page: data.selectedMenu,
company_id: this.company_id company_id: data.company_id
} }
const result = await axios.post(ROLE_ADD, formData, this.config) const result = await axios.post(ROLE_ADD, formData, this.config)
@ -218,7 +218,8 @@ class index extends Component {
const formData = { const formData = {
name: data.name, name: data.name,
description: data.description, description: data.description,
default_page: data.selectedMenu default_page: data.selectedMenu,
company_id: data.company_id
} }
const url = ROLE_EDIT(data.id) const url = ROLE_EDIT(data.id)
const result = await axios.put(url, formData, this.config) const result = await axios.put(url, formData, this.config)
@ -426,6 +427,9 @@ class index extends Component {
dataEdit={this.state.dataEdit} dataEdit={this.state.dataEdit}
showDialog={showDialog => this.showChildDialog = showDialog} showDialog={showDialog => this.showChildDialog = showDialog}
dataHs={this.state.dataIdHo} dataHs={this.state.dataIdHo}
companyID={this.state.company_id}
roleName={this.state.role_name}
/> />
<DialogMenuRoles <DialogMenuRoles
openDialog={dialogMenuForm} openDialog={dialogMenuForm}
@ -433,6 +437,8 @@ class index extends Component {
idRoles={this.state.idRoles} idRoles={this.state.idRoles}
showDialog={showDialog => this.showMenuRolesDialog = showDialog} showDialog={showDialog => this.showMenuRolesDialog = showDialog}
menuRoles={this.state.menuRoles} menuRoles={this.state.menuRoles}
companyID={this.state.company_id}
roleName={this.state.role_name}
/> />
<Card> <Card>
<CardHeader style={{ display: "flex", justifyContent: "space-between" }}> <CardHeader style={{ display: "flex", justifyContent: "space-between" }}>

5
src/views/SimproV2/CreatedProyek/index.js

@ -306,7 +306,7 @@ const CreatedProyek = ({ params, ...props }) => {
const getDataProyek = async () => { const getDataProyek = async () => {
let start = 0; let start = 0;
let hierarchy = []; let hierarchy = [];
//hierarchy.push(JSON.parse(localStorage.getItem("hierarchy"))); hierarchy.push(JSON.parse(localStorage.getItem("hierarchy")));
if (currentPage !== 1 && currentPage > 1) { if (currentPage !== 1 && currentPage > 1) {
start = currentPage * rowsPerPage - rowsPerPage; start = currentPage * rowsPerPage - rowsPerPage;
} }
@ -346,9 +346,8 @@ const CreatedProyek = ({ params, ...props }) => {
paging: { start: start, length: rowsPerPage }, paging: { start: start, length: rowsPerPage },
}; };
if (parseInt(role_id) !== 1) { if (parseInt(role_id) !== 70) {
payload["columns"] = [ payload["columns"] = [
{ name: "id", logic_operator: "=", value: proyek_id, operator: "AND" },
{ name: "created_by_id", logic_operator: "IN", value: hierarchy, operator: "AND" } { name: "created_by_id", logic_operator: "IN", value: hierarchy, operator: "AND" }
]; ];
} }

Loading…
Cancel
Save