|
|
@ -5,8 +5,13 @@ import { validateNumber, validateEmail } from "../../_base/Validate"; |
|
|
|
import { userConstants } from "../../_constants"; |
|
|
|
import { userConstants } from "../../_constants"; |
|
|
|
import { sendMsgContact } from "../../_services/user"; |
|
|
|
import { sendMsgContact } from "../../_services/user"; |
|
|
|
import moment from "moment"; |
|
|
|
import moment from "moment"; |
|
|
|
|
|
|
|
import { alertActions } from "../../_actions"; |
|
|
|
|
|
|
|
import { useDispatch } from "react-redux"; |
|
|
|
|
|
|
|
|
|
|
|
export const advisementLogic = (props) => { |
|
|
|
export const advisementLogic = (props) => { |
|
|
|
|
|
|
|
const urlParams = new URLSearchParams(window.location.search); |
|
|
|
|
|
|
|
const mds = urlParams.get('mds'); |
|
|
|
|
|
|
|
const dispatch = useDispatch() |
|
|
|
// Time Advisement
|
|
|
|
// Time Advisement
|
|
|
|
const [timeAdvisement, setTimeAdvisement] = useState({}); |
|
|
|
const [timeAdvisement, setTimeAdvisement] = useState({}); |
|
|
|
const [timeAdvisementError, setTimeAdvisementError] = useState(); |
|
|
|
const [timeAdvisementError, setTimeAdvisementError] = useState(); |
|
|
@ -130,6 +135,14 @@ export const advisementLogic = (props) => { |
|
|
|
|
|
|
|
|
|
|
|
const [errorAdviseTrial, setErrorAdviseTrial] = useState(""); |
|
|
|
const [errorAdviseTrial, setErrorAdviseTrial] = useState(""); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// message
|
|
|
|
|
|
|
|
const [message, setMessage] = useState(""); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Handle Change Address Teach for Teacher
|
|
|
|
|
|
|
|
const changeMessage = (newValue) => { |
|
|
|
|
|
|
|
setMessage(newValue); |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// Variable compulsory advise trial
|
|
|
|
// Variable compulsory advise trial
|
|
|
|
const [compulError, setCompulError] = useState(false); |
|
|
|
const [compulError, setCompulError] = useState(false); |
|
|
|
|
|
|
|
|
|
|
@ -198,39 +211,36 @@ export const advisementLogic = (props) => { |
|
|
|
phone && |
|
|
|
phone && |
|
|
|
!nameUserError && |
|
|
|
!nameUserError && |
|
|
|
!phoneWarning && |
|
|
|
!phoneWarning && |
|
|
|
timeAdvisement?.value && |
|
|
|
!!email?.trim() && |
|
|
|
!timeAdvisementError |
|
|
|
!emailError |
|
|
|
|
|
|
|
// timeAdvisement?.value &&
|
|
|
|
|
|
|
|
// !timeAdvisementError
|
|
|
|
) { |
|
|
|
) { |
|
|
|
if ( |
|
|
|
|
|
|
|
(!addressTeach && props.type == userConstants.ROLE_TEACHER) || |
|
|
|
|
|
|
|
(!gradeSelected?.value && props.type != userConstants.ROLE_TEACHER) |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
setAddressTeachError("Vui lòng nhập thông tin."); |
|
|
|
|
|
|
|
setGradeError("Vui lòng nhập thông tin."); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
try { |
|
|
|
try { |
|
|
|
let [from_time, end_time] = timeAdvisement?.value.split("-"); |
|
|
|
// let [from_time, end_time] = timeAdvisement?.value.split("-");
|
|
|
|
|
|
|
|
|
|
|
|
const data = { |
|
|
|
const data = { |
|
|
|
user_name: nameUser, |
|
|
|
agents_code: mds, |
|
|
|
|
|
|
|
guest_name: nameUser, |
|
|
|
phone, |
|
|
|
phone, |
|
|
|
from_time, |
|
|
|
grade: gradeSelected?.title, |
|
|
|
end_time, |
|
|
|
email, |
|
|
|
grade_id: gradeSelected?.value, |
|
|
|
message |
|
|
|
school: addressTeach, |
|
|
|
// from_time,
|
|
|
|
source: "advise", |
|
|
|
// end_time,
|
|
|
|
role: props.type, |
|
|
|
// school: addressTeach,
|
|
|
|
|
|
|
|
// source: "advise",
|
|
|
|
|
|
|
|
// role: props.type,
|
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const result = await sendMsgContact(data); |
|
|
|
const result = await sendMsgContact(data); |
|
|
|
if (result.status) { |
|
|
|
if (result.status) { |
|
|
|
// setIsSuccess(true);
|
|
|
|
|
|
|
|
setIsSuccessRegist(true); |
|
|
|
setIsSuccessRegist(true); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
dispatch(alertActions.error({ 'message': typeof result?.msg === 'string' ? result?.msg : Object.values(result?.msg)?.join('\n'), 'screen': 'form_register', isShowPopup: true })); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (e) { |
|
|
|
} catch (e) { |
|
|
|
// console.log(e);
|
|
|
|
dispatch(alertActions.error({ 'message': e, 'screen': 'form_register', isShowPopup: true })); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (!nameUser) { |
|
|
|
if (!nameUser) { |
|
|
|
setNameUserError("Vui lòng nhập thông tin."); |
|
|
|
setNameUserError("Vui lòng nhập thông tin."); |
|
|
@ -238,17 +248,8 @@ export const advisementLogic = (props) => { |
|
|
|
if (!phone) { |
|
|
|
if (!phone) { |
|
|
|
setPhoneWarning("Vui lòng nhập thông tin."); |
|
|
|
setPhoneWarning("Vui lòng nhập thông tin."); |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if ( |
|
|
|
if(!email) { |
|
|
|
(!addressTeach && props.type == userConstants.ROLE_TEACHER) || |
|
|
|
setEmailError("Vui lòng nhập thông tin.") |
|
|
|
(!gradeSelected?.value && props.type != userConstants.ROLE_TEACHER) |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
setAddressTeachError("Vui lòng nhập thông tin."); |
|
|
|
|
|
|
|
setGradeError("Vui lòng nhập thông tin."); |
|
|
|
|
|
|
|
} else if ( |
|
|
|
|
|
|
|
(!addressTeachError || !gradeError) && |
|
|
|
|
|
|
|
!timeAdvisement?.value |
|
|
|
|
|
|
|
) { |
|
|
|
|
|
|
|
setTimeAdvisementError("Vui lòng nhập thông tin."); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -454,5 +455,8 @@ export const advisementLogic = (props) => { |
|
|
|
setCompulError, |
|
|
|
setCompulError, |
|
|
|
setIsVisibleTime, |
|
|
|
setIsVisibleTime, |
|
|
|
setIsAgreePolicy, |
|
|
|
setIsAgreePolicy, |
|
|
|
|
|
|
|
message, |
|
|
|
|
|
|
|
setMessage, |
|
|
|
|
|
|
|
changeMessage |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|
}; |
|
|
|