Commit 60fd0171 authored by faisalhamdi's avatar faisalhamdi

Merge branch 'master' of http://103.44.149.204/d.arizona/tia-dev into faisal

parents a30c5bfb 586128e4
...@@ -2544,6 +2544,13 @@ ...@@ -2544,6 +2544,13 @@
"requires": { "requires": {
"axios": "^0.19.0", "axios": "^0.19.0",
"ramda": "^0.25.0" "ramda": "^0.25.0"
},
"dependencies": {
"ramda": {
"version": "0.25.0",
"resolved": "https://registry.npmjs.org/ramda/-/ramda-0.25.0.tgz",
"integrity": "sha512-GXpfrYVPwx3K7RQ6aYT8KPS8XViSXUVJT1ONhoKPE9VAleW42YE+U+8VEyGWt41EnEQW7gwecYJriTI0pKoecQ=="
}
} }
}, },
"aproba": { "aproba": {
...@@ -11559,9 +11566,9 @@ ...@@ -11559,9 +11566,9 @@
} }
}, },
"ramda": { "ramda": {
"version": "0.25.0", "version": "0.27.1",
"resolved": "https://registry.npmjs.org/ramda/-/ramda-0.25.0.tgz", "resolved": "https://registry.npmjs.org/ramda/-/ramda-0.27.1.tgz",
"integrity": "sha512-GXpfrYVPwx3K7RQ6aYT8KPS8XViSXUVJT1ONhoKPE9VAleW42YE+U+8VEyGWt41EnEQW7gwecYJriTI0pKoecQ==" "integrity": "sha512-PgIdVpn5y5Yns8vqb8FzBUEYn98V3xcPgawAkkgj0YJ0qDsnHCiNmZYfOGMgOvoB0eWFLpYbhxUR3mxfDIMvpw=="
}, },
"randombytes": { "randombytes": {
"version": "2.1.0", "version": "2.1.0",
......
...@@ -26,7 +26,7 @@ ...@@ -26,7 +26,7 @@
work correctly both with client-side routing and a non-root public URL. work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`. Learn how to configure a non-root public URL by running `npm run build`.
--> -->
<title>React App</title> <title>TIA App</title>
</head> </head>
<body> <body>
<noscript>You need to enable JavaScript to run this app.</noscript> <noscript>You need to enable JavaScript to run this app.</noscript>
......
{ {
"short_name": "React App", "short_name": "TIA App",
"name": "Create React App Sample", "name": "TIA App",
"icons": [ "icons": [
{ {
"src": "favicon.ico", "src": "favicon.ico",
......
...@@ -7,6 +7,7 @@ import Grid from '@material-ui/core/Grid'; ...@@ -7,6 +7,7 @@ import Grid from '@material-ui/core/Grid';
import { Typography, Avatar } from '@material-ui/core'; import { Typography, Avatar } from '@material-ui/core';
import Images from '../assets/Images'; import Images from '../assets/Images';
import { Link, useRouteMatch } from 'react-router-dom'; import { Link, useRouteMatch } from 'react-router-dom';
import Constant from '../library/Constant';
const useStyles = makeStyles({ const useStyles = makeStyles({
avatar: { avatar: {
...@@ -29,10 +30,14 @@ function FadeMenu() { ...@@ -29,10 +30,14 @@ function FadeMenu() {
const handleClose = () => { const handleClose = () => {
setAnchorEl(null); setAnchorEl(null);
localStorage.clear()
window.location.reload();
}; };
const handleLogout = () => {
localStorage.removeItem(Constant.TOKEN)
window.location.reload();
setAnchorEl(null);
}
const classes = useStyles(); const classes = useStyles();
let { path, url } = useRouteMatch(); let { path, url } = useRouteMatch();
...@@ -69,7 +74,7 @@ function FadeMenu() { ...@@ -69,7 +74,7 @@ function FadeMenu() {
</div> </div>
</Link> </Link>
</MenuItem> </MenuItem>
<MenuItem onClick={handleClose}> <MenuItem onClick={handleLogout}>
<div style={{ display: 'flex', padding: 10 }}> <div style={{ display: 'flex', padding: 10 }}>
<img src={Images.logout} style={{ height: 20, width: 20, marginRight: 20 }} /> <img src={Images.logout} style={{ height: 20, width: 20, marginRight: 20 }} />
<Typography>Logout</Typography> <Typography>Logout</Typography>
......
...@@ -62,29 +62,20 @@ export default class CreateApprovalMatrix extends Component { ...@@ -62,29 +62,20 @@ export default class CreateApprovalMatrix extends Component {
} }
componentDidMount() { componentDidMount() {
// console.log(this.props.data);
// let datas = this.props.data
// let userData = datas.map((item, index) => {
// return [item.fullname, item.user_id ]
// })
// console.log(userData)
this.getUserData() this.getUserData()
} }
getUserData() { getUserData() {
api.create().getApprovedByAM().then((response) => { api.create().getApprovedByAM().then((response) => {
// console.log("data masuk")
// console.log(response)
if (response.data.status == 'success') { if (response.data.status == 'success') {
let data = response.data.data let data = response.data.data
let userData = data.map((item) => { let userData = data.map((item) => {
// return [item.user_id, item.fullname]
return { return {
user_id: item.user_id, user_id: item.user_id,
fullname: item.fullname fullname: item.fullname
} }
}) })
console.log(userData) // console.log(userData)
let defaultProps = { let defaultProps = {
options: userData, options: userData,
getOptionLabel: (option) => option.fullname, getOptionLabel: (option) => option.fullname,
...@@ -95,6 +86,7 @@ export default class CreateApprovalMatrix extends Component { ...@@ -95,6 +86,7 @@ export default class CreateApprovalMatrix extends Component {
} }
}) })
} }
handleChange(e, type) { handleChange(e, type) {
let data = this.state let data = this.state
......
...@@ -53,26 +53,33 @@ export default class EditApprovalMatrix extends Component { ...@@ -53,26 +53,33 @@ export default class EditApprovalMatrix extends Component {
} }
} }
render() {
let { type } = this.props
return type === 'edit' ? this.renderEdit() : false
}
componentDidMount() { componentDidMount() {
console.log(this.props.data); if (this.props.type === 'edit') {
let data = this.props.data
this.setState({
id: data.business_unit_id,
name: data.business_unit_name,
startDate: data.start_date,
endDate: data.end_date
})
}
} }
handleChange(e, type) { handleChange(e, type) {
let data = this.state let data = this.state
let isDate = type !== ''? true : false let isDate = type !== '' ? true : false
if (isDate && type == 'start_date') { if (isDate && type == 'start_date') {
this.setState({...data, startDate : format(e, 'yyyy-MM-dd')}) this.setState({ startDate: format(e, 'yyyy-MM-dd') }, () => {
console.log(this.state.startDate)
})
} else if (isDate && type == 'end_date') { } else if (isDate && type == 'end_date') {
this.setState({...data, endDate : format(e, 'yyyy-MM-dd')}) this.setState({ endDate: format(e, 'yyyy-MM-dd') }, () => {
console.log(this.state.endDate)
})
} else { } else {
this.setState({...data, [e.target.name] : e.target.value}) // this.setState({...data, tempData: {...this.state.tempData, [e.target.name] : e.target.value}})
} }
} }
handleDate(item) { handleDate(item) {
...@@ -80,7 +87,7 @@ export default class EditApprovalMatrix extends Component { ...@@ -80,7 +87,7 @@ export default class EditApprovalMatrix extends Component {
return value return value
} }
renderEdit() { render() {
return ( return (
<div className="test app-popup-show" style={{ paddingTop: 100 }}> <div className="test app-popup-show" style={{ paddingTop: 100 }}>
<div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}> <div className="popup-content background-white border-radius" style={{ borderRadius: 8 }}>
......
...@@ -38,6 +38,7 @@ import Beranda from './Beranda'; ...@@ -38,6 +38,7 @@ import Beranda from './Beranda';
import { Avatar } from '@material-ui/core'; import { Avatar } from '@material-ui/core';
import HomeRoutes from '../router/homeRoutes' import HomeRoutes from '../router/homeRoutes'
import ArraySide from '../library/Array' import ArraySide from '../library/Array'
import Constant from '../library/Constant';
const drawerWidth = 307; const drawerWidth = 307;
...@@ -124,9 +125,10 @@ export default function MiniDrawer() { ...@@ -124,9 +125,10 @@ export default function MiniDrawer() {
const [open, setOpen] = React.useState(false); const [open, setOpen] = React.useState(false);
const [selectedIndex, setSelectedIndex] = React.useState([]); const [selectedIndex, setSelectedIndex] = React.useState([]);
React.useEffect(() => { // React.useEffect(() => {
// alert(ArraySide) // //
}) // })
const handleDrawerOpen = () => { const handleDrawerOpen = () => {
setOpen(true); setOpen(true);
}; };
...@@ -220,34 +222,36 @@ export default function MiniDrawer() { ...@@ -220,34 +222,36 @@ export default function MiniDrawer() {
} }
{open && {open &&
<div style={{ marginLeft: 20, marginTop: 20 }}> <div style={{ marginLeft: 20, marginTop: 20 }}>
<Typography style={{ color: 'white', fontSize: 12 }}>APLIKASI</Typography> <Typography style={{ color: 'white', fontSize: 14, fontFamily: 'nunito' }}>APLIKASI</Typography>
</div> </div>
} }
<List> <List>
{ArraySide.map((item, index) => ( {ArraySide.map((item, index) => (
<div style={{ marginTop: index === 0 ? null : 10}}> <div style={{ marginTop: index === 0 ? null : 10}}>
{item.subItem != null ? {item.subItem != null ?
<div style={{ justifyContent: 'space-between', flexDirection: 'row', display: 'flex', paddingRight: 10 }} onClick={() => selectedIndex == 0 ? setSelectedIndex(index) : setSelectedIndex(0)}> <div style={{ justifyContent: 'space-between', flexDirection: 'row', display: 'flex', paddingLeft: 10, paddingRight: 10 }} onClick={() => selectedIndex == 0 ? setSelectedIndex(index) : setSelectedIndex(0)}>
<ListItem button key={item.label}> <ListItem button key={item.label}>
<ListItemIcon><img src={item.img} /></ListItemIcon> <ListItemIcon><img src={item.img} /></ListItemIcon>
<Typography style={{ color: 'white', fontSize: 12 }}>{item.label}</Typography> <Typography style={{ fontFamily: 'nunito', color: 'white', fontSize: 14 }}>{item.label}</Typography>
</ListItem> </ListItem>
{item.subItem != null ? (index === selectedIndex ? <ExpandLess style={{ color: "white", marginLeft: 50, alignSelf: 'center' }} /> : <ExpandMore style={{ color: "white", marginLeft: 50, alignSelf: 'center' }} />) : null} {item.subItem != null ? (index === selectedIndex ? <ExpandLess style={{ color: "white", marginLeft: 50, alignSelf: 'center' }} /> : <ExpandMore style={{ color: "white", marginLeft: 50, alignSelf: 'center' }} />) : null}
</div> </div>
: :
item.label === 'PENGATURAN' ? item.label === 'PENGATURAN' ?
open ? open ?
<Link to={`${url}/${item.path}`}> <Link to={`${url}/${item.path}`}>
<ListItem button key={item.label} onClick={() => null}> <ListItem button key={item.label} onClick={() => null}>
<Typography style={{ color: 'white', fontSize: 12 }}>{item.label}</Typography> <Typography style={{ fontFamily: 'nunito', color: 'white', fontSize: 14 }}>{item.label}</Typography>
</ListItem> </ListItem>
</Link> : null : </Link> : null
:
<Link to={`${url}/${item.path}`}> <Link to={`${url}/${item.path}`}>
<ListItem button key={item.label} onClick={() => setSelectedIndex(index)}> <div style={{paddingLeft: 10}}>
<ListItemIcon><img src={item.img} /></ListItemIcon> <ListItem button key={item.label} onClick={() => setSelectedIndex(index)}>
<Typography style={{ color: 'white', fontSize: 12 }}>{item.label}</Typography> <ListItemIcon><img src={item.img} /></ListItemIcon>
</ListItem> <Typography style={{ fontFamily: 'nunito', color: 'white', fontSize: 14 }}>{item.label}</Typography>
</ListItem>
</div>
</Link> </Link>
} }
{item.subItem != null && {item.subItem != null &&
...@@ -257,9 +261,11 @@ export default function MiniDrawer() { ...@@ -257,9 +261,11 @@ export default function MiniDrawer() {
{item.subItem.map((sub, index) => { {item.subItem.map((sub, index) => {
return ( return (
<Link to={`${url}/${sub.path}`}> <Link to={`${url}/${sub.path}`}>
<ListItem style={{ paddingLeft: 72 }}> <div style={{paddingLeft: 10}}>
<Typography style={{ color: 'white', fontSize: 12 }}>{sub.label}</Typography> <ListItem style={{ paddingLeft: 72 }}>
</ListItem> <Typography style={{ fontFamily: 'nunito', color: 'white', fontSize: 14 }}>{sub.label}</Typography>
</ListItem>
</div>
</Link> </Link>
) )
})} })}
......
...@@ -28,12 +28,16 @@ class Login extends Component { ...@@ -28,12 +28,16 @@ class Login extends Component {
errorEmail: false, errorEmail: false,
errorPassword: false, errorPassword: false,
msgEmail: '', msgEmail: '',
msgPassword: '' msgPassword: '',
rememberMe: false
} }
} }
componentDidMount() { componentDidMount() {
// this.coba() this.getUser()
// localStorage.clear()
var email = localStorage.getItem(Constant.EMAIL)
console.log(email)
} }
handleChange(e) { handleChange(e) {
...@@ -53,7 +57,6 @@ class Login extends Component { ...@@ -53,7 +57,6 @@ class Login extends Component {
validateLogin() { validateLogin() {
var isEmail = this.isEmail(this.state.email) var isEmail = this.isEmail(this.state.email)
if (this.state.email.trim() == "") { if (this.state.email.trim() == "") {
this.setState({ errorEmail: true, msgEmail: 'Email harus diisi!' }) this.setState({ errorEmail: true, msgEmail: 'Email harus diisi!' })
} else if (!isEmail) { } else if (!isEmail) {
...@@ -73,6 +76,14 @@ class Login extends Component { ...@@ -73,6 +76,14 @@ class Login extends Component {
api.create().login(payload).then((response) => { api.create().login(payload).then((response) => {
if (response.data.status === 'success') { if (response.data.status === 'success') {
localStorage.setItem(Constant.TOKEN, response.data.data.token) localStorage.setItem(Constant.TOKEN, response.data.data.token)
if (this.state.rememberMe) {
localStorage.setItem(Constant.EMAIL, this.state.email)
localStorage.setItem(Constant.PASSWORD, this.state.password)
// console.log(this.state.email, this.state.password)
} else {
localStorage.setItem(Constant.EMAIL, '')
localStorage.setItem(Constant.PASSWORD, '')
}
this.props.history.push('/home/beranda') this.props.history.push('/home/beranda')
} else { } else {
if (response.data.message == 'Password Salah!') { if (response.data.message == 'Password Salah!') {
...@@ -84,6 +95,17 @@ class Login extends Component { ...@@ -84,6 +95,17 @@ class Login extends Component {
}) })
} }
getUser() {
var email = localStorage.getItem(Constant.EMAIL)
var password = localStorage.getItem(Constant.PASSWORD)
if (email == null || password == null) {
this.setState({email: '', password: ''})
} else if(email != '' && password != ''){
this.setState({email, password})
}
}
render() { render() {
return ( return (
<div style={{ flex: 1, display: 'flex' }}> <div style={{ flex: 1, display: 'flex' }}>
...@@ -141,7 +163,7 @@ class Login extends Component { ...@@ -141,7 +163,7 @@ class Login extends Component {
/> />
<div style={{ flexDirection: 'row', width: '100%', marginTop: this.state.errorPassword ? 26 : 16 }}> <div style={{ flexDirection: 'row', width: '100%', marginTop: this.state.errorPassword ? 26 : 16 }}>
<CustomCheckbox name="checked-remember" /> <CustomCheckbox name="checked-remember" checked={this.state.rememberMe} onChange={() => this.setState({rememberMe: !this.state.rememberMe})} />
<span style={{ color: 'rgba(0, 0, 0, 0.5)', fontSize: 12, fontFamily: 'Nunito Sans, sans-serif' }}>Remember Me</span> <span style={{ color: 'rgba(0, 0, 0, 0.5)', fontSize: 12, fontFamily: 'Nunito Sans, sans-serif' }}>Remember Me</span>
<Link to={{pathname: '/forgot-password'}} style={{textDecoration: 'none'}}><span style={{marginLeft: 30, color: '#51c6ea', cursor: 'pointer', fontSize: 12, fontFamily: 'Nunito Sans, sans-serif' }}>Lupa Kata Sandi?</span></Link> <Link to={{pathname: '/forgot-password'}} style={{textDecoration: 'none'}}><span style={{marginLeft: 30, color: '#51c6ea', cursor: 'pointer', fontSize: 12, fontFamily: 'Nunito Sans, sans-serif' }}>Lupa Kata Sandi?</span></Link>
</div> </div>
......
...@@ -6,6 +6,7 @@ import RemoveIcon from '@material-ui/icons/Remove'; ...@@ -6,6 +6,7 @@ import RemoveIcon from '@material-ui/icons/Remove';
import { DateTimePicker, KeyboardDatePicker, DatePicker} from "@material-ui/pickers"; import { DateTimePicker, KeyboardDatePicker, DatePicker} from "@material-ui/pickers";
import format from "date-fns/format"; import format from "date-fns/format";
import localeID from "date-fns/locale/id" import localeID from "date-fns/locale/id"
import * as R from 'ramda'
const CustomCheckbox = withStyles({ const CustomCheckbox = withStyles({
root: { root: {
...@@ -32,7 +33,13 @@ export default class AddRole extends Component { ...@@ -32,7 +33,13 @@ export default class AddRole extends Component {
roleName: '', roleName: '',
startDate: null, startDate: null,
endDate: null, endDate: null,
date: new Date() date: new Date(),
errorRoleName: false,
errorStartDate: false,
errorEndDate: false,
msgErrorRN: '',
msgErrorSD: '',
msgErrorED: '',
} }
} }
...@@ -48,16 +55,51 @@ export default class AddRole extends Component { ...@@ -48,16 +55,51 @@ export default class AddRole extends Component {
let data = this.state let data = this.state
let isDate = type !== ''? true : false let isDate = type !== ''? true : false
if (isDate && type == 'start_date') { if (isDate && type == 'start_date') {
this.setState({...data, startDate : format(e, 'yyyy-MM-dd')}) this.setState({...data, startDate: format(e, 'yyyy-MM-dd'), endDate: null,
errorRoleName: false,
errorStartDate: false,
errorEndDate: false,
msgErrorRN: '',
msgErrorSD: '',
msgErrorED: '',
})
} else if (isDate && type == 'end_date') { } else if (isDate && type == 'end_date') {
this.setState({...data, endDate : format(e, 'yyyy-MM-dd')}) this.setState({...data, endDate : format(e, 'yyyy-MM-dd'),
errorRoleName: false,
errorStartDate: false,
errorEndDate: false,
msgErrorRN: '',
msgErrorSD: '',
msgErrorED: '',
})
} else { } else {
this.setState({...data, [e.target.name] : e.target.value}) this.setState({...data, [e.target.name]: e.target.value,
errorRoleName: false,
errorStartDate: false,
errorEndDate: false,
msgErrorRN: '',
msgErrorSD: '',
msgErrorED: '',
})
} }
} }
updateRole() { validasi() {
if (R.isEmpty(this.state.roleName)) {
this.setState({errorRoleName: true, msgErrorRN: 'Role Name tidak boleh kosong'})
} else if (R.isNil(this.state.startDate)) {
this.setState({errorStartDate: true, msgErrorSD: 'Start Date tidak boleh kosong'})
} else if (R.isNil(this.state.endDate)) {
this.setState({errorEndDate: true, msgErrorED: 'End Date tidak boleh kosong'})
} else if (this.state.privileges.length < 1) {
alert('Hak Akses belum di pilih !!')
} else {
this.addRole()
}
}
addRole() {
// let startDate = format(this.state.tempData.start_date, 'yyyy-MM-dd') // let startDate = format(this.state.tempData.start_date, 'yyyy-MM-dd')
// let endDate = format(this.state.tempData.end_date, 'yyyy-MM-dd') // let endDate = format(this.state.tempData.end_date, 'yyyy-MM-dd')
let payload = { let payload = {
...@@ -199,6 +241,8 @@ export default class AddRole extends Component { ...@@ -199,6 +241,8 @@ export default class AddRole extends Component {
name="roleName" name="roleName"
label="User Role" label="User Role"
value={this.state.roleName} value={this.state.roleName}
error={this.state.errorRoleName}
helperText={this.state.msgErrorRN}
onChange={(e) => this.handleChange(e, '')} onChange={(e) => this.handleChange(e, '')}
// defaultValue="Default Value" // defaultValue="Default Value"
// helperText="Some important text" // helperText="Some important text"
...@@ -216,6 +260,8 @@ export default class AddRole extends Component { ...@@ -216,6 +260,8 @@ export default class AddRole extends Component {
label="Berlaku Mulai" label="Berlaku Mulai"
format="dd MMMM yyyy" format="dd MMMM yyyy"
value={this.state.startDate} value={this.state.startDate}
error={this.state.errorStartDate}
helperText={this.state.msgErrorSD}
onChange={(e) => this.handleChange(e, 'start_date')} onChange={(e) => this.handleChange(e, 'start_date')}
KeyboardButtonProps={{ KeyboardButtonProps={{
'aria-label': 'change date', 'aria-label': 'change date',
...@@ -234,6 +280,8 @@ export default class AddRole extends Component { ...@@ -234,6 +280,8 @@ export default class AddRole extends Component {
label="Berlaku Hingga" label="Berlaku Hingga"
format="dd MMMM yyyy" format="dd MMMM yyyy"
value={this.state.endDate} value={this.state.endDate}
error={this.state.errorEndDate}
helperText={this.state.msgErrorED}
onChange={(e) => this.handleChange(e, 'end_date')} onChange={(e) => this.handleChange(e, 'end_date')}
minDate={this.state.startDate} minDate={this.state.startDate}
KeyboardButtonProps={{ KeyboardButtonProps={{
...@@ -380,14 +428,25 @@ export default class AddRole extends Component { ...@@ -380,14 +428,25 @@ export default class AddRole extends Component {
</div> </div>
<div className="border-top grid grid-2x" style={{ height: 56, backgroundColor: '#f5f5f5', paddingLeft: 20, paddingRight: 20 }}> <div className="border-top grid grid-2x" style={{ height: 56, backgroundColor: '#f5f5f5', paddingLeft: 20, paddingRight: 20 }}>
<div className="column-1" style={{ alignSelf: 'center' }}> <div className="column-1" style={{ alignSelf: 'center' }}>
<div onClick={() => this.props.onClickClose()} style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}> <button
<span style={{ color: '#354960', fontSize: 11 }}>Batal</span> type="button"
</div> onClick={() => this.props.onClickClose()}
>
<div style={{ width: 102, height: 30, border: 'solid 1px #354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: '#354960', fontSize: 11 }}>Batal</span>
</div>
</button>
</div> </div>
<div className="column-2" style={{display: 'flex', justifyContent: 'flex-end', alignItems: 'center'}}> <div className="column-2" style={{display: 'flex', justifyContent: 'flex-end', alignItems: 'center'}}>
<div onClick={() => this.updateRole()}style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}> <button
<span style={{ color: '#fff', fontSize: 11 }}>Simpan</span> type="button"
</div> onClick={() => this.validasi()}
>
<div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: '#fff', fontSize: 11 }}>Simpan</span>
</div>
</button>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -5,6 +5,7 @@ import AddIcon from '@material-ui/icons/Add'; ...@@ -5,6 +5,7 @@ import AddIcon from '@material-ui/icons/Add';
import RemoveIcon from '@material-ui/icons/Remove'; import RemoveIcon from '@material-ui/icons/Remove';
import { DateTimePicker, KeyboardDatePicker, DatePicker } from "@material-ui/pickers"; import { DateTimePicker, KeyboardDatePicker, DatePicker } from "@material-ui/pickers";
import format from "date-fns/format"; import format from "date-fns/format";
import * as R from 'ramda'
const CustomCheckbox = withStyles({ const CustomCheckbox = withStyles({
root: { root: {
color: '#51c6ea', color: '#51c6ea',
...@@ -27,7 +28,13 @@ export default class EditRole extends Component { ...@@ -27,7 +28,13 @@ export default class EditRole extends Component {
privileges: [], privileges: [],
checked: false, checked: false,
selectedIndex: 0, selectedIndex: 0,
date: new Date() date: new Date(),
errorRoleName: false,
errorStartDate: false,
errorEndDate: false,
msgErrorRN: '',
msgErrorSD: '',
msgErrorED: '',
} }
} }
...@@ -44,15 +51,32 @@ export default class EditRole extends Component { ...@@ -44,15 +51,32 @@ export default class EditRole extends Component {
let data = this.state let data = this.state
let isDate = type !== '' ? true : false let isDate = type !== '' ? true : false
if (isDate && type == 'start_date') { if (isDate && type == 'start_date') {
this.setState({ ...data, tempData: { ...this.state.tempData, start_date: format(e, 'yyyy-MM-dd') } }, () => { this.setState({ ...data, tempData: { ...this.state.tempData, start_date: format(e, 'yyyy-MM-dd'), end_date: null },
console.log(this.state.tempData) errorRoleName: false,
errorStartDate: false,
errorEndDate: false,
msgErrorRN: '',
msgErrorSD: '',
msgErrorED: '',
}) })
} else if (isDate && type == 'end_date') { } else if (isDate && type == 'end_date') {
this.setState({ ...data, tempData: { ...this.state.tempData, end_date: format(e, 'yyyy-MM-dd') } }, () => { this.setState({ ...data, tempData: { ...this.state.tempData, end_date: format(e, 'yyyy-MM-dd') },
console.log(this.state.tempData) errorRoleName: false,
errorStartDate: false,
errorEndDate: false,
msgErrorRN: '',
msgErrorSD: '',
msgErrorED: '',
}) })
} else { } else {
this.setState({ ...data, tempData: { ...this.state.tempData, [e.target.name]: e.target.value } }) this.setState({ ...data, tempData: { ...this.state.tempData, [e.target.name]: e.target.value },
errorRoleName: false,
errorStartDate: false,
errorEndDate: false,
msgErrorRN: '',
msgErrorSD: '',
msgErrorED: '',
})
} }
} }
...@@ -68,6 +92,19 @@ export default class EditRole extends Component { ...@@ -68,6 +92,19 @@ export default class EditRole extends Component {
}) })
} }
validasi() {
if (R.isEmpty(this.state.tempData.role_name)) {
this.setState({errorRoleName: true, msgErrorRN: 'Role Name tidak boleh kosong'})
} else if (R.isNil(this.state.tempData.start_date)) {
this.setState({errorStartDate: true, msgErrorSD: 'Start Date tidak boleh kosong'})
} else if (R.isNil(this.state.tempData.end_date)) {
this.setState({errorEndDate: true, msgErrorED: 'End Date tidak boleh kosong'})
} else if (this.state.privileges.length < 1) {
alert('Hak Akses belum di pilih !!')
} else {
this.updateRole()
}
}
updateRole() { updateRole() {
// let startDate = format(this.state.tempData.start_date, 'yyyy-MM-dd') // let startDate = format(this.state.tempData.start_date, 'yyyy-MM-dd')
...@@ -212,6 +249,8 @@ export default class EditRole extends Component { ...@@ -212,6 +249,8 @@ export default class EditRole extends Component {
name="role_name" name="role_name"
label="User Role" label="User Role"
value={this.state.tempData == null ? '' : this.state.tempData.role_name} value={this.state.tempData == null ? '' : this.state.tempData.role_name}
error={this.state.errorRoleName}
helperText={this.state.msgErrorRN}
onChange={(e) => this.handleChange(e, '')} onChange={(e) => this.handleChange(e, '')}
// defaultValue="Default Value" // defaultValue="Default Value"
// helperText="Some important text" // helperText="Some important text"
...@@ -229,6 +268,8 @@ export default class EditRole extends Component { ...@@ -229,6 +268,8 @@ export default class EditRole extends Component {
label="Berlaku Mulai" label="Berlaku Mulai"
format="dd MMMM yyyy" format="dd MMMM yyyy"
value={this.state.tempData == null ? null : this.state.tempData.start_date} value={this.state.tempData == null ? null : this.state.tempData.start_date}
error={this.state.errorStartDate}
helperText={this.state.msgErrorSD}
onChange={(e) => this.handleChange(e, 'start_date')} onChange={(e) => this.handleChange(e, 'start_date')}
KeyboardButtonProps={{ KeyboardButtonProps={{
'aria-label': 'change date', 'aria-label': 'change date',
...@@ -247,6 +288,8 @@ export default class EditRole extends Component { ...@@ -247,6 +288,8 @@ export default class EditRole extends Component {
label="Berlaku Hingga" label="Berlaku Hingga"
format="dd MMMM yyyy" format="dd MMMM yyyy"
value={this.state.tempData == null ? null : this.state.tempData.end_date} value={this.state.tempData == null ? null : this.state.tempData.end_date}
error={this.state.errorEndDate}
helperText={this.state.msgErrorED}
minDate={this.state.tempData == null ? null : this.state.tempData.start_date} minDate={this.state.tempData == null ? null : this.state.tempData.start_date}
onChange={(e) => this.handleChange(e, 'end_date')} onChange={(e) => this.handleChange(e, 'end_date')}
KeyboardButtonProps={{ KeyboardButtonProps={{
...@@ -405,7 +448,7 @@ export default class EditRole extends Component { ...@@ -405,7 +448,7 @@ export default class EditRole extends Component {
<div className="column-2" style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}> <div className="column-2" style={{ display: 'flex', justifyContent: 'flex-end', alignItems: 'center' }}>
<button <button
type="button" type="button"
onClick={() => this.updateRole()} onClick={() => this.validasi()}
> >
<div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}> <div style={{ width: 102, height: 30, backgroundColor: '#354960', borderRadius: 5, alignItems: 'center', display: 'flex', justifyContent: 'center' }}>
<span style={{ color: '#fff', fontSize: 11 }}>Simpan</span> <span style={{ color: '#fff', fontSize: 11 }}>Simpan</span>
......
const Constant = { const Constant = {
TOKEN: null, TOKEN: null,
USER: null, USER: null,
EMAIL: 'TOKEN',
PASSWORD: 'PASSWORD'
} }
export default Constant; export default Constant;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment