{"version":3,"file":"index-BwvLu6ah.js","sources":["../../../app/javascript/components/sign-up/index.tsx"],"sourcesContent":["import React, { Component } from 'react'\n\nimport { EditableFields } from '~/actions/profile-details-edit'\nimport ContentBlock from '~/components/content-block'\nimport Form from '~/components/form'\nimport { i18n } from '~/i18n'\nimport { translateErrors } from '~/utils/error-messages'\nimport {\n INVALID,\n NOT_UNIQUE,\n HAS_UNCLAIMED_ONBOARDING,\n AGE_INVALID,\n REQUIRED,\n hasErrors,\n validateSignUp,\n} from '~/utils/validations'\n\nimport './sign-up.scss'\n\nimport type { GuestProfile, CreateGuestProfile } from '~/types'\n\nconst ageInvalidKey = () => {\n return i18n.t('components.errors.dob.min_13')\n}\n\nconst translationErrorsByKey = () => ({\n firstName: {\n [REQUIRED]: i18n.t('components.errors.first_name.required'),\n },\n lastName: {\n [REQUIRED]: i18n.t('components.errors.last_name.required'),\n },\n dob: {\n [AGE_INVALID]: ageInvalidKey(),\n [REQUIRED]: i18n.t('components.errors.dob.required'),\n },\n email: {\n [NOT_UNIQUE]: i18n.t('components.errors.email.not_unique'),\n [REQUIRED]: i18n.t('components.errors.email.required'),\n [INVALID]: i18n.t('components.errors.email.invalid'),\n [HAS_UNCLAIMED_ONBOARDING]: i18n.t(\n 'components.errors.email.has_unclaimed_onboarding',\n ),\n },\n password: {\n [INVALID]: i18n.t('components.password.errors.missing_requirements'),\n [REQUIRED]: i18n.t('components.password.errors.new_blank'),\n },\n})\n\nexport type BasicProps = {\n profile: GuestProfile\n errors: Record\n requirePassword: boolean\n subtitle: string\n hideHeading?: boolean\n renderDisabledEmailAsText?: boolean\n}\nexport type DispatchProps = {\n signUp: (profile: CreateGuestProfile) => void\n clearErrors?: () => void\n}\n\ntype Props = BasicProps & DispatchProps\n\ntype State = {\n errors: Record\n profile: GuestProfile\n}\n\nexport default class SignUp extends Component {\n state = {\n errors: {},\n profile: null,\n }\n\n UNSAFE_componentWillMount() {\n this.setState({\n profile: this.props.profile,\n })\n }\n\n handleCreate = (profile: CreateGuestProfile) => {\n if (this.props.clearErrors) this.props.clearErrors()\n\n const errors = validateSignUp(profile, this.props.requirePassword)\n this.setState({\n errors,\n })\n\n if (\n !hasErrors({\n errors,\n })\n ) {\n this.props.signUp(profile)\n }\n }\n\n onProfileChange = (field: string, value: any) => {\n const newProfileData = { ...(this.state.profile || {}), [field]: value }\n\n this.setState({\n profile: newProfileData,\n })\n\n if (hasErrors(this.state.errors)) {\n const errors = validateSignUp(newProfileData, this.props.requirePassword)\n this.setState({\n errors,\n })\n }\n }\n\n fieldDisabled(field: string): boolean {\n const { editableFields } = this.props.profile\n return !!editableFields && !editableFields.includes(field as EditableFields)\n }\n\n formFields() {\n const fields: Record = {\n firstName: {\n type: 'text',\n label: i18n.t('components.sign_up.fields.first_name.label'),\n disabled: this.fieldDisabled('firstName'),\n },\n lastName: {\n type: 'text',\n label: i18n.t('components.sign_up.fields.last_name.label'),\n disabled: this.fieldDisabled('lastName'),\n },\n email: {\n type: 'email',\n label: i18n.t('components.sign_up.fields.email.label'),\n disabled: this.fieldDisabled('email'),\n renderDisabledFieldAsText: this.props.renderDisabledEmailAsText,\n },\n dob: {\n type: 'date',\n label: i18n.t('components.sign_up.fields.dob.label'),\n disabled: this.fieldDisabled('dob'),\n },\n password: {\n id: 'sign-up-password',\n label: i18n.t('components.sign_up.fields.password.label'),\n placeholder: i18n.t('components.sign_up.fields.password.placeholder'),\n type: 'password',\n autoCompleteType: 'new-password',\n },\n }\n\n if (!this.props.requirePassword) {\n delete fields.password\n }\n\n return fields\n }\n\n renderForm() {\n const errors = translateErrors(\n { ...this.state.errors, ...this.props.errors },\n translationErrorsByKey(),\n )\n\n return (\n \n )\n }\n\n render() {\n return (\n
\n {!this.props.hideHeading && (\n

{i18n.t('components.sign_up.heading')}

\n )}\n \n {this.props.subtitle}\n \n {this.renderForm()}\n \n {i18n.t('components.sign_up.disclaimer')}\n \n
\n )\n }\n}\n"],"names":["ageInvalidKey","i18n","translationErrorsByKey","REQUIRED","AGE_INVALID","NOT_UNIQUE","INVALID","HAS_UNCLAIMED_ONBOARDING","SignUp","Component","profile","errors","validateSignUp","hasErrors","field","value","newProfileData","editableFields","fields","translateErrors","React","Form","ContentBlock"],"mappings":"iLAqBA,MAAMA,EAAgB,IACbC,EAAK,EAAE,8BAA8B,EAGxCC,EAAyB,KAAO,CACpC,UAAW,CACT,CAACC,CAAQ,EAAGF,EAAK,EAAE,uCAAuC,CAC5D,EACA,SAAU,CACR,CAACE,CAAQ,EAAGF,EAAK,EAAE,sCAAsC,CAC3D,EACA,IAAK,CACH,CAACG,CAAW,EAAGJ,EAAc,EAC7B,CAACG,CAAQ,EAAGF,EAAK,EAAE,gCAAgC,CACrD,EACA,MAAO,CACL,CAACI,CAAU,EAAGJ,EAAK,EAAE,oCAAoC,EACzD,CAACE,CAAQ,EAAGF,EAAK,EAAE,kCAAkC,EACrD,CAACK,CAAO,EAAGL,EAAK,EAAE,iCAAiC,EACnD,CAACM,CAAwB,EAAGN,EAAK,EAC/B,kDAAA,CAEJ,EACA,SAAU,CACR,CAACK,CAAO,EAAGL,EAAK,EAAE,iDAAiD,EACnE,CAACE,CAAQ,EAAGF,EAAK,EAAE,sCAAsC,CAAA,CAE7D,GAsBA,MAAqBO,UAAeC,EAAAA,SAAwB,CAA5D,aAAA,CAAA,MAAA,GAAA,SAAA,EACU,KAAA,MAAA,CACN,OAAQ,CAAC,EACT,QAAS,IACX,EAQA,KAAA,aAAgBC,GAAgC,CAC1C,KAAK,MAAM,aAAa,KAAK,MAAM,YAAY,EAEnD,MAAMC,EAASC,EAAeF,EAAS,KAAK,MAAM,eAAe,EACjE,KAAK,SAAS,CACZ,OAAAC,CAAA,CACD,EAGEE,EAAU,CACT,OAAAF,CAAA,CACD,GAEI,KAAA,MAAM,OAAOD,CAAO,CAE7B,EAEkB,KAAA,gBAAA,CAACI,EAAeC,IAAe,CACzC,MAAAC,EAAiB,CAAE,GAAI,KAAK,MAAM,SAAW,CAAK,EAAA,CAACF,CAAK,EAA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