|
|
@ -3,13 +3,14 @@ import onInput from "~/util/onInput"; |
|
|
|
import Input from "../Input/index"; |
|
|
|
import Input from "../Input/index"; |
|
|
|
import "./index.scss"; |
|
|
|
import "./index.scss"; |
|
|
|
import moment from "jalali-moment"; |
|
|
|
import moment from "jalali-moment"; |
|
|
|
|
|
|
|
|
|
|
|
export default function Birthdate(props) { |
|
|
|
export default function Birthdate(props) { |
|
|
|
const { defaultValue, parent, name } = props; |
|
|
|
const { defaultValue, parent, name } = props; |
|
|
|
let momentDate = moment(defaultValue[name]); |
|
|
|
let momentDate = moment(defaultValue[name]); |
|
|
|
let isvalid = momentDate.isValid(); |
|
|
|
let isvalid = momentDate?.isValid(); |
|
|
|
const day = isvalid ? momentDate.format("jDD") : null, |
|
|
|
const day = isvalid ? momentDate?.format("jDD") : null, |
|
|
|
month = isvalid ? momentDate.format("jMM") : null, |
|
|
|
month = isvalid ? momentDate?.format("jMM") : null, |
|
|
|
year = isvalid ? momentDate.format("jYYYY") : null; |
|
|
|
year = isvalid ? momentDate?.format("jYYYY") : null; |
|
|
|
const [state, setState] = useState({ day, month, year }); |
|
|
|
const [state, setState] = useState({ day, month, year }); |
|
|
|
const onChange = (_name, value) => { |
|
|
|
const onChange = (_name, value) => { |
|
|
|
let _state = { ...state, [_name]: value }; |
|
|
|
let _state = { ...state, [_name]: value }; |
|
|
@ -18,7 +19,11 @@ export default function Birthdate(props) { |
|
|
|
parent.onChange( |
|
|
|
parent.onChange( |
|
|
|
name, |
|
|
|
name, |
|
|
|
moment |
|
|
|
moment |
|
|
|
.from(`${_state.year}/${_state.month}/${_state.day}`, "fa", "YYYY/M/D") |
|
|
|
.from( |
|
|
|
|
|
|
|
`${_state?.year}/${_state?.month}/${_state?.day}`, |
|
|
|
|
|
|
|
"fa", |
|
|
|
|
|
|
|
"YYYY/M/D" |
|
|
|
|
|
|
|
) |
|
|
|
.locale("en") |
|
|
|
.locale("en") |
|
|
|
); |
|
|
|
); |
|
|
|
}; |
|
|
|
}; |
|
|
|