add edit items
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
d5b29bdc91
commit
42a82a2b31
@ -0,0 +1,51 @@
|
||||
<script setup lang="ts">
|
||||
import { useShoppingListStore } from '../store/shoppingList';
|
||||
import { ref, reactive, defineProps } from 'vue';
|
||||
import { useRouter } from 'vue-router';
|
||||
|
||||
const store = useShoppingListStore();
|
||||
const router = useRouter();
|
||||
|
||||
const props = defineProps({
|
||||
item: Object,
|
||||
});
|
||||
|
||||
const isValid = ref(false);
|
||||
const item = reactive({
|
||||
name: props.item.name,
|
||||
price: props.item.price / 100,
|
||||
user: props.item.user.name,
|
||||
});
|
||||
|
||||
const form = ref(null);
|
||||
|
||||
const submit = () => {
|
||||
props.item.name = item.name;
|
||||
props.item.price = item.price * 100;
|
||||
props.item.user = store.users.find(user => user.name === item.user);
|
||||
router.push('/shopping-list');
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<v-form ref="form" v-model="isValid" lazy-validation>
|
||||
<v-text-field
|
||||
label="Item Name"
|
||||
required
|
||||
v-model="item.name"
|
||||
/>
|
||||
<v-text-field
|
||||
label="Price"
|
||||
suffix="€"
|
||||
required
|
||||
v-model="item.price"
|
||||
/>
|
||||
<v-select
|
||||
label="User"
|
||||
:items="store.users.map(user => user.name)"
|
||||
required
|
||||
v-model="item.user"
|
||||
/>
|
||||
<v-btn color="primary" @click="submit()">edit item</v-btn>
|
||||
</v-form>
|
||||
</template>
|
@ -0,0 +1,24 @@
|
||||
<script setup lang="ts">
|
||||
import DefaultPage from '../components/DefaultPage.vue';
|
||||
import EditItemForm from '../components/EditItemForm.vue';
|
||||
import { useRoute } from 'vue-router';
|
||||
import { useShoppingListStore} from '../store/shoppingList';
|
||||
import { ref } from 'vue';
|
||||
|
||||
const route = useRoute();
|
||||
const store = useShoppingListStore();
|
||||
|
||||
const item = ref(store.items.find(item => item.id === Number(route.params.id)));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<DefaultPage title="Add Item">
|
||||
<v-container>
|
||||
<EditItemForm v-if="item" :item="item"/>
|
||||
<div v-else>
|
||||
<p>This item does not exist.</p>
|
||||
<v-btn color="primary" to="/shopping-list">back to shopping list</v-btn>
|
||||
</div>
|
||||
</v-container>
|
||||
</DefaultPage>
|
||||
</template>
|
Loading…
Reference in New Issue