content.tsx52 lines · main
| 1 | import { MultipleCodeBlock } from 'ui-patterns/MultipleCodeBlock' |
| 2 | |
| 3 | import type { StepContentProps } from '@/components/interfaces/ConnectSheet/Connect.types' |
| 4 | |
| 5 | function getEnvFile( |
| 6 | state: StepContentProps['state'], |
| 7 | projectKeys: StepContentProps['projectKeys'] |
| 8 | ) { |
| 9 | if (state.framework === 'nextjs') { |
| 10 | return { |
| 11 | name: '.env.local', |
| 12 | language: 'bash', |
| 13 | code: [ |
| 14 | `NEXT_PUBLIC_BRIVEN_URL=${projectKeys.apiUrl ?? 'your-project-url'}`, |
| 15 | projectKeys.publishableKey |
| 16 | ? `NEXT_PUBLIC_BRIVEN_PUBLISHABLE_KEY=${projectKeys.publishableKey}` |
| 17 | : `NEXT_PUBLIC_BRIVEN_ANON_KEY=${projectKeys.anonKey ?? 'your-anon-key'}`, |
| 18 | '', |
| 19 | ].join('\n'), |
| 20 | } |
| 21 | } |
| 22 | |
| 23 | if (state.framework === 'react') { |
| 24 | const isCreateReactApp = state.frameworkVariant === 'create-react-app' |
| 25 | const envFileName = isCreateReactApp ? '.env.local' : '.env' |
| 26 | const keyPrefix = isCreateReactApp ? 'REACT_APP' : 'VITE' |
| 27 | |
| 28 | return { |
| 29 | name: envFileName, |
| 30 | language: 'bash', |
| 31 | code: [ |
| 32 | `${keyPrefix}_BRIVEN_URL=${projectKeys.apiUrl ?? 'your-project-url'}`, |
| 33 | projectKeys.publishableKey |
| 34 | ? `${keyPrefix}_BRIVEN_PUBLISHABLE_KEY=${projectKeys.publishableKey}` |
| 35 | : `${keyPrefix}_BRIVEN_ANON_KEY=${projectKeys.anonKey ?? 'your-anon-key'}`, |
| 36 | '', |
| 37 | ].join('\n'), |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | return null |
| 42 | } |
| 43 | |
| 44 | function ShadcnEnvContent({ state, projectKeys }: StepContentProps) { |
| 45 | const envFile = getEnvFile(state, projectKeys) |
| 46 | |
| 47 | if (!envFile) return null |
| 48 | |
| 49 | return <MultipleCodeBlock files={[envFile]} /> |
| 50 | } |
| 51 | |
| 52 | export default ShadcnEnvContent |