| @@ -234,20 +234,20 @@ const ContactInfo: React.FC<Props> = ({ | |||||
| if (getValues("addContacts").length === 0) { | if (getValues("addContacts").length === 0) { | ||||
| clearErrors("addContacts") | clearErrors("addContacts") | ||||
| } else { | } else { | ||||
| const errorRows = rows.filter(row => String(row.name).trim().length === 0 || String(row.phone).trim().length === 0 || String(row.email).trim().length === 0) | |||||
| const errorRows = rows.filter(row => String(row.name).trim().length === 0) | |||||
| if (errorRows.length > 0) { | if (errorRows.length > 0) { | ||||
| setError("addContacts", { message: "Contact details include empty fields", type: "required" }) | setError("addContacts", { message: "Contact details include empty fields", type: "required" }) | ||||
| } else { | } else { | ||||
| const errorRows_EmailFormat = rows.filter(row => !/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})$/.test(String(row.email))) | |||||
| // const errorRows_EmailFormat = rows.filter(row => !/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})$/.test(String(row.email))) | |||||
| const errorRows_PhoneFormat = rows.filter(row => !/^[+0-9][0-9\s]*$/.test(String(row.phone))) | |||||
| // const errorRows_PhoneFormat = rows.filter(row => !/^[+0-9][0-9\s]*$/.test(String(row.phone))) | |||||
| if (errorRows_EmailFormat.length > 0 || errorRows_PhoneFormat.length > 0) { | |||||
| setError("addContacts", { message: "Contact details include empty fields", type: "format" }) | |||||
| } else { | |||||
| // if (errorRows_EmailFormat.length > 0 || errorRows_PhoneFormat.length > 0) { | |||||
| // setError("addContacts", { message: "Contact details include empty fields", type: "format" }) | |||||
| // } else { | |||||
| clearErrors("addContacts") | clearErrors("addContacts") | ||||
| } | |||||
| // } | |||||
| } | } | ||||
| } | } | ||||
| }, [rows, rowModesModel]) | }, [rows, rowModesModel]) | ||||
| @@ -273,7 +273,7 @@ const ContactInfo: React.FC<Props> = ({ | |||||
| {t("Contact Info")} | {t("Contact Info")} | ||||
| </Typography> | </Typography> | ||||
| {Boolean(errors.addContacts?.type === "required") && <Typography sx={(theme) => ({ color: theme.palette.error.main })} variant="overline" display='inline-block' noWrap> | {Boolean(errors.addContacts?.type === "required") && <Typography sx={(theme) => ({ color: theme.palette.error.main })} variant="overline" display='inline-block' noWrap> | ||||
| {t("Please ensure at least one row is created, and all the fields are inputted and saved")} | |||||
| {t("Please ensure at least one row is created, and all the 'Contact Name' fields are inputted and saved")} | |||||
| </Typography>} | </Typography>} | ||||
| {Boolean(errors.addContacts?.type === "format") && <Typography sx={(theme) => ({ color: theme.palette.error.main })} variant="overline" display='inline-block' noWrap> | {Boolean(errors.addContacts?.type === "format") && <Typography sx={(theme) => ({ color: theme.palette.error.main })} variant="overline" display='inline-block' noWrap> | ||||
| {t("Please ensure all the email and phone formats are correct")} | {t("Please ensure all the email and phone formats are correct")} | ||||
| @@ -177,17 +177,17 @@ const CustomerSave: React.FC<Props> = ({ | |||||
| formProps.setError("brNo", { message: "Br No. format is not valid", type: "custom" }) | formProps.setError("brNo", { message: "Br No. format is not valid", type: "custom" }) | ||||
| } | } | ||||
| if (data.addContacts.length === 0 || data.addContacts.filter(row => String(row.name).trim().length === 0 || String(row.phone).trim().length === 0 || String(row.email).trim().length === 0).length > 0) { | |||||
| if (data.addContacts.length === 0 || data.addContacts.filter(row => String(row.name).trim().length === 0).length > 0) { | |||||
| haveError = true | haveError = true | ||||
| formProps.setError("addContacts", { message: "Contact info includes empty fields", type: "required" }) | formProps.setError("addContacts", { message: "Contact info includes empty fields", type: "required" }) | ||||
| } | } | ||||
| if (data.addContacts.length > 0 | |||||
| && data.addContacts.filter(row => !/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})$/.test(String(row.email))).length > 0 | |||||
| && data.addContacts.filter(row => !/^[+0-9][0-9\s]*$/.test(String(row.phone))).length > 0) { | |||||
| haveError = true | |||||
| formProps.setError("addContacts", { message: "Contact info includes invalid email or phone", type: "format" }) | |||||
| } | |||||
| // if (data.addContacts.length > 0 | |||||
| // && data.addContacts.filter(row => !/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})$/.test(String(row.email))).length > 0 | |||||
| // && data.addContacts.filter(row => !/^[+0-9][0-9\s]*$/.test(String(row.phone))).length > 0) { | |||||
| // haveError = true | |||||
| // formProps.setError("addContacts", { message: "Contact info includes invalid email or phone", type: "format" }) | |||||
| // } | |||||
| if (haveError) { | if (haveError) { | ||||
| // go to the error tab | // go to the error tab | ||||
| @@ -226,20 +226,20 @@ const ContactInfo: React.FC<Props> = ({ | |||||
| if (getValues("addContacts").length === 0) { | if (getValues("addContacts").length === 0) { | ||||
| clearErrors("addContacts") | clearErrors("addContacts") | ||||
| } else { | } else { | ||||
| const errorRows = rows.filter(row => String(row.name).trim().length === 0 || String(row.phone).trim().length === 0 || String(row.email).trim().length === 0) | |||||
| const errorRows = rows.filter(row => String(row.name).trim().length === 0) | |||||
| if (errorRows.length > 0) { | if (errorRows.length > 0) { | ||||
| setError("addContacts", { message: "Contact details include empty fields", type: "required" }) | setError("addContacts", { message: "Contact details include empty fields", type: "required" }) | ||||
| } else { | } else { | ||||
| const errorRows_EmailFormat = rows.filter(row => !/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})$/.test(String(row.email))) | |||||
| // const errorRows_EmailFormat = rows.filter(row => !/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})$/.test(String(row.email))) | |||||
| const errorRows_PhoneFormat = rows.filter(row => !/^[+0-9][0-9\s]*$/.test(String(row.phone))) | |||||
| // const errorRows_PhoneFormat = rows.filter(row => !/^[+0-9][0-9\s]*$/.test(String(row.phone))) | |||||
| if (errorRows_EmailFormat.length > 0 || errorRows_PhoneFormat.length > 0) { | |||||
| setError("addContacts", { message: "Contact details include empty fields", type: "format" }) | |||||
| } else { | |||||
| // if (errorRows_EmailFormat.length > 0 || errorRows_PhoneFormat.length > 0) { | |||||
| // setError("addContacts", { message: "Contact details include empty fields", type: "format" }) | |||||
| // } else { | |||||
| clearErrors("addContacts") | clearErrors("addContacts") | ||||
| } | |||||
| // } | |||||
| } | } | ||||
| } | } | ||||
| }, [rows]) | }, [rows]) | ||||
| @@ -265,7 +265,7 @@ const ContactInfo: React.FC<Props> = ({ | |||||
| {t("Contact Info")} | {t("Contact Info")} | ||||
| </Typography> | </Typography> | ||||
| {Boolean(errors.addContacts?.type === "required") && <Typography sx={(theme) => ({ color: theme.palette.error.main })} variant="overline" display='inline-block' noWrap> | {Boolean(errors.addContacts?.type === "required") && <Typography sx={(theme) => ({ color: theme.palette.error.main })} variant="overline" display='inline-block' noWrap> | ||||
| {t("Please ensure at least one row is created, and all the fields are inputted and saved")} | |||||
| {t("Please ensure at least one row is created, and all the 'Contact Name' fields are inputted and saved")} | |||||
| </Typography>} | </Typography>} | ||||
| {Boolean(errors.addContacts?.type === "format") && <Typography sx={(theme) => ({ color: theme.palette.error.main })} variant="overline" display='inline-block' noWrap> | {Boolean(errors.addContacts?.type === "format") && <Typography sx={(theme) => ({ color: theme.palette.error.main })} variant="overline" display='inline-block' noWrap> | ||||
| {t("Please ensure all the email and phone formats are correct")} | {t("Please ensure all the email and phone formats are correct")} | ||||
| @@ -152,17 +152,17 @@ const SubsidiaryDetail: React.FC<Props> = ({ | |||||
| formProps.setError("brNo", { message: "Br No. format is not valid", type: "custom" }) | formProps.setError("brNo", { message: "Br No. format is not valid", type: "custom" }) | ||||
| } | } | ||||
| if (data.addContacts.length === 0 || data.addContacts.filter(row => String(row.name).trim().length === 0 || String(row.phone).trim().length === 0 || String(row.email).trim().length === 0).length > 0) { | |||||
| if (data.addContacts.length === 0 || data.addContacts.filter(row => String(row.name).trim().length === 0).length > 0) { | |||||
| haveError = true | haveError = true | ||||
| formProps.setError("addContacts", { message: "Contact info includes empty fields", type: "required" }) | formProps.setError("addContacts", { message: "Contact info includes empty fields", type: "required" }) | ||||
| } | } | ||||
| if (data.addContacts.length > 0 | |||||
| && data.addContacts.filter(row => !/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})$/.test(String(row.email))).length > 0 | |||||
| && data.addContacts.filter(row => !/^[+0-9][0-9\s]*$/.test(String(row.phone))).length > 0) { | |||||
| haveError = true | |||||
| formProps.setError("addContacts", { message: "Contact info includes invalid email or phone", type: "format" }) | |||||
| } | |||||
| // if (data.addContacts.length > 0 | |||||
| // && data.addContacts.filter(row => !/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})$/.test(String(row.email))).length > 0 | |||||
| // && data.addContacts.filter(row => !/^[+0-9][0-9\s]*$/.test(String(row.phone))).length > 0) { | |||||
| // haveError = true | |||||
| // formProps.setError("addContacts", { message: "Contact info includes invalid email or phone", type: "format" }) | |||||
| // } | |||||
| if (haveError) { | if (haveError) { | ||||
| // go to the error tab | // go to the error tab | ||||
| @@ -43,7 +43,7 @@ | |||||
| "Contact Name": "聯絡姓名", | "Contact Name": "聯絡姓名", | ||||
| "Contact Email": "聯絡電郵", | "Contact Email": "聯絡電郵", | ||||
| "Contact Phone": "聯絡電話", | "Contact Phone": "聯絡電話", | ||||
| "Please ensure at least one row is created, and all the fields are inputted and saved": "請確保已建立至少一行, 及已輸入和儲存所有欄位", | |||||
| "Please ensure at least one row is created, and all the 'Contact Name' fields are inputted and saved": "請確保已建立至少一行, 及已輸入和儲存所有聯絡姓名欄位", | |||||
| "Please ensure all the email and phone formats are correct": "請確保所有電郵和電話格式輸入正確", | "Please ensure all the email and phone formats are correct": "請確保所有電郵和電話格式輸入正確", | ||||
| "Do you want to submit?": "你是否確認要提交?", | "Do you want to submit?": "你是否確認要提交?", | ||||
| @@ -43,7 +43,7 @@ | |||||
| "Contact Name": "聯絡姓名", | "Contact Name": "聯絡姓名", | ||||
| "Contact Email": "聯絡電郵", | "Contact Email": "聯絡電郵", | ||||
| "Contact Phone": "聯絡電話", | "Contact Phone": "聯絡電話", | ||||
| "Please ensure at least one row is created, and all the fields are inputted and saved": "請確保已建立至少一行, 及已輸入和儲存所有欄位", | |||||
| "Please ensure at least one row is created, and all the 'Contact Name' fields are inputted and saved": "請確保已建立至少一行, 及已輸入和儲存所有聯絡姓名欄位", | |||||
| "Please ensure all the email and phone formats are correct": "請確保所有電郵和電話格式輸入正確", | "Please ensure all the email and phone formats are correct": "請確保所有電郵和電話格式輸入正確", | ||||
| "Do you want to submit?": "你是否確認要提交?", | "Do you want to submit?": "你是否確認要提交?", | ||||