|
@@ -1,4 +1,4 @@
|
|
|
-import React, { ReactComponentElement, useState } from 'react';
|
|
|
|
|
|
|
+import React, { useState } from 'react';
|
|
|
import { Formik, Field, FieldArray, FormikActions, FormikProps, FieldArrayRenderProps } from 'formik';
|
|
import { Formik, Field, FieldArray, FormikActions, FormikProps, FieldArrayRenderProps } from 'formik';
|
|
|
import Recipe, { Ingredient, SubRecipe } from 'src/types/recipes';
|
|
import Recipe, { Ingredient, SubRecipe } from 'src/types/recipes';
|
|
|
import { Grid, Row, Cell } from '@material/react-layout-grid';
|
|
import { Grid, Row, Cell } from '@material/react-layout-grid';
|
|
@@ -26,75 +26,73 @@ const custom = (label: string, component = 'text') => ({field}: any) => (
|
|
|
</span>
|
|
</span>
|
|
|
);
|
|
);
|
|
|
|
|
|
|
|
-class IngredientsList extends React.Component<IngredientsListProps, {selectedTab: number}> {
|
|
|
|
|
- constructor(props: IngredientsListProps) {
|
|
|
|
|
- super(props);
|
|
|
|
|
- this.state = {
|
|
|
|
|
- selectedTab: 0
|
|
|
|
|
- };
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- render() {
|
|
|
|
|
- const ingredients = this.props.ingredients;
|
|
|
|
|
- return (
|
|
|
|
|
- <section className='ingredient-tabs'>
|
|
|
|
|
-
|
|
|
|
|
- <ul className='tab-header'>
|
|
|
|
|
- {
|
|
|
|
|
- ingredients.map((subgroup: any, index: number) => (
|
|
|
|
|
- <li className='tab' key={index} onClick={()=>{ this.setState({ selectedTab: index })}}>
|
|
|
|
|
- {subgroup.name}
|
|
|
|
|
- </li>
|
|
|
|
|
- ))
|
|
|
|
|
- }
|
|
|
|
|
- </ul>
|
|
|
|
|
- <div>
|
|
|
|
|
- {
|
|
|
|
|
- ingredients[this.state.selectedTab].ingredients.map(i => i.name)
|
|
|
|
|
- }
|
|
|
|
|
- </div>
|
|
|
|
|
- </section>
|
|
|
|
|
- )
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-const Pls = ({form, remove, push}:any) => {
|
|
|
|
|
|
|
+const SubrecipeForm = ({form, remove, push}: any) => {
|
|
|
const [selectedTab, setSelectedTab] = useState(0);
|
|
const [selectedTab, setSelectedTab] = useState(0);
|
|
|
return (
|
|
return (
|
|
|
- <div className='ingredient-tabs'>
|
|
|
|
|
|
|
+ <div className='subrecipe-tabs'>
|
|
|
<ul className='tab-header'>
|
|
<ul className='tab-header'>
|
|
|
{
|
|
{
|
|
|
- form.values.ingredients.map((subrecipe: any, index: number) => (
|
|
|
|
|
|
|
+ form.values.ingredients.map((subrecipe: any, i: number) => (
|
|
|
<li
|
|
<li
|
|
|
- className={`tab${selectedTab === index ? ' tab--selected' : ''}`}
|
|
|
|
|
- key={index}
|
|
|
|
|
|
|
+ className={`tab${selectedTab === i ? ' tab--selected' : ''}`}
|
|
|
|
|
+ key={i}
|
|
|
>
|
|
>
|
|
|
- <div className='tab__content' onClick={()=> setSelectedTab(index)}>
|
|
|
|
|
- <Field name={`ingredients[${index}].name`}/>
|
|
|
|
|
|
|
+ <div className='tab__content' onClick={()=> setSelectedTab(i)}>
|
|
|
|
|
+ <Field name={`ingredients[${i}].name`}/>
|
|
|
</div>
|
|
</div>
|
|
|
- <button onClick={()=> remove(index)}>X</button>
|
|
|
|
|
|
|
+ <button type='button' onClick={()=> remove(i)}>X</button>
|
|
|
</li>
|
|
</li>
|
|
|
))
|
|
))
|
|
|
}
|
|
}
|
|
|
<li className='tab tab--add'>
|
|
<li className='tab tab--add'>
|
|
|
- <button onClick={()=> push({name: '', ingredients: []})}>+</button>
|
|
|
|
|
|
|
+ <button type='button' onClick={()=> push({name: '', ingredients: []})}>+</button>
|
|
|
</li>
|
|
</li>
|
|
|
</ul>
|
|
</ul>
|
|
|
- {
|
|
|
|
|
- form.values.ingredients[selectedTab].ingredients.map((i: any) => i.name + ' ')
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ <div className='ingredients-form'>
|
|
|
|
|
+ <div className='ingredients-form-header'>
|
|
|
|
|
+ <span>Ingredient Name</span>
|
|
|
|
|
+ <span>Quantity</span>
|
|
|
|
|
+ <span>Unit</span>
|
|
|
|
|
+ <span>Notes</span>
|
|
|
|
|
+ <span>Original</span>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ {
|
|
|
|
|
+ form.values.ingredients[selectedTab].ingredients.map((ingredient: Ingredient, index: number) => (
|
|
|
|
|
+ <div key={index}>
|
|
|
|
|
+ <div className='ingredients-form-item'>
|
|
|
|
|
+ <Field name={`ingredients[${selectedTab}].ingredients[${index}].name`} />
|
|
|
|
|
+ <Field name={`ingredients[${selectedTab}].ingredients[${index}].quantity`}/>
|
|
|
|
|
+ <Field component='select' name={`ingredients[${selectedTab}].ingredients[${index}].unit`}>
|
|
|
|
|
+ <option value='gr'>gr</option>
|
|
|
|
|
+ <option value='cup'>cup</option>
|
|
|
|
|
+ <option value='ml'>ml</option>
|
|
|
|
|
+ <option value='tablespoon'>tbsp</option>
|
|
|
|
|
+ <option value='teaspoon'>tsp</option>
|
|
|
|
|
+ </Field>
|
|
|
|
|
+ <Field name={`ingredients[${selectedTab}].ingredients[${index}].notes`} />
|
|
|
|
|
+ <Field name={`ingredients[${selectedTab}].ingredients[${index}]._original`}/>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ <div className='ingredients-form-suggestions'>
|
|
|
|
|
+ {
|
|
|
|
|
+ ingredient.suggestions && ingredient.suggestions.map((suggestion, index) => (
|
|
|
|
|
+ <button type='button' key={index}>{suggestion.name}</button>
|
|
|
|
|
+ ))
|
|
|
|
|
+ }
|
|
|
|
|
+ <button type='button'>Add convertion</button>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ </div>
|
|
|
|
|
+ ))
|
|
|
|
|
+ }
|
|
|
|
|
+ </div>
|
|
|
</div>
|
|
</div>
|
|
|
)
|
|
)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const RenderForm = ({
|
|
const RenderForm = ({
|
|
|
values,
|
|
values,
|
|
|
- status,
|
|
|
|
|
handleChange,
|
|
handleChange,
|
|
|
handleSubmit
|
|
handleSubmit
|
|
|
-}: any) => {
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
|
|
+}: FormikProps<Recipe>) => {
|
|
|
return (
|
|
return (
|
|
|
<Grid>
|
|
<Grid>
|
|
|
<form onSubmit={handleSubmit} className='cbk-recipe-form'>
|
|
<form onSubmit={handleSubmit} className='cbk-recipe-form'>
|
|
@@ -146,7 +144,7 @@ const RenderForm = ({
|
|
|
<section>
|
|
<section>
|
|
|
<FieldArray
|
|
<FieldArray
|
|
|
name='ingredients'
|
|
name='ingredients'
|
|
|
- component={Pls}
|
|
|
|
|
|
|
+ component={SubrecipeForm}
|
|
|
/>
|
|
/>
|
|
|
</section>
|
|
</section>
|
|
|
|
|
|
|
@@ -174,6 +172,7 @@ const RenderForm = ({
|
|
|
|
|
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
const RecipeForm = ({ initialValues }: RecipeFormProps) => (
|
|
const RecipeForm = ({ initialValues }: RecipeFormProps) => (
|
|
|
<Formik
|
|
<Formik
|
|
|
initialValues={initialValues}
|
|
initialValues={initialValues}
|