Skip to content

Commit

Permalink
feat: add search to order, transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Jangkuz committed Jul 10, 2024
1 parent ac43e31 commit fb67ec8
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 17 deletions.
1 change: 1 addition & 0 deletions backend/Helper/OrderQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class OrderQuery
public DateTime? MinDate { get; set; } = null;
public DateTime? MaxDate { get; set; } = null;
public string PhoneNumber { get; set; } = string.Empty;
public string? SearchCustomerName { get; set; } = string.Empty;
public double? MinTotalPrice { get; set; } = 0;
public double? MaxTotalPrice { get; set; } = 1000000000;
public int PageSize { get; set; } = 5;
Expand Down
1 change: 1 addition & 0 deletions backend/Helper/TransactionQuery.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ namespace backend.Helper
{
public class TransactionQuery
{
public string? SearchOrderId { get; set; } = string.Empty;
public int? PageSize { get; set; }
public int? PageNumber { get; set; }
}
Expand Down
7 changes: 7 additions & 0 deletions backend/Repository/OrderRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,13 @@ public OrderRepository(ApplicationDbContext context)
);
}

if (!string.IsNullOrEmpty(query.SearchCustomerName))
{
orderQueries = orderQueries.Where(x =>
x.Customer!.Name.Contains(query.SearchCustomerName)
);
}

if (query.SaleStaffId.HasValue)
{
orderQueries = orderQueries.Where(x => x.SaleStaffId == query.SaleStaffId);
Expand Down
8 changes: 8 additions & 0 deletions backend/Repository/TransactionRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using backend.Mappers;
using backend.Models;
using Microsoft.EntityFrameworkCore;
using Microsoft.IdentityModel.Tokens;

namespace backend.Repository
{
Expand Down Expand Up @@ -59,6 +60,13 @@ public TransactionRepository(ApplicationDbContext context)
{
var transactionsQuery = _context.Transactions.AsQueryable();

if (!query.SearchOrderId.IsNullOrEmpty())
{
transactionsQuery = transactionsQuery.Where( tq =>
tq.OrderId!.Contains(query.SearchOrderId!)
);
}

var totalCount = await transactionsQuery.CountAsync();
var totalPages = totalCount / (query.PageSize ?? 10);
var Transactions = await transactionsQuery
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/constants/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ import BlogsManage from "../pages/dashboard/blog/BlogsManage";
import BlogView from "../pages/dashboard/blog/BlogView";
import AccessoriesManage from "../pages/dashboard/accessory/AccessoriesManage";
import AccessoryView from "../pages/dashboard/accessory/AccessoryView";
import DiamondPriceManage from "../pages/dashboard/diamondPrice/DiamondPriceManage";
import AccessoryPriceManage from "../pages/dashboard/accessoryPrice/AccessoryPriceManage";
import DiamondPriceManage from "../pages/dashboard/diamondprice/DiamondPriceManage";
import AccessoryPriceManage from "../pages/dashboard/accessoryprice/AccessoryPriceManage";
import CustomerManage from "../pages/dashboard/customer/CustomerManage";
import TransactionManage from "../pages/dashboard/transaction/TransactionManage";
import OrderManage from "../pages/dashboard/order/OrderManage";
Expand Down
29 changes: 17 additions & 12 deletions frontend/src/pages/dashboard/order/OrderManage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,14 @@ export default function OrderManage() {
status === "1"
? "Pending"
: status === "2"
? "Processing"
: status === "3"
? "Confirmed"
: status === "4"
? "Delivering"
: status === "5"
? "Completed"
: "Failed"
? "Processing"
: status === "3"
? "Confirmed"
: status === "4"
? "Delivering"
: status === "5"
? "Completed"
: "Failed"
);
}
}, [location.search]);
Expand Down Expand Up @@ -105,11 +105,16 @@ export default function OrderManage() {
<Form.Item className="flex-grow">
<Input
type="text"
placeholder="Search"
placeholder="Search by customer name"
id="keyword"
className="border p-2 rounded-md w-full"
className="border p-2 rounded-md w-[300px]"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
onChange={(e) => {
setSearchTerm(e.target.value)
params.set("SearchCustomerName", e.target.value);
setQueryUrl(`/api/Order?` + params.toString());
navigate({ search: params.toString() });
}}
/>
</Form.Item>
<Form.Item>
Expand All @@ -129,7 +134,7 @@ export default function OrderManage() {
// Clear the URL parameters
const params = new URLSearchParams(location.search);
setQueryUrl(`/api/Order?` + params.toString());
// params.delete("type");
params.delete("SearchCustomerName");
navigate({ search: params.toString() });
}}
>
Expand Down
11 changes: 8 additions & 3 deletions frontend/src/pages/dashboard/transaction/TransactionManage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ export default function TransactionManage() {
id="keyword"
className="border p-2 rounded-md w-full"
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
onChange={(e) => {
setSearchTerm(e.target.value)
params.set("SearchOrderId", e.target.value);
setQueryUrl(`/api/Transactions?` + params.toString());
navigate({ search: params.toString() });
}}
/>
</Form.Item>
</Form>
Expand All @@ -95,8 +100,8 @@ export default function TransactionManage() {
setSearchTerm("");
// Clear the URL parameters
const params = new URLSearchParams(location.search);
params.delete("SearchOrderId");
setQueryUrl(`/api/Transactions?` + params.toString());
// params.delete("type");
navigate({ search: params.toString() });
}}
>
Expand Down Expand Up @@ -135,7 +140,7 @@ export default function TransactionManage() {
<LoadingItem key={key} />
))}
{TransactionsList?.data &&
TransactionsList?.data?.transactions?.length > 0 ? (
TransactionsList?.data?.transactions?.length > 0 ? (
TransactionsList?.data?.transactions?.map(
renderTransactionsRow
)
Expand Down
22 changes: 22 additions & 0 deletions frontend/src/pages/dashboard/warranty_card/CardManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,28 @@ export default function CardManagement() {
</Form.Item>
</Form>
</h3>

<div className="flex space-x-075">
<div className="card-action ">
<a
href="/admin/diamonds"
className="text-interactive "
onClick={(event) => {
event.preventDefault();
setSearchTerm("");
setSearchProductName("");
// Clear the URL parameters
const params = new URLSearchParams(location.search);
params.delete("CustomerName");
params.delete("ProductName");
setQueryUrl(`/api/WarrantyCards?` + params.toString());
navigate({ search: params.toString() });
}}
>
Clear filter
</a>
</div>
</div>
</div>
<div className="pt-lg"></div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit fb67ec8

Please sign in to comment.