allow edit of pending items (#1431)

This commit is contained in:
Keyan 2024-09-24 15:42:32 -05:00 committed by GitHub
parent 1641b58e55
commit 450c969dfc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 31 additions and 17 deletions

View File

@ -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) {

View File

@ -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

View File

@ -65,6 +65,29 @@ export default function ItemInfo ({
const meSats = (me ? item.meSats : item.meAnonSats) || 0
const EditInfo = () => {
if (canEdit) {
return (
<>
<span> \ </span>
<span
className='text-reset pointer fw-bold'
onClick={() => onEdit ? onEdit() : router.push(`/items/${item.id}/edit`)}
>
<span>{editText || 'edit'} </span>
{(!item.invoice?.actionState || item.invoice?.actionState === 'PAID') &&
<Countdown
date={editThreshold}
onComplete={() => { setCanEdit(false) }}
/>}
</span>
</>
)
}
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 = () => (
<>
<span>{editText || 'edit'} </span>
<Countdown
date={editThreshold}
onComplete={() => {
setCanEdit(false)
}}
/>
</>)
onClick = () => onEdit ? onEdit() : router.push(`/items/${item.id}/edit`)
} else {
return null
}
@ -207,6 +218,7 @@ export default function ItemInfo ({
showActionDropdown &&
<>
<EditInfo />
<PaymentInfo />
<ActionDropdown>
<CopyLinkDropdownItem item={item} />
<InfoDropdownItem item={item} />