Track comment bounties

This commit is contained in:
Ian Philips 2022-09-30 09:23:59 -06:00
parent ae9210c744
commit 0255b23bff
4 changed files with 34 additions and 16 deletions

View File

@ -27,6 +27,7 @@ export function AwardBountyButton(prop: {
awardCommentBounty(data)
.then((_) => {
console.log('success')
track('award comment bounty', data)
})
.catch((reason) => console.log('Server error:', reason))

View File

@ -31,6 +31,10 @@ export function AddCommentBountyPanel(props: { contract: Contract }) {
addCommentBounty({ amount, contractId })
.then((_) => {
track('offer comment bounty', {
amount,
contractId,
})
setIsSuccess(true)
setError(undefined)
setIsLoading(false)

View File

@ -219,28 +219,32 @@ export function ContractCommentInput(props: {
onSubmitComment?: () => void
}) {
const user = useUser()
const { contract, parentAnswerOutcome, parentCommentId, replyTo, className } =
props
const { openCommentBounties } = contract
async function onSubmitComment(editor: Editor) {
if (!user) {
track('sign in to comment')
return await firebaseLogin()
}
await createCommentOnContract(
props.contract.id,
contract.id,
editor.getJSON(),
user,
props.parentAnswerOutcome,
props.parentCommentId
!!openCommentBounties,
parentAnswerOutcome,
parentCommentId
)
props.onSubmitComment?.()
}
return (
<CommentInput
replyTo={props.replyTo}
parentAnswerOutcome={props.parentAnswerOutcome}
parentCommentId={props.parentCommentId}
replyTo={replyTo}
parentAnswerOutcome={parentAnswerOutcome}
parentCommentId={parentCommentId}
onSubmitComment={onSubmitComment}
className={props.className}
className={className}
/>
)
}

View File

@ -35,6 +35,7 @@ export async function createCommentOnContract(
contractId: string,
content: JSONContent,
user: User,
onContractWithBounty: boolean,
answerOutcome?: string,
replyToCommentId?: string
) {
@ -50,7 +51,8 @@ export async function createCommentOnContract(
content,
user,
ref,
replyToCommentId
replyToCommentId,
onContractWithBounty
)
}
export async function createCommentOnGroup(
@ -95,7 +97,8 @@ async function createComment(
content: JSONContent,
user: User,
ref: DocumentReference<DocumentData>,
replyToCommentId?: string
replyToCommentId?: string,
onContractWithBounty?: boolean
) {
const comment = removeUndefinedProps({
id: ref.id,
@ -108,13 +111,19 @@ async function createComment(
replyToCommentId: replyToCommentId,
...extraFields,
})
track(`${extraFields.commentType} message`, {
user,
commentId: ref.id,
surfaceId,
replyToCommentId: replyToCommentId,
})
track(
`${extraFields.commentType} message`,
removeUndefinedProps({
user,
commentId: ref.id,
surfaceId,
replyToCommentId: replyToCommentId,
onContractWithBounty:
extraFields.commentType === 'contract'
? onContractWithBounty
: undefined,
})
)
return await setDoc(ref, comment)
}