{"version":3,"file":"NameField.mjs","names":[],"sources":["../../../../../src/components/Poll/PollCreationDialog/NameField.tsx"],"sourcesContent":["import React, { useMemo } from 'react';\nimport { TextInput } from '../../Form';\nimport { useTranslationContext } from '../../../context';\nimport { useMessageComposerController } from '../../MessageComposer/hooks/useMessageComposerController';\nimport { useStateStore } from '../../../store';\nimport { POLL_COMPOSER_VALIDATION_CODE } from 'stream-chat';\nimport type { PollComposerState, PollComposerValidationCode } from 'stream-chat';\n\nconst pollComposerStateSelector = (state: PollComposerState) => ({\n  error: state.errors.name,\n  name: state.data.name,\n});\n\nexport const NameField = () => {\n  const { t } = useTranslationContext();\n  const { pollComposer } = useMessageComposerController();\n  const { error, name } = useStateStore(pollComposer.state, pollComposerStateSelector);\n  // Keyed on the validation code: the English `message` from `stream-chat` may be reworded.\n  const knownValidationErrors = useMemo<\n    Partial<Record<PollComposerValidationCode, string>>\n  >(\n    () => ({\n      [POLL_COMPOSER_VALIDATION_CODE.nameRequired]: t(\n        'poll.nameField.questionRequired.label',\n        'Question is required',\n      ),\n    }),\n    [t],\n  );\n\n  return (\n    // `data-autofocus` marks the dialog's default field. Initial focus stays on the dialog surface\n    // so screen readers announce the dialog; Enter there moves focus here (see GlobalModal).\n    <TextInput\n      className='str-chat__form__input-field__value'\n      data-autofocus\n      error={!!error}\n      errorMessage={\n        error ? (\n          <span data-testid='poll-name-input-field-error'>\n            {knownValidationErrors[error.code] ?? error.message}\n          </span>\n        ) : undefined\n      }\n      id='name'\n      label={t('poll.question.question.text', 'Question')}\n      onBlur={() => {\n        pollComposer.handleFieldBlur('name');\n      }}\n      onChange={(e) => {\n        pollComposer.updateFields({ data: { name: e.target.value } });\n      }}\n      placeholder={t('poll.nameField.askQuestion.placeholder', 'Ask a Question')}\n      type='text'\n      value={name}\n    />\n  );\n};\n"],"mappings":";;;;;;;;AAQA,IAAM,6BAA6B,WAA8B;CAC/D,OAAO,MAAM,OAAO;CACpB,MAAM,MAAM,KAAK;AACnB;AAEA,IAAa,kBAAkB;CAC7B,MAAM,EAAE,MAAM,sBAAsB;CACpC,MAAM,EAAE,iBAAiB,6BAA6B;CACtD,MAAM,EAAE,OAAO,SAAS,cAAc,aAAa,OAAO,yBAAyB;CAEnF,MAAM,wBAAwB,eAGrB,GACJ,8BAA8B,eAAe,EAC5C,yCACA,sBACF,EACF,IACA,CAAC,CAAC,CACJ;CAEA,OAGE,oBAAC,WAAD;EACE,WAAU;EACV,kBAAA;EACA,OAAO,CAAC,CAAC;EACT,cACE,QACE,oBAAC,QAAD;GAAM,eAAY;aACf,sBAAsB,MAAM,SAAS,MAAM;EACxC,CAAA,IACJ,KAAA;EAEN,IAAG;EACH,OAAO,EAAE,+BAA+B,UAAU;EAClD,cAAc;GACZ,aAAa,gBAAgB,MAAM;EACrC;EACA,WAAW,MAAM;GACf,aAAa,aAAa,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,MAAM,EAAE,CAAC;EAC9D;EACA,aAAa,EAAE,0CAA0C,gBAAgB;EACzE,MAAK;EACL,OAAO;CACR,CAAA;AAEL"}