From 65b247573eba3cc188d8ad84cfd2d4718bb26ccb Mon Sep 17 00:00:00 2001 From: Tonya Date: Sat, 12 Oct 2024 14:29:21 +0000 Subject: [PATCH] Merge pull request #259 * feat: duplicate item button --- frontend/pages/item/[id]/index/edit.vue | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/frontend/pages/item/[id]/index/edit.vue b/frontend/pages/item/[id]/index/edit.vue index 1f3cd0bc..9afb3ff8 100644 --- a/frontend/pages/item/[id]/index/edit.vue +++ b/frontend/pages/item/[id]/index/edit.vue @@ -8,6 +8,7 @@ import MdiDelete from "~icons/mdi/delete"; import MdiPencil from "~icons/mdi/pencil"; import MdiContentSaveOutline from "~icons/mdi/content-save-outline"; + import MdiContentCopy from "~icons/mdi/content-copy"; definePageMeta({ middleware: ["auth"], @@ -59,6 +60,37 @@ refresh(); }); + async function duplicateItem() { + const { error, data } = await api.items.create({ + name: `${item.value.name} Copy`, + description: item.value.description, + locationId: item.value.location!.id, + parentId: item.value.parent?.id, + labelIds: item.value.labels.map(l => l.id), + }); + + if (error) { + toast.error("Failed to duplicate item"); + return; + } + + // add extra fields + const { error: updateError } = await api.items.update(data.id, { + ...item.value, + id: data.id, + labelIds: data.labels.map(l => l.id), + locationId: data.location!.id, + name: data.name, + }); + + if (updateError) { + toast.error("Failed to duplicate item"); + return; + } + + navigateTo(`/item/${data.id}`); + } + async function saveItem() { if (!item.value.location?.id) { toast.error("Failed to save item: no location selected"); @@ -470,6 +502,12 @@ Advanced + + + Duplicate +