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

View File

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