mirror of
https://github.com/ThisIsBenny/wishlist-app.git
synced 2025-04-19 23:37:41 +00:00
allow to delete wishlist
Signed-off-by: Benny Samir Hierl <bennysamir@posteo.de>
This commit is contained in:
parent
5bc3b4c35d
commit
435e96d9ad
7 changed files with 146 additions and 59 deletions
|
@ -1,47 +1,57 @@
|
||||||
<template>
|
<template>
|
||||||
<form @submit="onSubmit" class="w-full flex-col">
|
<div class="flex w-full flex-col justify-between space-y-2">
|
||||||
<InputText
|
<form @submit="onSubmit" class="w-full flex-col">
|
||||||
name="title"
|
<InputText
|
||||||
type="text"
|
name="title"
|
||||||
:value="wishlist?.title"
|
type="text"
|
||||||
:label="t('components.form-wishlist.title.label')"
|
:value="wishlist?.title"
|
||||||
/>
|
:label="t('components.form-wishlist.title.label')"
|
||||||
<InputToggle
|
/>
|
||||||
name="public"
|
<InputToggle
|
||||||
:value="wishlist?.public"
|
name="public"
|
||||||
:label="t('components.form-wishlist.public.label')"
|
:value="wishlist?.public"
|
||||||
/>
|
:label="t('components.form-wishlist.public.label')"
|
||||||
<InputTextArea
|
/>
|
||||||
name="description"
|
<InputTextArea
|
||||||
type="text"
|
name="description"
|
||||||
:value="wishlist?.description"
|
type="text"
|
||||||
height-class="h-20"
|
:value="wishlist?.description"
|
||||||
:label="t('components.form-wishlist.description.label')"
|
height-class="h-20"
|
||||||
/>
|
:label="t('components.form-wishlist.description.label')"
|
||||||
<InputText
|
/>
|
||||||
name="imageSrc"
|
<InputText
|
||||||
type="text"
|
name="imageSrc"
|
||||||
:value="wishlist?.imageSrc"
|
type="text"
|
||||||
:label="t('components.form-wishlist.image-src.label')"
|
:value="wishlist?.imageSrc"
|
||||||
/>
|
:label="t('components.form-wishlist.image-src.label')"
|
||||||
<InputFile
|
/>
|
||||||
name="imageFile"
|
<InputFile
|
||||||
:label="t('components.form-wishlist.image-file.label')"
|
name="imageFile"
|
||||||
/>
|
:label="t('components.form-wishlist.image-file.label')"
|
||||||
<InputText
|
/>
|
||||||
name="slugUrlText"
|
<InputText
|
||||||
type="text"
|
name="slugUrlText"
|
||||||
:value="wishlist?.slugUrlText"
|
type="text"
|
||||||
:label="t('components.form-wishlist.slug-text.label')"
|
:value="wishlist?.slugUrlText"
|
||||||
/>
|
:label="t('components.form-wishlist.slug-text.label')"
|
||||||
|
/>
|
||||||
|
<ButtonBase
|
||||||
|
class="h-12 w-full"
|
||||||
|
mode="primary"
|
||||||
|
:disabled="!meta.valid"
|
||||||
|
:icon="IconSave"
|
||||||
|
>{{ t('components.form-wishlist.submit.text') }}</ButtonBase
|
||||||
|
>
|
||||||
|
</form>
|
||||||
<ButtonBase
|
<ButtonBase
|
||||||
|
v-if="wishlist?.id"
|
||||||
class="h-12 w-full"
|
class="h-12 w-full"
|
||||||
mode="primary"
|
mode="danger"
|
||||||
:disabled="!meta.valid"
|
@click.prevent="() => emits('delete')"
|
||||||
:icon="IconSave"
|
:icon="IconDelete"
|
||||||
>{{ t('components.form-wishlist.submit.text') }}</ButtonBase
|
>{{ t('components.form-wishlist.delete-button.text') }}</ButtonBase
|
||||||
>
|
>
|
||||||
</form>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
|
@ -49,13 +59,14 @@ import { Wishlist } from '@/types'
|
||||||
import { useI18n } from 'vue-i18n'
|
import { useI18n } from 'vue-i18n'
|
||||||
import { useForm } from 'vee-validate'
|
import { useForm } from 'vee-validate'
|
||||||
import IconSave from '@/components/icons/IconSave.vue'
|
import IconSave from '@/components/icons/IconSave.vue'
|
||||||
|
import IconDelete from '@/components/icons/IconDelete.vue'
|
||||||
import { object, string, boolean } from 'yup'
|
import { object, string, boolean } from 'yup'
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
wishlist?: Wishlist
|
wishlist?: Wishlist
|
||||||
}>()
|
}>()
|
||||||
|
|
||||||
const emits = defineEmits(['create', 'update'])
|
const emits = defineEmits(['create', 'update', 'delete'])
|
||||||
|
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
|
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
mode="danger"
|
mode="danger"
|
||||||
@click.prevent="() => emits('delete')"
|
@click.prevent="() => emits('delete')"
|
||||||
:icon="IconDelete"
|
:icon="IconDelete"
|
||||||
>{{ t('components.wishlist-item.delete-button.text') }}</ButtonBase
|
>{{ t('components.form-wishlist-item.delete-button.text') }}</ButtonBase
|
||||||
>
|
>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -15,7 +15,7 @@ const fetch = async (slugText: string) => {
|
||||||
error.value = request.error.value
|
error.value = request.error.value
|
||||||
}
|
}
|
||||||
|
|
||||||
const create = async (wishlist: Wishlist): Promise<void> => {
|
const createWishlist = async (wishlist: Wishlist): Promise<void> => {
|
||||||
const { data, error } = await useFetch('/wishlist/')
|
const { data, error } = await useFetch('/wishlist/')
|
||||||
.post(unref(wishlist))
|
.post(unref(wishlist))
|
||||||
.json()
|
.json()
|
||||||
|
@ -24,7 +24,7 @@ const create = async (wishlist: Wishlist): Promise<void> => {
|
||||||
}
|
}
|
||||||
state.value = <Wishlist>data.value
|
state.value = <Wishlist>data.value
|
||||||
}
|
}
|
||||||
const update = async (updatedData: Wishlist): Promise<void> => {
|
const updateWishlist = async (updatedData: Wishlist): Promise<void> => {
|
||||||
const id = state.value?.id
|
const id = state.value?.id
|
||||||
const payload = {
|
const payload = {
|
||||||
...state.value,
|
...state.value,
|
||||||
|
@ -40,6 +40,13 @@ const update = async (updatedData: Wishlist): Promise<void> => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const deleteWishlist = async (): Promise<void> => {
|
||||||
|
const { error } = await useFetch(`/wishlist/${state.value.id}`).delete()
|
||||||
|
if (error.value) {
|
||||||
|
throw error.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const createItem = async (values: WishlistItem): Promise<void> => {
|
const createItem = async (values: WishlistItem): Promise<void> => {
|
||||||
const id = state.value?.id
|
const id = state.value?.id
|
||||||
const payload = {
|
const payload = {
|
||||||
|
@ -114,8 +121,9 @@ export const useWishlistStore = () => {
|
||||||
state,
|
state,
|
||||||
isFinished,
|
isFinished,
|
||||||
error,
|
error,
|
||||||
create,
|
createWishlist,
|
||||||
update,
|
updateWishlist,
|
||||||
|
deleteWishlist,
|
||||||
createItem,
|
createItem,
|
||||||
updateItem,
|
updateItem,
|
||||||
itemBought,
|
itemBought,
|
||||||
|
|
|
@ -14,6 +14,12 @@
|
||||||
},
|
},
|
||||||
"saving-failed": {
|
"saving-failed": {
|
||||||
"text": "Speichern ist fehlgeschlagen!"
|
"text": "Speichern ist fehlgeschlagen!"
|
||||||
|
},
|
||||||
|
"deleted": {
|
||||||
|
"text": "Gelöscht"
|
||||||
|
},
|
||||||
|
"deleting-failed": {
|
||||||
|
"text": "Löschen ist fehlgeschlagen!"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"errors": {
|
"errors": {
|
||||||
|
@ -62,6 +68,17 @@
|
||||||
"text": "Diese Wunschliste ist leer."
|
"text": "Diese Wunschliste ist leer."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"modal-delete-wishlist": {
|
||||||
|
"title": {
|
||||||
|
"text": "Möchten Sie die Wunschliste löschen?"
|
||||||
|
},
|
||||||
|
"confirm-button": {
|
||||||
|
"text": "Ja"
|
||||||
|
},
|
||||||
|
"cancel-button": {
|
||||||
|
"text": "Nein"
|
||||||
|
}
|
||||||
|
},
|
||||||
"modal-bought-item": {
|
"modal-bought-item": {
|
||||||
"title": {
|
"title": {
|
||||||
"text": "Möchten Sie den Gegenstand von der Liste nehmen?"
|
"text": "Möchten Sie den Gegenstand von der Liste nehmen?"
|
||||||
|
@ -103,9 +120,6 @@
|
||||||
},
|
},
|
||||||
"bought-button": {
|
"bought-button": {
|
||||||
"text": "Gekauft"
|
"text": "Gekauft"
|
||||||
},
|
|
||||||
"delete-button": {
|
|
||||||
"text": "Löschen"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"form-wishlist": {
|
"form-wishlist": {
|
||||||
|
@ -137,6 +151,9 @@
|
||||||
},
|
},
|
||||||
"submit": {
|
"submit": {
|
||||||
"text": "Speichern"
|
"text": "Speichern"
|
||||||
|
},
|
||||||
|
"delete-button": {
|
||||||
|
"text": "Löschen"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"form-wishlist-item": {
|
"form-wishlist-item": {
|
||||||
|
@ -168,6 +185,9 @@
|
||||||
},
|
},
|
||||||
"submit": {
|
"submit": {
|
||||||
"text": "Speichern"
|
"text": "Speichern"
|
||||||
|
},
|
||||||
|
"delete-button": {
|
||||||
|
"text": "Löschen"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"header": {
|
"header": {
|
||||||
|
|
|
@ -13,7 +13,13 @@
|
||||||
"text": "Saved"
|
"text": "Saved"
|
||||||
},
|
},
|
||||||
"saving-failed": {
|
"saving-failed": {
|
||||||
"text": "Saving failed"
|
"text": "Saving failed!"
|
||||||
|
},
|
||||||
|
"deleted": {
|
||||||
|
"text": "Deleted"
|
||||||
|
},
|
||||||
|
"deleting-failed": {
|
||||||
|
"text": "Deleting faild!"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"errors": {
|
"errors": {
|
||||||
|
@ -62,6 +68,17 @@
|
||||||
"text": "This wishlist is empty."
|
"text": "This wishlist is empty."
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"modal-delete-wishlist": {
|
||||||
|
"title": {
|
||||||
|
"text": "Do you want delete the wishlist?"
|
||||||
|
},
|
||||||
|
"confirm-button": {
|
||||||
|
"text": "Yes"
|
||||||
|
},
|
||||||
|
"cancel-button": {
|
||||||
|
"text": "No"
|
||||||
|
}
|
||||||
|
},
|
||||||
"modal-bought-item": {
|
"modal-bought-item": {
|
||||||
"title": {
|
"title": {
|
||||||
"text": "Do you want to remove the item from the list?"
|
"text": "Do you want to remove the item from the list?"
|
||||||
|
@ -103,9 +120,6 @@
|
||||||
},
|
},
|
||||||
"bought-button": {
|
"bought-button": {
|
||||||
"text": "Bought"
|
"text": "Bought"
|
||||||
},
|
|
||||||
"delete-button": {
|
|
||||||
"text": "Delete"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"form-wishlist": {
|
"form-wishlist": {
|
||||||
|
@ -134,6 +148,9 @@
|
||||||
},
|
},
|
||||||
"submit": {
|
"submit": {
|
||||||
"text": "Save"
|
"text": "Save"
|
||||||
|
},
|
||||||
|
"delete-button": {
|
||||||
|
"text": "Delete"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"form-wishlist-item": {
|
"form-wishlist-item": {
|
||||||
|
@ -165,6 +182,9 @@
|
||||||
},
|
},
|
||||||
"submit": {
|
"submit": {
|
||||||
"text": "Save"
|
"text": "Save"
|
||||||
|
},
|
||||||
|
"delete-button": {
|
||||||
|
"text": "Delete"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"header": {
|
"header": {
|
||||||
|
|
|
@ -9,13 +9,13 @@ import { useToast } from 'vue-toastification'
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { t } = useI18n()
|
const { t } = useI18n()
|
||||||
const toast = useToast()
|
const toast = useToast()
|
||||||
const { create } = useWishlistStore()
|
const { createWishlist } = useWishlistStore()
|
||||||
|
|
||||||
useTitle(t('pages.create-wishlist-view.title.text'))
|
useTitle(t('pages.create-wishlist-view.title.text'))
|
||||||
|
|
||||||
const handleCreateWishlist = async (wishlist: Wishlist): Promise<void> => {
|
const handleCreateWishlist = async (wishlist: Wishlist): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
await create(wishlist)
|
await createWishlist(wishlist)
|
||||||
toast.success(t('common.saved.text'))
|
toast.success(t('common.saved.text'))
|
||||||
router.push(`/${wishlist.slugUrlText}`)
|
router.push(`/${wishlist.slugUrlText}`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -17,7 +17,8 @@ const {
|
||||||
fetch,
|
fetch,
|
||||||
state,
|
state,
|
||||||
isFinished,
|
isFinished,
|
||||||
update,
|
updateWishlist,
|
||||||
|
deleteWishlist,
|
||||||
createItem,
|
createItem,
|
||||||
updateItem,
|
updateItem,
|
||||||
itemBought,
|
itemBought,
|
||||||
|
@ -36,7 +37,7 @@ useTitle(title)
|
||||||
|
|
||||||
const handleUpdateWishlist = async (wishlist: Wishlist): Promise<void> => {
|
const handleUpdateWishlist = async (wishlist: Wishlist): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
await update(wishlist)
|
await updateWishlist(wishlist)
|
||||||
toast.success(t('common.saved.text'))
|
toast.success(t('common.saved.text'))
|
||||||
router.push(`/${wishlist.slugUrlText}`)
|
router.push(`/${wishlist.slugUrlText}`)
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
@ -44,6 +45,23 @@ const handleUpdateWishlist = async (wishlist: Wishlist): Promise<void> => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const handleDelete = async (): Promise<void> => {
|
||||||
|
const confirmed = await modal.show(
|
||||||
|
t('pages.detail-view.modal-delete-wishlist.title.text'),
|
||||||
|
t('pages.detail-view.modal-delete-wishlist.confirm-button.text'),
|
||||||
|
t('pages.detail-view.modal-delete-wishlist.cancel-button.text')
|
||||||
|
)
|
||||||
|
if (confirmed) {
|
||||||
|
try {
|
||||||
|
await deleteWishlist()
|
||||||
|
toast.success(t('common.deleted.text'))
|
||||||
|
router.push('/')
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(t('common.deleting-failed.text'))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const handleCreateItem = async (values: WishlistItemType): Promise<void> => {
|
const handleCreateItem = async (values: WishlistItemType): Promise<void> => {
|
||||||
try {
|
try {
|
||||||
await createItem(values)
|
await createItem(values)
|
||||||
|
@ -83,7 +101,12 @@ const handleDeleteItem = async (item: WishlistItemType): Promise<void> => {
|
||||||
t('pages.detail-view.modal-delete-item.cancel-button.text')
|
t('pages.detail-view.modal-delete-item.cancel-button.text')
|
||||||
)
|
)
|
||||||
if (confirmed) {
|
if (confirmed) {
|
||||||
itemDelete(item)
|
try {
|
||||||
|
await itemDelete(item)
|
||||||
|
toast.success(t('common.deleted.text'))
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(t('common.deleting-failed.text'))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@ -110,7 +133,12 @@ const handleDeleteItem = async (item: WishlistItemType): Promise<void> => {
|
||||||
{{ state.description }}
|
{{ state.description }}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<FormWishlist v-else :wishlist="state" @update="handleUpdateWishlist" />
|
<FormWishlist
|
||||||
|
v-else
|
||||||
|
:wishlist="state"
|
||||||
|
@update="handleUpdateWishlist"
|
||||||
|
@delete="handleDelete"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
|
|
Loading…
Add table
Reference in a new issue