Skip to content

Commit

Permalink
Merge branch 'external_api_integration' of https://github.com/SaintAn…
Browse files Browse the repository at this point in the history
…geLs/courier_app into external_api_integration
  • Loading branch information
eggwhat committed Jan 24, 2024
2 parents 95007f7 + b7fb5c4 commit 46a1603
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,13 @@ modules:
bind:
- customerId:{customerId}

- upstream: /requests
- upstream: /requests/customerId={customerId}
method: GET
use: downstream
downstream: orders-service/orders/requests
downstream: orders-service/orders/requests?customerId={customerId}
auth: true
bind:
- customerId:{customerId}

- upstream: /office-worker
method: GET
Expand Down
13 changes: 11 additions & 2 deletions SwiftParcel.Web/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@ import Inquiries from "./pages/inquiries/inquiries";
import Offers from "./pages/offers/offersUser";
import OfferRequests from "./pages/offers/offerRequests";
import PendingOffers from "./pages/offers/pendingOffers";
import Orders from "./pages/orders/orders";
import YourDeliveries from "./pages/deliveries/yourDeliveries";
import PendingDeliveries from "./pages/deliveries/pendingDeliveries";
import OrdersUser from "./pages/orders/ordersUser";
import OfferRequestsUser from "./pages/orders/offerRequestsUser";

