Browse Source

feat: add type paket in company management

pull/1/head
wahyun 8 months ago
parent
commit
40812f9142
  1. 36
      src/views/Master/MasterCompany/DialogForm.js
  2. 129
      src/views/Master/MasterCompany/index.js

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

@ -23,7 +23,7 @@ const config = {
"Content-type": `application/json` "Content-type": `application/json`
} }
}; };
const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, companyID, companyNameProp, dataEditCompany, imageHeader, imageFavIcon, imageLogin, imageSlider, lastIdCompany }) => { const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, companyID, companyNameProp, transaction, dataEditCompany, imageHeader, imageFavIcon, imageLogin, imageSlider, lastIdCompany }) => {
const { Option } = Select const { Option } = Select
const { t } = useTranslation() const { t } = useTranslation()
const [registrationnumber, setRegistrationNumber] = useState('') const [registrationnumber, setRegistrationNumber] = useState('')
@ -44,6 +44,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
const [baseUrl, setBaseUrl] = useState([]) const [baseUrl, setBaseUrl] = useState([])
const [statusCompany, setStatusCompany] = useState(true) const [statusCompany, setStatusCompany] = useState(true)
const [template, setTemplate] = useState('') const [template, setTemplate] = useState('')
const [typePaket, setTypePaket] = useState('')
const [lastIdxURL, setLastIdxURL] = useState(0); const [lastIdxURL, setLastIdxURL] = useState(0);
const [availableUrl, setAvailableBaseUrl] = useState(false); const [availableUrl, setAvailableBaseUrl] = useState(false);
const [id, setId] = useState(0) const [id, setId] = useState(0)
@ -96,6 +97,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
setHtmlTitle(dataEditCompany.html_title) setHtmlTitle(dataEditCompany.html_title)
setStatusCompany(dataEditCompany.is_active) setStatusCompany(dataEditCompany.is_active)
setTemplate(dataEditCompany.template_id) setTemplate(dataEditCompany.template_id)
setTypePaket(transaction ? transaction?.type_paket : '')
setBaseUrl(dataEditCompany.base_url ? dataEditCompany.base_url : []) setBaseUrl(dataEditCompany.base_url ? dataEditCompany.base_url : [])
if (dataEditCompany.base_url) { if (dataEditCompany.base_url) {
setAvailableBaseUrl(true) setAvailableBaseUrl(true)
@ -114,6 +116,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
setHtmlTitle('') setHtmlTitle('')
setStatusCompany('') setStatusCompany('')
setTemplate('') setTemplate('')
setTypePaket('')
setLogoLogin(null) setLogoLogin(null)
setLogoHeader(null) setLogoHeader(null)
setSliderLogin(null) setSliderLogin(null)
@ -377,6 +380,26 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
alert("Please input the name"); alert("Please input the name");
return; return;
} }
if (!statusCompany && statusCompany === "") {
alert("Please select the company status");
return;
}
if (!template && template === "") {
alert("Please select the template company");
return;
}
if (!template && template === "") {
alert("Please select the template company");
return;
}
if (!typeAccount && typeAccount === "") {
alert("Please select the type account");
return;
}
if (!typePaket && typePaket === "") {
alert("Please select the type paket");
return;
}
if (typeDialog === "Save") { if (typeDialog === "Save") {
data = { data = {
@ -394,6 +417,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
is_active: statusCompany, is_active: statusCompany,
template_id: parseInt(template), template_id: parseInt(template),
type_account: typeAccount, type_account: typeAccount,
type_paket: typePaket,
date_register: moment() date_register: moment()
} }
data.imageLogin = logoLogin ? logoLogin : null; data.imageLogin = logoLogin ? logoLogin : null;
@ -419,6 +443,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
is_active: statusCompany, is_active: statusCompany,
template_id: parseInt(template), template_id: parseInt(template),
type_account: typeAccount, type_account: typeAccount,
type_paket: typePaket
} }
data.imageLogin = logoLogin ? logoLogin : null; data.imageLogin = logoLogin ? logoLogin : null;
data.imageHeader = logoHeader ? logoHeader : null; data.imageHeader = logoHeader ? logoHeader : null;
@ -723,6 +748,15 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, company
</Select> </Select>
</FormGroup> </FormGroup>
</Col> </Col>
<Col md={6}>
<FormGroup>
<Label className="capitalize">Type Paket<span style={{ color: "red" }}>*</span></Label>
<Select style={{ width: "100%" }} defaultValue={typePaket} value={typePaket} onChange={(e) => setTypePaket(e)} placeholder="Select a type paket">
<Option value="Free">Free</Option>
<Option value="Basic">Basic</Option>
</Select>
</FormGroup>
</Col>
</Row> </Row>
<Row> <Row>
<Col md={6}> <Col md={6}>

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

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

Loading…
Cancel
Save