content.tsx 1.6 KB

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