|
|
|
@ -6,7 +6,8 @@ import DialogForm from './DialogForm'
|
|
|
|
|
import { NotificationContainer, NotificationManager } from 'react-notifications'; |
|
|
|
|
import { Pagination, Table, Button, Tooltip, Spin } from 'antd'; |
|
|
|
|
import { |
|
|
|
|
COMPANY_MANAGEMENT_SEARCH, COMPANY_MANAGEMENT_ADD, COMPANY_MANAGEMENT_EDIT, COMPANY_MANAGEMENT_DELETE, IMAGE_UPLOAD, IMAGE_MULTIPLE_UPLOAD, IMAGE_MULTIPLE_DELETE, IMAGE_GET_BY_ID, IMAGE_DELETE, IMAGE_SEARCH |
|
|
|
|
COMPANY_MANAGEMENT_SEARCH, COMPANY_MANAGEMENT_ADD, COMPANY_MANAGEMENT_EDIT, COMPANY_MANAGEMENT_DELETE, IMAGE_UPLOAD, IMAGE_MULTIPLE_UPLOAD, IMAGE_MULTIPLE_DELETE, IMAGE_GET_BY_ID, IMAGE_DELETE, IMAGE_SEARCH, |
|
|
|
|
TRANSACTION_SEARCH |
|
|
|
|
} from '../../../const/ApiConst'; |
|
|
|
|
import { useTranslation } from 'react-i18next'; |
|
|
|
|
const token = window.localStorage.getItem('token'); |
|
|
|
@ -19,12 +20,8 @@ const config = {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const MasterCompany = ({ params }) => { |
|
|
|
|
const token = localStorage.getItem("token") |
|
|
|
|
let company_id = ''; |
|
|
|
|
const role = window.localStorage.getItem('role_name'); |
|
|
|
|
if(role != 'Super Admin') { |
|
|
|
|
company_id = localStorage.getItem("company_id"); |
|
|
|
|
} |
|
|
|
|
const token = localStorage.getItem("token"); |
|
|
|
|
|
|
|
|
|
const HEADER = { |
|
|
|
|
headers: { |
|
|
|
|
"Content-Type": "application/json", |
|
|
|
@ -54,13 +51,11 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
const [imageSlider, setProjectImageSlider] = useState([]); |
|
|
|
|
const [imageFavIcon, setProjectImageFavicon] = useState(null); |
|
|
|
|
const [lastIdCompany,setLastCompanyId] = useState(''); |
|
|
|
|
const [transaction, setTransaction] = useState([]); |
|
|
|
|
const [loading, setLoading] = useState(true); |
|
|
|
|
const pageName = params.name; |
|
|
|
|
const { t } = useTranslation(); |
|
|
|
|
let configApp = ''; |
|
|
|
|
if (role !== 'Super Admin') { |
|
|
|
|
configApp = JSON.parse(window.localStorage.getItem('configApp')); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
setLoading(true) |
|
|
|
|
getDataCompany() |
|
|
|
@ -192,6 +187,33 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const getDataTransaction = async (company_id) => { |
|
|
|
|
const formData = { |
|
|
|
|
"paging": {"start": 0, "length": 1}, |
|
|
|
|
"columns": [ |
|
|
|
|
{"name": "company_id", "logic_operator": "=", "value": parseInt(company_id), "operator": "AND"} |
|
|
|
|
], |
|
|
|
|
"select": [ |
|
|
|
|
"company_id", |
|
|
|
|
"type_paket", |
|
|
|
|
"amount", |
|
|
|
|
"exp_ospro", |
|
|
|
|
"pay_date", |
|
|
|
|
"created_at" |
|
|
|
|
] |
|
|
|
|
} |
|
|
|
|
const result = await axios |
|
|
|
|
.post(TRANSACTION_SEARCH, formData, config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response ); |
|
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
|
let dataRes = result.data.data[0]; |
|
|
|
|
setTransaction(dataRes); |
|
|
|
|
} else { |
|
|
|
|
NotificationManager.error("Gagal Mengambil Data!!", "Failed"); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleSearch = e => { |
|
|
|
|
const value = e.target.value |
|
|
|
|
setSearch(value); |
|
|
|
@ -201,11 +223,13 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
const handleOpenDialog = async (type) => { |
|
|
|
|
await setTypeDialog(type) |
|
|
|
|
setOpenDialog(true) |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleEdit = async (data) => { |
|
|
|
|
setDataEdit(data); |
|
|
|
|
setCompanyID(data.id); |
|
|
|
|
getDataTransaction(data.id); |
|
|
|
|
setCompanyName(data.company_name); |
|
|
|
|
await getProjectImageHeader(data.id); |
|
|
|
|
await getProjectImageSlider(data.id); |
|
|
|
|
await getProjectImageLogin(data.id); |
|
|
|
@ -228,9 +252,11 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleDelete = async (id) => { |
|
|
|
|
await setAlertDelete(true) |
|
|
|
|
await setIdDelete(id) |
|
|
|
|
const handleDelete = async (data) => { |
|
|
|
|
setCompanyID(data.id); |
|
|
|
|
setCompanyName(data.company_name); |
|
|
|
|
await setAlertDelete(true); |
|
|
|
|
await setIdDelete(data.id); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const handleCloseDialog = (type, data) => { |
|
|
|
@ -247,7 +273,7 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
setOpenDialog(false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const packFiles = (id, files) => { |
|
|
|
|
const packFiles = (id, files, company_name) => { |
|
|
|
|
const data = new FormData(); |
|
|
|
|
|
|
|
|
|
for (let i = 0; i < files.length; i++) { |
|
|
|
@ -256,11 +282,10 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
|
|
|
|
|
data.append('ref_id', id); |
|
|
|
|
data.append('category', 'company_slider_login'); |
|
|
|
|
|
|
|
|
|
data.append('company_name', company_name) |
|
|
|
|
return data; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const saveCompany = async (data) => { |
|
|
|
|
const formData = data |
|
|
|
|
const result = await axios.post(COMPANY_MANAGEMENT_ADD, formData, HEADER) |
|
|
|
@ -272,26 +297,31 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
const logoLogin = data.imageLogin; |
|
|
|
|
const favIcon = data.imageFavicon; |
|
|
|
|
const slider = data.imageSlider; |
|
|
|
|
const resultData = result.data.data; |
|
|
|
|
setCompanyName(resultData.company_name); |
|
|
|
|
if (logoHeader) { |
|
|
|
|
await saveImageHeader( |
|
|
|
|
result.data.data.id, |
|
|
|
|
logoHeader |
|
|
|
|
resultData.id, |
|
|
|
|
logoHeader, |
|
|
|
|
resultData.company_name |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
if (logoLogin) { |
|
|
|
|
await saveImageLogin( |
|
|
|
|
result.data.data.id, |
|
|
|
|
logoLogin |
|
|
|
|
resultData.id, |
|
|
|
|
logoLogin, |
|
|
|
|
resultData.company_name |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
if (favIcon) { |
|
|
|
|
await saveFavIcon( |
|
|
|
|
result.data.data.id, |
|
|
|
|
favIcon |
|
|
|
|
resultData.id, |
|
|
|
|
favIcon, |
|
|
|
|
resultData.company_name |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
if(slider) { |
|
|
|
|
const dataPack = packFiles(result.data.data.id,slider) |
|
|
|
|
const dataPack = packFiles(resultData.id, slider, resultData.company_name) |
|
|
|
|
await saveSliderLogin(dataPack) |
|
|
|
|
} |
|
|
|
|
getDataCompany(); |
|
|
|
@ -304,7 +334,6 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const editCompany = async (data) => { |
|
|
|
|
|
|
|
|
|
let urlEdit = COMPANY_MANAGEMENT_EDIT(data.id) |
|
|
|
|
const logoHeader = data.imageHeader; |
|
|
|
|
const logoLogin = data.imageLogin; |
|
|
|
@ -321,7 +350,8 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
); |
|
|
|
|
await saveImageHeader( |
|
|
|
|
data.id, |
|
|
|
|
logoHeader |
|
|
|
|
logoHeader, |
|
|
|
|
companyName |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
if (logoLogin) { |
|
|
|
@ -330,7 +360,8 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
); |
|
|
|
|
await saveImageLogin( |
|
|
|
|
data.id, |
|
|
|
|
logoLogin |
|
|
|
|
logoLogin, |
|
|
|
|
companyName |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
if (favIcon) { |
|
|
|
@ -339,14 +370,15 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
); |
|
|
|
|
await saveFavIcon( |
|
|
|
|
data.id, |
|
|
|
|
favIcon |
|
|
|
|
favIcon, |
|
|
|
|
companyName |
|
|
|
|
); |
|
|
|
|
} |
|
|
|
|
if(slider) { |
|
|
|
|
await deleteImageSlider( |
|
|
|
|
data.id |
|
|
|
|
); |
|
|
|
|
const dataPack = packFiles(data.id,slider) |
|
|
|
|
const dataPack = packFiles(data.id, slider, companyName) |
|
|
|
|
await saveSliderLogin(dataPack) |
|
|
|
|
} |
|
|
|
|
if (result && result.data && result.data.code === 200) { |
|
|
|
@ -359,14 +391,12 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// Save Image Function
|
|
|
|
|
const saveImageHeader = async (id, data) => { |
|
|
|
|
const saveImageHeader = async (id, data, company_name) => { |
|
|
|
|
const formData = new FormData; |
|
|
|
|
formData.append('ref_id', id); |
|
|
|
|
formData.append('category', 'company_logo_header'); |
|
|
|
|
formData.append('files', data); |
|
|
|
|
if(role != 'Super Admin') { |
|
|
|
|
formData.append('company_name',configApp.company_name); |
|
|
|
|
} |
|
|
|
|
formData.append('company_name', company_name); |
|
|
|
|
|
|
|
|
|
await axios |
|
|
|
|
.post(IMAGE_UPLOAD, formData, HEADER_MULTIPART) |
|
|
|
@ -375,14 +405,12 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
return "berhasil"; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const saveImageLogin = async (id, data) => { |
|
|
|
|
const saveImageLogin = async (id, data, company_name) => { |
|
|
|
|
const formData = new FormData; |
|
|
|
|
formData.append('ref_id', id); |
|
|
|
|
formData.append('category', 'company_logo_login'); |
|
|
|
|
formData.append('files', data); |
|
|
|
|
if(role != 'Super Admin') { |
|
|
|
|
formData.append('company_name',configApp.company_name); |
|
|
|
|
} |
|
|
|
|
formData.append('company_name', company_name); |
|
|
|
|
|
|
|
|
|
await axios |
|
|
|
|
.post(IMAGE_UPLOAD, formData, HEADER_MULTIPART) |
|
|
|
@ -391,14 +419,12 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
return "berhasil"; |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const saveFavIcon = async (id, data) => { |
|
|
|
|
const saveFavIcon = async (id, data, company_name) => { |
|
|
|
|
const formData = new FormData; |
|
|
|
|
formData.append('ref_id', id); |
|
|
|
|
formData.append('category', 'company_favicon'); |
|
|
|
|
formData.append('files', data); |
|
|
|
|
if(role != 'Super Admin') { |
|
|
|
|
formData.append('company_name',configApp.company_name); |
|
|
|
|
} |
|
|
|
|
formData.append('company_name', company_name); |
|
|
|
|
|
|
|
|
|
await axios |
|
|
|
|
.post(IMAGE_UPLOAD, formData, HEADER_MULTIPART) |
|
|
|
@ -408,7 +434,6 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const saveSliderLogin = async (data) => { |
|
|
|
|
data.company_name = configApp.company_name; |
|
|
|
|
await axios |
|
|
|
|
.post(IMAGE_MULTIPLE_UPLOAD, data, HEADER_MULTIPART) |
|
|
|
|
.then(res => res) |
|
|
|
@ -418,7 +443,7 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
|
|
|
|
|
// Delete Image Function
|
|
|
|
|
const deleteImageHeader = async (id) => { |
|
|
|
|
const URL = IMAGE_DELETE(id, 'company_logo_header', company_id != '' ? company_id : 'undifined'); |
|
|
|
|
const URL = IMAGE_DELETE(id, 'company_logo_header', companyID != '' ? companyID : 'undifined'); |
|
|
|
|
await axios |
|
|
|
|
.delete(URL, HEADER) |
|
|
|
|
.then(res => res) |
|
|
|
@ -427,7 +452,7 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const deleteImageLogin = async (id) => { |
|
|
|
|
const URL = IMAGE_DELETE(id, 'company_logo_login', company_id != '' ? company_id : 'undifined'); |
|
|
|
|
const URL = IMAGE_DELETE(id, 'company_logo_login', companyID != '' ? companyID : 'undifined'); |
|
|
|
|
await axios |
|
|
|
|
.delete(URL, HEADER) |
|
|
|
|
.then(res => res) |
|
|
|
@ -436,7 +461,7 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const deleteImageFavicon = async (id) => { |
|
|
|
|
const URL = IMAGE_DELETE(id, 'company_favicon', company_id != '' ? company_id : 'undifined'); |
|
|
|
|
const URL = IMAGE_DELETE(id, 'company_favicon', companyID != '' ? companyID : 'undifined'); |
|
|
|
|
await axios |
|
|
|
|
.delete(URL, HEADER) |
|
|
|
|
.then(res => res) |
|
|
|
@ -445,7 +470,7 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
const deleteImageSlider = async (id) => { |
|
|
|
|
const URL = IMAGE_MULTIPLE_DELETE(id, 'company_slider_login', company_id != '' ? company_id : 'undifined'); |
|
|
|
|
const URL = IMAGE_MULTIPLE_DELETE(id, 'company_slider_login', companyID != '' ? companyID : 'undifined'); |
|
|
|
|
await axios |
|
|
|
|
.delete(URL, HEADER) |
|
|
|
|
.then(res => res) |
|
|
|
@ -458,18 +483,13 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const onConfirmDelete = async () => { |
|
|
|
|
let url = COMPANY_MANAGEMENT_DELETE(idDelete); |
|
|
|
|
|
|
|
|
|
const url = COMPANY_MANAGEMENT_DELETE(idDelete); |
|
|
|
|
const result = await axios.delete(url, config) |
|
|
|
|
.then(res => res) |
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
|
|
if (result && result.data && result.data.code === 200) { |
|
|
|
|
getDataCompany() |
|
|
|
|
deleteImageHeader(idDelete) |
|
|
|
|
deleteImageLogin(idDelete) |
|
|
|
|
deleteImageFavicon(idDelete) |
|
|
|
|
deleteImageSlider(idDelete) |
|
|
|
|
setIdDelete(0) |
|
|
|
|
setAlertDelete(false) |
|
|
|
|
setLoading(false) |
|
|
|
@ -498,7 +518,7 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
<Button size="small" type="link" style={{ color: 'green' }} onClick={() => handleEdit(text)}><i className="fa fa-edit"></i></Button> |
|
|
|
|
</Tooltip> |
|
|
|
|
<Tooltip title={t('delete')}> |
|
|
|
|
<Button size="small" type="link" style={{ color: 'red' }} onClick={() => handleDelete(text.id)}><i className="fa fa-trash"></i></Button> |
|
|
|
|
<Button size="small" type="link" style={{ color: 'red' }} onClick={() => handleDelete(text)}><i className="fa fa-trash"></i></Button> |
|
|
|
|
</Tooltip> |
|
|
|
|
<Tooltip title="Set User"> |
|
|
|
|
<Button size="small" type="link" style={{ color: 'primary' }} onClick={() => handleSetWorker(text)}><i className="fa fa-users"></i></Button> |
|
|
|
@ -554,6 +574,7 @@ const MasterCompany = ({ params }) => {
|
|
|
|
|
imageFavIcon={imageFavIcon} |
|
|
|
|
imageSlider={imageSlider} |
|
|
|
|
imageLogin={imageLogin} |
|
|
|
|
transaction={transaction} |
|
|
|
|
lastIdCompany={lastIdCompany} |
|
|
|
|
/> |
|
|
|
|
|
|
|
|
|