import React, {useEffect, useRef, useState} from 'react'; import {postJson} from '../api'; import CropPicker from './CropPicker'; import Modal from './Modal'; const FIELD_NAMES = {crop: 'Crop', garden: 'Garden'}; const STEPS = ['Choose a crop', 'Confirm']; function humanize(field) { return FIELD_NAMES[field] || field.replace(/_/g, ' ').replace(/^./, (c) => c.toUpperCase()); } function errorMessages(status, data) { if (status === 422 && data && data.errors) { const messages = Object.entries(data.errors).flatMap(([field, list]) => list.map((m) => `${humanize(field)} ${m}`)); if (messages.length > 0) return messages; } if (status === 403) return ['You can\'t plant in this garden.']; if (status === 401) return ['Please sign in again to plant something.']; return ['Something went wrong saving that. Please try again.']; } // Where you are: done steps get a tick, the current one is marked for // assistive technology as well as by colour. function Steps({current}) { return (
    {STEPS.map((label, index) => { const number = index + 1; const state = number < current ? 'done' : number === current ? 'current' : 'todo'; return (
  1. {state === 'done' ?