make bio work as paid action
This commit is contained in:
parent
5fab3abb82
commit
65a7ef10d0
|
@ -23,8 +23,8 @@ export async function getCost ({ subName, parentId, uploadIds, boost = 0, bio },
|
|||
|
||||
// sub allows freebies (or is a bio or a comment), cost is less than baseCost, not anon,
|
||||
// cost must be greater than user's balance, and user has not disabled freebies
|
||||
const freebie = bio || (parentId && cost <= baseCost && !!me &&
|
||||
cost > me?.msats && !me?.disableFreebies)
|
||||
const freebie = (parentId || bio) && cost <= baseCost && !!me &&
|
||||
cost > me?.msats && !me?.disableFreebies
|
||||
|
||||
return freebie ? BigInt(0) : BigInt(cost)
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ export async function getCost ({ id, boost = 0, uploadIds, bio }, { me, models }
|
|||
throw new Error('creation invoice not paid')
|
||||
}
|
||||
|
||||
return bio ? BigInt(0) : cost
|
||||
return cost
|
||||
}
|
||||
|
||||
export async function perform (args, context) {
|
||||
|
|
|
@ -691,22 +691,20 @@ export default {
|
|||
|
||||
return Number(photoId)
|
||||
},
|
||||
upsertBio: async (parent, { bio }, { me, models, lnd }) => {
|
||||
upsertBio: async (parent, { text }, { me, models, lnd }) => {
|
||||
if (!me) {
|
||||
throw new GqlAuthenticationError()
|
||||
}
|
||||
|
||||
await ssValidate(bioSchema, { bio })
|
||||
await ssValidate(bioSchema, { text })
|
||||
|
||||
const user = await models.user.findUnique({ where: { id: me.id } })
|
||||
|
||||
if (user.bioId) {
|
||||
await updateItem(parent, { id: user.bioId, text: bio, title: `@${user.name}'s bio` }, { me, models, lnd })
|
||||
return await updateItem(parent, { id: user.bioId, bio: true, text, title: `@${user.name}'s bio` }, { me, models, lnd })
|
||||
} else {
|
||||
await createItem(parent, { bio: true, text: bio, title: `@${user.name}'s bio` }, { me, models, lnd })
|
||||
return await createItem(parent, { bio: true, text, title: `@${user.name}'s bio` }, { me, models, lnd })
|
||||
}
|
||||
|
||||
return await models.user.findUnique({ where: { id: me.id } })
|
||||
},
|
||||
generateApiKey: async (parent, { id }, { models, me }) => {
|
||||
if (!me) {
|
||||
|
|
|
@ -33,7 +33,7 @@ export default gql`
|
|||
setName(name: String!): String
|
||||
setSettings(settings: SettingsInput!): User
|
||||
setPhoto(photoId: ID!): Int!
|
||||
upsertBio(bio: String!): User!
|
||||
upsertBio(text: String!): ItemPaidAction!
|
||||
setWalkthrough(tipPopover: Boolean, upvotePopover: Boolean): Boolean
|
||||
unlinkAuth(authType: String!): AuthMethods!
|
||||
linkUnverifiedEmail(email: String!): Boolean
|
||||
|
|
|
@ -107,7 +107,7 @@ export default function Item ({
|
|||
{item.position && (pinnable || !item.subName)
|
||||
? <Pin width={24} height={24} className={styles.pin} />
|
||||
: item.mine || item.meForward
|
||||
? <Boost item={item} className={styles.upvote} />
|
||||
? <Boost item={item} className={classNames(styles.upvote, item.bio && 'invisible')} />
|
||||
: item.meDontLikeSats > item.meSats
|
||||
? <DownZap width={24} height={24} className={styles.dontLike} item={item} />
|
||||
: Number(item.user?.id) === USER_ID.ad
|
||||
|
|
|
@ -205,6 +205,16 @@ export const POLL_VOTE = gql`
|
|||
}
|
||||
}`
|
||||
|
||||
export const UPSERT_BIO = gql`
|
||||
${ITEM_PAID_ACTION_FIELDS}
|
||||
${PAID_ACTION}
|
||||
mutation upsertBio($text: String!) {
|
||||
upsertBio(text: $text) {
|
||||
...ItemPaidActionFields
|
||||
...PaidActionFields
|
||||
}
|
||||
}`
|
||||
|
||||
export const CREATE_COMMENT = gql`
|
||||
${ITEM_PAID_ACTION_FIELDS}
|
||||
${PAID_ACTION}
|
||||
|
|
|
@ -800,7 +800,7 @@ export const phoenixdSchema = object().shape({
|
|||
}, ['primaryPassword', 'secondaryPassword'])
|
||||
|
||||
export const bioSchema = object({
|
||||
bio: string().required('required').trim()
|
||||
text: string().required('required').trim()
|
||||
})
|
||||
|
||||
export const inviteSchema = object({
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import Layout from '@/components/layout'
|
||||
import { gql, useMutation, useQuery } from '@apollo/client'
|
||||
import { useQuery } from '@apollo/client'
|
||||
import UserHeader from '@/components/user-header'
|
||||
import Button from 'react-bootstrap/Button'
|
||||
import styles from '@/styles/user.module.css'
|
||||
|
@ -8,13 +8,14 @@ import ItemFull from '@/components/item-full'
|
|||
import { Form, MarkdownInput } from '@/components/form'
|
||||
import { useMe } from '@/components/me'
|
||||
import { USER_FULL } from '@/fragments/users'
|
||||
import { ITEM_FIELDS } from '@/fragments/items'
|
||||
import { getGetServerSideProps } from '@/api/ssrApollo'
|
||||
import { FeeButtonProvider } from '@/components/fee-button'
|
||||
import { bioSchema } from '@/lib/validate'
|
||||
import { useRouter } from 'next/router'
|
||||
import PageLoading from '@/components/page-loading'
|
||||
import { ItemButtonBar } from '@/components/post'
|
||||
import useItemSubmit from '@/components/use-item-submit'
|
||||
import { UPSERT_BIO } from '@/fragments/paidAction'
|
||||
|
||||
export const getServerSideProps = getGetServerSideProps({
|
||||
query: USER_FULL,
|
||||
|
@ -22,49 +23,41 @@ export const getServerSideProps = getGetServerSideProps({
|
|||
})
|
||||
|
||||
export function BioForm ({ handleDone, bio, me }) {
|
||||
const [upsertBio] = useMutation(
|
||||
gql`
|
||||
${ITEM_FIELDS}
|
||||
mutation upsertBio($bio: String!) {
|
||||
upsertBio(bio: $bio) {
|
||||
id
|
||||
bio {
|
||||
...ItemFields
|
||||
text
|
||||
}
|
||||
}
|
||||
}`, {
|
||||
update (cache, { data: { upsertBio } }) {
|
||||
const onSubmit = useItemSubmit(UPSERT_BIO, {
|
||||
navigateOnSubmit: false,
|
||||
paidMutationOptions: {
|
||||
update (cache, { data: { upsertBio: { result, invoice } } }) {
|
||||
if (!result) return
|
||||
|
||||
cache.modify({
|
||||
id: `User:${upsertBio.id}`,
|
||||
id: `User:${me.id}`,
|
||||
fields: {
|
||||
bio () {
|
||||
return upsertBio.bio
|
||||
return result.text
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
onSuccessfulSubmit: (data, { resetForm }) => {
|
||||
handleDone?.()
|
||||
}
|
||||
)
|
||||
})
|
||||
|
||||
return (
|
||||
<div className={styles.createFormContainer}>
|
||||
<FeeButtonProvider>
|
||||
<Form
|
||||
initial={{
|
||||
bio: bio?.text || ''
|
||||
text: bio?.text || ''
|
||||
}}
|
||||
schema={bioSchema}
|
||||
onSubmit={async values => {
|
||||
const { error } = await upsertBio({ variables: values })
|
||||
if (error) throw error
|
||||
handleDone?.()
|
||||
}}
|
||||
onSubmit={onSubmit}
|
||||
storageKeyPrefix={`bio-${me.id}`}
|
||||
>
|
||||
<MarkdownInput
|
||||
topLevel
|
||||
name='bio'
|
||||
name='text'
|
||||
minRows={6}
|
||||
/>
|
||||
<ItemButtonBar createText='save' onCancel={handleDone} />
|
||||
|
|
Loading…
Reference in New Issue