Skip to content

Commit

Permalink
Merge pull request #8 from ish-2000/ishara's_branch
Browse files Browse the repository at this point in the history
update orders system
  • Loading branch information
ish-2000 authored Sep 20, 2024
2 parents 0a03730 + 4eac758 commit fa7484e
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 290 deletions.
12 changes: 12 additions & 0 deletions backend/controllers/couponController.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,15 @@ export const validCoupon = async (req, res) => {
res.status(500).json({ message: error.message })
}
}

export const createCoupon = async (req, res) => {
try {
const { couponCode, discount, expiryDate } = req.body

const coupon = await Coupon.create({ couponCode, discount, expiryDate })

res.status(201).json({ coupon })
} catch (error) {
res.status(409).json({ message: error.message })
}
}
4 changes: 2 additions & 2 deletions backend/controllers/orderController.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ export const getAllOrders = async (req, res) => {
console.log('shopId', shopId)
try {
const orders = shopId
? await Order.find({ 'farmer.shopId': shopId })
: await Order.find()
? await Order.find({ 'farmer.shopId': shopId }).sort({ _id: 1 })
: await Order.find().sort({ _id: 1 })

res.status(200).json(orders)
} catch (error) {
Expand Down
13 changes: 13 additions & 0 deletions backend/models/OrderModel.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import mongoose from 'mongoose'
import { type } from 'os'

const orderSchema = new mongoose.Schema({
farmer: {
Expand Down Expand Up @@ -39,6 +40,18 @@ const orderSchema = new mongoose.Schema({
deliveryDate: {
type: Date,
},
deliveredAt: {
type: Date,
default: null,
},
deliverId: {
type: String,
default: null,
},
deliverName: {
type: String,
default: null,
},
})

const Order = mongoose.model('Order', orderSchema)
Expand Down
3 changes: 2 additions & 1 deletion backend/routes/couponRouter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import express from 'express'
import { validCoupon } from '../controllers/couponController.js'
import { createCoupon, validCoupon } from '../controllers/couponController.js'

const couponRouter = express.Router()

couponRouter.post('/valid-coupon', validCoupon)
couponRouter.post('/create', createCoupon)

export default couponRouter
2 changes: 0 additions & 2 deletions frontend/src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ const router = createBrowserRouter(
<Route path="/cart" element={<Cart />} />
<Route path="/checkOut" element={<CheckOut />} />
<Route path="*" element={<NotFound />} />

<Route path="/shop/:id/product/:productId" element={<ShopList />} />
</Route>
)
)
Expand Down
30 changes: 25 additions & 5 deletions frontend/src/Pages/Customer/UserAllOrders.jsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import React, { useEffect, useMemo, useState } from 'react'
import OrderTable from '../../Components/OrderTable'
import { Pagination, Table, TableBody, TableCell, TableColumn, TableHeader, TableRow } from '@nextui-org/react'
import {
Pagination,
Table,
TableBody,
TableCell,
TableColumn,
TableHeader,
TableRow,
} from '@nextui-org/react'

function UserAllOrders() {
const [page, setPage] = useState(1)
Expand Down Expand Up @@ -132,14 +140,26 @@ function UserAllOrders() {
<span
className={
item.orderStatus === 'Pending'
? 'text-yellow-500 p-1 rounded-md font-bold ring-0'
? 'bg-yellow-500 p-1 rounded-md text-white ring-0'
: item.orderStatus ===
'Delivered'
? 'text-green-500 p-1 rounded-md font-bold ring-0'
? 'bg-green-500 p-1 rounded-md text-white ring-0'
: item.orderStatus ===
'Accept'
? 'text-blue-500 p-1 rounded-md font-bold ring-0'
: 'text-red-500 p-1 rounded-md font-bold ring-0'
? 'bg-blue-500 p-1 rounded-md text-white ring-0'
: item.orderStatus ===
'Ready'
? 'bg-purple-500 p-1 rounded-md text-white ring-0'
: item.orderStatus ===
'Pickup'
? 'bg-orange-500 p-1 rounded-md text-white ring-0'
: item.orderStatus ===
'OnTheWay'
? 'bg-indigo-500 p-1 rounded-md text-white ring-0'
: item.orderStatus ===
'Rejected'
? 'bg-red-500 p-1 rounded-md text-white ring-0'
: 'bg-gray-500 p-1 rounded-md text-white ring-0'
}
>
{item.orderStatus}
Expand Down
7 changes: 0 additions & 7 deletions frontend/src/Pages/Shop/ShopList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ const ShopList = () => {
fetchShops();
}, []);

// Fetch bug fix
// Filtering and Sorting Logic
const filteredShops = shops
.filter((shop) =>
Expand Down Expand Up @@ -107,7 +106,6 @@ const ShopList = () => {
<h2 className="text-xl font-bold">Special Promotion: 20% off on all products!</h2>
</div> */}


{/* Search Bar */}
<input
type="text"
Expand All @@ -117,8 +115,6 @@ const ShopList = () => {
className="border p-2 rounded w-full mb-4 focus:outline-none focus:ring-2 focus:ring-blue-500"
/>



{/* Loading Message */}
{loading ? (
<Loading />
Expand Down Expand Up @@ -155,9 +151,6 @@ const ShopList = () => {
</div>
</div>
);



};

export default ShopList;
4 changes: 2 additions & 2 deletions frontend/src/Pages/Shop/ShopPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ const ShopPage = () => {
setSearchTerm(e.target.value);
};

//Filter products based on search term
// Filter products based on search term
const filteredProducts = shop.products?.filter(product =>
product.name.toLowerCase().includes(searchTerm.toLowerCase())
);
);

return (

Expand Down
23 changes: 22 additions & 1 deletion frontend/src/Pages/farmer/FarmerDashboard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,19 @@ const Dashboard = () => {
: item.orderStatus ===
'Accept'
? 'bg-blue-500 p-1 rounded-md text-white ring-0'
: 'bg-red-500 p-1 rounded-md text-white ring-0'
: item.orderStatus ===
'Ready'
? 'bg-purple-500 p-1 rounded-md text-white ring-0'
: item.orderStatus ===
'Pickup'
? 'bg-orange-500 p-1 rounded-md text-white ring-0'
: item.orderStatus ===
'OnTheWay'
? 'bg-indigo-500 p-1 rounded-md text-white ring-0'
: item.orderStatus ===
'Rejected'
? 'bg-red-500 p-1 rounded-md text-white ring-0'
: 'bg-gray-500 p-1 rounded-md text-white ring-0'
}
value={item.orderStatus}
onChange={(e) =>
Expand All @@ -386,6 +398,15 @@ const Dashboard = () => {
<option value="Accept">
Accept
</option>
<option value="Ready">
Ready
</option>
<option value="Pickup">
Pickup
</option>
<option value="OnTheWay">
On the way
</option>
<option value="Delivered">
Delivered
</option>
Expand Down
13 changes: 8 additions & 5 deletions frontend/src/Pages/order/Cart.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { useDisclosure } from '@nextui-org/react'
import { useEffect, useState } from 'react'
import { Link } from 'react-router-dom'
// import CheckOutModal from './CheckOutModal'
// test
// import { useGlobalRefetch } from '../Context/GlobalRefetch'
import axios from 'axios'
import toast from 'react-hot-toast'
Expand All @@ -14,6 +13,7 @@ const Cart = () => {
const [originalPrice, setOriginalPrice] = useState(0)
// const { globalRefetch, setGlobalRefetch } = useGlobalReefetch()
const [couponDiscount, setCouponDiscount] = useState(0)
const [disabledCouponButton, setDisabledCouponButton] = useState(false)

useEffect(() => {
const getCart = async () => {
Expand All @@ -34,8 +34,6 @@ const Cart = () => {
}
// console.log('cart', cart)

//special handling for kg test

useEffect(() => {
const calculateOriginalPrice = () => {
const originalPrice = cart.reduce((acc, item) => {
Expand Down Expand Up @@ -79,6 +77,7 @@ const Cart = () => {
JSON.stringify((total * couponDiscount) / 100)
)
toast.success('Coupon Applied Successfully')
setDisabledCouponButton(true)
}
}
} catch (error) {
Expand Down Expand Up @@ -313,9 +312,13 @@ const Cart = () => {
</div>
<button
type="submit"
disabled={cart.length === 0}
disabled={
cart.length === 0 ||
disabledCouponButton
}
className={`flex w-full items-center justify-center rounded-lg px-5 py-2.5 text-sm font-medium ${
cart.length === 0
cart.length === 0 ||
disabledCouponButton
? 'bg-gray-400 text-gray-700 cursor-not-allowed'
: 'bg-primary-700 text-white hover:bg-primary-800 focus:outline-none focus:ring-4 focus:ring-primary-300 dark:bg-primary-600 dark:hover:bg-primary-700 dark:focus:ring-primary-800'
}`}
Expand Down
Loading

0 comments on commit fa7484e

Please sign in to comment.