|
|
@ -5,14 +5,11 @@ import axios from "../../../const/interceptorApi" |
|
|
|
import { Card, CardBody, CardHeader, Col, Row, Input, Table, Button } from 'reactstrap'; |
|
|
|
import { Card, CardBody, CardHeader, Col, Row, Input, Table, Button } from 'reactstrap'; |
|
|
|
import { NotificationContainer, NotificationManager } from 'react-notifications'; |
|
|
|
import { NotificationContainer, NotificationManager } from 'react-notifications'; |
|
|
|
import { Pagination, Tooltip } from 'antd'; |
|
|
|
import { Pagination, Tooltip } from 'antd'; |
|
|
|
import { USER_EDIT, SATUAN_ADD, SATUAN_EDIT, SATUAN_DELETE, SATUAN_SEARCH } from '../../../const/ApiConst'; |
|
|
|
import { USER_EDIT, USER_GET_ID, REFFERAL_GET_ID, REFFERAL_ADD, REFFERAL_EDIT } from '../../../const/ApiConst'; |
|
|
|
import profile from '../../../assets/img/profile.png' |
|
|
|
import profile from '../../../assets/img/profile.png' |
|
|
|
import DialogForm from './DialogForm' |
|
|
|
import DialogForm from './DialogForm' |
|
|
|
import { ROLE_SEARCH, BASE_OSPRO } from '../../../const/ApiConst' |
|
|
|
import { ROLE_SEARCH, BASE_OSPRO } from '../../../const/ApiConst' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Setting = ({ params }) => { |
|
|
|
const Setting = ({ params }) => { |
|
|
|
const token = localStorage.getItem("token") |
|
|
|
const token = localStorage.getItem("token") |
|
|
|
const config = { |
|
|
|
const config = { |
|
|
@ -21,17 +18,13 @@ const Setting = ({ params }) => { |
|
|
|
"Authorization": `Bearer ${token}` |
|
|
|
"Authorization": `Bearer ${token}` |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const pageName = params.name; |
|
|
|
const pageName = params.name; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [openDialog, setOpenDialog] = useState(false) |
|
|
|
const [openDialog, setOpenDialog] = useState(false) |
|
|
|
const [typeDialog, setTypeDialog] = useState('Personal') |
|
|
|
const [typeDialog, setTypeDialog] = useState('Personal') |
|
|
|
const [id, setId] = useState(0) |
|
|
|
const [id, setId] = useState(0) |
|
|
|
const [roleList, setRoleList] = useState([]) |
|
|
|
const [roleList, setRoleList] = useState([]) |
|
|
|
const [userProfile, setUserprofile] = useState(null) |
|
|
|
const [userProfile, setUserprofile] = useState(null) |
|
|
|
|
|
|
|
const [refferal, setReferralCode] = useState(null) |
|
|
|
const [userName, setUserName] = useState("") |
|
|
|
const [userName, setUserName] = useState("") |
|
|
|
const [name, setName] = useState('') |
|
|
|
const [name, setName] = useState('') |
|
|
|
const [noHp, setNohp] = useState("") |
|
|
|
const [noHp, setNohp] = useState("") |
|
|
@ -44,7 +37,7 @@ const Setting = ({ params }) => { |
|
|
|
const [role, setRole] = useState("") |
|
|
|
const [role, setRole] = useState("") |
|
|
|
const [email, setEmail] = useState("") |
|
|
|
const [email, setEmail] = useState("") |
|
|
|
const [employeeType, setEmployeeType] = useState("") |
|
|
|
const [employeeType, setEmployeeType] = useState("") |
|
|
|
|
|
|
|
const [isCopied, setIsCopied] = useState(false); |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
getDataProfileUser(); |
|
|
|
getDataProfileUser(); |
|
|
@ -68,7 +61,7 @@ const Setting = ({ params }) => { |
|
|
|
setEmployeeType(userProfile?.employee_type); |
|
|
|
setEmployeeType(userProfile?.employee_type); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}, [userProfile]) |
|
|
|
}, [userProfile, typeDialog]) |
|
|
|
|
|
|
|
|
|
|
|
const handleOpenDialog = (type) => { |
|
|
|
const handleOpenDialog = (type) => { |
|
|
|
setOpenDialog(true) |
|
|
|
setOpenDialog(true) |
|
|
@ -78,12 +71,13 @@ const Setting = ({ params }) => { |
|
|
|
const handleCloseDialog = (type, data) => { |
|
|
|
const handleCloseDialog = (type, data) => { |
|
|
|
if (type === "profile") { |
|
|
|
if (type === "profile") { |
|
|
|
saveProfile(data); |
|
|
|
saveProfile(data); |
|
|
|
|
|
|
|
} else if(type === "refferal_code") { |
|
|
|
|
|
|
|
updateRefferal(data); |
|
|
|
} |
|
|
|
} |
|
|
|
setOpenDialog(false) |
|
|
|
setOpenDialog(false) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const saveProfile = async (data) => { |
|
|
|
const saveProfile = async (data) => { |
|
|
|
|
|
|
|
|
|
|
|
let urlEdit = USER_EDIT(id) |
|
|
|
let urlEdit = USER_EDIT(id) |
|
|
|
const formData = data |
|
|
|
const formData = data |
|
|
|
|
|
|
|
|
|
|
@ -99,6 +93,20 @@ const Setting = ({ params }) => { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const updateRefferal = async (data) => { |
|
|
|
|
|
|
|
let urlEdit = REFFERAL_EDIT(id) |
|
|
|
|
|
|
|
const formData = data |
|
|
|
|
|
|
|
const result = await axios.put(urlEdit, formData, config) |
|
|
|
|
|
|
|
.then(res => res) |
|
|
|
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
if (result && result.data && result.data.code === 200) { |
|
|
|
|
|
|
|
getDataRefferal(data.user_id, data.username, data.ktp_number); |
|
|
|
|
|
|
|
NotificationManager.success(`Code refferal berhasil diedit`, 'Success!!'); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
NotificationManager.error(`Code refferal gagal di edit`, `Failed!!`); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const toggleAddDialog = () => { |
|
|
|
const toggleAddDialog = () => { |
|
|
|
setOpenDialog(!openDialog) |
|
|
|
setOpenDialog(!openDialog) |
|
|
|
} |
|
|
|
} |
|
|
@ -121,10 +129,7 @@ const Setting = ({ params }) => { |
|
|
|
|
|
|
|
|
|
|
|
const getDataProfileUser = async () => { |
|
|
|
const getDataProfileUser = async () => { |
|
|
|
const id = localStorage.getItem("user_id") |
|
|
|
const id = localStorage.getItem("user_id") |
|
|
|
|
|
|
|
const url = USER_GET_ID(id); |
|
|
|
const url = `${BASE_OSPRO}/api/human-resource/edit/${id}` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const result = await axios |
|
|
|
const result = await axios |
|
|
|
.get(url, config) |
|
|
|
.get(url, config) |
|
|
|
.then((res) => res) |
|
|
|
.then((res) => res) |
|
|
@ -132,11 +137,49 @@ const Setting = ({ params }) => { |
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
let dataRes = result.data.data; |
|
|
|
let dataRes = result.data.data; |
|
|
|
setUserprofile(dataRes); |
|
|
|
setUserprofile(dataRes); |
|
|
|
|
|
|
|
await getDataRefferal(id, dataRes.username, dataRes.ktp_number); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
NotificationManager.error("Gagal Mengambil Data!!", "Failed"); |
|
|
|
NotificationManager.error("Gagal Mengambil Data!!", "Failed"); |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getDataRefferal = async (user_id, username, ktp_number) => { |
|
|
|
|
|
|
|
const url = REFFERAL_GET_ID(user_id); |
|
|
|
|
|
|
|
const result = await axios |
|
|
|
|
|
|
|
.get(url, config) |
|
|
|
|
|
|
|
.then((res) => res) |
|
|
|
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
|
|
|
|
let dataRes = result.data.data; |
|
|
|
|
|
|
|
setReferralCode(dataRes); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
saveRefferalCode(user_id, username, ktp_number); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const saveRefferalCode = async (user_id, username, ktp_number) => { |
|
|
|
|
|
|
|
const formData = { |
|
|
|
|
|
|
|
'id': parseInt(user_id), |
|
|
|
|
|
|
|
'code': username + ktp_number.substring(0, 4), |
|
|
|
|
|
|
|
'amount': 0 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const result = await axios |
|
|
|
|
|
|
|
.post(REFFERAL_ADD, formData, config) |
|
|
|
|
|
|
|
.then((res) => res) |
|
|
|
|
|
|
|
.catch((error) => error.response); |
|
|
|
|
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
|
|
|
|
await getDataRefferal(user_id, username, ktp_number); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function copyToClipboard(text) { |
|
|
|
|
|
|
|
navigator.clipboard.writeText(text).then(() => { |
|
|
|
|
|
|
|
setIsCopied(true); |
|
|
|
|
|
|
|
setTimeout(() => setIsCopied(false), 2000); |
|
|
|
|
|
|
|
}, (err) => { |
|
|
|
|
|
|
|
console.error('Gagal menyalin teks ke clipboard: ', err); |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
@ -158,6 +201,8 @@ const Setting = ({ params }) => { |
|
|
|
addressProp={address} |
|
|
|
addressProp={address} |
|
|
|
emailProp={email} |
|
|
|
emailProp={email} |
|
|
|
userNameProp={userName} |
|
|
|
userNameProp={userName} |
|
|
|
|
|
|
|
refferalCode={refferal?.code} |
|
|
|
|
|
|
|
userProfile={userProfile} |
|
|
|
/> |
|
|
|
/> |
|
|
|
|
|
|
|
|
|
|
|
<Card> |
|
|
|
<Card> |
|
|
@ -233,6 +278,15 @@ const Setting = ({ params }) => { |
|
|
|
<td><b>Tanggal Lahir </b></td> |
|
|
|
<td><b>Tanggal Lahir </b></td> |
|
|
|
<td>: {birthdayDate}</td> |
|
|
|
<td>: {birthdayDate}</td> |
|
|
|
</tr> |
|
|
|
</tr> |
|
|
|
|
|
|
|
<tr> |
|
|
|
|
|
|
|
<td><b>Referral Code </b></td> |
|
|
|
|
|
|
|
<td>: {refferal?.code} <small style={{ color:'blue', cursor: 'pointer' }} onClick={() => copyToClipboard(refferal?.code)}>{isCopied ? 'Copied' : 'Copy'}</small></td> |
|
|
|
|
|
|
|
<td> |
|
|
|
|
|
|
|
<Tooltip title='Custom Refferal Code'> |
|
|
|
|
|
|
|
<Button color="success" onClick={() => handleOpenDialog('Refferal')}>Custom Refferal Code</Button> |
|
|
|
|
|
|
|
</Tooltip> |
|
|
|
|
|
|
|
</td> |
|
|
|
|
|
|
|
</tr> |
|
|
|
</tbody> |
|
|
|
</tbody> |
|
|
|
<br /> |
|
|
|
<br /> |
|
|
|
</Col> |
|
|
|
</Col> |
|
|
|