Browse Source

Merge pull request 'default page' (#135) from dev-wahyu into staging

Reviewed-on: ordo/adw-frontend#135
pull/2/head
farhantock 11 months ago
parent
commit
eb294bc2e0
  1. 63
      src/views/Master/MasterRoles/DialogForm.js
  2. 6
      src/views/Master/MasterRoles/index.js
  3. 49
      src/views/Pages/Login/Login.js

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

@ -3,6 +3,19 @@ import { Modal, ModalHeader, ModalBody, ModalFooter, Row, Col } from 'reactstrap
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 { withTranslation } from 'react-i18next'; import { withTranslation } from 'react-i18next';
import axios from 'axios';
import { Select } from 'antd';
import { MENU_SEARCH } from '../../../const/ApiConst.js';
const { Option } = Select
const token = window.localStorage.getItem('token');
const config = {
headers:
{
Authorization: `Bearer ${token}`,
"Content-type": `application/json`
}
};
class DialogForm extends Component { class DialogForm extends Component {
constructor(props) { constructor(props) {
@ -13,11 +26,14 @@ class DialogForm extends Component {
description: "", description: "",
openDialog: false, openDialog: false,
isParentClick: false, isParentClick: false,
menu: [],
selectedMenu: null
} }
} }
async componentDidMount() { async componentDidMount() {
this.props.showDialog(this.showDialog); this.props.showDialog(this.showDialog);
this.getAllMenu();
} }
async componentDidUpdate() { async componentDidUpdate() {
@ -27,19 +43,38 @@ class DialogForm extends Component {
this.setState({ this.setState({
id: dataEdit.id, id: dataEdit.id,
name: dataEdit.name, name: dataEdit.name,
description: dataEdit.description description: dataEdit.description,
selectedMenu: dataEdit.default_page
}) })
} else { } else {
this.setState({ this.setState({
id: 0, id: 0,
name: "", name: "",
description: "" description: "",
selectedMenu: null
}) })
} }
this.setState({ isParentClick: false }); this.setState({ isParentClick: false });
} }
} }
getAllMenu = async () => {
const payload = {
"paging": { "start": 0, "length": -1 },
"columns": [
{ "name": "name", "logic_operator": "ilike", "value": "", "operator": "AND" }
],
"joins": [],
"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 });
}
}
showDialog = () => { showDialog = () => {
this.setState({ isParentClick: true }); this.setState({ isParentClick: true });
@ -60,7 +95,8 @@ class DialogForm extends Component {
const { const {
id, id,
name, name,
description description,
selectedMenu
} = this.state } = this.state
let data = ''; let data = '';
@ -70,14 +106,16 @@ class DialogForm extends Component {
data = { data = {
id, id,
name, name,
description description,
selectedMenu
} }
this.props.closeDialog('save', data); this.props.closeDialog('save', data);
} else { } else {
data = { data = {
id, id,
name, name,
description description,
selectedMenu
} }
this.props.closeDialog('edit', data); this.props.closeDialog('edit', data);
} }
@ -113,6 +151,21 @@ class DialogForm extends Component {
<Input type="text" value={this.state.description} onChange={(e) => this.setState({ description: e.target.value })} placeholder={this.props.t('inputDescription')} /> <Input type="text" value={this.state.description} onChange={(e) => this.setState({ description: e.target.value })} placeholder={this.props.t('inputDescription')} />
</FormGroup> </FormGroup>
</Col> </Col>
<Col md={12}>
<FormGroup>
<Label>Default Page<span style={{ color: "red" }}>*</span></Label>
<Input type="select" value={this.state.selectedMenu} placeholder={"Select default page"}
onChange={(e) => {
this.setState({ selectedMenu: e.target.value });
}}>
{this.state.menu.map((item) => (
<option key={item.id} value={item.id}>
{item.name}
</option>
))}
</Input>
</FormGroup>
</Col>
</Row> </Row>
</Form> </Form>
) )

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

@ -179,7 +179,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
} }
const result = await axios.post(ROLE_ADD, formData, config) const result = await axios.post(ROLE_ADD, formData, config)
@ -198,7 +199,8 @@ class index extends Component {
editRole = async (data) => { editRole = async (data) => {
const formData = { const formData = {
name: data.name, name: data.name,
description: data.description description: data.description,
default_page: data.selectedMenu
} }
const url = ROLE_EDIT(data.id) const url = ROLE_EDIT(data.id)
const result = await axios.put(url, formData, config) const result = await axios.put(url, formData, config)

49
src/views/Pages/Login/Login.js

@ -27,7 +27,7 @@ import {
CarouselItem, CarouselItem,
CarouselControl CarouselControl
} from 'reactstrap'; } from 'reactstrap';
import { USER_LOGIN, USER_LOGIN_V2, CALERTUSER_SEARCH, MENU_MANAGEMENT, APP_MODE } from '../../../const/ApiConst.js'; import { USER_LOGIN, USER_LOGIN_V2, CALERTUSER_SEARCH, MENU_MANAGEMENT, APP_MODE, ROLE_SEARCH } from '../../../const/ApiConst.js';
import { appConfig, reloadConstants } from '../../../const/MapConst.js'; import { appConfig, reloadConstants } from '../../../const/MapConst.js';
import { APP_NAME } from '../../../const/AppConst.js' import { APP_NAME } from '../../../const/AppConst.js'
import moment from "moment" import moment from "moment"
@ -65,7 +65,8 @@ class Login extends Component {
emailState: '', emailState: '',
}, },
loader: false, loader: false,
type: 'password' type: 'password',
defaultPage: ''
} }
this.handleChange = this.handleChange.bind(this); this.handleChange = this.handleChange.bind(this);
this.showHide = this.showHide.bind(this); this.showHide = this.showHide.bind(this);
@ -97,6 +98,41 @@ class Login extends Component {
}); });
} }
getDataRole = async (token, role_id) => {
const config = {
headers:
{
Authorization: `Bearer ${token}`,
"Content-type": `application/json`
}
};
const payload = {
"paging": { "start": 0, "length": -1 },
"columns": [
{ "name": "id", "logic_operator": "=", "value": `${role_id}`, "operator": "AND" }
],
"joins": [
{
"name": "m_menu",
"column_join": "default_page",
"column_results": ["id", "name", "url"],
},
],
"orders": { "columns": ["id"], "ascending": false }
}
const result = await axios
.post(ROLE_SEARCH, payload, config)
.then(res => res)
.catch((error) => error.response);
if (result && result.data && result.data.code == 200) {
let resData = result.data.data
this.setState({defaultPage: resData[0].join_first_url})
}
}
getDataMenu = async (token, role_id) => { getDataMenu = async (token, role_id) => {
const config = { const config = {
headers: headers:
@ -123,6 +159,14 @@ class Login extends Component {
else { else {
this.props.history.push("/dashboard"); this.props.history.push("/dashboard");
} }
if (this.state.defaultPage) {
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");
}
} else { } else {
NotificationManager.error('Login Failed', 'Failed'); NotificationManager.error('Login Failed', 'Failed');
this.setState({ loader: false }) this.setState({ loader: false })
@ -164,6 +208,7 @@ class Login extends Component {
if (doLogin && doLogin.data && doLogin.data.code === 200) { if (doLogin && doLogin.data && doLogin.data.code === 200) {
const { access_token, data_user } = doLogin.data.data 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)
window.localStorage.setItem('isLogin', true); window.localStorage.setItem('isLogin', true);
window.localStorage.setItem('token', access_token); window.localStorage.setItem('token', access_token);

Loading…
Cancel
Save