Unverified Commit f285dfe7 authored by benguedj's avatar benguedj Committed by GitHub
Browse files

fix: 馃悰 Corrige le formulaire "Etre contact茅" (EPDS) (#552)

parent b102d48a
......@@ -83,11 +83,11 @@ export default {
epdsSurvey: {
beContacted: {
beContactedSent: "Votre demande de contact a bien 茅t茅 envoy茅e",
button: "脢tre appel茅(e)",
button: "脢tre contact茅(e)",
invalidEmail: "L'email n'est pas valide",
invalidPhoneNumber: "Le t茅l. n'est pas valide",
numberOfChildren: "Nombre d'enfants",
title: "脢tre appel茅(e)",
title: "脢tre contact茅(e)",
yourEmail: "Votre email",
yourFirstname: "Votre pr茅nom",
yourPhoneNumber: "Votre n掳 de t茅l.",
......
......@@ -139,12 +139,18 @@ const BeContacted: React.FC<Props> = ({ visible, hideModal }) => {
}
};
const renderTextInputView = (informationType: PersonalInformationType) => {
const renderTextInputView = (
informationType: PersonalInformationType,
isMandatory: boolean
) => {
const { label, isEmptyVariable } =
getLabelAndIsEmptyVariable(informationType);
return (
<View style={styles.rowView}>
<CommonText style={styles.textStyle}>{label}</CommonText>
<CommonText style={styles.textStyle}>
{isMandatory ? `${label} *` : label}
</CommonText>
<View>
<TextInput
keyboardType={
......@@ -158,7 +164,7 @@ const BeContacted: React.FC<Props> = ({ visible, hideModal }) => {
}}
placeholder={label}
/>
{isEmptyVariable && (
{isMandatory && isEmptyVariable && (
<HelperText type="error">{Labels.mandatoryField}</HelperText>
)}
{informationType === PersonalInformationType.email &&
......@@ -178,22 +184,24 @@ const BeContacted: React.FC<Props> = ({ visible, hideModal }) => {
);
};
const onValidate = async () => {
if (
!StringUtils.stringIsNotNullNorEmpty(firstName) &&
!StringUtils.stringIsNotNullNorEmpty(email) &&
!StringUtils.stringIsNotNullNorEmpty(childBirthDate) &&
emailIsValid &&
phoneNumberIsValid
) {
setFirstNameIsEmpty(!StringUtils.stringIsNotNullNorEmpty(firstName));
const isValidForm = () => {
let isValid = true;
if (!StringUtils.stringIsNotNullNorEmpty(email)) {
setEmailIsEmpty(!StringUtils.stringIsNotNullNorEmpty(email));
setChildBirthDateIsEmpty(
!StringUtils.stringIsNotNullNorEmpty(childBirthDate)
);
} else {
const date = new Date(childBirthDate);
const dateAsString = format(date, Formats.dateFR).replace(/\//g, "-");
isValid = false;
}
if (!emailIsValid || !phoneNumberIsValid) isValid = false;
return isValid;
};
const onValidate = async () => {
if (isValidForm()) {
let dateAsString = null;
if (StringUtils.stringIsNotNullNorEmpty(childBirthDate)) {
const date = new Date(childBirthDate);
dateAsString = format(date, Formats.dateFR).replace(/\//g, "-");
}
await sendContactInformation({
variables: {
......@@ -241,9 +249,9 @@ const BeContacted: React.FC<Props> = ({ visible, hideModal }) => {
/>
</TouchableOpacity>
<ScrollView>
{renderTextInputView(PersonalInformationType.firstName)}
{renderTextInputView(PersonalInformationType.email)}
{renderTextInputView(PersonalInformationType.phoneNumber)}
{renderTextInputView(PersonalInformationType.firstName, false)}
{renderTextInputView(PersonalInformationType.email, true)}
{renderTextInputView(PersonalInformationType.phoneNumber, false)}
<View style={styles.rowView}>
<CommonText style={styles.textStyle}>
{Labels.epdsSurvey.beContacted.numberOfChildren}
......@@ -365,6 +373,9 @@ const styles = StyleSheet.create({
margin: Margins.default,
padding: Paddings.default,
},
mandatory: {
color: "red",
},
rowView: {
alignItems: "center",
flexDirection: "row",
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment