ClientLibraryInfo.tsx 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. // End of third-party imports
  2. import { CLIENT_LIBRARIES } from 'common/constants'
  3. import { ExternalLink } from 'lucide-react'
  4. import Link from 'next/link'
  5. import type { UseFormReturn } from 'react-hook-form'
  6. import {
  7. Button,
  8. cn,
  9. FormControl,
  10. FormField,
  11. Select,
  12. SelectContent,
  13. SelectGroup,
  14. SelectItem,
  15. SelectTrigger,
  16. SelectValue,
  17. } from 'ui'
  18. import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
  19. import type { ExtendedSupportCategories } from './Support.constants'
  20. import type { SupportFormValues } from './SupportForm.schema'
  21. import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
  22. interface ClientLibraryInfoProps {
  23. form: UseFormReturn<SupportFormValues>
  24. category: ExtendedSupportCategories
  25. library: string | undefined
  26. }
  27. export function ClientLibraryInfo({ form, category, library }: ClientLibraryInfoProps) {
  28. const showClientLibraries = useIsFeatureEnabled('support:show_client_libraries')
  29. if (!showClientLibraries) return null
  30. if (category !== 'Problem') return null
  31. return (
  32. <div className="flex flex-col gap-y-1">
  33. <FormField
  34. name="library"
  35. control={form.control}
  36. render={({ field }) => (
  37. <FormItemLayout layout="vertical" label="Which library are you having issues with">
  38. <FormControl>
  39. <Select {...field} defaultValue={field.value} onValueChange={field.onChange}>
  40. <SelectTrigger className="w-full" aria-label="Select a library">
  41. <SelectValue placeholder="Select a library" />
  42. </SelectTrigger>
  43. <SelectContent>
  44. <SelectGroup>
  45. {CLIENT_LIBRARIES.map((option) => (
  46. <SelectItem key={option.language} value={option.language}>
  47. {option.language}
  48. </SelectItem>
  49. ))}
  50. </SelectGroup>
  51. </SelectContent>
  52. </Select>
  53. </FormControl>
  54. </FormItemLayout>
  55. )}
  56. />
  57. {library && library.length > 0 && <LibrarySuggestions library={library} />}
  58. </div>
  59. )
  60. }
  61. interface LibrarySuggestionsProps {
  62. library: string
  63. }
  64. const LibrarySuggestions = ({ library }: LibrarySuggestionsProps) => {
  65. const selectedLibrary = CLIENT_LIBRARIES.find((lib) => lib.language === library)
  66. const selectedClientLibraries = selectedLibrary?.libraries.filter((library) =>
  67. library.name.includes('briven-')
  68. )
  69. return (
  70. <div className="flex flex-col gap-y-4">
  71. <div className="space-y-2">
  72. <p className="text-sm text-foreground-light">
  73. Found an issue or a bug? Try searching our GitHub issues or submit a new one.
  74. </p>
  75. </div>
  76. <div className="flex items-center space-x-4 overflow-x-auto">
  77. {selectedClientLibraries?.map((lib) => {
  78. const libraryLanguage = library === 'Dart (Flutter)' ? lib.name.split('-')[1] : library
  79. return (
  80. <div
  81. key={lib.name}
  82. className="w-[230px] min-w-[230px] min-h-[128px] rounded-sm border border-control bg-surface-100 space-y-3 px-4 py-3"
  83. >
  84. <div className="space-y-1">
  85. <p className="text-sm">{lib.name}</p>
  86. <p className="text-sm text-foreground-light">
  87. For issues regarding the {libraryLanguage} client library
  88. </p>
  89. </div>
  90. <div>
  91. <Button asChild type="default" icon={<ExternalLink size={14} strokeWidth={1.5} />}>
  92. <Link href={lib.url} target="_blank" rel="noreferrer">
  93. View GitHub issues
  94. </Link>
  95. </Button>
  96. </div>
  97. </div>
  98. )
  99. })}
  100. <div
  101. className={cn(
  102. 'px-4 py-3 rounded-sm border border-control bg-surface-100',
  103. 'w-[230px] min-w-[230px] min-h-[128px] flex flex-col justify-between space-y-3'
  104. )}
  105. >
  106. <div className="space-y-1">
  107. <p className="text-sm">briven</p>
  108. <p className="text-sm text-foreground-light">For any issues about our API</p>
  109. </div>
  110. <div>
  111. <Button asChild type="default" icon={<ExternalLink size={14} strokeWidth={1.5} />}>
  112. <Link href="https://github.com/briven/briven" target="_blank" rel="noreferrer">
  113. View GitHub issues
  114. </Link>
  115. </Button>
  116. </div>
  117. </div>
  118. </div>
  119. </div>
  120. )
  121. }