diff --git a/components/ShippingRates/InfoModal.vue b/components/ShippingRates/InfoModal.vue new file mode 100644 index 000000000..e2e2d5049 --- /dev/null +++ b/components/ShippingRates/InfoModal.vue @@ -0,0 +1,188 @@ + + + + + + {{ modalTitle }} + + + + + + + + + handleInputShippingRates(e, 'nameEn', index)" + /> + handleInputShippingRates(e, 'nameZh', index)" + /> + + + + handleInputShippingRates(e, 'price', index)" + /> + + + + + + + + + + + + + + No items + + + + + + + + + + + + + + + + + + + + + diff --git a/components/ShippingRates/index.vue b/components/ShippingRates/index.vue new file mode 100644 index 000000000..968cb3081 --- /dev/null +++ b/components/ShippingRates/index.vue @@ -0,0 +1,160 @@ + + + + + + + Shipping Options + + + + + + + + + + + en: {{ row.name.en }} + zh: {{ row.name.zh }} + + + + {{ row.price }} + + + + + + + + + + + + emit('on-update-shipping-rates', value)" + /> + + + + diff --git a/pages/nft-book-store/collection/new.vue b/pages/nft-book-store/collection/new.vue index 3cbf35ea6..540a7ca85 100644 --- a/pages/nft-book-store/collection/new.vue +++ b/pages/nft-book-store/collection/new.vue @@ -108,62 +108,21 @@ - - - Physical Goods - - - + + (Includes physical good that requires shipping) + - + - - - - Shipping Options and Prices - - - - - - - - - - updateShippingRate(e, 'price', index)" /> - - - - updateShippingRate(e, 'nameEn', index)" /> - updateShippingRate(e, 'nameZh', index)" /> - - - - - - + + + Books in Collection + + + - - - - Shipping Options - - - - - - {{ row.price }} - - - + @@ -511,6 +499,7 @@ const activeCoupon = ref('') const collectionListingInfo = ref({}) const ordersData = ref({}) const connectStatus = ref({}) +const isUpdatingShippingRates = ref(false) // Search const searchInput = ref('') @@ -591,17 +580,6 @@ const couponsTableRows = computed(() => { })) }) -const shippingRatesTableRows = computed(() => { - if (!collectionListingInfo.value.shippingRates) { - return [] - } - return collectionListingInfo.value.shippingRates.map((r: any, index: number) => ({ - index: index + 1, - name: r.name, - price: r.priceInDecimal / 100 - })) -}) - const orderTableColumns = computed(() => { const columns = [ { key: 'actions', label: 'Actions', sortable: false }, @@ -951,6 +929,21 @@ async function updateSettings () { } } +async function updateShippingRates (value: any) { + isUpdatingShippingRates.value = true + try { + await updateNFTBookCollectionById(collectionId.value as string, { + shippingRates: value + }) + collectionListingInfo.value = (await collectionStore.fetchCollectionById(collectionId.value as string)).value + } catch (err) { + const errorData = (err as any).data || err + error.value = errorData + } finally { + isUpdatingShippingRates.value = false + } +} + async function copyPurchaseLink () { await navigator.clipboard.writeText(purchaseLink.value) toast.add({ diff --git a/pages/nft-book-store/collection/status/[collectionId]/edit.vue b/pages/nft-book-store/collection/status/[collectionId]/edit.vue index 173817ccb..157d0ae1c 100644 --- a/pages/nft-book-store/collection/status/[collectionId]/edit.vue +++ b/pages/nft-book-store/collection/status/[collectionId]/edit.vue @@ -84,22 +84,11 @@ :sanitize="sanitizeHtml" /> - - - - Physical Goods - - - - - + @@ -138,6 +127,7 @@ const descriptionEn = ref('') const descriptionZh = ref('') const image = ref('') const hasShipping = ref(false) +const shippingRates = ref([]) const toolbarOptions = ref([ 'bold', @@ -186,6 +176,7 @@ onMounted(async () => { descriptionEn.value = collectionListingInfo.value.description?.en || ' ' descriptionZh.value = collectionListingInfo.value.description?.zh || ' ' hasShipping.value = collectionListingInfo.value.hasShipping || false + shippingRates.value = collectionListingInfo.value.shippingRates || [] } catch (error) { // eslint-disable-next-line no-console console.error(error) diff --git a/pages/nft-book-store/new.vue b/pages/nft-book-store/new.vue index 11d34d9c9..6bd9dd14c 100644 --- a/pages/nft-book-store/new.vue +++ b/pages/nft-book-store/new.vue @@ -42,10 +42,18 @@ + + @@ -122,64 +130,16 @@ :sanitize="sanitizeHtml" /> - - - - - - Physical Goods - - - updatePrice(e, 'hasShipping', index)" - /> - - - - - - - - - Shipping Options and Prices - - - - - - - - - updateShippingRate(e, 'price', index)" /> - - - - updateShippingRate(e, 'nameEn', index)" /> - updateShippingRate(e, 'nameZh', index)" /> - - + - + - - - Shipping Options - - - - - - {{ row.price }} - - - + @@ -594,7 +577,6 @@ - @@ -631,6 +613,7 @@ const prices = ref([]) const isUpdatingPricesOrder = ref(false) const ordersData = ref({}) const connectStatus = ref({}) +const isUpdatingShippingRates = ref(false) // Search const searchInput = ref('') @@ -711,18 +694,6 @@ const couponsTableRows = computed(() => { discount: (value as any).discount })) }) - -const shippingRatesTableRows = computed(() => { - if (!classListingInfo.value.shippingRates) { - return [] - } - return classListingInfo.value.shippingRates.map((r: any, index: number) => ({ - index: index + 1, - name: r.name, - price: r.priceInDecimal / 100 - })) -}) - const orderTableColumns = computed(() => { const columns = [ { key: 'actions', label: 'Actions', sortable: false }, @@ -1140,6 +1111,29 @@ async function updateSettings () { } } +async function updateShippingRates (value: any) { + isUpdatingShippingRates.value = true + try { + await updateBookListingSetting(classId.value as string, { + shippingRates: value + }) + const { data: classData } = await useFetch( + `${LIKE_CO_API}/likernft/book/store/${classId.value}`, + { + headers: { + authorization: `Bearer ${token.value}` + } + } + ) + classListingInfo.value = classData.value + } catch (err) { + const errorData = (err as any).data || err + error.value = errorData + } finally { + isUpdatingShippingRates.value = false + } +} + async function copyPurchaseLink () { await navigator.clipboard.writeText(purchaseLink.value) toast.add({ diff --git a/pages/nft-book-store/status/[classId]/edit/[editionIndex].vue b/pages/nft-book-store/status/[classId]/edit/[editionIndex].vue index fea721e5f..f5fee2ce9 100644 --- a/pages/nft-book-store/status/[classId]/edit/[editionIndex].vue +++ b/pages/nft-book-store/status/[classId]/edit/[editionIndex].vue @@ -90,25 +90,13 @@ :sanitize="sanitizeHtml" /> - - - - Physical Goods - - - - - + ([]) +const isUpdatingShippingRates = ref(false) const oldStock = ref(0) const oldIsAutoDeliver = ref(false) @@ -227,6 +217,7 @@ onMounted(async () => { const classResData = classRes?.data?.value if (classResData) { + shippingRates.value = classResData?.shippingRates || [] if (classResData?.ownerWallet !== wallet.value) { throw new Error('NOT_OWNER_OF_NFT_CLASS') } @@ -243,7 +234,7 @@ onMounted(async () => { const legacyDescription = typeof currentEdition.description === 'string' ? currentEdition.description : undefined descriptionEn.value = currentEdition.description?.en || legacyDescription || ' ' descriptionZh.value = currentEdition.description?.zh || legacyDescription || ' ' - hasShipping.value = currentEdition.hasShipping || false + hasShipping.value = !!(currentEdition.hasShipping) || false isPhysicalOnly.value = currentEdition.isPhysicalOnly || false oldStock.value = currentEdition.stock @@ -286,6 +277,29 @@ function handleClickBack () { }) } +async function updateShippingRates (value: any) { + isUpdatingShippingRates.value = true + try { + await updateBookListingSetting(classId.value as string, { + shippingRates: value + }) + const { data: classData } = await useFetch( + `${LIKE_CO_API}/likernft/book/store/${classId.value}`, + { + headers: { + authorization: `Bearer ${token.value}` + } + } + ) + shippingRates.value = classData.value?.shippingRates || [] + } catch (err) { + const errorData = (err as any).data || err + error.value = errorData + } finally { + isUpdatingShippingRates.value = false + } +} + async function handleSubmit () { try { const editedPrice = { diff --git a/pages/nft-book-store/status/[classId]/edit/new.vue b/pages/nft-book-store/status/[classId]/edit/new.vue index 31477694a..95749ed8c 100644 --- a/pages/nft-book-store/status/[classId]/edit/new.vue +++ b/pages/nft-book-store/status/[classId]/edit/new.vue @@ -89,25 +89,13 @@ :sanitize="sanitizeHtml" /> - - - - Physical Goods - - - - - + ([]) +const isUpdatingShippingRates = ref(false) + const priceItemLabel = computed(() => hasMultiplePrices.value ? 'edition' : 'book') const toolbarOptions = [ @@ -207,6 +199,7 @@ onMounted(async () => { const classResData = classRes?.data?.value if (classResData) { + shippingRates.value = classResData.shippingRates if (classResData?.ownerWallet !== wallet.value) { throw new Error('NOT_OWNER_OF_NFT_CLASS') } @@ -247,6 +240,29 @@ function handleClickBack () { }) } +async function updateShippingRates (value: any) { + isUpdatingShippingRates.value = true + try { + await updateBookListingSetting(classId.value as string, { + shippingRates: value + }) + const { data: classData } = await useFetch( + `${LIKE_CO_API}/likernft/book/store/${classId.value}`, + { + headers: { + authorization: `Bearer ${token.value}` + } + } + ) + shippingRates.value = classData.value?.shippingRates || [] + } catch (err) { + const errorData = (err as any).data || err + error.value = errorData + } finally { + isUpdatingShippingRates.value = false + } +} + async function handleSubmit () { try { const editedPrice = {