import React, { useState } from "react"; import onInput from "~/util/onInput"; import Input from "../Input/index"; import "./index.scss"; import moment from "jalali-moment"; export default function Birthdate(props) { const { defaultValue, parent, name } = props; let momentDate = moment(defaultValue[name]); let isvalid = momentDate.isValid(); const day = isvalid ? momentDate.format("jDD") : null, month = isvalid ? momentDate.format("jMM") : null, year = isvalid ? momentDate.format("jYYYY") : null; const [state, setState] = useState({ day, month, year }); const onChange = (_name, value) => { let _state = { ...state, [_name]: value }; setState(_state); parent.onChange( name, moment .from(`${_state.year}/${_state.month}/${_state.day}`, "fa", "YYYY/M/D") .locale("en") ); }; return ( <> {window.innerWidth < 1000 ? (