Skip to content

Commit

Permalink
checkbox for user to enable/disable email sharing (briefercloud#167)
Browse files Browse the repository at this point in the history
* checkbox for user to enable/disable email sharing

* Update apps/api/src/events/posthog.ts

---------

Co-authored-by: Lucas Vieira <[email protected]>
  • Loading branch information
lucasfcosta and vieiralucas authored Oct 25, 2024
1 parent 5930074 commit 616d331
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 5 deletions.
6 changes: 5 additions & 1 deletion apps/api/src/auth/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
} from './token.js'
import { createWorkspace } from '../workspace/index.js'
import { isWorkspaceNameValid } from '../utils/validation.js'
import { captureWorkspaceCreated } from '../events/posthog.js'

type BaseAuthConfig = {
FRONTEND_URL: string
Expand Down Expand Up @@ -67,6 +68,7 @@ export default function getRouter<H extends ApiUser>(
name: z.string().trim(),
email: z.string().trim().email(),
password: z.string(),
shareEmail: z.boolean(),
})
.safeParse(req.body)

Expand All @@ -77,7 +79,7 @@ export default function getRouter<H extends ApiUser>(
return
}

const { email, password } = payload.data
const { email, password, shareEmail } = payload.data
if (!isValidPassword(password)) {
res.status(400).json({
reason: 'invalid-password',
Expand Down Expand Up @@ -115,6 +117,8 @@ export default function getRouter<H extends ApiUser>(
return { workspace, user }
})

captureWorkspaceCreated(user, workspace, shareEmail)

const loginLink = createLoginLink(user.id, config.FRONTEND_URL)

res.status(201).json({ workspace, loginLink })
Expand Down
7 changes: 3 additions & 4 deletions apps/api/src/events/posthog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@ export function getPostHogClient() {

export const captureWorkspaceCreated = async (
sender: ApiUser,
workspace: ApiWorkspace
workspace: ApiWorkspace,
shareEmail: boolean
) => {
const posthog = getPostHogClient()
posthog?.capture({
distinctId: sender.id,
event: 'workspace_created',
properties: {
workspaceId: workspace.id,
workspaceUseContext: workspace.useContext,
workspaceUseCases: workspace.useCases,
workspaceSource: workspace.source,
creatorId: sender.id,
ownerEmail: shareEmail ? sender.email : null,
},
})
}
Expand Down
28 changes: 28 additions & 0 deletions apps/web/src/components/setup/UserForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import {
UseFormRegister,
} from 'react-hook-form'
import Spin from '../Spin'
import { Tooltip } from '../Tooltips'

export type UserStepFormValues = {
firstName: string
lastName: string
email: string
password: string
confirmPassword: string
shareEmail: boolean
}

interface Props {
Expand Down Expand Up @@ -100,6 +102,32 @@ function UserSetupForm(props: Props) {
})}
/>
</div>
<div className="mt-2 flex items-center">
<input
{...props.register('shareEmail')}
id="shareEmail"
tabIndex={-1}
type="checkbox"
className="h-4 w-4 text-primary-600 transition duration-150 ease-in-out outline-0 ring-0 focus:ring-0 rounded-sm"
/>
<span className="ml-2 text-sm text-gray-500 hover:cursor-pointer">
<label htmlFor="shareEmail">
{`I'm okay to share my email with the Briefer team. `}
</label>
<Tooltip
title="We will NOT send you spam, we promise."
message="We use this field to understand who our users are and how we can improve Briefer."
position="top"
active
className="inline-block"
tooltipClassname="w-64"
>
<span className="underline cursor-help hover:text-gray-600 flex gap-x-1.5 items-center">
{'That will help us a lot!'}
</span>
</Tooltip>
</span>
</div>
<FormError msg={props.formErrors.email?.message} />
</div>
</div>
Expand Down
5 changes: 5 additions & 0 deletions apps/web/src/pages/setup.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ function SetupForm() {
} = useForm<UserStepFormValues>({
mode: 'onSubmit',
reValidateMode: 'onSubmit',
defaultValues: {
shareEmail: true,
},
})

const [formValues, setFormValues] = useState<
Expand All @@ -65,6 +68,7 @@ function SetupForm() {
email: '',
password: '',
confirmPassword: '',
shareEmail: true,
})

const [currentStep, setCurrentStep] = useState<'workspace' | 'user'>(
Expand Down Expand Up @@ -94,6 +98,7 @@ function SetupForm() {
name: `${payload.firstName} ${payload.lastName}`,
email: payload.email,
password: payload.password,
shareEmail: payload.shareEmail,
}),
}
)
Expand Down

0 comments on commit 616d331

Please sign in to comment.