Skip to content

Commit

Permalink
#60 (#95): update logic of delivery details modal for courier operations
Browse files Browse the repository at this point in the history
  • Loading branch information
an2508374 committed Jan 17, 2024
1 parent 84ebaff commit 8a947da
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,23 +94,44 @@ import { getUserIdFromStorage } from "../../../utils/storage";
valueB={formatDateToUTC(detailsData.delivery.lastUpdate)}
/>

{ (!finalized && detailsData.pageContent == "your-deliveries") ? (
<div>
{ detailsData.delivery.status === "assigned" ?
<div className="mb-4 pb-1 grid grid-cols-2 md:grid-cols-2 gap-4">
<Button onClick={() => {complete()}}>Complete</Button>
<Button onClick={() => {setFailed(false)}}>Cannot deliver</Button>
</div>
:
<div className="mb-4 pb-1 grid grid-cols-1 md:grid-cols-1 gap-4">
<Button onClick={() => {pickup()}}>Pickup</Button>
</div>
}
</div>
) : (
<div className="mb-4 pb-1 grid grid-cols-1 md:grid-cols-1 gap-4">
<Button onClick={() => {assign()}}>Assign to you</Button>
</div> ) }
{ (detailsData.pageContent == "pending-deliveries") ? (
<div className="mb-4 pb-1 grid grid-cols-1 md:grid-cols-1 gap-4">
<Button onClick={() => {if (!finalized) {assign();} }}>Assign to you</Button>
</div>
) : null }

{ (detailsData.pageContent == "your-deliveries") ? (
<div>
{ detailsData.delivery.status === "assigned" ?
<div className="mb-4 pb-1 grid grid-cols-1 md:grid-cols-1 gap-4">
<Button onClick={() => {if (!finalized) {pickup();} }}>Pickup</Button>
</div>
: null}
{ detailsData.delivery.status === "inprogress" ?
<div className="mb-4 pb-1 grid grid-cols-2 md:grid-cols-2 gap-4">
<Button onClick={() => {if (!finalized) {complete();} }}>Complete</Button>
<Button onClick={() => {if (!finalized) {setFailed(true);} }}>Cannot deliver</Button>
</div>
: null}
</div>
) : null }

{ failed ? (
<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 failing delivery:
</Label>
<TextInput
id="cannot-deliver-reason"
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={() => fail()}>Confirm failing delivery</Button>
</div>
) : null }

{ finalized ? (
<div className="mb-4 pb-1 grid grid-cols-1 md:grid-cols-1 gap-4">
Expand Down
18 changes: 9 additions & 9 deletions SwiftParcel.Web/frontend/src/utils/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -600,7 +600,7 @@ export const assignCourierToDelivery = async (

console.log("JSON being sent:", JSON.parse(JSON.stringify(payload)));

const response = await api.post(`/deliveries/${deliveryId}/pick-up`, JSON.parse(JSON.stringify(payload)), {
const response = await api.post(`/deliveries/${deliveryId}/courier`, JSON.parse(JSON.stringify(payload)), {
headers: {
//'Authorization': `${userInfo.accessToken}`,
'Content-Type': 'application/json'
Expand All @@ -613,9 +613,9 @@ export const assignCourierToDelivery = async (
if (axios.isAxiosError(orderError) && orderError.response) {
console.error('Error status:', orderError.response.status);
console.error('Error data:', orderError.response.data);
console.error('Error during picking up delivery:', orderError.message);
console.error('Error during assigning delivery to courier:', orderError.message);
} else {
console.error('Error during picking up delivery:', orderError);
console.error('Error during assigning delivery to courier:', orderError);
}
throw orderError;
}
Expand Down Expand Up @@ -670,7 +670,7 @@ export const completeDelivery = async (

console.log("JSON being sent:", JSON.parse(JSON.stringify(payload)));

const response = await api.post(`/deliveries/${deliveryId}/pick-up`, JSON.parse(JSON.stringify(payload)), {
const response = await api.post(`/deliveries/${deliveryId}/complete`, JSON.parse(JSON.stringify(payload)), {
headers: {
//'Authorization': `${userInfo.accessToken}`,
'Content-Type': 'application/json'
Expand All @@ -683,9 +683,9 @@ export const completeDelivery = async (
if (axios.isAxiosError(orderError) && orderError.response) {
console.error('Error status:', orderError.response.status);
console.error('Error data:', orderError.response.data);
console.error('Error during picking up delivery:', orderError.message);
console.error('Error during completing delivery:', orderError.message);
} else {
console.error('Error during picking up delivery:', orderError);
console.error('Error during completing delivery:', orderError);
}
throw orderError;
}
Expand All @@ -708,7 +708,7 @@ export const failDelivery = async (

console.log("JSON being sent:", JSON.parse(JSON.stringify(payload)));

const response = await api.post(`/deliveries/${deliveryId}/pick-up`, JSON.parse(JSON.stringify(payload)), {
const response = await api.post(`/deliveries/${deliveryId}/fail`, JSON.parse(JSON.stringify(payload)), {
headers: {
//'Authorization': `${userInfo.accessToken}`,
'Content-Type': 'application/json'
Expand All @@ -721,9 +721,9 @@ export const failDelivery = async (
if (axios.isAxiosError(orderError) && orderError.response) {
console.error('Error status:', orderError.response.status);
console.error('Error data:', orderError.response.data);
console.error('Error during picking up delivery:', orderError.message);
console.error('Error during failing delivery:', orderError.message);
} else {
console.error('Error during picking up delivery:', orderError);
console.error('Error during failing delivery:', orderError);
}
throw orderError;
}
Expand Down

0 comments on commit 8a947da

Please sign in to comment.