export function App() {

Expand Down Expand Up @@ -71,7 +72,15 @@ export function App() {
path="/orders"
element={
<RolesAuthRoute roles={['user']}>
<Orders/>
<OrdersUser/>
</RolesAuthRoute>
}
/>
<Route
path="/offer-requests-user"
element={
<RolesAuthRoute roles={['user']}>
<OfferRequestsUser/>
</RolesAuthRoute>
}
/>
Expand Down
4 changes: 3 additions & 1 deletion SwiftParcel.Web/frontend/src/components/details/order.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import formatOfferStatus from "../parsing/formatOfferStatus";

interface OrderDetailsProps {
orderData: any;
pageContent: string;
}

export function isPackageValid(validTo : string) {
Expand All @@ -16,7 +17,7 @@ export function isPackageValid(validTo : string) {
};

export function OrderDetails({
orderData
orderData, pageContent
}: OrderDetailsProps) {

const [order, setOrder] = React.useState<any>(orderData);
Expand Down Expand Up @@ -91,6 +92,7 @@ export function OrderDetails({
show={showOrderDetailsModal}
setShow={setShowOrderDetailsModal}
order={order}
pageContent={pageContent}
/>
</>
);
Expand Down
1 change: 1 addition & 0 deletions SwiftParcel.Web/frontend/src/components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export function Header(props: {
<AppNavLink to="/" text="Check Order" />
<AppNavLink to="/create-inquiry" text="Create Inquiry" />
<AppNavLink to="/inquiries" text="Your Inquiries" />
<AppNavLink to="/offer-requests-user" text="Your Offer Requests" />
<AppNavLink to="/orders" text="Your Orders" />
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,9 @@ import {
navigate("/", {state:{parcelId: null}});
};

const redirectToOrders = () => {
const redirectToOfferRequests = () => {
close();
navigate("/orders", {state:{parcelId: null}});
navigate("/offer-requests-user", {state:{parcelId: null}});
};

return (
Expand Down Expand Up @@ -426,7 +426,7 @@ import {
:
<div className="space-y-6 gap-6">
<div className="flex justify-end">
<Button onClick={() => redirectToOrders()}>Go to your orders</Button>
<Button onClick={() => redirectToOfferRequests()}>Go to your offer requests</Button>
</div>
</div>
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
inputData: any;
tableData: any;
setTableData: any;
pageContent: string;
}

type FilteringDetails = {
Expand Down Expand Up @@ -468,7 +469,7 @@ import {
<form onSubmit={submit}>
<div className="space-y-6 px-6 pb-4 sm:pb-6 lg:px-8 xl:pb-8">
<h1 className="mb-2 text-2xl font-bold text-gray-900 dark:text-white">
Filter orders by attributes:
Filter {props.pageContent == "orders" ? 'orders' : 'offer requests'} by attributes:
</h1>
{error ? (
<Alert color="failure" icon={HiInformationCircle}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { confirmOrder, cancelOrder } from "../../../utils/api";
show: boolean;
setShow: (show: boolean) => void;
order: any;
pageContent: string;
}

const formatDate = (date: string) => {
Expand Down Expand Up @@ -252,7 +253,7 @@ import { confirmOrder, cancelOrder } from "../../../utils/api";
<form onSubmit={submit}>
<div className="space-y-6 px-6 pb-4 sm:pb-6 lg:px-8 xl:pb-8">
<h1 className="mb-2 text-2xl font-bold text-gray-900 dark:text-white">
Details of your order:
Details of your {props.pageContent == "orders" ? 'order' : 'offer request'}:
</h1>
<div className="space-y-6 gap-6" style={{ maxHeight: '70vh', paddingBottom: '20px' }}>
<div className="space-y-6 gap-6">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Orders from "./orders";

export default function OfferRequestsUser() {
return Orders("offer-requests");
}
30 changes: 19 additions & 11 deletions SwiftParcel.Web/frontend/src/pages/orders/orders.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { Table, Pagination, Button } from "flowbite-react";
import React from "react";
import { Header } from "../../components/header";
import { Footer } from "../../components/footer";
import { getOrdersUser } from "../../utils/api";
import { getOrdersUser, getOfferRequestsUser } from "../../utils/api";
import { Loader } from "../../components/loader";
import { OrderDetails } from "../../components/details/order";
import { FilterOrdersModal } from "../../components/modals/orders/filterOrdersModal";
import { getUserIdFromStorage } from "../../utils/storage";
import { AddOrderByIdModal } from "../../components/modals/orders/addOrderByIdModal";

export default function Orders() {
export default function Orders(pageContent: string) {
const [page, setPage] = React.useState(1);
const [inputData, setInputData] = React.useState<any>(null);
const [tableData, setTableData] = React.useState<any>(null);
Expand All @@ -25,7 +25,7 @@ export default function Orders() {

React.useEffect(() => {

getOrdersUser(getUserIdFromStorage())
((pageContent == "orders") ? getOrdersUser(getUserIdFromStorage()) : getOfferRequestsUser(getUserIdFromStorage()))
.then((res) => {
if (res.status === 200) {
setInputData(res?.data);
Expand Down Expand Up @@ -164,7 +164,7 @@ export default function Orders() {
<Header loading={loadingHeader} setLoading={setLoadingHeader} />
<div style={tableHeaderStyle.row}>
<h1 className="mb-2 text-3xl font-bold text-gray-900 dark:text-white" style={tableHeaderStyle.left}>
Your orders
{pageContent == "orders" ? 'Your orders' : 'Your offer requests'}
</h1>
<div className="grid grid-cols-1 md:grid-cols-2 gap-2">
<Button className="mr-2" onClick={() => setShowAddOrderByIdModal(true)}>
Expand All @@ -175,9 +175,15 @@ export default function Orders() {
</Button>
</div>
</div>
<p className="mb-5">
To see details of an order or check its full status, click button in the last column of the table.
</p>
{ pageContent == "orders" ?
<p className="mb-5">
To see details of an order or check its full status, click button in the last column of the table.
</p>
:
<p className="mb-5">
To see details of an offer request or check its full status, click button in the last column of the table.
</p>
}
<AddOrderByIdModal
show={showAddOrderByIdModal}
setShow={setShowAddOrderByIdModal}
Expand All @@ -188,6 +194,7 @@ export default function Orders() {
inputData={inputData}
tableData={tableData}
setTableData={setTableData}
pageContent={pageContent}
/>
<Table>
<Table.Head>
Expand Down Expand Up @@ -222,14 +229,15 @@ export default function Orders() {
<OrderDetails
key={order.id}
orderData={order}
pageContent={pageContent}
/>
))
) : (
<tr>
<td colSpan={10} className="text-center">
No orders found
</td>
</tr>
<td colSpan={10} className="text-center">
No {pageContent == "orders" ? 'orders' : 'offer requests'} found
</td>
</tr>
)}
</Table.Body>
</Table>
Expand Down
5 changes: 5 additions & 0 deletions SwiftParcel.Web/frontend/src/pages/orders/ordersUser.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Orders from "./orders";

export default function OrdersUser() {
return Orders("orders");
}
10 changes: 10 additions & 0 deletions SwiftParcel.Web/frontend/src/utils/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,16 @@ export const getOrdersUser = async (customerId: string) => {
}
};

export const getOfferRequestsUser = async (customerId: string) => {
try {
const response = await api.get(`/orders/requests/customerId=${customerId}`, { headers: getAuthHeader() });
return response;
} catch (error) {
console.error('Error during getting offer requests:', error);
throw error;
}
};

export const getOffers = async (parcelId: string) => {
try {
const response = await api.get(`/parcels/${parcelId}/offers`, { headers: getAuthHeader() });
Expand Down

0 comments on commit 46a1603

Please sign in to comment.