Files
Eventment/app/components/Profile/EditNomDeBid.js
Mike Fitzpatrick f0460a1b76 - more
2019-08-12 17:44:01 -04:00

80 lines
2.4 KiB
JavaScript

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(false);
const _handleEndEditing = (nomDeBid) => {
getNomAvailaibility(nomDeBid).then((result) => {
setValidNom(result.available);
if (isStandalone) {
updateNomDeBid({ nomDeBid });
}
});
};
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 (
<View style={styles.profileFormWrap}>
<Text style={styles.hintText}>{explanationString}</Text>
<TextInput
onChangeText={(text) => setNomDeBid(text)}
onEndEditing={(text) => _handleEndEditing(text)}
placeholder="nom de bid"
style={[styles.textInput, styles.requiredInput]}
value={newNom}
/>
{!isStandalone && (
<Button
title={STRINGS.SUBMIT_NOM}
onPress={_handleSubmitNom}
disabled={!isNomValid}
/>
)}
</View>
);
}
EditNomDeBid.propTypes = {
isGeneratedNomDeBid: PropTypes.bool,
isStandalone: PropTypes.bool,
nomDeBid: PropTypes.string,
updateNomDeBid: PropTypes.func.isRequired,
};
EditNomDeBid.defaultProps = {
isGeneratedNomDeBid: false,
isStandalone: false,
nomDeBid: null,
};