diff --git a/src/components/CreateProject/ProjectClientDetails.tsx b/src/components/CreateProject/ProjectClientDetails.tsx index 1d68084..110f722 100644 --- a/src/components/CreateProject/ProjectClientDetails.tsx +++ b/src/components/CreateProject/ProjectClientDetails.tsx @@ -382,9 +382,9 @@ const ProjectClientDetails: React.FC = ({ fullWidth type="number" inputProps={{ step: "0.01" }} - InputLabelProps={{ - shrink: Boolean(watch("subContractFee")), - }} + // InputLabelProps={{ + // shrink: Boolean(watch("subContractFee")), + // }} {...register("subContractFee", { valueAsNumber: true })} /> @@ -412,9 +412,9 @@ const ProjectClientDetails: React.FC = ({ {t("Client Details")} - + */} diff --git a/src/components/CustomerSave/ContactInfo.tsx b/src/components/CustomerSave/ContactInfo.tsx index fdc6c76..983a6d6 100644 --- a/src/components/CustomerSave/ContactInfo.tsx +++ b/src/components/CustomerSave/ContactInfo.tsx @@ -142,7 +142,7 @@ const ContactInfo: React.FC = ({ resetField("addContacts") // reset({addContacts: defaultValues.addContacts}) setRows((prev) => defaultValues.addContacts) - setRowModesModel(rows.reduce((acc, row) => ({...acc, [row.id]: { mode: GridRowModes.View } }), {})) + setRowModesModel(rows.reduce((acc, row) => ({ ...acc, [row.id]: { mode: GridRowModes.View } }), {})) } }, [defaultValues]) @@ -159,6 +159,14 @@ const ContactInfo: React.FC = ({ headerName: t('Contact Phone'), editable: true, flex: 1, + // type: "number", + + // valueSetter: ({ value, row }) => { + + // const phone = value.replace(/\D/g, '') + + // return { ...row, phone } + // }, }, { field: 'email', @@ -232,8 +240,11 @@ const ContactInfo: React.FC = ({ setError("addContacts", { message: "Contact details include empty fields", type: "required" }) } else { const errorRows_EmailFormat = rows.filter(row => !/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})$/.test(String(row.email))) - if (errorRows_EmailFormat.length > 0) { - setError("addContacts", { message: "Contact details include empty fields", type: "email_format" }) + + 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 { clearErrors("addContacts") } @@ -264,8 +275,8 @@ const ContactInfo: React.FC = ({ {Boolean(errors.addContacts?.type === "required") && ({ 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")} } - {Boolean(errors.addContacts?.type === "email_format") && ({ color: theme.palette.error.main })} variant="overline" display='inline-block' noWrap> - {t("Please ensure all the email formats are correct")} + {Boolean(errors.addContacts?.type === "format") && ({ color: theme.palette.error.main })} variant="overline" display='inline-block' noWrap> + {t("Please ensure all the email and phone formats are correct")} } {/* */} = ({ toolbar: { setRows, setRowModesModel }, }} sx={{ - height: '100%' + height: '100%', + '& input[type=number]::-webkit-outer-spin-button': { + '-webkit-appearance': 'none', + margin: 0 + }, + '& input[type=number]::-webkit-inner-spin-button': { + '-webkit-appearance': 'none', + margin: 0 + } }} /> diff --git a/src/components/CustomerSave/CustomerSave.tsx b/src/components/CustomerSave/CustomerSave.tsx index acb4ecf..13ebcfc 100644 --- a/src/components/CustomerSave/CustomerSave.tsx +++ b/src/components/CustomerSave/CustomerSave.tsx @@ -182,9 +182,11 @@ const CustomerSave: React.FC = ({ 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) { + 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", type: "email_format" }) + formProps.setError("addContacts", { message: "Contact info includes invalid email or phone", type: "format" }) } if (haveError) { @@ -199,20 +201,20 @@ const CustomerSave: React.FC = ({ setServerError(""); submitDialog(async () => { - const response = await saveCustomer(data); - - if (response.message === "Success") { - successDialog(t("Submit Success"), t).then(() => { - router.replace("/settings/customer"); - }) - } else { - errorDialog(t("Submit Fail"), t).then(() => { - formProps.setError("code", { message: response.message, type: "custom" }) - setTabIndex(0) - return false - }) - } - }, t) + const response = await saveCustomer(data); + + if (response.message === "Success") { + successDialog(t("Submit Success"), t).then(() => { + router.replace("/settings/customer"); + }) + } else { + errorDialog(t("Submit Fail"), t).then(() => { + formProps.setError("code", { message: response.message, type: "custom" }) + setTabIndex(0) + return false + }) + } + }, t) } catch (e) { console.log(e) setServerError(t("An error has occurred. Please try again later.")); diff --git a/src/components/SubsidiaryDetail/ContactInfo.tsx b/src/components/SubsidiaryDetail/ContactInfo.tsx index e88201c..68797c0 100644 --- a/src/components/SubsidiaryDetail/ContactInfo.tsx +++ b/src/components/SubsidiaryDetail/ContactInfo.tsx @@ -233,8 +233,10 @@ const ContactInfo: React.FC = ({ } else { const errorRows_EmailFormat = rows.filter(row => !/^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,})$/.test(String(row.email))) - if (errorRows_EmailFormat.length > 0) { - setError("addContacts", { message: "Contact details include empty fields", type: "email_format" }) + 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 { clearErrors("addContacts") } @@ -265,8 +267,8 @@ const ContactInfo: React.FC = ({ {Boolean(errors.addContacts?.type === "required") && ({ 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")} } - {Boolean(errors.addContacts?.type === "email_format") && ({ color: theme.palette.error.main })} variant="overline" display='inline-block' noWrap> - {t("Please ensure all the email formats are correct")} + {Boolean(errors.addContacts?.type === "format") && ({ color: theme.palette.error.main })} variant="overline" display='inline-block' noWrap> + {t("Please ensure all the email and phone formats are correct")} } {/* */} = ({ toolbar: { setRows, setRowModesModel }, }} sx={{ - height: '100%' + height: '100%', + '& input[type=number]::-webkit-outer-spin-button': { + '-webkit-appearance': 'none', + margin: 0 + }, + '& input[type=number]::-webkit-inner-spin-button': { + '-webkit-appearance': 'none', + margin: 0 + } }} /> diff --git a/src/components/SubsidiaryDetail/SubsidiaryDetail.tsx b/src/components/SubsidiaryDetail/SubsidiaryDetail.tsx index 5f89570..77b83c7 100644 --- a/src/components/SubsidiaryDetail/SubsidiaryDetail.tsx +++ b/src/components/SubsidiaryDetail/SubsidiaryDetail.tsx @@ -157,9 +157,11 @@ const SubsidiaryDetail: React.FC = ({ 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) { + 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", type: "email_format" }) + formProps.setError("addContacts", { message: "Contact info includes invalid email or phone", type: "format" }) } if (haveError) { diff --git a/src/i18n/en/customer.json b/src/i18n/en/customer.json index f7b7dff..0f828fc 100644 --- a/src/i18n/en/customer.json +++ b/src/i18n/en/customer.json @@ -44,7 +44,7 @@ "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 fields are inputted and saved", - "Please ensure all the email formats are correct": "Please ensure all the email formats are correct", + "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?", "Submit Success": "Submit Success", diff --git a/src/i18n/en/subsidiary.json b/src/i18n/en/subsidiary.json index f62a640..1150ac3 100644 --- a/src/i18n/en/subsidiary.json +++ b/src/i18n/en/subsidiary.json @@ -44,7 +44,7 @@ "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 fields are inputted and saved", - "Please ensure all the email formats are correct": "Please ensure all the email formats are correct", + "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?", "Submit Success": "Submit Success", diff --git a/src/i18n/zh/customer.json b/src/i18n/zh/customer.json index d682f81..92947a0 100644 --- a/src/i18n/zh/customer.json +++ b/src/i18n/zh/customer.json @@ -44,7 +44,7 @@ "Contact Email": "聯絡電郵", "Contact Phone": "聯絡電話", "Please ensure at least one row is created, and all the fields are inputted and saved": "請確保已建立至少一行, 及已輸入和儲存所有欄位", - "Please ensure all the email formats are correct": "請確保所有電郵格式輸入正確", + "Please ensure all the email and phone formats are correct": "請確保所有電郵和電話格式輸入正確", "Do you want to submit?": "你是否確認要提交?", "Submit Success": "提交成功", diff --git a/src/i18n/zh/subsidiary.json b/src/i18n/zh/subsidiary.json index c56a884..dc50dc5 100644 --- a/src/i18n/zh/subsidiary.json +++ b/src/i18n/zh/subsidiary.json @@ -44,7 +44,7 @@ "Contact Email": "聯絡電郵", "Contact Phone": "聯絡電話", "Please ensure at least one row is created, and all the fields are inputted and saved": "請確保已建立至少一行, 及已輸入和儲存所有欄位", - "Please ensure all the email formats are correct": "請確保所有電郵格式輸入正確", + "Please ensure all the email and phone formats are correct": "請確保所有電郵和電話格式輸入正確", "Do you want to submit?": "你是否確認要提交?", "Submit Success": "提交成功",