parsley/app/javascript/components/TheRecipeCreator.vue

60 lines
1.2 KiB
Vue
Raw Normal View History

2018-04-01 21:43:23 -05:00
<template>
<div>
<recipe-edit :recipe="recipe" action="Creating"></recipe-edit>
2018-04-01 22:32:13 -05:00
<button type="button" class="button is-primary" @click="save">Save</button>
<router-link class="button is-secondary" to="/">Cancel</router-link>
2018-04-01 21:43:23 -05:00
</div>
</template>
<script>
import RecipeEdit from "./RecipeEdit";
import { mapState } from "vuex";
import api from "../lib/Api";
2018-04-01 22:32:13 -05:00
import * as Errors from '../lib/Errors';
2018-04-01 21:43:23 -05:00
export default {
data() {
return {
recipe: {
name: null,
source: null,
description: null,
yields: null,
total_time: null,
active_time: null,
step_text: null,
tags: [],
ingredients: []
}
}
},
computed: {
...mapState({
recipeId: state => state.route.params.id,
})
},
2018-04-01 22:32:13 -05:00
methods: {
save() {
this.loadResource(
api.postRecipe(this.recipe)
.then(() => this.$router.push('/'))
.catch(Errors.onlyFor(Errors.ApiValidationError, err => this.validationErrors = err.validationErrors()))
);
}
},
2018-04-01 21:43:23 -05:00
components: {
RecipeEdit
}
}
</script>
<style lang="scss" scoped>
</style>