Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

2.3 KB
Raw Blame
import { LemonField } from 'lib/lemon-ui/LemonField'
import { LemonSelect, LemonSelectOption } from 'lib/lemon-ui/LemonSelect'

const ROLE_OPTIONS: LemonSelectOption<string>[] = [
    { label: 'Engineering', value: 'engineering' },
    { label: 'Data', value: 'data' },
    { label: 'Product Management', value: 'product' },
    { label: 'Founder', value: 'founder' },
    { label: 'Leadership', value: 'leadership' },
    { label: 'Marketing', value: 'marketing' },
    { label: 'Sales / Success', value: 'sales' },
    { label: 'Student', value: 'student' },
]

const OTHER_ROLE_OPTION: LemonSelectOption<string> = { label: 'Other', value: 'other' }

// Fisher-Yates, so every ordering is equally likely rather than merely jumbled
const shuffle = <T,>(items: T[]): T[] => {
    const shuffled = [...items]
    for (let i = shuffled.length - 1; i > 0; i--) {
        const j = Math.floor(Math.random() * (i + 1))
        ;[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]]
    }
    return shuffled
}

// Roles are shuffled so their order doesn't sway what people pick, with "Other" pinned last.
// Done at module scope so the list is stable for the page rather than reordering on every render.
const roleOptions = [...shuffle(ROLE_OPTIONS), OTHER_ROLE_OPTION]

export default function SignupRoleSelect({
    className,
    showOptional,
}: {
    className?: string
    // Only the invite signup form lets people submit without a role
    showOptional?: boolean
}): JSX.Element {
    return (
        <LemonField
            name="role_at_organization"
            label="What is your role?"
            className={className}
            showOptional={showOptional}
        >
            {({ value, onChange, error, id }) => (
                <LemonSelect
                    id={id}
                    fullWidth
                    data-attr="signup-role-at-organization"
                    options={roleOptions}
                    // The signup forms default this to an empty string, which LemonSelect treats as a
                    // selected value and renders as a blank button rather than the placeholder
                    value={value || undefined}
                    onChange={onChange}
                    placeholder="Select your role"
                    status={error ? 'danger' : 'default'}
                />
            )}
        </LemonField>
    )
}