Skip to content

Commit

Permalink
Merge pull request #41 from atlp-rwanda/some-bugs-fix
Browse files Browse the repository at this point in the history
fixing some bugs for better appearance
  • Loading branch information
niyontwali authored and P-Rwirangira committed Jul 23, 2024
2 parents 3fb8f9d + 7104c0f commit 303f262
Show file tree
Hide file tree
Showing 21 changed files with 948 additions and 48 deletions.
23 changes: 6 additions & 17 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,16 @@ import AdminPage from './pages/admin';
import Category from './pages/admin/Category';
import Sellers from './pages/admin/Sellers';
import Buyers from './pages/admin/Buyers';
import Messages from './pages/admin/Messages';
import UserManagement from './pages/admin/UserManagement';
import NotFoundPage from './pages/NotFoundPage';
import Settings from './pages/admin/Settings';
import SellerSettings from './pages/seller/Settings';
import SellersPage from './pages/seller';
import Orders from './pages/seller/Orders';
import Products from './pages/seller/Products';
import Customers from './pages/seller/Customers';
import SellerMessages from './pages/seller/Messages';
import SellerSettings from './pages/seller/Settings';
import AdminSettings from './pages/admin/Settings';
import AddNewProduct from './pages/seller/AddNewProduct';
import RestrictedSellerRoute from './components/dashboard/RestrictedSellerLayout';

import CategoriesPage from './pages/CategoriesPage';
import ResetPassword from './pages/ResetPassword';
import NewPassword from './pages/NewPassword';
Expand Down Expand Up @@ -140,12 +137,12 @@ const App = () => {
element: <Buyers />,
},
{
path: 'messages',
element: <SellerMessages />,
path: 'users',
element: <UserManagement />,
},
{
path: 'settings',
element: <SellerSettings />,
element: <AdminSettings />,
},
],
},
Expand Down Expand Up @@ -173,17 +170,9 @@ const App = () => {
path: 'customers',
element: <Customers />,
},
{
path: 'messages',
element: <Messages />,
},
{
path: 'users',
element: <UserManagement />,
},
{
path: 'settings',
element: <Settings />,
element: <SellerSettings />,
},
],
},
Expand Down
162 changes: 162 additions & 0 deletions src/components/OrderTables.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import React, { useState } from 'react';
import { Button } from './ui/button';
import { useGetOrdersQuery } from "../services/ordersApi";
import { Order } from "../types/Types";
import { CiSearch } from 'react-icons/ci';

const statusColors: { [key: string]: string } = {
'delivered': 'bg-[#d1fae5] text-[#065f46]',
'cancelled': 'bg-[#fee2e2] text-[#991b1b]',
'pending': 'bg-[#e9d5ff] text-[#6b21a8]',
'paid': 'bg-[#fef3c7] text-[#854d0e]',
};

const itemsPerPage = 15;

const TransactionTable: React.FC = () => {
const [selectedStatus, setSelectedStatus] = useState<string>('all');
const [currentPage, setCurrentPage] = useState<number>(1);
const [searchQuery, setSearchQuery] = useState<string>('');
const { data: ordersData, isLoading, isError } = useGetOrdersQuery();
const orders = ordersData?.data || [];

const handleStatusChange = (status: string) => {
setSelectedStatus(status);
setCurrentPage(1);
};

const handleSearchChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setSearchQuery(event.target.value);
setCurrentPage(1);
};

const filteredTransactions = selectedStatus === 'all'
? orders
: orders.filter((transaction: Order) => transaction.status.toLowerCase() === selectedStatus);

const searchedTransactions = searchQuery
? filteredTransactions.filter((transaction: Order) =>
transaction.orderItems.some((item) =>
item.products.name.toLowerCase().includes(searchQuery.toLowerCase())
)
)
: filteredTransactions;

const totalPages = Math.ceil(searchedTransactions.length / itemsPerPage);

const currentTransactions = searchedTransactions.slice(
(currentPage - 1) * itemsPerPage,
currentPage * itemsPerPage
);

const handlePageChange = (page: number) => {
if (page >= 1 && page <= totalPages) {
setCurrentPage(page);
}
};

if (isLoading) {
return <div>Loading...</div>;
}

if (isError) {
return <div>Error loading orders.</div>;
}

