import React, { Fragment, useState } from 'react'; import { Element, Link } from 'react-scroll'; import CopyToClipboard from 'react-copy-to-clipboard'; import Header from '../../general/Header'; import Footer from '../../general/Footer'; import Loader from 'Shared/Loader'; import { __wprm } from 'Shared/Translations'; import Api from 'Shared/Api'; import Icon from 'Shared/Icon'; import FieldGroup from '../../fields/FieldGroup'; import RecipeImport from './RecipeImport'; import RecipeMedia from './RecipeMedia'; import RecipePostType from './RecipePostType'; import RecipeGeneral from './RecipeGeneral'; import RecipeTimes from './RecipeTimes'; import RecipeCategories from './RecipeCategories'; import RecipeIngredients from './RecipeIngredients'; import RecipeEquipment from './RecipeEquipment'; import RecipeInstructions from './RecipeInstructions'; import RecipeNutrition from './RecipeNutrition'; import RecipeCustomFields from './RecipeCustomFields'; import RecipeNotes from './RecipeNotes'; const EditRecipe = (props) => { const hasUpload = props.recipe.video_id > 0; const hasEmbed = ! hasUpload && ( -1 == props.recipe.video_id || props.recipe.video_embed ); const hasVideo = hasUpload || hasEmbed; const [nutritionWarning, setNutritionWarning] = useState(false); let structure = [ { id: 'import', name: __wprm( 'Import' ), elem: ( ) }, { id: 'media', name: __wprm( 'Media' ), elem: ( ) } ]; if ( 'public' === wprm_admin.settings.post_type_structure || 'manual' === wprm_admin.settings.recipe_use_author ) { structure.push({ id: 'postType', name: __wprm( 'Post Type' ), elem: ( ) }); } structure.push({ id: 'general', name: __wprm( 'General' ), elem: ( ) }); structure.push({ id: 'times', name: __wprm( 'Times' ), elem: ( ) }); structure.push({ id: 'categories', name: __wprm( 'Categories' ), elem: ( ) }); structure.push({ id: 'equipment', name: __wprm( 'Equipment' ), elem: ( ) }); structure.push({ id: 'ingredients', name: 'howto' === props.recipe.type ? __wprm( 'Materials' ) : __wprm( 'Ingredients' ), elem: ( ) }); structure.push({ id: 'instructions', name: __wprm( 'Instructions' ), elem: ( ) }); // Only show nutrition for food recipes. if ( 'howto' !== props.recipe.type ) { let nutritionName = __wprm( 'Nutrition' ); let nutritionClassName = 'wprm-admin-modal-recipe-quicklink'; if ( nutritionWarning ) { nutritionClassName += ' wprm-admin-modal-recipe-quicklink-warning'; nutritionName = ( { __wprm( 'Nutrition' ) } ); } structure.push({ id: 'nutrition', name: nutritionName, className: nutritionClassName, elem: ( ) }); } // Only show custom fields when available and at least 1 is set. if ( wprm_admin_modal.custom_fields && wprm_admin_modal.custom_fields.fields && 0 < Object.keys( wprm_admin_modal.custom_fields.fields ).length ) { structure.push({ id: 'custom-fields', name: __wprm( 'Custom Fields' ), elem: ( { let newFields = Object.assign({}, JSON.parse( JSON.stringify( props.recipe.custom_fields ) ) ); newFields[ field ] = value; props.onRecipeChange({ custom_fields: newFields, }); }} /> ) }); } structure.push({ id: 'notes', name: __wprm( 'Notes' ), elem: ( ) }); return (
{ props.loadingRecipe ? __wprm( 'Loading Recipe...' ) : { props.recipe.id ? `${ __wprm( 'Editing Recipe' ) } #${props.recipe.id}${props.recipe.name ? ` - ${props.recipe.name}` : ''}` : `${ __wprm( 'Creating new Recipe' ) }${props.recipe.name ? ` - ${props.recipe.name}` : ''}` } }
{ structure.map((group, index) => ( { group.name } )) }
{ props.loadingRecipe ? :
{ structure.map((group, index) => ( { group.elem } )) }
}
{ 'waiting' === props.saveResult ? :
{ 'failed' === props.saveResult && { if ( result ) { alert( __wprm( 'The recipe has been copied and can be used in the "Import from JSON" feature.' ) ); } else { alert( __wprm( 'Something went wrong. Please contact support.' ) ); } }} > { e.preventDefault(); } }> { __wprm( 'Something went wrong during saving.' ) } { __wprm( 'Click to copy the recipe to your clipboard.' ) } } { 'ok' === props.saveResult ? { __wprm( 'Saved successfully' ) } : null }
}
); } export default EditRecipe;const conversionEndpoint = wprmp_admin.endpoints.unit_conversion; import ApiWrapper from 'Shared/ApiWrapper'; export default { get( ingredients, system = 'default' ) { const data = { ingredients, system, }; return ApiWrapper.call( `${conversionEndpoint}`, 'POST', data ); }, };
/** * WordPress dependencies */ import { Path, SVG } from '@wordpress/components'; export default ( );