Browse Source

update upload file in register

master
Alex Cheung 2 years ago
parent
commit
004c57a222
3 changed files with 49 additions and 38 deletions
  1. +40
    -31
      src/pages/authentication/auth-forms/CustomFormWizard.js
  2. +8
    -7
      src/pages/authentication/auth-forms/UploadFileTable.js
  3. +1
    -0
      src/utils/HttpUtils.js

+ 40
- 31
src/pages/authentication/auth-forms/CustomFormWizard.js View File

@@ -30,7 +30,7 @@ import { strengthColorChi, strengthIndicator } from 'utils/password-strength';
import {apiPath} from "auth/utils"; import {apiPath} from "auth/utils";
import axios from "axios"; import axios from "axios";
import {POST_PUBLIC_USER_REGISTER} from "utils/ApiPathConst"; import {POST_PUBLIC_USER_REGISTER} from "utils/ApiPathConst";
// import * as HttpUtils from 'utils/HttpUtils';
import * as HttpUtils from 'utils/HttpUtils';
import UploadFileTable from './UploadFileTable'; import UploadFileTable from './UploadFileTable';


// assets // assets
@@ -44,7 +44,8 @@ const CustomFormWizard = (props) => {
const [level, setLevel] = useState(); const [level, setLevel] = useState();
const [showPassword, setShowPassword] = useState(false); const [showPassword, setShowPassword] = useState(false);
const [showConfirmPassword, setshowConfirmPassword] = useState(false); const [showConfirmPassword, setshowConfirmPassword] = useState(false);
const [fileList, setFileList] = useState(null);
const [fileList, setFileList] = useState([]);
const [fileListData, setFileListData] = useState([]);


const handleClickShowPassword = () => { const handleClickShowPassword = () => {
setShowPassword(!showPassword); setShowPassword(!showPassword);
@@ -111,28 +112,28 @@ const CustomFormWizard = (props) => {
}; };


const handleFileUpload = (event)=>{ 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({}) const {handleSubmit} = useForm({})
@@ -182,16 +183,24 @@ const CustomFormWizard = (props) => {
.then((response) => { .then((response) => {
console.log("Success") console.log("Success")
console.log(response) console.log(response)
HttpUtils.fileUpload(
{
refType:"identification",
refId: response.data.id,
file: fileList[0],
onSuccess: (response)=>{
console.log(response);
// setOpen(true);
}
}
);
}) })
.catch(error => { .catch(error => {
console.error(error); console.error(error);
}); });
// uploadFile();
}
} }


}

