Merge branch 'master' of https://gitlab.chiefsoft.net/WrenchBoard/Users-Wrench into wallet-styles
This commit was merged in pull request #390.
This commit is contained in:
@@ -8,7 +8,7 @@ import ProductUploadField from "./ProductUploadField";
|
|||||||
import LoadingSpinner from "../Spinners/LoadingSpinner";
|
import LoadingSpinner from "../Spinners/LoadingSpinner";
|
||||||
import usersService from "../../services/UsersService";
|
import usersService from "../../services/UsersService";
|
||||||
|
|
||||||
export default function UploadProduct() {
|
export default function UploadProduct({uploadTypes}) {
|
||||||
const apiCall = new usersService()
|
const apiCall = new usersService()
|
||||||
const [requestStatus, setRequestStatus] = useState({loading: false, status: null, message: ''}) // DETERMINES THE STATUS OF UPLOAD
|
const [requestStatus, setRequestStatus] = useState({loading: false, status: null, message: ''}) // DETERMINES THE STATUS OF UPLOAD
|
||||||
|
|
||||||
@@ -88,7 +88,7 @@ export default function UploadProduct() {
|
|||||||
// most importend
|
// most importend
|
||||||
imgRead.readAsDataURL(e.target.files[0]);
|
imgRead.readAsDataURL(e.target.files[0]);
|
||||||
}
|
}
|
||||||
if (file.length) {
|
if (file?.length) {
|
||||||
if (file[0].name) {
|
if (file[0].name) {
|
||||||
setSelectedFile(file?.[0].name);
|
setSelectedFile(file?.[0].name);
|
||||||
setImgDetails(file?.[0])
|
setImgDetails(file?.[0])
|
||||||
@@ -135,25 +135,32 @@ export default function UploadProduct() {
|
|||||||
},5000)
|
},5000)
|
||||||
}
|
}
|
||||||
|
|
||||||
if(imgDetails.size > 2097152){ // CHECKS IF IMAGE SIZE IS MORE THAN "MB"
|
let reqData = { // PAYLOAD FOR API CALL
|
||||||
setRequestStatus({loading: false, status: null, message: 'Image must be less than 2MB'})
|
file_name: selectedFile.substring(0,21).replace(/ /gi, ""),//selectedFile.replace(/[ -]/gi, ""),
|
||||||
|
file_size: imgDetails.size,
|
||||||
|
file_type: imgDetails.type,
|
||||||
|
file_data: img,
|
||||||
|
title: itemName,
|
||||||
|
description: description,
|
||||||
|
msg_type: 'FILE',
|
||||||
|
// action: 'WRENCHBOARD_RESOURCE_MYFILES',
|
||||||
|
action: 11307
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!isValidFile(imgDetails, uploadTypes?.data)){ // FUNCTION TO CHECK IF FILE TYPE IS VALID
|
||||||
|
setRequestStatus({loading: false, status: null, message: 'File type not supported'})
|
||||||
return setTimeout(()=>{
|
return setTimeout(()=>{
|
||||||
setRequestStatus({loading: false, status: false, message: ''})
|
setRequestStatus({loading: false, status: false, message: ''})
|
||||||
},5000)
|
},5000)
|
||||||
}
|
}
|
||||||
|
|
||||||
let reqData = { // PAYLOAD FOR API CALL
|
let validSize = isValidFileSize(imgDetails, uploadTypes?.data) // FUNCTION TO CHECK IF FILE SIZE IS VALID
|
||||||
file_name: selectedFile,
|
if(!validSize.status){
|
||||||
file_size: imgDetails.size,
|
setRequestStatus({loading: false, status: null, message: validSize.message})
|
||||||
file_type: imgDetails.type,
|
return setTimeout(()=>{
|
||||||
file_data: img,
|
setRequestStatus({loading: false, status: false, message: ''})
|
||||||
item_name: itemName,
|
},5000)
|
||||||
item_description: description,
|
|
||||||
msg_type: 'FILE',
|
|
||||||
// action: 'WRENCHBOARD_RESOURCE_MYFILES',
|
|
||||||
action: 11307
|
|
||||||
}
|
}
|
||||||
// console.log('TESTING', reqData)
|
|
||||||
|
|
||||||
//API CALL TO UPLOAD COMES HERE
|
//API CALL TO UPLOAD COMES HERE
|
||||||
setRequestStatus({loading: true, status: null, message: ''}) // SETS REQUEST LOADING TRUE
|
setRequestStatus({loading: true, status: null, message: ''}) // SETS REQUEST LOADING TRUE
|
||||||
@@ -263,8 +270,15 @@ export default function UploadProduct() {
|
|||||||
Image,Video,Audio or Documents
|
Image,Video,Audio or Documents
|
||||||
</h1>
|
</h1>
|
||||||
<p className="text-thin-light-gray text-base tracking-wide font-medium">
|
<p className="text-thin-light-gray text-base tracking-wide font-medium">
|
||||||
File types supported: JPG, PNG, GIP, SVG, MP4, MP3, WEBM,
|
File types supported: {uploadTypes.loading && <span className="italic">loading...</span>}
|
||||||
OGG, GLB, GLTF
|
{/* JPG, PNG, GIP, SVG, MP4, MP3, WEBM, OGG, GLB, GLTF */}
|
||||||
|
{uploadTypes?.data?.length ?
|
||||||
|
uploadTypes?.data?.map((item, index) => {
|
||||||
|
return index != uploadTypes.data.length-1 ? `${item.name}, ` : `${item.name}`
|
||||||
|
})
|
||||||
|
:
|
||||||
|
null
|
||||||
|
}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<div className="main-content w-full lg:flex justify-between lg:px-9 px-4">
|
<div className="main-content w-full lg:flex justify-between lg:px-9 px-4">
|
||||||
@@ -415,7 +429,7 @@ export default function UploadProduct() {
|
|||||||
<div className="preview-upload-product lg:w-[580px] lg:h-[622px] w-full h-full bg-white dark:bg-[#11131F] lg:rounded-2xl">
|
<div className="preview-upload-product lg:w-[580px] lg:h-[622px] w-full h-full bg-white dark:bg-[#11131F] lg:rounded-2xl">
|
||||||
<div className="w-full h-full flex flex-col justify-between">
|
<div className="w-full h-full flex flex-col justify-between">
|
||||||
{/* heading */}
|
{/* heading */}
|
||||||
<div className="lg:px-[40px] lg:py-[33px] px-[30px] py-[23px] flex justify-between border-b dark:border-[#5356fb29] border-light-purple dark:border-[#5356fb29] mb-4 lg:mb-0">
|
<div className="lg:px-[40px] lg:py-[33px] px-[30px] py-[23px] flex justify-between border-b border-light-purple dark:border-[#5356fb29] mb-4 lg:mb-0">
|
||||||
<h1 className="text-dark-gray dark:text-white tracking-wide text-26 font-bold">
|
<h1 className="text-dark-gray dark:text-white tracking-wide text-26 font-bold">
|
||||||
Item Privew
|
Item Privew
|
||||||
</h1>
|
</h1>
|
||||||
@@ -561,3 +575,37 @@ export default function UploadProduct() {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//FUNCTIONS to check if file upload type is valid
|
||||||
|
const isValidFile = (file, supportedFile=[]) => {
|
||||||
|
let fileType = file.type.split("/")[1];
|
||||||
|
let valid = supportedFile.filter(item => (
|
||||||
|
item.name.toLowerCase() == fileType.toLowerCase()
|
||||||
|
))
|
||||||
|
if(valid.length){
|
||||||
|
return true
|
||||||
|
}else{
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//FUNCTIONS TO CHECK IF FILE SIZE IS VALID
|
||||||
|
const isValidFileSize = (file, supportedFile=[]) => {
|
||||||
|
let fileType = file.type.split("/")[1];
|
||||||
|
let fileSize = file.size;
|
||||||
|
let valid = supportedFile.filter(item => (
|
||||||
|
item.name.toLowerCase() == fileType.toLowerCase()
|
||||||
|
))
|
||||||
|
if(valid.length){
|
||||||
|
if((Number(valid[0].max_size_mb) * 1048576) >= fileSize){
|
||||||
|
return {status: true}
|
||||||
|
}else{
|
||||||
|
return {status: false, message: `File must not exceed ${valid[0].max_size_mb}MB`}
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,6 +1,22 @@
|
|||||||
import React from "react";
|
import React, { useEffect, useState } from "react";
|
||||||
import UploadProduct from "../components/UploadProduct";
|
import UploadProduct from "../components/UploadProduct";
|
||||||
|
import usersService from "../services/UsersService";
|
||||||
|
|
||||||
export default function UploadProductPage() {
|
export default function UploadProductPage() {
|
||||||
return <UploadProduct />;
|
const [uploadTypes, setUploadTypes] = useState({loading: true, data: []});
|
||||||
|
const api = new usersService();
|
||||||
|
|
||||||
|
const getUploadTypes = async () => {
|
||||||
|
try {
|
||||||
|
const res = await api.getResourceList();
|
||||||
|
setUploadTypes({loading: false, data: res?.data?.upload_types.data});
|
||||||
|
} catch (error) {
|
||||||
|
setUploadTypes({loading: false, data: []});
|
||||||
|
throw new Error("Error getting mode");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
useEffect(() => {
|
||||||
|
getUploadTypes();
|
||||||
|
}, []);
|
||||||
|
return <UploadProduct uploadTypes={uploadTypes} />;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user