import React, { useState } from 'react'; import PropTypes from 'prop-types'; import { Button, Text, TextInput, View } from 'react-native'; import { Avatar } from 'react-native-elements'; import { getNomAvailaibility } from '../../api/profile.js'; import styles from './Profile.styles.js'; const STRINGS = { ABOUT_GENERATED_NOM: 'You currently have a generated Nom De Bid - the alias other bidders will know you as - why not personalize it?', NOM_EXPLANATION: "Selecting a nom de bid allows you to bid anonymously - or not. By default, we'll use your first initial and last name.", ONLY_SET_ONCE: 'This can only be set once!', SUBMIT_NOM: 'Set Nom De Bid', }; export default function EditNomDeBid({ isGeneratedNomDeBid, isStandalone, nomDeBid, updateNomDeBid, }) { const [newNom, setNomDeBid] = useState(isGeneratedNomDeBid || !nomDeBid ? '' : nomDeBid); const [isNomValid, setValidNom] = useState(null); const _handleEndEditing = () => { getNomAvailaibility(newNom).then((result) => { setValidNom(result.available); if (isStandalone) { updateNomDeBid(newNom); } }); }; const _handleSubmitNom = () => { if (isNomValid) { updateNomDeBid(newNom); } }; const explanationString = isGeneratedNomDeBid ? `${STRINGS.ABOUT_GENERATED_NOM} ${STRINGS.ONLY_SET_ONCE}` : `${STRINGS.NOM_EXPLANATION} ${STRINGS.ONLY_SET_ONCE}`; return ( {explanationString} setNomDeBid(text)} onEndEditing={() => _handleEndEditing()} placeholder="nom de bid" style={[styles.textInput, styles.requiredInput]} value={newNom} /> {isNomValid === false && ( Nom De Bid is taken! )} {isNomValid === true && ( Nom De Bid is available! )} {!isStandalone && (