const formik = useFormik({ const formik = useFormik({
initialValues:({ initialValues:({
username:'', username:'',
@@ -857,7 +866,7 @@ const CustomFormWizard = (props) => {
<Typography display="inline" variant="h6" sx={{ fontSize: 12,color: 'primary.primary'}}>請上傳你的 有效身份證明文件 的數碼檔案,以驗證你的身份。</Typography> <Typography display="inline" variant="h6" sx={{ fontSize: 12,color: 'primary.primary'}}>請上傳你的 有效身份證明文件 的數碼檔案,以驗證你的身份。</Typography>
<Typography display="inline" variant="h6" sx={{ fontSize: 12,color: 'primary.primary'}}>如: 香港身份證; 護照; 中國內地身份證等</Typography> <Typography display="inline" variant="h6" sx={{ fontSize: 12,color: 'primary.primary'}}>如: 香港身份證; 護照; 中國內地身份證等</Typography>
<Stack mt={1} direction="row" justifyContent="flex-start" alignItems="center" spacing={2}> <Stack mt={1} direction="row" justifyContent="flex-start" alignItems="center" spacing={2}>
<Button variant="contained" component="label" sx={{ fontSize: 12,height:'25px'}}>上傳身份證明文件
<Button variant="contained" component="label" sx={{ fontSize: 12,height:'40px'}}>上傳身份證明文件
<input <input
accept="image/*" accept="image/*"
//className={classes.input} //className={classes.input}
@@ -868,10 +877,10 @@ const CustomFormWizard = (props) => {
style={{display: 'none'}} style={{display: 'none'}}
/> />
</Button> </Button>
{fileList !=null?
<UploadFileTable recordList={fileList} />:null}
<Typography display="inline" variant="h6" sx={{ fontSize: 12, color: 'primary.primary'}}>如: 香港身份證; 護照; 中國內地身份證等</Typography> <Typography display="inline" variant="h6" sx={{ fontSize: 12, color: 'primary.primary'}}>如: 香港身份證; 護照; 中國內地身份證等</Typography>
</Stack> </Stack>
{fileList !=null?
<UploadFileTable recordList={fileListData} />:null}
{/* <Stack mt={1} direction="row" justifyContent="flex-start" alignItems="center" spacing={2}> {/* <Stack mt={1} direction="row" justifyContent="flex-start" alignItems="center" spacing={2}>
<Button variant="contained" type="submit" sx={{ fontSize: 12,height:'25px'}}>Submit</Button> <Button variant="contained" type="submit" sx={{ fontSize: 12,height:'25px'}}>Submit</Button>
<Button disabled={!formik.isValid} variant="contained" type="submit" sx={{ fontSize: 12,height:'25px'}}>Submit</Button> <Button disabled={!formik.isValid} variant="contained" type="submit" sx={{ fontSize: 12,height:'25px'}}>Submit</Button>


+ 8
- 7
src/pages/authentication/auth-forms/UploadFileTable.js View File

@@ -8,7 +8,7 @@ import {
import {useEffect} from "react"; import {useEffect} from "react";
// import {useNavigate} from "react-router-dom"; // import {useNavigate} from "react-router-dom";
// import { useTheme } from '@mui/material/styles'; // import { useTheme } from '@mui/material/styles';
// import Checkbox from '@mui/material/Checkbox';
import {Box} from '@mui/material';
// ==============================|| EVENT TABLE ||============================== // // ==============================|| EVENT TABLE ||============================== //


export default function UploadFileTable({recordList}) { export default function UploadFileTable({recordList}) {
@@ -48,38 +48,39 @@ export default function UploadFileTable({recordList}) {
{ {
id: 'name', id: 'name',
field: 'name', field: 'name',
headerName: 'Name',
headerName: '檔案名稱',
flex: 1, flex: 1,
}, },
{ {
id: 'size', id: 'size',
field: 'size', field: 'size',
headerName: 'Size',
headerName: '檔案大小',
flex: 1, flex: 1,
}, },
{ {
id: 'type', id: 'type',
field: 'type', field: 'type',
headerName: 'Type',
headerName: '檔案類型',
flex: 1, flex: 1,
}, },
]; ];


return ( return (
<div style={{height: 400, width: '100%'}}>
<Box style={{height: '20%', width: '100%',}}>
<DataGrid <DataGrid
rows={rows} rows={rows}
columns={columns} columns={columns}
editMode="row" editMode="row"
sx={{border:1}}
rowModesModel={rowModesModel} rowModesModel={rowModesModel}
initialState={{ initialState={{
pagination: { pagination: {
paginationModel: {page: 0, pageSize: 5}, paginationModel: {page: 0, pageSize: 5},
}, },
}} }}
pageSizeOptions={[5, 10]}
// pageSizeOptions={[5, 10]}
autoHeight autoHeight
/> />
</div>
</Box>
); );
} }

+ 1
- 0
src/utils/HttpUtils.js View File

@@ -62,6 +62,7 @@ export const fileUpload = ({ refType, refId, file,refCode, onSuccess, onFail, on
if(refCode){ if(refCode){
formData.append("refCode", refCode); formData.append("refCode", refCode);
} }
console.log(formData)
axios.post(FILE_UP_POST,formData,{ axios.post(FILE_UP_POST,formData,{
headers: { headers: {
"Content-Type":"multipart/form-data" "Content-Type":"multipart/form-data"


Loading…
Cancel
Save