Skip to content

Commit

Permalink
#60: some updates at home page and modals for details
Browse files Browse the repository at this point in the history
  • Loading branch information
an2508374 committed Jan 17, 2024
1 parent 8a947da commit 2f15a42
Show file tree
Hide file tree
Showing 6 changed files with 98 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -327,42 +327,6 @@ import { getUserIdFromStorage } from "../../../utils/storage";
detailsData={props}
/>

{/* { props.pageContent == "pending-offers" ? (
<div className="mb-4 border-b border-gray-200 pb-1 grid grid-cols-1 md:grid-cols-2 gap-4">
<Button onClick={() => {setAccepted(true); setRejected(false);}}>Accept</Button>
<Button onClick={() => {setAccepted(false); setRejected(true);}}>Reject</Button>
</div>
) : null }
{ (accepted && !finalized) ? (
<div className="mb-4 pb-1 grid grid-cols-1 md:grid-cols-1 gap-4">
<Button onClick={() => accept()}>Confirm acceptation</Button>
</div>
) : null }
{ (rejected && !finalized) ? (
<div className="mb-4 pb-1 grid grid-cols-1 md:grid-cols-1 gap-4">
<Label htmlFor="reason-of-rejection" className="mb-2 block text-sm font-medium text-gray-700">
Input reason of rejection:
</Label>
<TextInput
id="reason-of-rejection"
type="string"
lang="en"
value={reason}
onChange={(e) => 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`}
/>
<Button onClick={() => reject(reason)}>Confirm rejection</Button>
</div>
) : null }
{ finalized ? (
<div className="mb-4 pb-1 grid grid-cols-1 md:grid-cols-1 gap-4">
<Button onClick={() => refresh()}>Refresh page</Button>
</div>
) : null } */}

<div style={{ marginBottom: '40px' }}></div>

</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,10 @@ import {

{error ? null : <SubmitButton userInfoLoading={userInfoLoading} />}
</div>

<div className="space-y-6 gap-6">
<div style={{ marginBottom: '40px' }}></div>
</div>
</div>
) : null}
{success ? (
Expand Down Expand Up @@ -391,17 +395,20 @@ import {
/>

<div className="space-y-6 gap-6">
<div style={{ marginBottom: '20px' }}></div>
<div style={{ marginBottom: '30px' }}></div>
</div>

<p className="text-blue-500">Remember to confirm or cancel your offer request after potential approval.</p>

<div className="space-y-6 gap-6">
<div style={{ marginBottom: '30px' }}></div>
</div>

<div className="flex justify-end">
<Button onClick={() => refresh()}>Go to your orders</Button>
</div>
</div>
) : null}
<div className="space-y-6 gap-6">
<div style={{ marginBottom: '20px' }}></div>
</div>
</div>
</div>
</form>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,14 @@ import { confirmOrder, cancelOrder } from "../../../utils/api";
<Button onClick={() => confirm()}>Confirm</Button>
<Button onClick={() => cancel()}>Cancel</Button>
</div>
) : null }
) : (
<div className="mb-4 border-b border-gray-200 pb-1 grid gap-4">
<Label
id="offer-request-expired"
value="Your offer request has been expired!"
/>
</div>
) }

{ finalized ? (
<div className="mb-4 pb-1 grid grid-cols-1 md:grid-cols-1 gap-4">
Expand All @@ -113,7 +120,7 @@ import { confirmOrder, cancelOrder } from "../../../utils/api";
valueB={detailsData.order.cancellationReason}
/>
: null }
{ detailsData.order.status === "pickedupat" ?
{ detailsData.order.status === "pickedup" ?
<LabelsWithBorder
idA="picked-up-at"
valueA="Picked up at:"
Expand Down
12 changes: 5 additions & 7 deletions SwiftParcel.Web/frontend/src/pages/home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,11 @@ export default function Home() {
setTimeout(() => {
setTrackingNumber("");
setError(true);
setErrorText("Invalid tracking number");
setErrorText("Invalid Order Id");
setLoadingParcel(false);
}, 1000);
};



return (
<>
{loading ? <Loader /> : null}
Expand Down Expand Up @@ -85,10 +83,10 @@ export default function Home() {
<form onSubmit={onSubmit}>
<div className="flex flex-col items-center justify-center my-20">
<h1 className="mb-2 text-3xl font-bold text-gray-900 dark:text-white">
Track Your Parcel
Check Your Order
</h1>
<p className="mb-4 text-gray-600 dark:text-gray-400">
Track your parcel with the parcel tracking number.
Give id of your order to see its details.
</p>

<div
Expand All @@ -105,7 +103,7 @@ export default function Home() {
</div>

<TextInput
placeholder="Parcel Tracking Number"
placeholder="Order Id"
className="w-full md:w-1/2"
type="text"
sizing="lg"
Expand All @@ -128,7 +126,7 @@ export default function Home() {
Loading ...
</>
) : (
"Track Parcel"
"Check Order"
)}
</Button>
</div>
Expand Down
99 changes: 65 additions & 34 deletions SwiftParcel.Web/frontend/src/utils/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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'
}
})
Expand Down Expand Up @@ -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'
}
})
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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'
}
})
Expand Down Expand Up @@ -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,
Expand All @@ -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'
}
})
Expand Down Expand Up @@ -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() });
Expand Down Expand Up @@ -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
Expand All @@ -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'
}
})
Expand Down Expand Up @@ -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
Expand All @@ -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'
}
})
Expand All @@ -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
};
Expand All @@ -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'
}
})
Expand All @@ -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
Expand All @@ -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'
}
})
Expand All @@ -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,
Expand All @@ -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'
}
})
Expand Down

0 comments on commit 2f15a42

Please sign in to comment.