import React, { useState } from 'react';
import { Formik, Field, FieldArray, FormikActions, FormikProps, FieldArrayRenderProps } from 'formik';
import Recipe, { Ingredient, SubRecipe } from 'src/types/recipes';
import { Grid, Row, Cell } from '@material/react-layout-grid';
import './styles.scss';
import sample_image from 'sample.png';
type IngredientsListProps = {
ingredients: SubRecipe[],
}
type RecipeFormProps = {
initialValues: Recipe
}
const custom = (label: string, component = 'text') => ({field}: any) => (
{
component === 'text' ?
:
}
);
const SubrecipeForm = ({form, remove, push}: any) => {
const [selectedTab, setSelectedTab] = useState(0);
return (
{
form.values.ingredients.map((subrecipe: any, i: number) => (
-
setSelectedTab(i)}>
))
}
-
Ingredient Name
Quantity
Unit
Notes
Original
{
form.values.ingredients[selectedTab].ingredients.map((ingredient: Ingredient, index: number) => (
{
ingredient.suggestions && ingredient.suggestions.map((suggestion, index) => (
))
}
))
}
)
}
const RenderForm = ({
values,
handleChange,
handleSubmit
}: FormikProps) => {
return (
);
}
const RecipeForm = ({ initialValues }: RecipeFormProps) => (
{
console.log('submit', values, actions)
}}
render={RenderForm}
/>
);
export default RecipeForm;