templAte fix

This commit is contained in:
2026-05-03 13:55:52 -04:00
parent d950988e62
commit 0794dfb8e0
@@ -1,130 +1,165 @@
import React, {useState} from 'react' import React, { useState } from "react";
//import getImage from "../../../utils/getImage"; //import getImage from "../../../utils/getImage";
import { useQuery, useQueryClient} from '@tanstack/react-query'; import { useQuery, useQueryClient } from "@tanstack/react-query";
import queryKeys from '../../../services/queryKeys'; import queryKeys from "../../../services/queryKeys";
import {getTemplateConfig} from '../../../services/services'; import { getTemplateConfig } from "../../../services/services";
//import {Link} from "react-router-dom"; //import {Link} from "react-router-dom";
//import siteLinks from "../../../links/siteLinks"; //import siteLinks from "../../../links/siteLinks";
import UploadModal from './UploadModal'; import UploadModal from "./UploadModal";
const TemplateConfigure = ({productData}) => { const TemplateConfigure = ({ productData }) => {
const [selectedSectionDetails, setSelectedSectionDetails] = useState({});
const [selectedSectionDetails, setSelectedSectionDetails] = useState({}) const {
data: templateData,
isFetching,
isError,
error,
} = useQuery({
queryKey: queryKeys.myTemplateConfig,
queryFn: () => {
let reqData = {
token: localStorage.getItem("token"), // USER TOKEN
uid: localStorage.getItem("uid"), // USER UID
product_id: productData?.product_id,
};
return getTemplateConfig(reqData);
},
staleTime: 0,
});
// /panel/myproduct/template-config const templateResponse = templateData?.data;
const templateImages = Array.isArray(templateResponse?.template_images?.data)
? templateResponse.template_images.data
: [];
console.log("templateResponse", templateResponse);
//const queryClient = useQueryClient() return (
<>
<div className="card card-statistics">
{isFetching ? (
<>
<div className="row">
<div className="col-12">
<p className="text-mute">Loading...</p>
</div>
</div>
</>
) : isError ? (
<div className="row">
<div className="col-12">
<p className="text-danger">{error?.message}</p>
</div>
</div>
) : (
<>
<div className="card-header">
<div className="card-heading">
<h4 className="card-title" style={{ textTransform: "none" }}>
{templateResponse?.template_name}
</h4>
</div>
</div>
const {data: templateData, isFetching, isError, error} = useQuery({ <div>
queryKey: queryKeys.myTemplateConfig, <div className="col-12">
queryFn: () => { <div>
let reqData = { <div>
token: localStorage.getItem('token'), // USER TOKEN <div>
uid: localStorage.getItem('uid'), // USER UID <h4>Image List</h4>
product_id: productData?.product_id
}
return getTemplateConfig(reqData)
},
staleTime: 0
})
const templateResponse = templateData?.data
const templateImages = templateResponse?.template_images?.data;
// debugger;
console.log("templateResponse", templateResponse);
// const currentColorUID = templateResponse?.current_colorstyle_uid
// const color_styles = templateResponse?.color_styles
// const custom_template_name = templateResponse?.custom_template_name
return <>
<div className="card card-statistics">
{isFetching ?
<>
<div className="row">
<div className="col-12">
<p className='text-mute'>Loading...</p>
</div>
</div> </div>
</> </div>
: isError ? <div>
<div className="row"> <ul className="list-unstyled">
<div className="col-12"> {templateImages &&
<p className='text-danger'>{error?.message}</p> templateImages.map((item) => {
</div> const currImage = item?.default_val;
</div> return (
: <li className="media">
<> <div
<div className="card-header"> style={{
<div className="card-heading"> display: "flex",
<h4 className="card-title" flexDirection: "row",
style={{textTransform: 'none'}}>{templateResponse?.template_name}</h4> padding: "5px",
</div> backgroundColor: "aliceblue",
</div> margin: "2px",
maxHeight: "150px",
}}
<div> >
<div className="col-12"> <div
<div> className="d-flex justify-content-center align-items-center"
<div> style={{
<div> padding: "6px",
<h4>Image List</h4> width: "120px",
</div> height: "100px",
</div> }}
<div> >
<ul className="list-unstyled"> <img
{templateImages && templateImages.map( className="mb-xxs-0 img-fluid"
(item) => { style={{
const currImage = item?.default_val; height: "auto",
return ( maxHeight: "100px",
<li className="media"> }}
<div style={{ src={currImage}
display: 'flex', alt="image"
flexDirection: 'row', />
padding: '5px',
backgroundColor: 'aliceblue',
margin: '2px',
maxHeight: '150px'
}}>
<div className='d-flex justify-content-center align-items-center' style={{padding: '6px', width: '120px', height: '100px'}}>
<img className="mb-xxs-0 img-fluid"
style={{height: 'auto', maxHeight: '100px'}}
src={currImage} alt="image"/>
</div>
<div className="media-body" style={{padding: '2px'}}>
<div style={{
display: 'flex',
flexDirection: 'column'
}}>
<div style={{textAlign: 'right',width: '100%'}}></div>
{/* [Change Image] */}
<label onClick={()=>setSelectedSectionDetails(item)} className='w-100 text-end' data-bs-toggle="modal" data-bs-target="#verticalCenter" style={{cursor: 'pointer'}}>[Change Image]</label>
{/* <input id={item?.id} name={item?.id} className="d-none form-control form-control-sm" type="file" onChange={handleFileChange}/> */}
<div>
<h5 className="mt-0 mb-1">{item?.name}</h5>
{item?.description}
</div>
</div>
</div>
</div>
</li>
)
}
)
}
</ul>
</div>
</div> </div>
</div>
</div>
</> <div
className="media-body"
style={{ padding: "2px" }}
} </div> >
<UploadModal productId={productData?.product_id} selectedSectionDetails={selectedSectionDetails} /> <div
style={{
display: "flex",
flexDirection: "column",
}}
>
<div
style={{
textAlign: "right",
width: "100%",
}}
></div>
{/* [Change Image] */}
<label
onClick={() =>
setSelectedSectionDetails(item)
}
className="w-100 text-end"
data-bs-toggle="modal"
data-bs-target="#verticalCenter"
style={{ cursor: "pointer" }}
>
[Change Image]
</label>
{/* <input id={item?.id} name={item?.id} className="d-none form-control form-control-sm" type="file" onChange={handleFileChange}/> */}
<div>
<h5 className="mt-0 mb-1">
{item?.name}
</h5>
{item?.description}
</div>
</div>
</div>
</div>
</li>
);
})}
</ul>
</div>
</div>
</div>
</div>
</>
)}{" "}
</div>
<UploadModal
productId={productData?.product_id}
selectedSectionDetails={selectedSectionDetails}
/>
</> </>
} );
};
export default TemplateConfigure export default TemplateConfigure;