AffectedServicesSelector.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. // End of third-party imports
  2. import { SupportCategories } from '@supabase/shared-types/out/constants'
  3. import type { UseFormReturn } from 'react-hook-form'
  4. import { FormControl, FormField } from 'ui'
  5. import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
  6. import {
  7. MultiSelector,
  8. MultiSelectorContent,
  9. MultiSelectorItem,
  10. MultiSelectorList,
  11. MultiSelectorTrigger,
  12. } from 'ui-patterns/multi-select'
  13. import { SERVICE_OPTIONS, type ExtendedSupportCategories } from './Support.constants'
  14. import type { SupportFormValues } from './SupportForm.schema'
  15. interface AffectedServicesSelectorProps {
  16. form: UseFormReturn<SupportFormValues>
  17. category: ExtendedSupportCategories
  18. }
  19. export const CATEGORIES_WITHOUT_AFFECTED_SERVICES: ExtendedSupportCategories[] = [
  20. SupportCategories.LOGIN_ISSUES,
  21. 'Plan_upgrade',
  22. ]
  23. export function AffectedServicesSelector({ form, category }: AffectedServicesSelectorProps) {
  24. if (CATEGORIES_WITHOUT_AFFECTED_SERVICES.includes(category)) return null
  25. return (
  26. <FormField
  27. name="affectedServices"
  28. control={form.control}
  29. render={({ field }) => (
  30. <FormItemLayout hideMessage layout="vertical" label="Which services are affected?">
  31. <FormControl>
  32. <MultiSelector
  33. values={field.value.length === 0 ? [] : field.value?.split(', ')}
  34. onValuesChange={(services) => field.onChange(services.join(', '))}
  35. >
  36. <MultiSelectorTrigger
  37. mode="inline-combobox"
  38. label={field.value.length === 0 ? 'No particular service' : 'Search for a service'}
  39. deletableBadge
  40. badgeLimit="wrap"
  41. showIcon={false}
  42. />
  43. <MultiSelectorContent>
  44. <MultiSelectorList>
  45. {SERVICE_OPTIONS.map((service) => (
  46. <MultiSelectorItem
  47. key={service.id}
  48. value={service.value}
  49. disabled={service.disabled}
  50. >
  51. {service.name}
  52. </MultiSelectorItem>
  53. ))}
  54. </MultiSelectorList>
  55. </MultiSelectorContent>
  56. </MultiSelector>
  57. </FormControl>
  58. </FormItemLayout>
  59. )}
  60. />
  61. )
  62. }