|
|
@ -9,7 +9,7 @@ import { roleRegister } from "../../../_constants/register"; |
|
|
|
import { useParams } from "react-router-dom"; |
|
|
|
import { useParams } from "react-router-dom"; |
|
|
|
import { useDispatch, useSelector } from "react-redux"; |
|
|
|
import { useDispatch, useSelector } from "react-redux"; |
|
|
|
import { Alert } from "../../../_components/Alert"; |
|
|
|
import { Alert } from "../../../_components/Alert"; |
|
|
|
import { userConstants } from "../../../_constants"; |
|
|
|
import { configConstants, userConstants } from "../../../_constants"; |
|
|
|
import { alertActions } from "../../../_actions"; |
|
|
|
import { alertActions } from "../../../_actions"; |
|
|
|
import { isEmail } from "../../../_helpers/validateEmail"; |
|
|
|
import { isEmail } from "../../../_helpers/validateEmail"; |
|
|
|
|
|
|
|
|
|
|
@ -29,6 +29,7 @@ const CreateAccount = () => { |
|
|
|
|
|
|
|
|
|
|
|
const [phoneWarning, setPhoneWarning] = useState(""); |
|
|
|
const [phoneWarning, setPhoneWarning] = useState(""); |
|
|
|
const [nameWarning, setNameWarning] = useState(""); |
|
|
|
const [nameWarning, setNameWarning] = useState(""); |
|
|
|
|
|
|
|
const [addressWarning, setAddressWarning] = useState(""); |
|
|
|
const [birthdayWarning, setBirthdayWarning] = useState(""); |
|
|
|
const [birthdayWarning, setBirthdayWarning] = useState(""); |
|
|
|
const [password, setPassword] = useState(""); |
|
|
|
const [password, setPassword] = useState(""); |
|
|
|
const [rePassword, setRePassword] = useState(""); |
|
|
|
const [rePassword, setRePassword] = useState(""); |
|
|
@ -47,7 +48,7 @@ const CreateAccount = () => { |
|
|
|
agents_code, |
|
|
|
agents_code, |
|
|
|
password, |
|
|
|
password, |
|
|
|
address, |
|
|
|
address, |
|
|
|
birthday, |
|
|
|
birthday: dayjs(birthday).format('YYYY-MM-DD'), |
|
|
|
email, |
|
|
|
email, |
|
|
|
fullname, |
|
|
|
fullname, |
|
|
|
gender, |
|
|
|
gender, |
|
|
@ -55,9 +56,11 @@ const CreateAccount = () => { |
|
|
|
role |
|
|
|
role |
|
|
|
} |
|
|
|
} |
|
|
|
try { |
|
|
|
try { |
|
|
|
const res = await apiCaller(url, "POST", dataSubmit) |
|
|
|
const res = await apiCaller(url, "POST", dataSubmit, null, true, configConstants.API_URL_SETEST, true, true) |
|
|
|
if (res.status) { |
|
|
|
if (res.status) { |
|
|
|
dispatch(alertActions.success({ 'message': res?.msg, 'screen': userConstants.SCREEN_REGISTER })); |
|
|
|
dispatch(alertActions.success({ 'message': res?.msg, 'screen': userConstants.SCREEN_REGISTER })); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
dispatch(alertActions.error({ 'message': Object.values(res?.msg)?.join('\n'), 'screen': userConstants.SCREEN_REGISTER, isShowPopup: true })); |
|
|
|
} |
|
|
|
} |
|
|
|
} catch (err) { |
|
|
|
} catch (err) { |
|
|
|
dispatch(alertActions.error({ 'message': err, 'screen': userConstants.SCREEN_REGISTER, isShowPopup: true })); |
|
|
|
dispatch(alertActions.error({ 'message': err, 'screen': userConstants.SCREEN_REGISTER, isShowPopup: true })); |
|
|
@ -74,6 +77,9 @@ const CreateAccount = () => { |
|
|
|
if (password.length < 6 || password.trim() === "") { |
|
|
|
if (password.length < 6 || password.trim() === "") { |
|
|
|
setPwError("Mật khẩu cần tối thiểu 6 kí tự và không gồm toàn dấu cách"); |
|
|
|
setPwError("Mật khẩu cần tối thiểu 6 kí tự và không gồm toàn dấu cách"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if(password?.trim()?.length > 50) { |
|
|
|
|
|
|
|
setPwError("Mật khẩu không được quá 50 kí tự"); |
|
|
|
|
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const checkRePw = () => { |
|
|
|
const checkRePw = () => { |
|
|
@ -164,6 +170,18 @@ const CreateAccount = () => { |
|
|
|
} |
|
|
|
} |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
case 'fullname': { |
|
|
|
|
|
|
|
if (!!fullname && fullname?.trim()?.length > 50 && !nameWarning) { |
|
|
|
|
|
|
|
setNameWarning("Họ tên không được quá 50 kí tự"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case 'address': { |
|
|
|
|
|
|
|
if (!!address && address?.trim()?.length > 80 && !addressWarning) { |
|
|
|
|
|
|
|
setAddressWarning("Địa chỉ không được quá 80 kí tự"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
default: { |
|
|
|
default: { |
|
|
|
if (rePassword && !rePwError) { |
|
|
|
if (rePassword && !rePwError) { |
|
|
|
checkRePw(); |
|
|
|
checkRePw(); |
|
|
@ -189,6 +207,8 @@ const CreateAccount = () => { |
|
|
|
password.trim() !== "" && |
|
|
|
password.trim() !== "" && |
|
|
|
!!fullname.trim() && |
|
|
|
!!fullname.trim() && |
|
|
|
!!gender && |
|
|
|
!!gender && |
|
|
|
|
|
|
|
!nameWarning && |
|
|
|
|
|
|
|
!addressWarning && |
|
|
|
!disabledBtn |
|
|
|
!disabledBtn |
|
|
|
) { |
|
|
|
) { |
|
|
|
if (emailError) { |
|
|
|
if (emailError) { |
|
|
@ -375,12 +395,9 @@ const CreateAccount = () => { |
|
|
|
removeWarningOnType={true} |
|
|
|
removeWarningOnType={true} |
|
|
|
errorText={nameWarning} |
|
|
|
errorText={nameWarning} |
|
|
|
setErrorText={setNameWarning} |
|
|
|
setErrorText={setNameWarning} |
|
|
|
|
|
|
|
onBlur={() => { |
|
|
|
onBlur={() => |
|
|
|
onBlurField("fullname"); |
|
|
|
fullname.trim() === "" |
|
|
|
}} |
|
|
|
? setFullname("") |
|
|
|
|
|
|
|
: setFullname(fullname.trim()) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
autoFocus={true} |
|
|
|
autoFocus={true} |
|
|
|
></InputText> |
|
|
|
></InputText> |
|
|
|
<div className="flex-m field_item"> |
|
|
|
<div className="flex-m field_item"> |
|
|
@ -449,9 +466,14 @@ const CreateAccount = () => { |
|
|
|
type="text" |
|
|
|
type="text" |
|
|
|
name="name" |
|
|
|
name="name" |
|
|
|
placeholder="Địa chỉ" |
|
|
|
placeholder="Địa chỉ" |
|
|
|
required={true} |
|
|
|
removeWarningOnType={true} |
|
|
|
|
|
|
|
errorText={addressWarning} |
|
|
|
|
|
|
|
setErrorText={setAddressWarning} |
|
|
|
renderLabelIcon={renderLocationIcon} |
|
|
|
renderLabelIcon={renderLocationIcon} |
|
|
|
autoFocus={true} |
|
|
|
autoFocus={true} |
|
|
|
|
|
|
|
onBlur={() => { |
|
|
|
|
|
|
|
onBlurField("address"); |
|
|
|
|
|
|
|
}} |
|
|
|
></InputText> |
|
|
|
></InputText> |
|
|
|
{/* <div> |
|
|
|
{/* <div> |
|
|
|
<p style={{fontWeight: 600}}>Vai trò</p> |
|
|
|
<p style={{fontWeight: 600}}>Vai trò</p> |
|
|
|