|
|
|
@ -5,14 +5,11 @@ import axios from "../../../const/interceptorApi"
|
|
|
|
|
import { Card, CardBody, CardHeader, Col, Row, Input, Table, Button } from 'reactstrap'; |
|
|
|
|
import { NotificationContainer, NotificationManager } from 'react-notifications'; |
|
|
|
|
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 DialogForm from './DialogForm' |
|
|
|
|
import { ROLE_SEARCH, BASE_OSPRO } from '../../../const/ApiConst' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const Setting = ({ params }) => { |
|
|
|
|
const token = localStorage.getItem("token") |
|
|
|
|
const config = { |
|
|
|
@ -21,17 +18,13 @@ const Setting = ({ params }) => {
|
|
|
|
|
"Authorization": `Bearer ${token}` |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const pageName = params.name; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [openDialog, setOpenDialog] = useState(false) |
|
|
|
|
const [typeDialog, setTypeDialog] = useState('Personal') |
|
|
|
|
const [id, setId] = useState(0) |
|
|
|
|
const [roleList, setRoleList] = useState([]) |
|
|
|
|
const [userProfile, setUserprofile] = useState(null) |
|
|
|
|
const [refferal, setReferralCode] = useState(null) |
|
|
|
|
const [userName, setUserName] = useState("") |
|
|
|
|
const [name, setName] = useState('') |
|
|
|
|
const [noHp, setNohp] = useState("") |
|
|
|
@ -44,7 +37,7 @@ const Setting = ({ params }) => {
|
|
|
|
|
const [role, setRole] = useState("") |
|
|
|
|
const [email, setEmail] = useState("") |
|
|
|
|
const [employeeType, setEmployeeType] = useState("") |
|
|
|
|
|
|
|
|
|
const [isCopied, setIsCopied] = useState(false); |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
getDataProfileUser(); |
|
|
|
@ -68,7 +61,7 @@ const Setting = ({ params }) => {
|
|
|
|
|
setEmployeeType(userProfile?.employee_type); |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
}, [userProfile]) |
|
|
|
|
}, [userProfile, typeDialog]) |
|
|
|
|
|
|
|
|
|
const handleOpenDialog = (type) => { |
|
|
|
|
setOpenDialog(true) |
|
|
|
@ -78,12 +71,13 @@ const Setting = ({ params }) => {
|
|
|
|
|
const handleCloseDialog = (type, data) => { |
|
|
|
|
if (type === "profile") { |
|
|
|
|
saveProfile(data); |
|
|
|
|
} else if(type === "refferal_code") { |
|
|
|
|
updateRefferal(data); |
|
|
|
|
} |
|
|
|
|
setOpenDialog(false) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const saveProfile = async (data) => { |
|
|
|
|
|
|
|
|
|
let urlEdit = USER_EDIT(id) |
|
|
|
|
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 = () => { |
|
|
|
|
setOpenDialog(!openDialog) |
|
|
|
|
} |
|
|
|
@ -121,10 +129,7 @@ const Setting = ({ params }) => {
|
|
|
|
|
|
|
|
|
|
const getDataProfileUser = async () => { |
|
|
|
|
const id = localStorage.getItem("user_id") |
|
|
|
|
|
|
|
|
|
const url = `${BASE_OSPRO}/api/human-resource/edit/${id}` |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const url = USER_GET_ID(id); |
|
|
|
|
const result = await axios |
|
|
|
|
.get(url, config) |
|
|
|
|
.then((res) => res) |
|
|
|
@ -132,11 +137,49 @@ const Setting = ({ params }) => {
|
|
|
|
|
if (result && result.data && result.data.code == 200) { |
|
|
|
|
let dataRes = result.data.data; |
|
|
|
|
setUserprofile(dataRes); |
|
|
|
|
await getDataRefferal(id, dataRes.username, dataRes.ktp_number); |
|
|
|
|
} else { |
|
|
|
|
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 ( |
|
|
|
@ -158,6 +201,8 @@ const Setting = ({ params }) => {
|
|
|
|
|
addressProp={address} |
|
|
|
|
emailProp={email} |
|
|
|
|
userNameProp={userName} |
|
|
|
|
refferalCode={refferal?.code} |
|
|
|
|
userProfile={userProfile} |
|
|
|
|
/> |
|
|
|
|
|
|
|
|
|
<Card> |
|
|
|
@ -233,6 +278,15 @@ const Setting = ({ params }) => {
|
|
|
|
|
<td><b>Tanggal Lahir </b></td> |
|
|
|
|
<td>: {birthdayDate}</td> |
|
|
|
|
</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> |
|
|
|
|
<br /> |
|
|
|
|
</Col> |
|
|
|
|