Merge branch 'mytask-file-download-link' of WrenchBoard/Users-Wrench into master
This commit is contained in:
@@ -7,7 +7,7 @@ import usersService from '../../services/UsersService'
|
|||||||
export default function AttachFile({data='', fontSize='text-sm', showOnData=false}) {
|
export default function AttachFile({data='', fontSize='text-sm', showOnData=false}) {
|
||||||
|
|
||||||
const apiCall = new usersService()
|
const apiCall = new usersService()
|
||||||
|
|
||||||
let [uploadedList, setUploadedList] = useState({loading: true, data:{}})
|
let [uploadedList, setUploadedList] = useState({loading: true, data:{}})
|
||||||
let [reloadList, setReloadList] = useState(false) // Triggers list of upload reload
|
let [reloadList, setReloadList] = useState(false) // Triggers list of upload reload
|
||||||
|
|
||||||
@@ -19,9 +19,9 @@ export default function AttachFile({data='', fontSize='text-sm', showOnData=fals
|
|||||||
let inputs = {
|
let inputs = {
|
||||||
file: event.target.files[0],
|
file: event.target.files[0],
|
||||||
job_uid: data?.job_uid,
|
job_uid: data?.job_uid,
|
||||||
uid: localStorage.getItem("uid"),
|
// uid: localStorage.getItem("uid"),
|
||||||
// member_id: localStorage.getItem("member_id"),
|
// member_id: localStorage.getItem("member_id"),
|
||||||
sessionid: localStorage.getItem("session_token"),
|
// sessionid: localStorage.getItem("session_token"),
|
||||||
};
|
};
|
||||||
setRequestStatus({loading: true, status:false, message:''})
|
setRequestStatus({loading: true, status:false, message:''})
|
||||||
if(!inputs.file){
|
if(!inputs.file){
|
||||||
@@ -31,12 +31,11 @@ export default function AttachFile({data='', fontSize='text-sm', showOnData=fals
|
|||||||
}, 3000)
|
}, 3000)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
const formData = new FormData()
|
// const formData = new FormData()
|
||||||
for (let input in inputs) {
|
// for (let input in inputs) {
|
||||||
formData.append(input, inputs[input]);
|
// formData.append(input, inputs[input]);
|
||||||
}
|
// }
|
||||||
|
apiCall.uploadTaskFile(inputs).then(res => {
|
||||||
axios.post(`${process.env.REACT_APP_MEDIA_LINK}/upload/task`,formData).then(res => {
|
|
||||||
if(res.data.internal_return < 0){
|
if(res.data.internal_return < 0){
|
||||||
inputFile.current.value = null
|
inputFile.current.value = null
|
||||||
setRequestStatus({loading: false, status:false, message:'upload failed'})
|
setRequestStatus({loading: false, status:false, message:'upload failed'})
|
||||||
@@ -97,6 +96,7 @@ export default function AttachFile({data='', fontSize='text-sm', showOnData=fals
|
|||||||
uploadedList.data.result_list.length > 0 ?
|
uploadedList.data.result_list.length > 0 ?
|
||||||
uploadedList.data.result_list.map((item, index) => {
|
uploadedList.data.result_list.map((item, index) => {
|
||||||
let fileNameExt = item.originalname.split('.')[item.originalname.split('.').length - 1]
|
let fileNameExt = item.originalname.split('.')[item.originalname.split('.').length - 1]
|
||||||
|
let downloadLink = fileNameExt == 'mp4' ? `${process.env.REACT_APP_MEDIA_LINK}/mytask/${item.file_uid}` : `${uploadedList?.data?.session_image_server}/${localStorage.getItem("session_token")}/jobfile/${item.file_uid}`
|
||||||
return(
|
return(
|
||||||
<div key={item.file_uid} className={`my-[6px] flex justify-start gap-2 ${fontSize}`}>
|
<div key={item.file_uid} className={`my-[6px] flex justify-start gap-2 ${fontSize}`}>
|
||||||
<span>{index + 1}:</span>
|
<span>{index + 1}:</span>
|
||||||
@@ -104,7 +104,7 @@ export default function AttachFile({data='', fontSize='text-sm', showOnData=fals
|
|||||||
target='_blank'
|
target='_blank'
|
||||||
alt='download-link'
|
alt='download-link'
|
||||||
className=''
|
className=''
|
||||||
href={`${uploadedList?.data?.session_image_server}/${localStorage.getItem("session_token")}/jobfile/${item.file_uid}`}
|
href={downloadLink}
|
||||||
>
|
>
|
||||||
{(item.originalname).toString().length > 30 ? (item.originalname).toString().slice(0, 26) + '..._.' + fileNameExt : (item.originalname).toString()}
|
{(item.originalname).toString().length > 30 ? (item.originalname).toString().slice(0, 26) + '..._.' + fileNameExt : (item.originalname).toString()}
|
||||||
</a>
|
</a>
|
||||||
@@ -139,6 +139,7 @@ export default function AttachFile({data='', fontSize='text-sm', showOnData=fals
|
|||||||
<div className='text-[12px] w-full p-2 h-20 overflow-y-auto flex flex-col gap-2'>
|
<div className='text-[12px] w-full p-2 h-20 overflow-y-auto flex flex-col gap-2'>
|
||||||
{uploadedList.data.result_list.map((item, index) => {
|
{uploadedList.data.result_list.map((item, index) => {
|
||||||
let fileNameExt = item.originalname.split('.')[item.originalname.split('.').length - 1]
|
let fileNameExt = item.originalname.split('.')[item.originalname.split('.').length - 1]
|
||||||
|
let downloadLink = fileNameExt == 'mp4' ? `${process.env.REACT_APP_MEDIA_LINK}/mytask/${item.file_uid}` : `${uploadedList?.data?.session_image_server}/${localStorage.getItem("session_token")}/jobfile/${item.file_uid}`
|
||||||
return(
|
return(
|
||||||
<div key={item.file_uid} className={`my-[6px] flex justify-start gap-2 ${fontSize}`}>
|
<div key={item.file_uid} className={`my-[6px] flex justify-start gap-2 ${fontSize}`}>
|
||||||
<span>{index + 1}:</span>
|
<span>{index + 1}:</span>
|
||||||
@@ -146,7 +147,7 @@ export default function AttachFile({data='', fontSize='text-sm', showOnData=fals
|
|||||||
target='_blank'
|
target='_blank'
|
||||||
alt='download-link'
|
alt='download-link'
|
||||||
className=''
|
className=''
|
||||||
href={`${uploadedList?.data?.session_image_server}/${localStorage.getItem("session_token")}/jobfile/${item.file_uid}`}
|
href={downloadLink}
|
||||||
>
|
>
|
||||||
{(item.originalname).toString().length > 30 ? (item.originalname).toString().slice(0, 26) + '..._.' + fileNameExt : (item.originalname).toString()}
|
{(item.originalname).toString().length > 30 ? (item.originalname).toString().slice(0, 26) + '..._.' + fileNameExt : (item.originalname).toString()}
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
@@ -908,7 +908,7 @@ class usersService {
|
|||||||
return this.postAuxEnd("/uploads", postData);
|
return this.postAuxEnd("/uploads", postData);
|
||||||
}
|
}
|
||||||
|
|
||||||
// FUNCTION TO SEND FILE UPLOAD
|
// FUNCTION TO UPLOAD RESOURCE FILES
|
||||||
uploadFile(reqData) {
|
uploadFile(reqData) {
|
||||||
var postData = {
|
var postData = {
|
||||||
uid: localStorage.getItem("uid"),
|
uid: localStorage.getItem("uid"),
|
||||||
@@ -926,6 +926,24 @@ class usersService {
|
|||||||
return this.postAuxEnd("/upload/resources", formData, true);
|
return this.postAuxEnd("/upload/resources", formData, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FUNCTION TO UPLOAD TASK FILES
|
||||||
|
uploadTaskFile(reqData) {
|
||||||
|
var postData = {
|
||||||
|
uid: localStorage.getItem("uid"),
|
||||||
|
member_id: localStorage.getItem("member_id"),
|
||||||
|
sessionid: localStorage.getItem("session_token"),
|
||||||
|
// action: apiConst.WRENCHBOARD_CONTRACT_MESSAGE,
|
||||||
|
...reqData,
|
||||||
|
};
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
for (let data in postData) {
|
||||||
|
formData.append(data, postData[data]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.postAuxEnd("/upload/task", formData, true);
|
||||||
|
}
|
||||||
|
|
||||||
// END POINT TO DELETE A JOB
|
// END POINT TO DELETE A JOB
|
||||||
deleteJob(reqData) {
|
deleteJob(reqData) {
|
||||||
var postData = {
|
var postData = {
|
||||||
|
|||||||
Reference in New Issue
Block a user