return (
<div className='md:ml-64 p-4'>
<div className='bg-[#ffffff] shadow-md rounded-lg p-6 border border-grayColor'>
<div className='mb-4 flex justify-between items-center'>
<div>
<h2 className='text-lg font-semibold'>Orders Details</h2>
<p className='text-sm text-[#8F88f]'>Manage orders</p>
</div>
<div className='flex items-center rounded bg-whiteColor p-2 border border-grayColor'>
<CiSearch className='mr-1.5 text-[#A08D8D]' size={20} />
<input
type='text'
placeholder='Search orders'
className='border-none outline-none'
value={searchQuery}
onChange={handleSearchChange}
/>
</div>
</div>
<nav className="flex gap-4 sm:gap-6 text-sm font-medium">
{["all", "paid", "pending", "delivered", "canceled"].map(status => (
<Button
key={status}
variant={selectedStatus === status ? 'primary' : 'outline'}
onClick={() => handleStatusChange(status)}
className="px-4 py-2 rounded-md"
>
{status.charAt(0).toUpperCase() + status.slice(1)}
</Button>
))}
</nav>
<div className='overflow-x-auto'>
<table className='min-w-full bg-[#ffffff]'>
<thead>
<tr>
<th className='px-4 py-2 border-b border-[#e5e7eb] text-start'>Order ID</th>
<th className='px-4 py-2 border-b border-[#e5e7eb] text-start'>CUSTOMER</th>
<th className='px-4 py-2 border-b border-[#e5e7eb] text-start'>PRODUCT</th>
<th className='px-4 py-2 border-b border-[#e5e7eb] text-start'>DATE</th>
<th className='px-4 py-2 border-b border-[#e5e7eb] text-start'>STATUS</th>
<th className='px-4 py-2 border-b border-[#e5e7eb] text-start'>PRICE</th>
</tr>
</thead>
<tbody>
{currentTransactions.map((transaction: Order) => (
<React.Fragment key={transaction.id}>
{transaction.orderItems.map((orderItem, itemIndex) => (
<tr key={`${transaction.id}-${itemIndex}`}>
<td className='px-4 py-2 border-b border-[#e5e7eb] font-light'>#{(transaction.id).slice(0, 3)}</td>
<td className='px-4 py-2 border-b border-[#e5e7eb] font-light'>{transaction.user?.firstName} {transaction.user?.lastName}</td>
<td className='px-4 py-2 border-b border-[#e5e7eb] font-light'>{orderItem.products.name}</td>
<td className='px-4 py-2 border-b border-[#e5e7eb] font-light'>
{new Date(transaction.createdAt).toLocaleDateString('en-US', {
year: 'numeric',
month: 'short',
day: '2-digit',
})}
</td>
<td className='px-4 py-2 border-b border-[#e5e7eb] font-light'>
<span className={`px-2 py-1 rounded-full text-xs font-medium ${statusColors[transaction.status]}`}>
{transaction.status}
</span>
</td>
<td className='px-4 py-2 border-b border-[#e5e7eb] font-light'>{orderItem.price.toFixed(1)}</td>
</tr>
))}
</React.Fragment>
))}
</tbody>
</table>
</div>
<div className="flex justify-between items-center mt-4">
<div>{`${searchedTransactions.length} out of ${orders.length} orders`}</div>
<div className="flex space-x-2">
<Button
variant="outline"
disabled={currentPage === 1}
onClick={() => handlePageChange(currentPage - 1)}
>
Previous
</Button>
<span>Page {currentPage} of {totalPages}</span>
<Button
variant="outline"
disabled={currentPage === totalPages}
onClick={() => handlePageChange(currentPage + 1)}
>
Next
</Button>
</div>
</div>
</div>
</div>
);
};

export default TransactionTable;
6 changes: 3 additions & 3 deletions src/components/admin/AdminLayout.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { Outlet } from 'react-router-dom';
import Sidebar from '../dashboard/Sidebar';
import { RxDashboard } from 'react-icons/rx';
import { FaCog, FaRegListAlt, FaUserFriends } from 'react-icons/fa';
import { FaRegEnvelope, FaUserTie } from 'react-icons/fa6';
import { FaCog, FaRegListAlt, FaUserFriends, FaUsers } from 'react-icons/fa';
import { FaUserTie } from 'react-icons/fa6';

export default function AdminLayout() {
const adminSidebarLinks = [
{ name: 'Dashboard', path: '/admin', icon: <RxDashboard className='mr-3' /> },
{ name: 'Categories', path: 'categories', icon: <FaRegListAlt className='mr-3' /> },
{ name: 'Sellers', path: 'sellers', icon: <FaUserFriends className='mr-3' /> },
{ name: 'Buyers', path: 'buyers', icon: <FaUserTie className='mr-3' /> },
{ name: 'Messages', path: 'messages', icon: <FaRegEnvelope className='mr-3' /> },
{ name: 'Users', path: 'users', icon: <FaUsers className='mr-3' /> },
{ name: 'Settings', path: 'settings', icon: <FaCog className='mr-3' /> },
];

Expand Down
8 changes: 4 additions & 4 deletions src/components/chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ const Chat: React.FC = () => {
</div>

{showChat && (
<div className='fixed inset-0 z-40 flex items-center justify-end mx-2 sm:mr-6'>
<div className='w-9/10 max-w-sm h-3/4 rounded-2xl shadow-xl relative bg-grayColor overflow-hidden '>
<div className='header bg-darkGreen flex justify-between items-center px-6 py-3 text-white'>
<div className='flex items-center gap-4'>
<div className='fixed inset-0 z-40 flex items-center justify-end mx-2 sm:mr-6'>
<div className='w-9/10 max-w-sm h-3/4 rounded-2xl shadow-xl relative bg-grayColor overflow-hidden pt-10'>
<div className='header bg-darkGreen flex justify-between items-center px-6 py-3 text-whiteColor'>
<div className='flex items-center gap-4'>
<img
src={`${profileImage !== null ? profileImage : chatAvatar}`}
alt='Mavericks'
Expand Down
Loading

0 comments on commit 303f262

Please sign in to comment.