From 2f15a420b0647032bfdb6c8bc74f48d1b5c5b928 Mon Sep 17 00:00:00 2001 From: an2508374 Date: Thu, 18 Jan 2024 00:40:09 +0100 Subject: [PATCH] #60: some updates at home page and modals for details --- .../src/SwiftParcel.API.Gateway/ntrada.yml | 8 ++ .../deliveries/deliveryDetailsModal.tsx | 36 ------- .../modals/offers/userDetailsModal.tsx | 15 ++- .../modals/orders/orderDetailsModal.tsx | 11 ++- SwiftParcel.Web/frontend/src/pages/home.tsx | 12 +-- SwiftParcel.Web/frontend/src/utils/api.tsx | 99 ++++++++++++------- 6 files changed, 98 insertions(+), 83 deletions(-) diff --git a/SwiftParcel.API.Gateway/src/SwiftParcel.API.Gateway/ntrada.yml b/SwiftParcel.API.Gateway/src/SwiftParcel.API.Gateway/ntrada.yml index 92456d7..9cd2095 100644 --- a/SwiftParcel.API.Gateway/src/SwiftParcel.API.Gateway/ntrada.yml +++ b/SwiftParcel.API.Gateway/src/SwiftParcel.API.Gateway/ntrada.yml @@ -116,6 +116,14 @@ modules: orders: path: /orders routes: + - upstream: /{orderId} + method: GET + use: downstream + downstream: orders-service/orders/{orderId} + auth: true + bind: + - orderId:{orderId} + - upstream: /customerId={customerId} method: GET use: downstream diff --git a/SwiftParcel.Web/frontend/src/components/modals/deliveries/deliveryDetailsModal.tsx b/SwiftParcel.Web/frontend/src/components/modals/deliveries/deliveryDetailsModal.tsx index cd76603..c389cb1 100644 --- a/SwiftParcel.Web/frontend/src/components/modals/deliveries/deliveryDetailsModal.tsx +++ b/SwiftParcel.Web/frontend/src/components/modals/deliveries/deliveryDetailsModal.tsx @@ -327,42 +327,6 @@ import { getUserIdFromStorage } from "../../../utils/storage"; detailsData={props} /> - {/* { props.pageContent == "pending-offers" ? ( -
- - -
- ) : null } - - { (accepted && !finalized) ? ( -
- -
- ) : null } - - { (rejected && !finalized) ? ( -
- - setReason(e.target.value)} - className={`border-gray-300 focus:ring-blue-500 focus:border-blue-500 block w-full shadow-sm sm:text-sm rounded-md`} - /> - -
- ) : null } - - { finalized ? ( -
- -
- ) : null } */} -
diff --git a/SwiftParcel.Web/frontend/src/components/modals/offers/userDetailsModal.tsx b/SwiftParcel.Web/frontend/src/components/modals/offers/userDetailsModal.tsx index 2686e73..f1b998c 100644 --- a/SwiftParcel.Web/frontend/src/components/modals/offers/userDetailsModal.tsx +++ b/SwiftParcel.Web/frontend/src/components/modals/offers/userDetailsModal.tsx @@ -361,6 +361,10 @@ import { {error ? null : } + +
+
+
) : null} {success ? ( @@ -391,7 +395,13 @@ import { />
-
+
+
+ +

Remember to confirm or cancel your offer request after potential approval.

+ +
+
@@ -399,9 +409,6 @@ import {
) : null} -
-
-
diff --git a/SwiftParcel.Web/frontend/src/components/modals/orders/orderDetailsModal.tsx b/SwiftParcel.Web/frontend/src/components/modals/orders/orderDetailsModal.tsx index 4f3614a..632d2ab 100644 --- a/SwiftParcel.Web/frontend/src/components/modals/orders/orderDetailsModal.tsx +++ b/SwiftParcel.Web/frontend/src/components/modals/orders/orderDetailsModal.tsx @@ -96,7 +96,14 @@ import { confirmOrder, cancelOrder } from "../../../utils/api"; - ) : null } + ) : ( +
+
+ ) } { finalized ? (
@@ -113,7 +120,7 @@ import { confirmOrder, cancelOrder } from "../../../utils/api"; valueB={detailsData.order.cancellationReason} /> : null } - { detailsData.order.status === "pickedupat" ? + { detailsData.order.status === "pickedup" ? { setTrackingNumber(""); setError(true); - setErrorText("Invalid tracking number"); + setErrorText("Invalid Order Id"); setLoadingParcel(false); }, 1000); }; - - return ( <> {loading ? : null} @@ -85,10 +83,10 @@ export default function Home() {

- Track Your Parcel + Check Your Order

- Track your parcel with the parcel tracking number. + Give id of your order to see its details.

) : ( - "Track Parcel" + "Check Order" )}
diff --git a/SwiftParcel.Web/frontend/src/utils/api.tsx b/SwiftParcel.Web/frontend/src/utils/api.tsx index 0bf0a74..2baa9ee 100644 --- a/SwiftParcel.Web/frontend/src/utils/api.tsx +++ b/SwiftParcel.Web/frontend/src/utils/api.tsx @@ -48,25 +48,6 @@ export const login = async (email: string, password: string) => { } }; -// export const register = async ( -// ) => { -// try { -// const response = await api.post(`/identity/sign-up`, { -// username, -// password, -// email, -// }); -// return response.data; -// } catch (error) { -// if (axios.isAxiosError(error)) { -// console.error('Error during registration (Axios error):', error.response?.data || error.message); -// } else { -// console.error('Error during registration:', error); -// } -// throw error; -// } -// }; - export const register = async ( email: string, password: string, @@ -86,7 +67,6 @@ export const register = async ( const response = await api.post(`/identity/sign-up`, JSON.parse(JSON.stringify(payload)), { headers: { - //'Authorization': `${userInfo.accessToken}`, 'Content-Type': 'application/json' } }) @@ -130,7 +110,6 @@ export const completeCustomerRegistration = async ( const response = await api.post(`/customers`, JSON.parse(JSON.stringify(payload)), { headers: { - //'Authorization': `${userInfo.accessToken}`, 'Content-Type': 'application/json' } }) @@ -258,12 +237,12 @@ export const createInquiry = async ( ) => { try { - //const userInfo = getUserInfo(); - // if (!userInfo || !userInfo.accessToken) { - // console.warn('No user token found. Redirecting to login.'); - // window.location.href = '/login'; - // return; - // } + const userInfo = getUserInfo(); + if (!userInfo || !userInfo.accessToken) { + console.warn('No user token found. Redirecting to login.'); + window.location.href = '/login'; + return; + } // Log the token for debugging //console.log("Using access token:", userInfo.accessToken); @@ -304,7 +283,7 @@ export const createInquiry = async ( const response = await api.post(`/parcels`, JSON.parse(JSON.stringify(payload)), { headers: { - //'Authorization': `${userInfo.accessToken}`, + 'Authorization': `${userInfo.accessToken}`, 'Content-Type': 'application/json' } }) @@ -360,6 +339,13 @@ export const createOrder = async ( ) => { try { + const userInfo = getUserInfo(); + if (!userInfo || !userInfo.accessToken) { + console.warn('No user token found. Redirecting to login.'); + window.location.href = '/login'; + return; + } + const payload = { CustomerId: customerId, ParcelId: parcelId, @@ -382,7 +368,7 @@ export const createOrder = async ( const response = await api.post(`/orders`, JSON.parse(JSON.stringify(payload)), { headers: { - //'Authorization': `${userInfo.accessToken}`, + 'Authorization': `${userInfo.accessToken}`, 'Content-Type': 'application/json' } }) @@ -421,6 +407,16 @@ export const getInquiriesOfficeWorker = async () => { } }; +export const getOrder = async (orderId: string) => { + try { + const response = await api.get(`/orders/${orderId}`, { headers: getAuthHeader() }); + return response; + } catch (error) { + console.error('Error during getting orders:', error); + throw error; + } +}; + export const getOrdersUser = async (customerId: string) => { try { const response = await api.get(`/orders/customerId=${customerId}`, { headers: getAuthHeader() }); @@ -504,6 +500,13 @@ export const confirmOrder = async ( ) => { try { + const userInfo = getUserInfo(); + if (!userInfo || !userInfo.accessToken) { + console.warn('No user token found. Redirecting to login.'); + window.location.href = '/login'; + return; + } + const payload = { OrderId: orderId, Company: company @@ -515,7 +518,7 @@ export const confirmOrder = async ( const response = await api.post(`/orders/${orderId}/confirm`, JSON.parse(JSON.stringify(payload)), { headers: { - //'Authorization': `${userInfo.accessToken}`, + 'Authorization': `${userInfo.accessToken}`, 'Content-Type': 'application/json' } }) @@ -591,6 +594,13 @@ export const assignCourierToDelivery = async ( ) => { try { + const userInfo = getUserInfo(); + if (!userInfo || !userInfo.accessToken) { + console.warn('No user token found. Redirecting to login.'); + window.location.href = '/login'; + return; + } + const payload = { DeliveryId: deliveryId, CourierId: courierId @@ -602,7 +612,7 @@ export const assignCourierToDelivery = async ( const response = await api.post(`/deliveries/${deliveryId}/courier`, JSON.parse(JSON.stringify(payload)), { headers: { - //'Authorization': `${userInfo.accessToken}`, + 'Authorization': `${userInfo.accessToken}`, 'Content-Type': 'application/json' } }) @@ -626,6 +636,13 @@ export const pickupDelivery = async ( ) => { try { + const userInfo = getUserInfo(); + if (!userInfo || !userInfo.accessToken) { + console.warn('No user token found. Redirecting to login.'); + window.location.href = '/login'; + return; + } + const payload = { DeliveryId: deliveryId }; @@ -636,7 +653,7 @@ export const pickupDelivery = async ( const response = await api.post(`/deliveries/${deliveryId}/pick-up`, JSON.parse(JSON.stringify(payload)), { headers: { - //'Authorization': `${userInfo.accessToken}`, + 'Authorization': `${userInfo.accessToken}`, 'Content-Type': 'application/json' } }) @@ -661,6 +678,13 @@ export const completeDelivery = async ( ) => { try { + const userInfo = getUserInfo(); + if (!userInfo || !userInfo.accessToken) { + console.warn('No user token found. Redirecting to login.'); + window.location.href = '/login'; + return; + } + const payload = { DeliveryId: deliveryId, DeliveryAttemptDate: deliveryAttemptDate @@ -672,7 +696,7 @@ export const completeDelivery = async ( const response = await api.post(`/deliveries/${deliveryId}/complete`, JSON.parse(JSON.stringify(payload)), { headers: { - //'Authorization': `${userInfo.accessToken}`, + 'Authorization': `${userInfo.accessToken}`, 'Content-Type': 'application/json' } }) @@ -698,6 +722,13 @@ export const failDelivery = async ( ) => { try { + const userInfo = getUserInfo(); + if (!userInfo || !userInfo.accessToken) { + console.warn('No user token found. Redirecting to login.'); + window.location.href = '/login'; + return; + } + const payload = { DeliveryId: deliveryId, DeliveryAttemptDate: deliveryAttemptDate, @@ -710,7 +741,7 @@ export const failDelivery = async ( const response = await api.post(`/deliveries/${deliveryId}/fail`, JSON.parse(JSON.stringify(payload)), { headers: { - //'Authorization': `${userInfo.accessToken}`, + 'Authorization': `${userInfo.accessToken}`, 'Content-Type': 'application/json' } })