MessageField.tsx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import type { UseFormReturn } from 'react-hook-form'
  2. // End of third-party imports
  3. import { FormControl, FormField, TextArea } from 'ui'
  4. import { Admonition } from 'ui-patterns/admonition'
  5. import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
  6. import { IPV4SuggestionAlert } from './IPV4SuggestionAlert'
  7. import { IPV4_MIGRATION_STRINGS } from './Support.constants'
  8. import type { SupportFormValues } from './SupportForm.schema'
  9. interface MessageFieldProps {
  10. form: UseFormReturn<SupportFormValues>
  11. originalError: string | null | undefined
  12. }
  13. export function MessageField({ form, originalError }: MessageFieldProps) {
  14. return (
  15. <FormField
  16. name="message"
  17. control={form.control}
  18. render={({ field }) => (
  19. <FormItemLayout
  20. layout="vertical"
  21. label="Message"
  22. labelOptional="5000 character limit"
  23. description={
  24. IPV4_MIGRATION_STRINGS.some((str) => field.value.includes(str)) && (
  25. <IPV4SuggestionAlert />
  26. )
  27. }
  28. >
  29. <FormControl>
  30. <TextArea
  31. {...field}
  32. rows={4}
  33. maxLength={5000}
  34. placeholder="Describe the issue you’re facing, along with any relevant information. Please be as detailed and specific as possible."
  35. />
  36. </FormControl>
  37. {originalError && (
  38. <Admonition
  39. showIcon={false}
  40. type="default"
  41. className="mt-2 max-h-[150px] overflow-y-auto"
  42. title="The error that you ran into will be included in your message for reference"
  43. description={`Error: ${originalError}`}
  44. />
  45. )}
  46. </FormItemLayout>
  47. )}
  48. />
  49. )
  50. }