Skip to content

Commit

Permalink
fix: manageorder page date fix + better fields
Browse files Browse the repository at this point in the history
  • Loading branch information
RookieProgrammerSachin committed Apr 13, 2024
1 parent fed337c commit 3b555aa
Show file tree
Hide file tree
Showing 2 changed files with 14,880 additions and 71 deletions.
142 changes: 72 additions & 70 deletions src/components/payments.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,6 @@ export default function Payments() {
const [pageNo, setPageNo] = useState(0);
const [pageTotal, setPageTotal] = useState(0);

const manageOrders = async () => {
const params = new URLSearchParams({
pageNo: pageNo,
pageSize: 250,
});
const response = await axios.get(
"https://spring-madrasda-2f6mra4vwa-em.a.run.app/api/transaction/manageOrders?" +
params,
{
headers: {
Authorization: "Bearer " + localStorage.getItem("token_admin"),
},
}
);
console.log(response.data);
// let dataToSet = response.data.content.sort((a, b) => b.orderDate.localeCompare(a.orderDate))
// setOrdersData(dataToSet);
const ordersData = response.data.content.sort((a, b) => b.orderDate.localeCompare(a.orderDate))
setOrders(ordersData);
setDisplayOrders(ordersData.slice(pageNo * records, (pageNo+1) * records))
setPageNo((prev) => prev + 1)
setPageTotal(Math.floor(response.data.totalElements/records));
console.log(pageTotal)
};

const handlePageDecrease = () => {
// if (pageNo == 0) return;
console.log(displayOrders, pageNo, records, pageTotal)
Expand All @@ -58,6 +33,37 @@ export default function Payments() {
};

useEffect(() => {
const manageOrders = async () => {
const params = new URLSearchParams({
pageNo: pageNo,
pageSize: 250,
});
const response = await axios.get(
// "http://localhost:8080/api/transaction/manageOrders" +
"https://spring-madrasda-2f6mra4vwa-em.a.run.app/api/transaction/manageOrders?" +
params,
{
headers: {
Authorization: "Bearer " + localStorage.getItem("token_admin"),
},
}
);

console.log(response.data);
// let dataToSet = response.data.content.sort((a, b) => b.orderDate.localeCompare(a.orderDate))
// setOrdersData(dataToSet);
const ordersData = response.data.content.sort((a, b) =>
b.orderDate.localeCompare(a.orderDate)
);
setOrders(ordersData);
setDisplayOrders(
ordersData.slice(pageNo * records, (pageNo + 1) * records)
);
setPageNo((prev) => prev + 1);
setPageTotal(Math.floor(response.data.totalElements / records));
console.log(pageTotal);
};

manageOrders();
}, []);

Expand Down Expand Up @@ -118,22 +124,19 @@ export default function Payments() {
Order Date
</th>
<th scope='col' className=' px-6 py-4'>
Customer Name
Customer Details
</th>
<th scope='col' className=' px-6 py-4'>
Product Name
</th>
<th scope='col' className=' px-6 py-4'>
Vendor ID
Product Details
</th>
<th scope='col' className=' px-6 py-4'>
SKU
Quantity
</th>
<th scope='col' className=' px-6 py-4'>
Customer Email
Order Total
</th>
<th scope='col' className=' px-6 py-4'>
Quantity
Vendor ID
</th>
<th scope='col' className=' px-6 pl-2'>
Payment Id
Expand All @@ -150,12 +153,6 @@ export default function Payments() {
<th scope='col' className=' px-6 py-4'>
Mockup Name
</th>
<th scope='col' className=' px-6 py-4'>
Mockup Model
</th>
<th scope='col' className=' px-6 py-4'>
Product Type
</th>
<th scope='col' className=' px-6 py-4'>
Product Design URL
</th>
Expand All @@ -173,44 +170,43 @@ export default function Payments() {
<tbody>
{displayOrders &&
displayOrders.map((order, index) => {
const orderDate = new Date(order.orderDate);
const unformattedDate = new Date(order.orderDate);
unformattedDate.setMinutes((unformattedDate.getMinutes() + (60 * 0.5)))
const properDate = unformattedDate.toLocaleString('en-IN', { timeZone: 'Asia/Kolkata' }).split(', ');
return order.orderItems.map((item, i) => (
<tr
key={i}
className='border-b border-shadowGrey'>
<tr key={i} className='border-b border-shadowGrey'>
<td className='whitespace-nowrap px-2 py-4 font-medium'>
{index + 1}
</td>
<td className='whitespace-nowrap sticky top-0 left-0 z-10 px-6 pl-0 font-medium'>
{order.orderId}
</td>
<td className='whitespace-nowrap px-2 py-4'>
{`${orderDate
.getUTCDate()
.toString()
.padStart(2, "0")}-${(orderDate.getUTCMonth() + 1)
.toString()
.padStart(2, "0")}-${orderDate
.getUTCFullYear()
.toString()}`}
{properDate[0]}
<br />
{properDate[1]}
</td>
<td className='whitespace-nowrap px-2 py-4'>
{order.shippingAddress.name}
</td>
<td className='whitespace-nowrap px-2 py-4'>
{item.product.name}
</td>
<td className='whitespace-nowrap px-2 py-4'>
{item.product.vendorId}
{order.shippingAddress.name} <br />
{order.shippingAddress.email} <br />
{order.shippingAddress.phone}
</td>
<td className='whitespace-nowrap px-2 py-4'>
{item.product.name} <br />
{item.sku}
</td>
<td className='whitespace-nowrap px-2 py-4'>
{order.shippingAddress.email}
{item.quantity}
</td>
<td className='whitespace-nowrap px-6 min-w-10 pl-2'>
{order.orderTotal} <br />+ ₹{" "}
{order.deliveryCharges} <br />={" "}
<strong>
{order.orderTotal + order.deliveryCharges}
</strong>
</td>
<td className='whitespace-nowrap px-2 py-4'>
{item.quantity}
{item.product.vendorId}
</td>
<td className='whitespace-nowrap px-6 pl-2'>
{order.paymentId}
Expand All @@ -229,30 +225,36 @@ export default function Payments() {
<td className='whitespace-nowrap px-2 py-4'>
{item.product.productMockup.name}
</td>
<td className='whitespace-nowrap px-2 py-4'>
{item.product.productMockup.model}
</td>
<td className='whitespace-nowrap px-2 py-4'>
{item.product.productMockup.productType}
</td>
<td className='whitespace-nowrap px-2 py-4'>
<a
href={item.product.frontDesignUrl}
target='_blank' rel="noreferrer" style={{textDecoration: 'underline'}}>
target='_blank'
rel='noreferrer'
style={{ textDecoration: "underline" }}
>
View Product Design
</a>
</td>
<td className='whitespace-nowrap px-2 py-4'>
<a
href={item.product.backDesignUrl}
target='_blank' rel="noreferrer" style={{textDecoration: 'underline'}}>
target='_blank'
rel='noreferrer'
style={{ textDecoration: "underline" }}
>
View Design
</a>
</td>
<td className='whitespace-nowrap px-2 py-4'>
<a
href={'https://app.shiprocket.in/seller/orders/details/' + order.orderId}
target='_blank' rel="noreferrer" style={{textDecoration: 'underline'}}>
href={
"https://app.shiprocket.in/seller/orders/details/" +
order.orderId
}
target='_blank'
rel='noreferrer'
style={{ textDecoration: "underline" }}
>
View Details
</a>
</td>
Expand Down
Loading

0 comments on commit 3b555aa

Please sign in to comment.