TmtDate.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import React from "react";
  2. import DatePicker from "react-datepicker";
  3. import "react-datepicker/dist/react-datepicker.css";
  4. import FormGroup from "reactstrap/lib/FormGroup";
  5. import ms from "ms";
  6. import { Component } from "react";
  7. class TmtDate extends Component {
  8. constructor(props) {
  9. super(props);
  10. const tmt_awal = new Date();
  11. this.state = {
  12. startDay: tmt_awal,
  13. maxDay: new Date(+new Date(tmt_awal) + ms("180d")),
  14. isiTmt: "",
  15. };
  16. }
  17. render() {
  18. return (
  19. <div>
  20. <FormGroup row className="mt-3">
  21. <label className="col-md-2 col-form-label">Isi TMT</label>
  22. <div className="col-md-10">
  23. <DatePicker
  24. selected={this.state.isiTmt}
  25. onChange={(e) => {
  26. this.setState({ isiTmt: e });
  27. this.props.setTmt({ startDate: this.state.startDay, endDate: this.state.isiTmt });
  28. }}
  29. dateFormat="dd/MM/yyyy"
  30. minDate={this.state.startDay}
  31. maxDate={this.state.maxDay}
  32. placeholderText="isi TMT"
  33. // maxDate={addDays(new Date(), 5)}
  34. />
  35. <strong>Max pengisian TMT 6 bulan</strong>
  36. </div>
  37. </FormGroup>
  38. <FormGroup row className="mt-1">
  39. <label className="col-md-2 col-form-label">TMT berlaku</label>
  40. <div className="col-md-10 mt-2">
  41. <b>{moment(this.state.startDay).format("DD-MM-YYYY")}</b> hingga <b>{this.state.isiTmt ? moment(this.state.isiTmt).format("DD-MM-YYYY") : "-"}</b>
  42. </div>
  43. </FormGroup>
  44. </div>
  45. );
  46. }
  47. }
  48. export default TmtDate;