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.5 KB
Raw Blame
import { useValues } from 'kea'

import { IconUpload } from '@posthog/icons'

import { LemonFileInput } from 'lib/lemon-ui/LemonFileInput'
import { preflightLogic } from 'lib/logic/preflightLogic'
import { cn } from 'lib/utils/css-classes'
import { cohortCsvMaxBytes, formatCohortCsvLimit } from 'scenes/cohorts/cohortUtils'

export const COHORT_CSV_HELP =
    "Upload a CSV file to add users to your cohort. For single-column files, include one distinct ID per row (all rows will be processed as data). For multi-column files, include a header row with a 'person_id', 'distinct_id', or 'email' column containing the user identifiers."

export function CohortCsvDropzone({
    value,
    onChange,
}: {
    value: File | null
    onChange: (file: File | null) => void
}): JSX.Element {
    const { preflight } = useValues(preflightLogic)
    return (
        <LemonFileInput
            accept=".csv"
            multiple={false}
            value={value ? [value] : []}
            onChange={(files) => onChange(files[0] ?? null)}
            showUploadedFiles={false}
            callToAction={
                <div
                    role="button"
                    tabIndex={0}
                    onKeyDown={(e) => {
                        if (e.key === 'Enter' || e.key === ' ') {
                            e.preventDefault()
                            e.currentTarget.click()
                        }
                    }}
                    className={cn(
                        'flex flex-col items-center justify-center flex-1 cohort-csv-dragger text-text-3000 deprecated-space-y-1',
                        'text-primary mt-0 bg-transparent border border-dashed border-primary hover:border-secondary p-8',
                        'focus-visible:outline focus-visible:outline-2 focus-visible:outline-accent',
                        value?.name && 'border-success'
                    )}
                >
                    <IconUpload className="text-5xl text-primary" />
                    {value ? (
                        <div>{value.name ?? 'File chosen'}</div>
                    ) : (
                        <>
                            <div>Drag a file here or click to browse for a file</div>
                            <div className="text-secondary text-xs">
                                {`Accepts .csv files up to ${formatCohortCsvLimit(cohortCsvMaxBytes(preflight))}`}
                            </div>
                        </>
                    )}
                </div>
            }
        />
    )
}