diff --git a/src/menu-items/setting.js b/src/menu-items/setting.js
index 679100f..8432005 100644
--- a/src/menu-items/setting.js
+++ b/src/menu-items/setting.js
@@ -105,6 +105,15 @@ const setting = {
breadcrumbs: false,
ability:['VIEW','USER']
},
+ {
+ id: 'consultant',
+ title: 'Consultant',
+ type: 'item',
+ url: '/consultant',
+ icon: icons.UserOutlined,
+ breadcrumbs: false,
+ ability:['VIEW','USER']
+ },
// {
// id: 'auditLog',
// title: 'Audit Log',
diff --git a/src/pages/client/ClientMaintainPage/ClientForm.js b/src/pages/client/ClientMaintainPage/ClientForm.js
index cdfc6cf..bf7a5ba 100644
--- a/src/pages/client/ClientMaintainPage/ClientForm.js
+++ b/src/pages/client/ClientMaintainPage/ClientForm.js
@@ -1,4 +1,3 @@
-// material-ui
import {
Button,
FormControlLabel,
@@ -24,8 +23,9 @@ import Autocomplete from "@mui/material/Autocomplete";
import axios from "axios";
import {apiPath} from "../../../auth/utils";
import {
- CHECK_EVENT_DUPLICATE, //GET_EVENT_NOTIFICATION_OVERTIME,
+ CHECK_EVENT_DUPLICATE,
GET_CLIENT_PATH,
+ GET_CONSULTANT_COMBO_LIST,
GET_SUB_DIVISION_COMBO_LIST,
POST_CLIENT_PATH
} from "../../../utils/ApiPathConst";
@@ -42,12 +42,7 @@ import {isObjEmpty} from "../../../utils/Utils";
import AbilityContext from "../../../components/AbilityProvider";
import {CARD_MAX_WIDTH} from "../../../themes/themeConst";
-// ==============================|| DASHBOARD - DEFAULT ||============================== //
-
-const ClientForm = ({ refClientDetail,
- isNewRecord,
- getClientDetail,
-}) => {
+const ClientForm = ({ refClientDetail, isNewRecord, getClientDetail }) => {
const location = useLocation();
const queryParams = new URLSearchParams(location.search);
const refId = queryParams.get("refId");
@@ -64,9 +59,10 @@ const ClientForm = ({ refClientDetail,
const [isEditing, setIsEditing] = useState(false);
const { setIsUploading } = useContext(UploadContext);
const [refClient, setRefClient] = useState({});
+ const [consultantComboList, setConsultantComboList] = useState([]);
- //form data
- const {register, getValues, setValue} = useForm();
+ // Form data
+ const { register, getValues, setValue } = useForm();
const [dob, setDob] = useState(null);
const [dobError, setDobError] = React.useState(null);
@@ -75,7 +71,6 @@ const ClientForm = ({ refClientDetail,
const [announceDateError, setAnnounceDateError] = React.useState(null);
const [fromError, setFromError] = React.useState(null);
const [toError, setToError] = React.useState(null);
- // const [nextApplicationDateError, setNextApplicationDateError] = React.useState(null);
const dobErrorMessage = React.useMemo(() => {
switch (dobError) {
@@ -125,14 +120,7 @@ const ClientForm = ({ refClientDetail,
}
}, [toError]);
- // const nextApplicationDateErrorMessage = React.useMemo(() => {
- // switch (nextApplicationDateError) {
- // case 'invalidDate': {
- // return "Invalid date";
- // }
- // }
- // }, [nextApplicationDateError]);
-// ==============================|| DELETE WINDOW RELATED ||============================== //
+ // DELETE WINDOW RELATED
const [isWindowOpen, setIsWindowOpen] = React.useState(false);
const handleClose = () => {
@@ -145,58 +133,10 @@ const ClientForm = ({ refClientDetail,
const copyClientAsNew = () => {
navigate(`/event/maintain/-1?refId=${params.id}`);
- }
-
- // useEffect(()=>{
- // if(applicationList.length===0){
- // validateReminder();
- // }
- // },[dob, nextApplicationDate, deadlineDate]);
-
- // const validateReminder = () =>{
- // const values = getValues();
- // let firstIssueDate = null;
- // let reminderDates = [];
- // if (dob !== null &&
- // nextApplicationDate !== null &&
- // values.reminderThreshold !== null &&
- // values.reminderInterval !== null &&
- // values.reminderLimit !== null
- // ) {
- // //have value
- // if(applicationList.length <=0){
- // firstIssueDate = dob.add(-values.reminderThreshold,'days');
- // }
- // else{
- // firstIssueDate = nextApplicationDate.add(-values.reminderThreshold, 'days');
- // }
-
- // reminderDates.push(firstIssueDate);
- // for(let i=1; i < parseInt(values.reminderLimit)+1 ; i++){
- // reminderDates.push(firstIssueDate.add(i*values.reminderInterval,'days'))
- // }
-
- // for(let j=0; j < reminderDates.length ; j++){
- // if(reminderDates[j]-deadlineDate > 0){
- // setOvertimeWarning(`Estimated reminder exceeds the application deadline, the last reminder will be generated on ${reminderDates[j>1?j-1:0].format('DD/MM/YYYY')}.`);
- // return false;
- // }
- // }
-
- // // setOvertimeWarning("");
- // return true;
- // }
- // return true;
- // }
+ };
- function updateData(){
- // if(applicationList.length >0){
- // notifyDeleteError("Delete restricted. Application exist in this event");
- // setIsWindowOpen(false);
- // }
- // else{
- axios.delete(`${apiPath}${GET_CLIENT_PATH}/${params.id}`,
- )
+ function updateData() {
+ axios.delete(`${apiPath}${GET_CLIENT_PATH}/${params.id}`)
.then((response) => {
if (response.status === 204) {
notifyDeleteSuccess();
@@ -208,163 +148,61 @@ const ClientForm = ({ refClientDetail,
console.log(error);
return false;
});
- // }
-
}
-// ==============================|| DELETE WINDOW RELATED ||============================== //
-
- // const validateReminderLimit = (value) => {
- // const maxValue = reminderLimitMax; // Set the maximum value here
- // if (/^[0-9]\d*$/.test(value) || value === '') {
- // if (parseInt(value) > maxValue) {
- // //console.log(value);
- // setValue("reminderLimit", maxValue)
- // }
- // }
- // else{
- // setValue("reminderLimit", '');
- // }
- // };
-
- // const handleReminderIntervalChange = (event) => {
- // const inputValue = event.target.value;
- // if (/^[0-9]\d*$/.test(inputValue) || inputValue === '') {
- // setValue("reminderInterval", inputValue);
- // }
- // else{
- // setValue("reminderInterval", '');
- // }
- // };
- // const handleReminderThresholdChange = (event) => {
- // const inputValue = event.target.value;
- // if (/^[0-9]\d*$/.test(inputValue) || inputValue === '') {
- // setValue("reminderThreshold", inputValue);
- // }
- // else{
- // setValue("reminderThreshold", '');
- // }
- // };
+ function getConsultantCombo() {
+ axios.get(`${apiPath}${GET_CONSULTANT_COMBO_LIST}`, {
+ params: {}
+ })
+ .then((response) => {
+ if (response.status === 200) {
+ setConsultantComboList(response.data.records);
+ }
+ })
+ .catch(error => {
+ console.log(error);
+ return false;
+ });
+ }
- useEffect(()=>{
+ useEffect(() => {
if (!isNewRecord) {
setRefClient(refClientDetail);
}
- // //if combo list ready
- // if (subDivisionList.length >0) {
- // }
- },[]);
+ getConsultantCombo();
+ }, []);
- // useEffect(()=>{
- // if(!isObjEmpty(refClient)){
- // setIsFlagFetched(true);
- // }
- // },[reminderFlag,refClient]);
-
- // useEffect(()=>{
- // if(isFlagFetched){
- // if(!reminderFlag){
- // setReminderInterval(null);
- // setReminderBefore(null);
- // setReminderLimit(null);
- // setValue("reminderThreshold",null);
- // setValue("reminderLimit",null);
- // setValue("reminderInterval",null);
- // }
- // }
- // },[isFlagFetched, refClient, reminderFlag]);
-
- // useEffect(()=>{
- // setReminderLimitMax(refReminderLimitMax);
- // if(!isObjEmpty(refClient) ) {
- // if(reminderFlag){
- // setReminderInterval(refReminderInterval);
- // setReminderBefore(refReminderBefore);
- // setReminderLimit(refReminderLimit);
- // }
- // }
- // },[reminderFlag, refReminderLimit,refReminderInterval,refReminderLimitMax,refReminderBefore,refClient]);
-
- useEffect(()=>{
- //if ref data ready
+ useEffect(() => {
if (!isObjEmpty(refClient)) {
- //checkOvertime();
- if(refId !== null){
- setValue("lastname", refClient.lastname);
- setValue("firstname", refClient.firstname);
- setValue("email", refClient.email);
- setValue("phone1", refClient.phone1);
- setValue("phone2", refClient.phone2);
- setValue("remarks", refClient.remarks);
- setValue("caseManagerId", 1);
- setValue("consultantId", 1);
- }
+ setValue("lastname", refClient.lastname);
+ setValue("firstname", refClient.firstname);
+ setValue("email", refClient.email);
+ setValue("phone1", refClient.phone1);
+ setValue("phone2", refClient.phone2);
+ setValue("remarks", refClient.remarks);
+ setValue("caseManagerId", 1);
+
+ // Set consultantId for Autocomplete
+ const selectedConsultant = consultantComboList.find(
+ (option) => option.id === refClient.consultantId
+ );
+ setValue("consultantId", selectedConsultant || null);
+
setDob(dayjs(getDateString(refClient.dob)));
}
- },[refClient]);
+ }, [refClient, consultantComboList]);
- useEffect(()=>{
- if(!isObjEmpty(refClient)) {
+ useEffect(() => {
+ if (!isObjEmpty(refClient)) {
setOnReady(true);
- }
- else if(isNewRecord){
+ } else if (isNewRecord) {
setOnReady(true);
setIsEditing(true);
}
- },[refClient]);
- // },[refClient,selectedSubDivision,selectedRegion,selectedType, dob, deadlineDate]);
-
- // useEffect(()=>{
- // if(selectedFrequency !== null){
- // if(selectedFrequency.key === 5 && isNewRecord){
- // }
- // else if (isFirstInit && refId !== null){
- // setIsFirstInit(false);
- // }
- // else if(isNewRecord){
- // }
-
- // if (isEditing){
- // if (dob !== null){
- // switch(selectedFrequency.key){
- // case 1:
- // setNextApplicationDate(dob.add(1,'month'));
- // break;
- // case 2:
- // setNextApplicationDate(dob.add(3,'month'));
- // break;
- // case 3:
- // setNextApplicationDate(dob.add(1,'year'));
- // break;
- // case 4:
- // setNextApplicationDate(dob.add(6,'month'));
- // break;
- // default:
- // setNextApplicationDate(nextApplicationDate);
- // break;
- // }
- // }
- // }
- // }
- // },[selectedFrequency,dob]);
-
- // useEffect(() => {
- // //if state data are ready and assign to different field
- // axios.get(`${apiPath}${GET_SUB_DIVISION_COMBO_LIST}`)
- // .then((response) => {
- // if (response.status === 200) {
- // setSubDivisionList(response.data.records);
- // }
- // })
- // .catch(error => {
- // console.log(error);
- // return false;
- // });
- // }, []);
+ }, [refClient]);
useEffect(() => {
- //upload latest data to parent
- if(isCollectData){
+ if (isCollectData) {
const values = getValues();
const formErrors = {};
@@ -372,127 +210,31 @@ const ClientForm = ({ refClientDetail,
formErrors.lastname = 'Last Name is required';
}
- // if (selectedRegion === null ) {
- // formErrors.region = 'Client Region is required';
- // }
-
- // if (dob === null) {
- // formErrors.dob = 'DoB is required';
- // }
-
- // if (deadlineDate === null) {
- // formErrors.deadlineDate = 'Deadline Date is required';
- // }
-
- // if (awardDate === null) {
- // formErrors.awardDate = 'Award Date is required';
- // }
-
- // if (selectedSubDivision.length <= 0){
- // formErrors.subDivision = 'Sub-Division is required';
- // }
-
- // if(reminderFlag){
- // if (selectedFrequency === null){
- // formErrors.frequency = 'Frequency is required';
- // }
-
- // if (!values.reminderThreshold){
- // formErrors.threshold = 'Threshold is required';
- // }
-
- // if (!values.reminderInterval){
- // formErrors.interval = 'Interval is required';
- // }
-
- // if (!values.reminderLimit){
- // formErrors.limit = 'Limit is required';
- // }
-
-
- // if(applicationList.length===0){
- // if(!validateReminder()){
- // formErrors.calError = "calError";
- // }
- // }
-
- // }
-
setErrors(formErrors);
- // if (Object.keys(formErrors).length === 0 //&&
- // !dobError && !awardDateError &&
- // !deadlineDateError && !announceDateError &&
- // !fromError && !toError && !nextApplicationDateError
- // ) {
- // axios.get(`${apiPath}${CHECK_EVENT_DUPLICATE}`,
- // {
- // params: {
- // "fullname": values.fullname.trim(),
- // "id": params.id,
- // },
- // })
- // .then((response) => {
- // if (response.status === 200) {
- // const formErrors = {};
- // if(response.data.isTaken){
- // formErrors.fullname = 'Client name must be unique.';
- // setErrors(formErrors);
- // setIsCollectData(false);
- // setUserConfirm(false);
- // }
- // else if(!response.data.isTaken){
- // if (Object.keys(formErrors).length === 0) {
- // let data = {};
- // data["id"] = isNewRecord ? params.id : refClientDetail.id;
- // data["fullname"] = values.fullname;
- // data["lastname"] = values.lastname;
- // data["firstname"] = values.firstname;
- // data["title"] = values.title;
- // data["email"] = values.email;
- // data["phone1"] = values.phone1;
- // data["phone2"] = values.phone2;
- // data["remarks"] = values.remarks;
- // data["dob"] = dob === null ? null : dayjs(dob).format('YYYY-MM-DD');
- // setClientDetail(data);
- // }
- // }
- // }
- // })
- // .catch(error => {
- // console.log(error);
- // return true;
- // });
if (Object.keys(formErrors).length === 0) {
let data = {};
- data["id"] = isNewRecord ? params.id : refClientDetail.id;
- data["lastname"] = values.lastname;
+ data["id"] = isNewRecord ? params.id : refClientDetail.id;
+ data["lastname"] = values.lastname;
data["firstname"] = values.firstname;
- data["email"] = values.email;
- data["phone1"] = values.phone1;
- data["phone2"] = values.phone2;
- data["remarks"] = values.remarks;
- data["caseManagerId"] = 1;
- data["consultantId"] = 1;
- data["dob"] = dob === null ? null : dayjs(dob).format('YYYY-MM-DD');
+ data["email"] = values.email;
+ data["phone1"] = values.phone1;
+ data["phone2"] = values.phone2;
+ data["remarks"] = values.remarks;
+ data["caseManagerId"] = 1;
+ data["consultantId"] = values.consultantId ? values.consultantId.id : null;
+ data["dob"] = dob === null ? null : dayjs(dob).format('YYYY-MM-DD');
setClientDetail(data);
- }
- else if(isCollectData){
+ } else if (isCollectData) {
setUserConfirm(false);
setIsCollectData(false);
}
- // setUserConfirm(false);
- // setIsCollectData(false);
}
}, [isCollectData]);
- function returnSearchPage(){
+ function returnSearchPage() {
navigate('/client');
}
- // function createNewApplication(){
- // navigate('/application/maintain/-1/'+ params.id);
- // }
-
useEffect(() => {
if (userConfirm) {
postClient();
@@ -500,43 +242,35 @@ const ClientForm = ({ refClientDetail,
setUserConfirm(false);
}, [clientDetail]);
-
const submitData = () => {
setIsCollectData(!isCollectData);
setUserConfirm(true);
- }
+ };
const updateIsEdit = () => {
setIsEditing(!isEditing);
- }
+ };
- function postClient(){
+ function postClient() {
setIsUploading(true);
const temp = trimDataBeforePost(clientDetail);
- // console.log("Posting:");
- // console.log(clientDetail);
- axios.post(`${apiPath}${POST_CLIENT_PATH}`,
- temp,
- )
+ axios.post(`${apiPath}${POST_CLIENT_PATH}`, temp)
.then((response) => {
if (response.status === 200) {
notifySaveSuccess();
- if(isNewRecord){
+ if (isNewRecord) {
setIsUploading(false);
- navigate('/client')
- }
- else{
+ navigate('/client');
+ } else {
setIsUploading(false);
getClientDetail(params.id);
- //checkOvertime();
setIsEditing(!isEditing);
}
setIsCollectData(!isCollectData);
-
}
})
.catch(error => {
- if (error.response.status === 422){
+ if (error.response.status === 422) {
const formErrors = {};
formErrors.subDivision = error.response.data.error;
setErrors(formErrors);
@@ -547,43 +281,31 @@ const ClientForm = ({ refClientDetail,
});
}
-
return (
!onReady ?
-