| @@ -28,6 +28,8 @@ const FormPanel = ({ formData }) => { | |||||
| const [columnPrice, setColumnPrice] = React.useState(ComboData.proofPrice[0]); | const [columnPrice, setColumnPrice] = React.useState(ComboData.proofPrice[0]); | ||||
| const [attachments, setAttachments] = React.useState([]); | const [attachments, setAttachments] = React.useState([]); | ||||
| const [wait, setWait] = React.useState(false); | |||||
| const [isWarningPopUp, setIsWarningPopUp] = React.useState(false); | const [isWarningPopUp, setIsWarningPopUp] = React.useState(false); | ||||
| const [warningText, setWarningText] = React.useState(""); | const [warningText, setWarningText] = React.useState(""); | ||||
| @@ -45,10 +47,10 @@ const FormPanel = ({ formData }) => { | |||||
| React.useEffect(() => { | React.useEffect(() => { | ||||
| if (!attachments || attachments.length <= 0){ | |||||
| formik.setFieldValue("length",0); | |||||
| formik.setFieldValue("noOfPages",0); | |||||
| formik.setFieldValue("fee",0); | |||||
| if (!attachments || attachments.length <= 0) { | |||||
| formik.setFieldValue("length", 0); | |||||
| formik.setFieldValue("noOfPages", 0); | |||||
| formik.setFieldValue("fee", 0); | |||||
| return; | return; | ||||
| } | } | ||||
| @@ -56,10 +58,12 @@ const FormPanel = ({ formData }) => { | |||||
| }, [attachments]); | }, [attachments]); | ||||
| const doCalculate=()=>{ | |||||
| if (!attachments || attachments.length <= 0){ | |||||
| setWarningText("無法計算,請上傳有效文件。"); | |||||
| const doCalculate = () => { | |||||
| setWait(true); | |||||
| if (!attachments || attachments.length <= 0) { | |||||
| setWarningText("Unable to calculate, please upload a valid document."); | |||||
| setIsWarningPopUp(true); | setIsWarningPopUp(true); | ||||
| setWait(false); | |||||
| return; | return; | ||||
| } | } | ||||
| HttpUtils.postWithFiles({ | HttpUtils.postWithFiles({ | ||||
| @@ -69,23 +73,25 @@ const FormPanel = ({ formData }) => { | |||||
| }, | }, | ||||
| files: attachments, | files: attachments, | ||||
| onSuccess: function (responseData) { | onSuccess: function (responseData) { | ||||
| if(responseData.data.detail){ | |||||
| setWarningText("無法計算,請上傳有效文件或手動輸入。"); | |||||
| if (responseData.data.detail) { | |||||
| setWarningText("Unable to calculate, please upload a valid document or input manually."); | |||||
| setIsWarningPopUp(true); | setIsWarningPopUp(true); | ||||
| return; | return; | ||||
| } | } | ||||
| formik.setFieldValue("length",responseData.data.length); | |||||
| formik.setFieldValue("length", responseData.data.length); | |||||
| let colValue = 0; | let colValue = 0; | ||||
| setColumnPrice(ComboData.proofPrice.find(obj=>{ | |||||
| setColumnPrice(ComboData.proofPrice.find(obj => { | |||||
| colValue = obj.value; | colValue = obj.value; | ||||
| return obj.colCount === responseData.data.column | return obj.colCount === responseData.data.column | ||||
| })); | })); | ||||
| formik.setFieldValue("noOfPages",responseData.data.no_of_page); | |||||
| formik.setFieldValue("fee",(data.groupType == "A"?6552*responseData.data.no_of_page :responseData.data.length*colValue)); | |||||
| formik.setFieldValue("noOfPages", responseData.data.no_of_page); | |||||
| formik.setFieldValue("fee", (data.groupType == "A" ? 6552 * responseData.data.no_of_page : responseData.data.length * colValue)); | |||||
| setWait(false); | |||||
| }, | }, | ||||
| onError: function(){ | |||||
| setWarningText("無法計算,請手動輸入。"); | |||||
| onError: function () { | |||||
| setWarningText("Unable to calculate, please input manually."); | |||||
| setIsWarningPopUp(true); | setIsWarningPopUp(true); | ||||
| setWait(false); | |||||
| } | } | ||||
| }); | }); | ||||
| } | } | ||||
| @@ -95,7 +101,7 @@ const FormPanel = ({ formData }) => { | |||||
| initialValues: data, | initialValues: data, | ||||
| onSubmit: values => { | onSubmit: values => { | ||||
| if (!attachments || attachments.length <= 0) { | if (!attachments || attachments.length <= 0) { | ||||
| setWarningText("請選擇上傳檔案"); | |||||
| setWarningText("Please upload file."); | |||||
| setIsWarningPopUp(true); | setIsWarningPopUp(true); | ||||
| return; | return; | ||||
| } | } | ||||
| @@ -121,13 +127,13 @@ const FormPanel = ({ formData }) => { | |||||
| let file = event.target.files[0]; | let file = event.target.files[0]; | ||||
| if (file) { | if (file) { | ||||
| if (!file.name.toLowerCase().substr(file.name.length - 4).includes(".pdf")) { | if (!file.name.toLowerCase().substr(file.name.length - 4).includes(".pdf")) { | ||||
| setWarningText("請上傳有效檔案 (檔案格式: .pdf)"); | |||||
| setWarningText("Please upload a valid file (File format: .pdf)."); | |||||
| setIsWarningPopUp(true); | setIsWarningPopUp(true); | ||||
| document.getElementById("uploadFileBtn").value = ""; | document.getElementById("uploadFileBtn").value = ""; | ||||
| return; | return; | ||||
| } | } | ||||
| if (file.size >= (10 * 1024 * 1034)) { | if (file.size >= (10 * 1024 * 1034)) { | ||||
| setWarningText("上傳檔案大小應<10MB"); | |||||
| setWarningText("The file size for uploading should be less than 10MB"); | |||||
| setIsWarningPopUp(true); | setIsWarningPopUp(true); | ||||
| return; | return; | ||||
| } | } | ||||
| @@ -186,17 +192,27 @@ const FormPanel = ({ formData }) => { | |||||
| <UploadFileTable key="uploadTable" recordList={attachments} setRecordList={setAttachments} /> | <UploadFileTable key="uploadTable" recordList={attachments} setRecordList={setAttachments} /> | ||||
| </Grid> | </Grid> | ||||
| <Grid item xs={12} md={12}> | |||||
| <Button | |||||
| size="large" | |||||
| variant="contained" | |||||
| sx={{ | |||||
| textTransform: 'capitalize', | |||||
| alignItems: 'end' | |||||
| }}> | |||||
| Calculate | |||||
| </Button> | |||||
| </Grid> | |||||
| { | |||||
| wait ? | |||||
| <Grid item xs={12} md={12}> | |||||
| Doing calculate, please wait ... | |||||
| </Grid> | |||||
| : | |||||
| <Grid item xs={12} md={12}> | |||||
| <Button | |||||
| size="large" | |||||
| variant="contained" | |||||
| onClick={doCalculate} | |||||
| sx={{ | |||||
| textTransform: 'capitalize', | |||||
| alignItems: 'end' | |||||
| }}> | |||||
| Calculate | |||||
| </Button> | |||||
| </Grid> | |||||
| } | |||||
| { | { | ||||
| formik.values.groupType == "A" ? | formik.values.groupType == "A" ? | ||||
| @@ -352,7 +368,7 @@ const FormPanel = ({ formData }) => { | |||||
| </form> | </form> | ||||
| <div> | <div> | ||||
| <Dialog open={isWarningPopUp} onClose={() => setIsWarningPopUp(false)} > | <Dialog open={isWarningPopUp} onClose={() => setIsWarningPopUp(false)} > | ||||
| <DialogTitle>注意</DialogTitle> | |||||
| <DialogTitle>Warning</DialogTitle> | |||||
| <DialogContent style={{ display: 'flex', }}> | <DialogContent style={{ display: 'flex', }}> | ||||
| <Typography variant="h3" style={{ padding: '16px' }}>{warningText}</Typography> | <Typography variant="h3" style={{ padding: '16px' }}>{warningText}</Typography> | ||||
| </DialogContent> | </DialogContent> | ||||