Use date from options or do not let react manage the value

This commit is contained in:
Florian Schroedl
2024-01-23 17:57:09 +01:00
parent 2fccd0c8ca
commit c80fd132bb
2 changed files with 9 additions and 5 deletions

View File

@@ -1,9 +1,11 @@
import React, { useState, useEffect } from "react";
import React from "react";
import { Input } from "@/components/ui/input";
import { path } from "ramda";
import { ForecastDatePicker } from "@/components/ui/DatePicker";
export const Options = function ({ state, updateState }) {
const defaultDate = path(["options", "defaultDate"], state);
return (
<div
className="flex flex-col p-5 bg-white border border-solid border-slate-300 rounded-lg space-y-5 w-full h-full"
@@ -24,9 +26,11 @@ export const Options = function ({ state, updateState }) {
</label>
<label>
<ForecastDatePicker
onChange={(dateTime) =>
updateState({ options: { defaultDate: dateTime } })
}
dateTime={defaultDate || null}
onChange={(dateTime) => {
console.log("CHANGE", dateTime);
updateState({ options: { defaultDate: dateTime } });
}}
/>
</label>
</div>

View File

@@ -29,7 +29,7 @@ export const ForecastDatePicker = function ({
<input
type="date"
defaultValue={formatDate(minDate(new Date()))}
value={formatDate(dateTime)}
value={dateTime ? formatDate(dateTime) : undefined}
min={formatDate(minDate(new Date()))}
max={formatDate(maxDate(new Date()))}
onChange={(e) => onChange(e.target.valueAsDate)}