From 004c57a2227c00668c85d054faa0330febde24d0 Mon Sep 17 00:00:00 2001 From: Alex Cheung Date: Mon, 28 Aug 2023 10:22:11 +0800 Subject: [PATCH] update upload file in register --- .../auth-forms/CustomFormWizard.js | 71 +++++++++++-------- .../auth-forms/UploadFileTable.js | 15 ++-- src/utils/HttpUtils.js | 1 + 3 files changed, 49 insertions(+), 38 deletions(-) diff --git a/src/pages/authentication/auth-forms/CustomFormWizard.js b/src/pages/authentication/auth-forms/CustomFormWizard.js index dac17b1..144edf1 100644 --- a/src/pages/authentication/auth-forms/CustomFormWizard.js +++ b/src/pages/authentication/auth-forms/CustomFormWizard.js @@ -30,7 +30,7 @@ import { strengthColorChi, strengthIndicator } from 'utils/password-strength'; import {apiPath} from "auth/utils"; import axios from "axios"; import {POST_PUBLIC_USER_REGISTER} from "utils/ApiPathConst"; -// import * as HttpUtils from 'utils/HttpUtils'; +import * as HttpUtils from 'utils/HttpUtils'; import UploadFileTable from './UploadFileTable'; // assets @@ -44,7 +44,8 @@ const CustomFormWizard = (props) => { const [level, setLevel] = useState(); const [showPassword, setShowPassword] = useState(false); const [showConfirmPassword, setshowConfirmPassword] = useState(false); - const [fileList, setFileList] = useState(null); + const [fileList, setFileList] = useState([]); + const [fileListData, setFileListData] = useState([]); const handleClickShowPassword = () => { setShowPassword(!showPassword); @@ -111,28 +112,28 @@ const CustomFormWizard = (props) => { }; const handleFileUpload = (event)=>{ - const getfileList = event.target.files - const currentIndex = fileList.length!=null?fileList.length:0 - const index = 0; - getfileList.forEach((element) => element.id=index+1); - getfileList.forEach((element) => { - console.log({ element }); - element.id=currentIndex+numCallbackRuns; - numCallbackRuns++; - }); - console.log(getfileList) - setFileList(getfileList) - // HttpUtils.fileUpload( - // { - // refType:"identification", - // refId: -1, - // file: event.target.files[0], - // onSuccess: (response)=>{ - // console.log(response); - // setOpen(true); - // } - // } - // ); + const uploadFileList = event.target.files; + const saveFileList = []; + var currentIndex = 0; + // var index = 0; + console.log(uploadFileList); + console.log(uploadFileList.length); + console.log(fileList); + + if (!fileList.length==null){ + currentIndex = fileList.length; + } + + for (let i = 0; i < uploadFileList.length; i++){ + const file = event.target.files[i] + file.id = currentIndex+i+1 + saveFileList.push(file) + } + + console.log(saveFileList); + console.log(uploadFileList); + setFileListData(saveFileList) + setFileList(uploadFileList); }; const {handleSubmit} = useForm({}) @@ -182,16 +183,24 @@ const CustomFormWizard = (props) => { .then((response) => { console.log("Success") console.log(response) + HttpUtils.fileUpload( + { + refType:"identification", + refId: response.data.id, + file: fileList[0], + onSuccess: (response)=>{ + console.log(response); + // setOpen(true); + } + } + ); }) .catch(error => { console.error(error); }); - // uploadFile(); - + } } -} - const formik = useFormik({ initialValues:({ username:'', @@ -857,7 +866,7 @@ const CustomFormWizard = (props) => { 請上傳你的 有效身份證明文件 的數碼檔案,以驗證你的身份。 如: 香港身份證; 護照; 中國內地身份證等 - - {fileList !=null? - :null} 如: 香港身份證; 護照; 中國內地身份證等 + {fileList !=null? + :null} {/* diff --git a/src/pages/authentication/auth-forms/UploadFileTable.js b/src/pages/authentication/auth-forms/UploadFileTable.js index 4cd72fc..3a1a0ef 100644 --- a/src/pages/authentication/auth-forms/UploadFileTable.js +++ b/src/pages/authentication/auth-forms/UploadFileTable.js @@ -8,7 +8,7 @@ import { import {useEffect} from "react"; // import {useNavigate} from "react-router-dom"; // import { useTheme } from '@mui/material/styles'; -// import Checkbox from '@mui/material/Checkbox'; +import {Box} from '@mui/material'; // ==============================|| EVENT TABLE ||============================== // export default function UploadFileTable({recordList}) { @@ -48,38 +48,39 @@ export default function UploadFileTable({recordList}) { { id: 'name', field: 'name', - headerName: 'Name', + headerName: '檔案名稱', flex: 1, }, { id: 'size', field: 'size', - headerName: 'Size', + headerName: '檔案大小', flex: 1, }, { id: 'type', field: 'type', - headerName: 'Type', + headerName: '檔案類型', flex: 1, }, ]; return ( -
+ -
+ ); } diff --git a/src/utils/HttpUtils.js b/src/utils/HttpUtils.js index 1206dcb..4b7dad0 100644 --- a/src/utils/HttpUtils.js +++ b/src/utils/HttpUtils.js @@ -62,6 +62,7 @@ export const fileUpload = ({ refType, refId, file,refCode, onSuccess, onFail, on if(refCode){ formData.append("refCode", refCode); } + console.log(formData) axios.post(FILE_UP_POST,formData,{ headers: { "Content-Type":"multipart/form-data"