|
| 1 | +<template> |
| 2 | + <Card class="sm:p-4 xl:px-9 max-w-3xl w-full py-0" :pt:body:class="'p-0'"> |
| 3 | + <template #content> |
| 4 | + <div v-if="albumPurchasable !== undefined" class="flex flex-col gap-4"> |
| 5 | + <template v-if="albumPurchasable === null"> |
| 6 | + <p class="font-bold text-muted-color text-lg text-center">This album is not purchasable (yet).</p> |
| 7 | + <Textarea v-model="description" placeholder="Description for clients" /> |
| 8 | + <Textarea v-model="note" placeholder="Owner's Note" /> |
| 9 | + <PricesInput :prices="prices" /> |
| 10 | + <div class="flex gap-4"> |
| 11 | + <Button |
| 12 | + icon="pi pi-plus" |
| 13 | + label="Set Purchasable" |
| 14 | + class="border-none w-full" |
| 15 | + @click="makePurchasable" |
| 16 | + :disabled="prices.length === 0" |
| 17 | + > |
| 18 | + </Button> |
| 19 | + <Button |
| 20 | + icon="pi pi-forward" |
| 21 | + severity="danger" |
| 22 | + label="Set Purchasable and propagate" |
| 23 | + class="font-bold w-full border-none" |
| 24 | + @click=" |
| 25 | + appliesToSubalbums = true; |
| 26 | + makePurchasable(); |
| 27 | + " |
| 28 | + :disabled="prices.length === 0" |
| 29 | + > |
| 30 | + </Button> |
| 31 | + </div> |
| 32 | + <Message severity="error" v-if="prices.length === 0">Set at least one price.</Message> |
| 33 | + </template> |
| 34 | + <template v-else> |
| 35 | + <Textarea v-model="description" placeholder="Description for clients" /> |
| 36 | + <Textarea v-model="note" placeholder="Owner's Note" /> |
| 37 | + <PricesInput :prices="prices" /> |
| 38 | + <div class="flex gap-4"> |
| 39 | + <Button |
| 40 | + class="text-danger-800 font-bold hover:text-white hover:bg-danger-800 w-full bg-transparent border-none" |
| 41 | + @click="disable" |
| 42 | + >Disable</Button |
| 43 | + > |
| 44 | + <Button class="border-none font-bold w-full" @click="makePurchasable" :disabled="prices.length === 0"> Update </Button> |
| 45 | + </div> |
| 46 | + <Message severity="error" v-if="prices.length === 0">Set at least one price.</Message> |
| 47 | + </template> |
| 48 | + </div> |
| 49 | + </template> |
| 50 | + </Card> |
| 51 | +</template> |
| 52 | +<script setup lang="ts"> |
| 53 | +import ShopManagementService, { Price } from "@/services/shop-management-service"; |
| 54 | +import Card from "primevue/card"; |
| 55 | +import { useToast } from "primevue/usetoast"; |
| 56 | +import { onMounted, ref } from "vue"; |
| 57 | +import Textarea from "@/components/forms/basic/Textarea.vue"; |
| 58 | +import Button from "primevue/button"; |
| 59 | +import PricesInput from "@/components/forms/shop-management/PricesInput.vue"; |
| 60 | +import Message from "primevue/message"; |
| 61 | +import { useAlbumStore } from "@/stores/AlbumState"; |
| 62 | +
|
| 63 | +const toast = useToast(); |
| 64 | +const albumStore = useAlbumStore(); |
| 65 | +
|
| 66 | +const albumPurchasable = ref<undefined | App.Http.Resources.Shop.EditablePurchasableResource | null>(undefined); |
| 67 | +
|
| 68 | +const description = ref<string | undefined>(undefined); |
| 69 | +const note = ref<string | undefined>(undefined); |
| 70 | +const appliesToSubalbums = ref<boolean>(false); |
| 71 | +const prices = ref<Price[]>([]); |
| 72 | +
|
| 73 | +function load() { |
| 74 | + if (!albumStore.albumId) { |
| 75 | + return; |
| 76 | + } |
| 77 | +
|
| 78 | + // Reset state |
| 79 | + appliesToSubalbums.value = false; |
| 80 | +
|
| 81 | + ShopManagementService.list([albumStore.albumId]) |
| 82 | + .then((response) => { |
| 83 | + albumPurchasable.value = response.data.find((p) => p.album_id === albumStore.albumId && p.photo_id === null) ?? null; |
| 84 | +
|
| 85 | + description.value = albumPurchasable.value?.description ?? undefined; |
| 86 | + note.value = albumPurchasable.value?.owner_notes ?? undefined; |
| 87 | + prices.value = |
| 88 | + albumPurchasable.value?.prices?.map((p: App.Http.Resources.Shop.PriceResource) => { |
| 89 | + return { price: p.price_cents, license_type: p.license_type, size_variant_type: p.size_variant }; |
| 90 | + }) ?? []; |
| 91 | + }) |
| 92 | + .catch((error) => { |
| 93 | + toast.add({ severity: "error", summary: "Error", detail: error.message, life: 3000 }); |
| 94 | + }); |
| 95 | +} |
| 96 | +
|
| 97 | +function makePurchasable() { |
| 98 | + if (!albumStore.albumId) { |
| 99 | + return; |
| 100 | + } |
| 101 | +
|
| 102 | + ShopManagementService.createPurchasableAlbum({ |
| 103 | + album_ids: [albumStore.albumId], |
| 104 | + note: note.value ?? null, |
| 105 | + description: description.value ?? null, |
| 106 | + prices: prices.value, |
| 107 | + applies_to_subalbums: appliesToSubalbums.value, |
| 108 | + }) |
| 109 | + .then(() => { |
| 110 | + toast.add({ severity: "success", summary: "Success", detail: "Album is now purchasable", life: 3000 }); |
| 111 | + load(); |
| 112 | + }) |
| 113 | + .catch((error) => { |
| 114 | + toast.add({ severity: "error", summary: "Error", detail: error.message, life: 3000 }); |
| 115 | + }); |
| 116 | +} |
| 117 | +
|
| 118 | +function disable() { |
| 119 | + if (albumPurchasable.value === null || albumPurchasable.value === undefined) { |
| 120 | + return; |
| 121 | + } |
| 122 | + ShopManagementService.deletePurchasable(albumPurchasable.value.purchasable_id) |
| 123 | + .then(() => { |
| 124 | + toast.add({ severity: "success", summary: "Success", detail: "Album is no longer purchasable", life: 3000 }); |
| 125 | + load(); |
| 126 | + }) |
| 127 | + .catch((error) => { |
| 128 | + toast.add({ severity: "error", summary: "Error", detail: error.message, life: 3000 }); |
| 129 | + }); |
| 130 | +} |
| 131 | +
|
| 132 | +onMounted(() => { |
| 133 | + load(); |
| 134 | +}); |
| 135 | +</script> |
0 commit comments