Skip to content
Snippets Groups Projects
Commit 0e8f60c6 authored by Jens Christian Aanestad's avatar Jens Christian Aanestad
Browse files

refactor/Changed ExpenseBox component to emit expense id when editing

parent 91237c04
No related branches found
No related tags found
1 merge request!53Refactor/integration budgetview
<script setup lang="ts"> <script setup lang="ts">
import Button1 from '@/components/Buttons/Button1.vue' import { ref } from 'vue'
import { type CreateAppFunction, ref } from 'vue'
const emit = defineEmits(['deleteEvent', 'editEvent']); const emit = defineEmits(['deleteEvent', 'editEvent']);
const props = defineProps({ const props = defineProps({
id: {
type: Number,
required: true
},
index: { index: {
type: Number, type: Number,
default: 0 default: 0
...@@ -19,24 +22,24 @@ const props = defineProps({ ...@@ -19,24 +22,24 @@ const props = defineProps({
}) })
// Reactive variables for expense description and amount // Reactive variables for expense description and amount
let editDescription = ref('') let editDescription = ref(props.description)
let editAmount = ref('') let editAmount = ref(props.amount)
/** /**
* Emits an event to parent component with the type 'deleteEvent' to signalize * Emits an event to parent component with the type 'deleteEvent' to signalize
* that an expense with index 'index' must be removed. * that an expense with given id must be removed.
*/ */
const emitDeleteEvent = () => { const emitDeleteEvent = () => {
emit('deleteEvent', props.index) emit('deleteEvent', props.id)
} }
/** /**
* Emits an event to parent component with the type 'editEvent' to signalize * Emits an event to parent component with the type 'editEvent' to signalize
* that an expense with index 'index' is to be edited with the values 'editDescription' * that an expense with given id is to be edited with the values 'editDescription'
* and 'editAmount' * and 'editAmount'
*/ */
const emitEditEvent = () => { const emitEditEvent = () => {
emit('editEvent', props.index, editDescription.value, editAmount.value) emit('editEvent', props.id, editDescription.value, editAmount.value)
} }
</script> </script>
...@@ -55,11 +58,11 @@ const emitEditEvent = () => { ...@@ -55,11 +58,11 @@ const emitEditEvent = () => {
</button> </button>
</div> </div>
<div class="collapse" id=index> <div class="collapse" :id=String(index)>
<div class="container collapse-container"> <div class="container collapse-container">
<form @submit.prevent="emitEditEvent"> <form @submit.prevent="emitEditEvent">
<div class="input-group"> <div class="input-group">
<span class="input-group-text">Edit expense #{{ index+1 }}: </span> <span class="input-group-text">Edit expense {{ index+1 }} </span>
<input type="text" class="form-control" placeholder="Expense description" required v-model="editDescription"> <input type="text" class="form-control" placeholder="Expense description" required v-model="editDescription">
<input type="number" min="0" class="form-control" placeholder="Amount (kr)" required v-model="editAmount"> <input type="number" min="0" class="form-control" placeholder="Amount (kr)" required v-model="editAmount">
<button type="submit" class="btn btn-primary" data-bs-toggle="collapse" :data-bs-target="'#' + index">Confirm</button> <button type="submit" class="btn btn-primary" data-bs-toggle="collapse" :data-bs-target="'#' + index">Confirm</button>
...@@ -70,6 +73,10 @@ const emitEditEvent = () => { ...@@ -70,6 +73,10 @@ const emitEditEvent = () => {
</template> </template>
<style scoped> <style scoped>
div.collapse {
margin-bottom: 10px;
}
.expense-container { .expense-container {
padding: 0 10px; padding: 0 10px;
display: grid; display: grid;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment