Browse Source

Merge pull request 'handle customer login' (#184) from dev-wahyun into staging

Reviewed-on: ordo/adw-frontend#184
pull/1/head
farhantock 1 year ago
parent
commit
3aefa1c3a8
  1. 23
      src/views/Pages/Login/Login.js
  2. 35
      src/views/SimproV2/CreatedProyek/index.js

23
src/views/Pages/Login/Login.js

@ -133,7 +133,7 @@ class Login extends Component {
}
}
getDataMenu = async (token, role_id) => {
getDataMenu = async (token, role_id,user_id) => {
const config = {
headers:
{
@ -157,15 +157,28 @@ class Login extends Component {
this.props.history.push("/dashboard-customer/58/63");
}
else {
this.props.history.push("/dashboard");
this.props.history.push({
pathname: "/dashboard",
state: { role_id: role_id, user_id: user_id }
});
}
if (this.state.defaultPage) {
this.props.history.push(this.state.defaultPage);
if (role_id === 44) {
this.props.history.push({
pathname: this.state.defaultPage,
state: { role_id: role_id, user_id: user_id }
});
} else {
this.props.history.push(this.state.defaultPage);
}
} else if (role_id == 28) {
this.props.history.push("/dashboard-customer/58/63");
}
else {
this.props.history.push("/dashboard");
this.props.history.push({
pathname: "/dashboard",
state: { role_id: role_id, user_id: user_id }
});
}
} else {
NotificationManager.error('Login Failed', 'Failed');
@ -209,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)
this.getDataMenu(access_token, data_user.role_id, data_user.id)
window.localStorage.setItem('isLogin', true);
window.localStorage.setItem('token', access_token);
window.localStorage.setItem('user_id', data_user.id);

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

@ -89,17 +89,27 @@ import AssignK3Project from "./AssignK3Project";
import ViewProject from "./ViewProject";
import ReportAnalysis from "./ReportAnalysis";
import { Icon } from "@iconify/react";
// import { Link } from 'react-router-dom';
// import SubProyekComp from './SubProyekComp';
import { Link, useHistory } from "react-router-dom";
import { Link, useHistory, withRouter } from "react-router-dom";
const url = "";
const proyek_id = localStorage.getItem("proyek_id");
const role_id = localStorage.getItem("role_id");
const user_id = localStorage.getItem("user_id");
// const proyek_id = localStorage.getItem("proyek_id");
// const role_id = localStorage.getItem("role_id");
// const user_id = localStorage.getItem("user_id");
const format = "DD-MM-YYYY";
const CreatedProyek = ({ params, ...props }) => {
let role_id = '', user_id='',proyek_id='';
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;
console.log('role_id:', role_id);
} else {
role_id = localStorage.getItem("role_id");
proyek_id = localStorage.getItem("proyek_id");
user_id = localStorage.getItem("user_id");
console.error('Role ID is undefined in props.location.state');
}
const history = useHistory();
const token = localStorage.getItem("token");
const HEADER = {
@ -200,7 +210,7 @@ const CreatedProyek = ({ params, ...props }) => {
}, [openDialogProyek]);
useEffect(() => {
role_id !== "44" ? getDataProyek() : getDataProyekByCustomer();
parseInt(role_id) !== 44 ? getDataProyek() : getDataProyekByCustomer();
}, [search, rowsPerPage, currentPage]);
useEffect(() => {
@ -894,7 +904,7 @@ const CreatedProyek = ({ params, ...props }) => {
.catch((error) => error.response);
if (result && result.data && result.data.code === 200) {
role_id !== "44" ? getDataProyek() : getDataProyekByCustomer();
parseInt(role_id) !== 44 ? getDataProyek() : getDataProyekByCustomer();
getProjectImage(idDelete);
deleteImage(idDelete);
setIdDelete(0);
@ -965,7 +975,7 @@ const CreatedProyek = ({ params, ...props }) => {
NotificationManager.success(`${result.data.message}`, "Success!!");
}
role_id !== "44" ? getDataProyek() : getDataProyekByCustomer();
parseInt(role_id) !== 44 ? getDataProyek() : getDataProyekByCustomer();
} else {
NotificationManager.error(`${result.data.message}`, "Failed!!");
}
@ -1144,7 +1154,7 @@ const CreatedProyek = ({ params, ...props }) => {
);
}
if (result && result.status === 200) {
role_id !== "44" ? getDataProyek() : getDataProyekByCustomer();
parseInt(role_id) !== 44 ? getDataProyek() : getDataProyekByCustomer();
NotificationManager.success(`Data proyek berhasil Ubah`, "Success!!");
} else {
NotificationManager.error(`${result.data.message}`, "Failed!!");
@ -1618,7 +1628,7 @@ const CreatedProyek = ({ params, ...props }) => {
dataIndex: "",
key: "x",
render: (text, record) =>
role_id == "44" ? (
parseInt(role_id) == 44 ? (
<>
<Tooltip title="Dashboard Project">
<Button
@ -1997,7 +2007,7 @@ const CreatedProyek = ({ params, ...props }) => {
/>
</Col>
<Col>
{role_id == "44" ? null : ( // role kustomer
{parseInt(role_id) == 44 ? null : ( // role kustomer
<Tooltip title="Add Project">
<Button
style={{ background: "#4caf50", color: "#fff" }}
@ -2068,5 +2078,4 @@ const CreatedProyek = ({ params, ...props }) => {
</div>
);
};
export default CreatedProyek;
export default withRouter(CreatedProyek);

Loading…
Cancel
Save