From 450c969dfc7535b41406b29d913404bdbc3295be Mon Sep 17 00:00:00 2001
From: Keyan <34140557+huumn@users.noreply.github.com>
Date: Tue, 24 Sep 2024 15:42:32 -0500
Subject: [PATCH] allow edit of pending items (#1431)
---
api/paidAction/itemUpdate.js | 8 +++++++-
api/resolvers/item.js | 4 ----
components/item-info.js | 36 ++++++++++++++++++++++++------------
3 files changed, 31 insertions(+), 17 deletions(-)
diff --git a/api/paidAction/itemUpdate.js b/api/paidAction/itemUpdate.js
index eec7a558..e3f9acc2 100644
--- a/api/paidAction/itemUpdate.js
+++ b/api/paidAction/itemUpdate.js
@@ -13,7 +13,13 @@ export async function getCost ({ id, boost = 0, uploadIds }, { me, models }) {
// or more boost
const old = await models.item.findUnique({ where: { id: parseInt(id) } })
const { totalFeesMsats } = await uploadFees(uploadIds, { models, me })
- return BigInt(totalFeesMsats) + satsToMsats(boost - old.boost)
+ const cost = BigInt(totalFeesMsats) + satsToMsats(boost - old.boost)
+
+ if (cost > 0 && old.invoiceActionState && old.invoiceActionState !== 'PAID') {
+ throw new Error('creation invoice not paid')
+ }
+
+ return cost
}
export async function perform (args, context) {
diff --git a/api/resolvers/item.js b/api/resolvers/item.js
index 6c452a27..76a56c84 100644
--- a/api/resolvers/item.js
+++ b/api/resolvers/item.js
@@ -1328,10 +1328,6 @@ export const updateItem = async (parent, { sub: subName, forward, hash, hmac, ..
throw new GqlInputError('item is deleted')
}
- if (old.invoiceActionState && old.invoiceActionState !== 'PAID') {
- throw new GqlInputError('cannot edit unpaid item')
- }
-
// author can edit their own item (except anon)
const meId = Number(me?.id ?? USER_ID.anon)
const authorEdit = !!me && Number(old.userId) === meId
diff --git a/components/item-info.js b/components/item-info.js
index cc79a276..e3ee688a 100644
--- a/components/item-info.js
+++ b/components/item-info.js
@@ -65,6 +65,29 @@ export default function ItemInfo ({
const meSats = (me ? item.meSats : item.meAnonSats) || 0
const EditInfo = () => {
+ if (canEdit) {
+ return (
+ <>
+ \
+ onEdit ? onEdit() : router.push(`/items/${item.id}/edit`)}
+ >
+ {editText || 'edit'}
+ {(!item.invoice?.actionState || item.invoice?.actionState === 'PAID') &&
+ { setCanEdit(false) }}
+ />}
+
+ >
+ )
+ }
+
+ return null
+ }
+
+ const PaymentInfo = () => {
const waitForQrPayment = useQrPayment()
if (item.deletedAt) return null
@@ -90,18 +113,6 @@ export default function ItemInfo ({
)
onClick = () => waitForQrPayment({ id: item.invoice?.id }, null, { cancelOnClose: false }).catch(console.error)
}
- } else if (canEdit) {
- Component = () => (
- <>
- {editText || 'edit'}
- {
- setCanEdit(false)
- }}
- />
- >)
- onClick = () => onEdit ? onEdit() : router.push(`/items/${item.id}/edit`)
} else {
return null
}
@@ -207,6 +218,7 @@ export default function ItemInfo ({
showActionDropdown &&
<>
+