mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-10-30 02:38:47 -04:00
The garden dialog now adds a garden as well as edits one (new.json and create.json on GardensController), and a GardenPicker button opens it from the home page. A plant_picker helper replaces the home page's separate plant links and the plant_button partial. The plant dialog asks when it was planted (Today, Yesterday, Enter date), using a WhenPicker shared with the harvest dialog. Members with no garden still get the full-page plant link. Part of #4933 Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
51 lines
1.7 KiB
React
51 lines
1.7 KiB
React
import React from 'react';
|
|
|
|
import {formatDate} from '../dates';
|
|
|
|
export const WHEN_CHOICES = [['today', 'Today'], ['yesterday', 'Yesterday'], ['other', 'Enter date']];
|
|
|
|
// Today, Yesterday or Enter date, as pills with a date box under Enter date.
|
|
// `when` is today, yesterday or other; `date` is the date typed under other.
|
|
// `choices` can leave out Yesterday; `min` is the earliest date the box takes.
|
|
// `hint` is the date the current choice means, shown under the pills.
|
|
export default function WhenPicker({id, legend, when, onWhen, date, onDate, choices = WHEN_CHOICES, min, hint}) {
|
|
return (
|
|
<fieldset>
|
|
<legend className="crop-picker-label step-legend">{legend}</legend>
|
|
<div className="pill-choices">
|
|
{choices.map(([choice, label]) => (
|
|
<React.Fragment key={choice}>
|
|
<input
|
|
type="radio"
|
|
className="visually-hidden"
|
|
name={`${id}-when`}
|
|
id={`${id}-when-${choice}`}
|
|
checked={when === choice}
|
|
onChange={() => onWhen(choice)}
|
|
autoFocus={choice === 'today'}
|
|
/>
|
|
<label className="pill-choice" htmlFor={`${id}-when-${choice}`}>{label}</label>
|
|
</React.Fragment>
|
|
))}
|
|
</div>
|
|
{when === 'other' ? (
|
|
<div className="mt-3">
|
|
<label className="form-label" htmlFor={`${id}-date`}>Date</label>
|
|
<input
|
|
id={`${id}-date`}
|
|
type="date"
|
|
className="form-control when-date"
|
|
value={date}
|
|
min={min}
|
|
onChange={onDate}
|
|
required
|
|
autoFocus
|
|
/>
|
|
</div>
|
|
) : (
|
|
<p className="step-hint">{hint && formatDate(hint)}</p>
|
|
)}
|
|
</fieldset>
|
|
);
|
|
}
|