From ec2b0224e41cb4cfb440500fb08eddb02568a6ba Mon Sep 17 00:00:00 2001 From: farhantock Date: Wed, 22 Nov 2023 16:25:36 +0700 Subject: [PATCH] update condition by company_id or super admin --- src/views/Master/MasterRoles/DialogForm.js | 1 - src/views/Master/MasterRoles/index.js | 61 ++++++++++++---------- src/views/Master/ProjectPhase/index.js | 40 +++++++------- src/views/Master/RoleProject/index.js | 18 ++++++- src/views/Pages/Login/Login.js | 10 ++-- src/views/SimproV2/Divisi/index.js | 35 +++++++------ src/views/SimproV2/Gantt/index.js | 6 +-- src/views/SimproV2/ProjectType/index.js | 42 +++++++-------- src/views/SimproV2/ResourceWorker/index.js | 43 +++++++-------- src/views/SimproV2/Satuan/index.js | 36 +++++++------ 10 files changed, 156 insertions(+), 136 deletions(-) diff --git a/src/views/Master/MasterRoles/DialogForm.js b/src/views/Master/MasterRoles/DialogForm.js index 4bc3ab1..fab37b4 100644 --- a/src/views/Master/MasterRoles/DialogForm.js +++ b/src/views/Master/MasterRoles/DialogForm.js @@ -37,7 +37,6 @@ class DialogForm extends Component { this.props.showDialog(this.showDialog); this.getAllMenu(); } - async componentDidUpdate() { if (this.state.isParentClick === true) { if (this.props.typeDialog === "Edit") { diff --git a/src/views/Master/MasterRoles/index.js b/src/views/Master/MasterRoles/index.js index af94704..243519f 100644 --- a/src/views/Master/MasterRoles/index.js +++ b/src/views/Master/MasterRoles/index.js @@ -11,28 +11,33 @@ import { Pagination, Tooltip, Table } from 'antd'; import { ROLE_ADD, ROLE_SEARCH, ROLE_EDIT, ROLE_DELETE, ROLEMENU_ADD, ROLEMENU_SEARCH, ROLEMENU_DELETE_ROLE } from '../../../const/ApiConst.js'; import { withTranslation } from 'react-i18next'; -const token = window.localStorage.getItem('token'); -const company_id = window.localStorage.getItem('company_id'); -const role_name = window.localStorage.getItem('role_name'); - - -const BASE_URL = "http://siopas.co.id/custom-php/api/geohr/"; - -const config = { - headers: - { - Authorization: `Bearer ${token}`, - "Content-type": `application/json` - } -}; - -const momentFormat = 'HH:mm'; const LENGTH_DATA = 10 class index extends Component { constructor(props) { + let role_id = '', user_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; + if (props.location.state && props.location.state.role_id && props.location.state.user_id) { + role_id = props.location.state.role_id; + user_id = props.location.state.user_id; + token = props.location.state.token; + isLogin = props.location.state.isLogin; + company_id = props.location.state.company_id; + role_name = props.location.state.role_name; + + + } else { + token = window.localStorage.getItem('token'); + role_name = window.localStorage.getItem('role_name'); + company_id = window.localStorage.getItem('company_id'); + } super(props) + this.config = { + headers: { + Authorization: `Bearer ${token}`, + "Content-type": "application/json" + } + }; this.state = { alertDelete: false, alertNotDelete: false, @@ -58,9 +63,9 @@ class index extends Component { tooltipTambah: false, totalPage: 0, typeDialog: 'Save', - company_id: company_id + company_id: company_id, + role_name: role_name } - this.columns = [ { title: this.props.t('action'), @@ -117,7 +122,7 @@ class index extends Component { "joins": [], "orders": { "columns": ["id"], "ascending": false } } - if (role_name !== "Super Admin") { + if (this.state.role_name !== "Super Admin") { formData.columns.push( { "name": "company_id", "logic_operator": "=", "value": this.state.company_id, "operator": "AND" }, ) @@ -127,7 +132,7 @@ class index extends Component { ) } const result = await axios - .post(ROLE_SEARCH, formData, config) + .post(ROLE_SEARCH, formData, this.config) .then(res => res) .catch((error) => error.response); @@ -172,7 +177,7 @@ class index extends Component { const { idDelete } = this.state const url = ROLE_DELETE(idDelete) - const result = await axios.delete(url, config) + const result = await axios.delete(url, this.config) .then(res => res) .catch((error) => error.response); @@ -193,10 +198,10 @@ class index extends Component { name: data.name, description: data.description, default_page: data.selectedMenu, - company_id: company_id + company_id: this.company_id } - const result = await axios.post(ROLE_ADD, formData, config) + const result = await axios.post(ROLE_ADD, formData, this.config) .then(res => res) .catch((error) => error.response); @@ -216,7 +221,7 @@ class index extends Component { default_page: data.selectedMenu } const url = ROLE_EDIT(data.id) - const result = await axios.put(url, formData, config) + const result = await axios.put(url, formData, this.config) .then(res => res) .catch((error) => error.response); @@ -285,7 +290,7 @@ class index extends Component { } const result = await axios - .post(ROLEMENU_SEARCH, formData, config) + .post(ROLEMENU_SEARCH, formData, this.config) .then(res => res) .catch((error) => error.response); if (result && result.data && result.data.code == 200) { @@ -309,7 +314,7 @@ class index extends Component { menu_id: val.menu_id, role_id: val.roles_id } - promises.push(axios.post(ROLEMENU_ADD, formData, config) + promises.push(axios.post(ROLEMENU_ADD, formData, this.config) .then(res => result.push(res))) } }) @@ -329,7 +334,7 @@ class index extends Component { deleteCurrentRoleMenu = async (id) => { let urlDel = ROLEMENU_DELETE_ROLE(id) - const result = await axios.delete(urlDel, config) + const result = await axios.delete(urlDel, this.config) .then(res => res) .catch((error) => error.response); if (result && result.data && result.data.code === 200) { @@ -352,7 +357,7 @@ class index extends Component { } const result = await axios - .post(ROLE_SEARCH, formData, config) + .post(ROLE_SEARCH, formData, this.config) .then(res => res) .catch((error) => error.response); diff --git a/src/views/Master/ProjectPhase/index.js b/src/views/Master/ProjectPhase/index.js index 56a3821..8d80b93 100644 --- a/src/views/Master/ProjectPhase/index.js +++ b/src/views/Master/ProjectPhase/index.js @@ -9,27 +9,27 @@ import { NotificationContainer, NotificationManager } from 'react-notifications' import { PROJECT_PHASE_ADD, PROJECT_PHASE_EDIT, PROJECT_PHASE_DELETE, PROJECT_PHASE_SEARCH, PROJECT_PHASE_LIST, BASE_OSPRO } from '../../../const/ApiConst'; import { Pagination, Button, Tooltip, Table } from 'antd'; import { useTranslation } from 'react-i18next'; -const token = window.localStorage.getItem('token'); -const company_id = window.localStorage.getItem('company_id'); -const role_name = window.localStorage.getItem('role_name'); -const config = { - headers: - { - Authorization: `Bearer ${token}`, - "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", + + +const ProjectPhase = ({ params, ...props }) => { + let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; + if (props.location.state && props.location.state.role_id && props.location.state.user_id) { + role_id = props.location.state.role_id; + user_id = props.location.state.user_id; + token = props.location.state.token; + isLogin = props.location.state.isLogin; + role_name = props.location.state.role_name; + } else { + role_id = localStorage.getItem("role_id"); + proyek_id = localStorage.getItem("proyek_id"); + user_id = localStorage.getItem("user_id"); + token = localStorage.getItem("token"); + isLogin = localStorage.getItem("isLogin"); + company_id = localStorage.getItem('company_id'); + role_name = localStorage.getItem('role_name'); } -}; -const ProjectPhase = ({ params }) => { - const token = localStorage.getItem("token") - const company_id = localStorage.getItem("company_id") - /*const HEADER = { - headers: { - "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8", - "Access-Control-Allow-Origin": "*", - "Authorization": `Bearer ${token}` - } - }*/ + console.log('company_id', company_id); const HEADER = { headers: { "Content-Type": "application/json", @@ -257,7 +257,7 @@ const ProjectPhase = ({ params }) => { const onConfirmDelete = async () => { let url = PROJECT_PHASE_DELETE(idDelete); - const result = await axios.delete(url, config) + const result = await axios.delete(url, HEADER) .then(res => res) .catch((error) => error.response); diff --git a/src/views/Master/RoleProject/index.js b/src/views/Master/RoleProject/index.js index d96c1d7..1a91e10 100644 --- a/src/views/Master/RoleProject/index.js +++ b/src/views/Master/RoleProject/index.js @@ -35,6 +35,19 @@ const LENGTH_DATA = 10 class index extends Component { constructor(props) { + let role_id = '', user_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; + if (props.location.state && props.location.state.role_id && props.location.state.user_id) { + role_id = props.location.state.role_id; + user_id = props.location.state.user_id; + token = props.location.state.token; + isLogin = props.location.state.isLogin; + company_id = props.location.state.company_id; + role_name = props.location.state.role_name; + } else { + token = window.localStorage.getItem('token'); + role_name = window.localStorage.getItem('role_name'); + company_id = window.localStorage.getItem('company_id'); + } super(props) this.state = { alertDelete: false, @@ -61,7 +74,8 @@ class index extends Component { tooltipTambah: false, totalPage: 0, typeDialog: 'Save', - company_id + company_id: company_id, + role_name: role_name } this.columns = [ { @@ -115,7 +129,7 @@ class index extends Component { "joins": [], "orders": { "columns": ["id"], "ascending": false } } - if (role_name !== "Super Admin") { + if (this.state.role_name !== "Super Admin") { formData.columns.push( { "name": "company_id", "logic_operator": "=", "value": this.state.company_id, "operator": "AND" }, ) diff --git a/src/views/Pages/Login/Login.js b/src/views/Pages/Login/Login.js index 9b64976..f3c7379 100644 --- a/src/views/Pages/Login/Login.js +++ b/src/views/Pages/Login/Login.js @@ -133,7 +133,7 @@ class Login extends Component { } } - getDataMenu = async (token, role_id, user_id) => { + getDataMenu = async (token, role_id, user_id, company_id, role_name) => { const config = { headers: { @@ -159,14 +159,14 @@ class Login extends Component { else { this.props.history.push({ pathname: "/dashboard", - state: { role_id: role_id, user_id: user_id, token: token, isLogin: true } + state: { role_id: role_id, user_id: user_id, token: token, isLogin: true, company_id: company_id, role_name: role_name } }); } if (this.state.defaultPage) { if (role_id === 44) { this.props.history.push({ pathname: this.state.defaultPage, - state: { role_id: role_id, user_id: user_id, token: token, isLogin: true } + state: { role_id: role_id, user_id: user_id, token: token, isLogin: true, company_id: company_id, role_name: role_name } }); } else { this.props.history.push(this.state.defaultPage); @@ -177,7 +177,7 @@ class Login extends Component { else { this.props.history.push({ pathname: "/dashboard", - state: { role_id: role_id, user_id: user_id, token: token, isLogin: true } + state: { role_id: role_id, user_id: user_id, token: token, isLogin: true, company_id: company_id, role_name: role_name } }); } } else { @@ -222,7 +222,7 @@ class Login extends Component { if (doLogin && doLogin.data && doLogin.data.code === 200) { const { access_token, data_user } = doLogin.data.data this.getDataRole(access_token, data_user.role_id) - this.getDataMenu(access_token, data_user.role_id, data_user.id) + this.getDataMenu(access_token, data_user.role_id, data_user.id, data_user.company_id, data_user.role.name) window.localStorage.setItem('isLogin', true); window.localStorage.setItem('token', access_token); window.localStorage.setItem('user_id', data_user.id); diff --git a/src/views/SimproV2/Divisi/index.js b/src/views/SimproV2/Divisi/index.js index 89b0b79..08a4d0d 100644 --- a/src/views/SimproV2/Divisi/index.js +++ b/src/views/SimproV2/Divisi/index.js @@ -9,20 +9,6 @@ import { NotificationContainer, NotificationManager } from 'react-notifications' import { Pagination, Button, Tooltip } from 'antd'; import { useTranslation } from 'react-i18next'; -const url = ""; -const proyek_id = localStorage.getItem('proyek_id'); -const role_id = localStorage.getItem('role_id'); -const company_id = localStorage.getItem("company_id") -const role_name = window.localStorage.getItem('role_name'); -const format = "DD-MM-YYYY"; -const token = window.localStorage.getItem('token'); -const config = { - headers: - { - Authorization: `Bearer ${token}`, - "Content-type": `application/json` - } -}; const column = [ { name: "Nama" }, @@ -30,8 +16,23 @@ const column = [ { name: "Color" }, ] -const ProjectType = ({ params }) => { - const token = localStorage.getItem("token") +const ProjectType = ({ params, ...props }) => { + let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; + if (props.location.state && props.location.state.role_id && props.location.state.user_id) { + role_id = props.location.state.role_id; + user_id = props.location.state.user_id; + token = props.location.state.token; + isLogin = props.location.state.isLogin; + role_name = props.location.state.role_name; + } else { + role_id = localStorage.getItem("role_id"); + proyek_id = localStorage.getItem("proyek_id"); + user_id = localStorage.getItem("user_id"); + token = localStorage.getItem("token"); + isLogin = localStorage.getItem("isLogin"); + company_id = localStorage.getItem('company_id'); + role_name = localStorage.getItem('role_name'); + } const HEADER = { headers: { "Content-Type": "application/json", @@ -256,7 +257,7 @@ const ProjectType = ({ params }) => { const onConfirmDelete = async () => { let url = DIVISI_DELETE(idDelete); - const result = await axios.delete(url, config) + const result = await axios.delete(url, HEADER) .then(res => res) .catch((error) => error.response); diff --git a/src/views/SimproV2/Gantt/index.js b/src/views/SimproV2/Gantt/index.js index b46b34d..4693f66 100644 --- a/src/views/SimproV2/Gantt/index.js +++ b/src/views/SimproV2/Gantt/index.js @@ -15,7 +15,7 @@ import GanttFrame from "./GanttFrame"; let roCount = 0; const Gantt = (props) => { - let role_id = '', userId='',isLogin='',token=''; + let role_id = '', userId = '', isLogin = '', token = ''; if (props.location.state && props.location.state.role_id && props.location.state.user_id) { role_id = props.location.state.role_id; userId = props.location.state.user_id; @@ -56,7 +56,7 @@ const Gantt = (props) => { cekPermission(); }, [listUserGant]); - useEffect(() => {}, [ro]); + useEffect(() => { }, [ro]); const getDataUserGantt = async () => { const payload = { @@ -94,7 +94,7 @@ const Gantt = (props) => { }; const cekPermission = () => { - let check = listUserGant.includes(userId); + let check = listUserGant.includes(parseInt(userId)); if (check) { setRo(0); } else { diff --git a/src/views/SimproV2/ProjectType/index.js b/src/views/SimproV2/ProjectType/index.js index 408fb93..9ca0621 100644 --- a/src/views/SimproV2/ProjectType/index.js +++ b/src/views/SimproV2/ProjectType/index.js @@ -11,28 +11,24 @@ import { NotificationContainer, NotificationManager } from 'react-notifications' import { PROJECT_TYPE_ADD, PROJECT_TYPE_EDIT, PROJECT_TYPE_DELETE, PROJECT_TYPE_SEARCH } from '../../../const/ApiConst'; import { Pagination, Button, Tooltip, Table } from 'antd'; import { useTranslation } from 'react-i18next'; -const url = ""; -const proyek_id = localStorage.getItem('proyek_id'); -const role_id = localStorage.getItem('role_id'); -const format = "DD-MM-YYYY"; -const token = window.localStorage.getItem('token'); -const company_id = window.localStorage.getItem('company_id'); -const role_name = window.localStorage.getItem('role_name'); -const config = { - headers: - { - Authorization: `Bearer ${token}`, - "Content-type": `application/json` - } -}; - -const column = [ - { name: "Nama" }, - { name: "Deskripsi" }, -] -const ProjectType = ({ params }) => { - const token = localStorage.getItem("token") +const ProjectType = ({ params, ...props }) => { + let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; + if (props.location.state && props.location.state.role_id && props.location.state.user_id) { + role_id = props.location.state.role_id; + user_id = props.location.state.user_id; + token = props.location.state.token; + isLogin = props.location.state.isLogin; + role_name = props.location.state.role_name; + } else { + role_id = localStorage.getItem("role_id"); + proyek_id = localStorage.getItem("proyek_id"); + user_id = localStorage.getItem("user_id"); + token = localStorage.getItem("token"); + isLogin = localStorage.getItem("isLogin"); + company_id = localStorage.getItem('company_id'); + role_name = localStorage.getItem('role_name'); + } const HEADER = { headers: { "Content-Type": "application/json", @@ -106,7 +102,7 @@ const ProjectType = ({ params }) => { ) } const result = await axios - .post(PROJECT_TYPE_SEARCH, payload, config, HEADER) + .post(PROJECT_TYPE_SEARCH, payload, HEADER, HEADER) .then(res => res) .catch((error) => error.response); @@ -263,7 +259,7 @@ const ProjectType = ({ params }) => { const onConfirmDelete = async () => { let url = PROJECT_TYPE_DELETE(idDelete); - const result = await axios.delete(url, config) + const result = await axios.delete(url, HEADER) .then(res => res) .catch((error) => error.response); diff --git a/src/views/SimproV2/ResourceWorker/index.js b/src/views/SimproV2/ResourceWorker/index.js index a466811..e7e9c78 100644 --- a/src/views/SimproV2/ResourceWorker/index.js +++ b/src/views/SimproV2/ResourceWorker/index.js @@ -13,24 +13,25 @@ import { PROYEK_SEARCH, USER_ADD, USER_SEARCH, USER_EDIT, USER_DELETE, ROLE_SEARCH, DIVISI_SEARCH, USER_SHIFT_ADD, USER_SYNC } from '../../../const/ApiConst'; import { useTranslation } from 'react-i18next'; -const url = ""; -const proyek_id = localStorage.getItem('proyek_id'); -const role_id = localStorage.getItem('role_id'); -const format = "DD-MM-YYYY"; -const token = window.localStorage.getItem('token'); - -const config = { - headers: - { - Authorization: `Bearer ${token}`, - "Content-type": `application/json` + +const ResourceWorker = ({ params, ...props }) => { + let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; + if (props.location.state && props.location.state.role_id && props.location.state.user_id) { + role_id = props.location.state.role_id; + user_id = props.location.state.user_id; + token = props.location.state.token; + isLogin = props.location.state.isLogin; + role_name = props.location.state.role_name; + } else { + role_id = localStorage.getItem("role_id"); + proyek_id = localStorage.getItem("proyek_id"); + user_id = localStorage.getItem("user_id"); + token = localStorage.getItem("token"); + isLogin = localStorage.getItem("isLogin"); + company_id = localStorage.getItem('company_id'); + role_name = localStorage.getItem('role_name'); } -}; -const role_name = window.localStorage.getItem('role_name'); -const company_id = window.localStorage.getItem('company_id'); -const ResourceWorker = ({ params }) => { - const token = localStorage.getItem("token") - const company_id = localStorage.getItem("company_id") + const HEADER = { headers: { "Content-Type": "application/json", @@ -90,7 +91,7 @@ const ResourceWorker = ({ params }) => { } const result = await axios - .post(ROLE_SEARCH, formData, config) + .post(ROLE_SEARCH, formData, HEADER) .then(res => res) .catch((error) => error.response); @@ -106,7 +107,7 @@ const ResourceWorker = ({ params }) => { } const result = await axios - .post(DIVISI_SEARCH, formData, config) + .post(DIVISI_SEARCH, formData, HEADER) .then(res => res) .catch((error) => error.response); @@ -215,7 +216,7 @@ const ResourceWorker = ({ params }) => { } const result = await axios - .post(USER_SEARCH, payload, config) + .post(USER_SEARCH, payload, HEADER) .then(res => res) .catch((error) => error.response); @@ -468,7 +469,7 @@ const ResourceWorker = ({ params }) => { const onConfirmDelete = async () => { let url = USER_DELETE(idDelete); - const result = await axios.delete(url, config) + const result = await axios.delete(url, HEADER) .then(res => res) .catch((error) => error.response); diff --git a/src/views/SimproV2/Satuan/index.js b/src/views/SimproV2/Satuan/index.js index 6db7072..f849360 100644 --- a/src/views/SimproV2/Satuan/index.js +++ b/src/views/SimproV2/Satuan/index.js @@ -9,20 +9,24 @@ import { Pagination, Button, Tooltip } from 'antd'; import { SATUAN_ADD, SATUAN_EDIT, SATUAN_DELETE, SATUAN_SEARCH } from '../../../const/ApiConst'; import { useTranslation } from 'react-i18next'; -const token = window.localStorage.getItem('token'); -const company_id = window.localStorage.getItem('company_id'); -const role_name = window.localStorage.getItem('role_name'); -const config = { - headers: - { - Authorization: `Bearer ${token}`, - "Content-type": `application/json` - } -}; -const Satuan = ({ params }) => { - const token = localStorage.getItem("token") - const company_id = localStorage.getItem("company_id") +const Satuan = ({ params, ...props }) => { + let role_id = '', user_id = '', proyek_id = '', isLogin = '', token = '', company_id = 0, role_name = ''; + if (props.location.state && props.location.state.role_id && props.location.state.user_id) { + role_id = props.location.state.role_id; + user_id = props.location.state.user_id; + token = props.location.state.token; + isLogin = props.location.state.isLogin; + role_name = props.location.state.role_name; + } else { + role_id = localStorage.getItem("role_id"); + proyek_id = localStorage.getItem("proyek_id"); + user_id = localStorage.getItem("user_id"); + token = localStorage.getItem("token"); + isLogin = localStorage.getItem("isLogin"); + company_id = localStorage.getItem('company_id'); + role_name = localStorage.getItem('role_name'); + } const HEADER = { headers: { "Content-Type": "application/json", @@ -101,7 +105,7 @@ const Satuan = ({ params }) => { const result = await axios - .post(SATUAN_SEARCH, payload, config) + .post(SATUAN_SEARCH, payload, HEADER) .then(res => res) .catch((error) => error.response); if (result && result.data && result.data.code == 200) { @@ -132,7 +136,7 @@ const Satuan = ({ params }) => { "orders": { "columns": ["id"], "ascending": false } } const result = await axios - .post(SATUAN_SEARCH, payload, config) + .post(SATUAN_SEARCH, payload, HEADER) .then(res => res) .catch((error) => error.response); if (result && result.data && result.data.code == 200) { @@ -218,7 +222,7 @@ const Satuan = ({ params }) => { const onConfirmDelete = async () => { let url = SATUAN_DELETE(idDelete); - const result = await axios.delete(url, config) + const result = await axios.delete(url, HEADER) .then(res => res) .catch((error) => error.response);