Skip to content

Commit

Permalink
Remove cart ID fields in double compose delivery form (#967)
Browse files Browse the repository at this point in the history
* Remove cart ID fields in double compose delivery form

Signed-off-by: Aaron Chong <[email protected]>

* Lint

Signed-off-by: Aaron Chong <[email protected]>

* Fix test

Signed-off-by: Aaron Chong <[email protected]>

---------

Signed-off-by: Aaron Chong <[email protected]>
  • Loading branch information
aaronchongth authored Jul 11, 2024
1 parent 090dd9b commit bf7e10b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 112 deletions.
1 change: 0 additions & 1 deletion packages/react-components/lib/tasks/create-task.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,6 @@ export function CreateTaskForm({
<DoubleComposeDeliveryTaskForm
taskDesc={taskRequest.description as DoubleComposeDeliveryTaskDescription}
pickupPoints={pickupPoints}
cartIds={cartIds}
dropoffPoints={dropoffPoints}
onChange={(desc: DoubleComposeDeliveryTaskDescription) => {
desc.category = taskRequest.description.category;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ describe('Custom deliveries', () => {
"unix_millis_action_duration_estimate": 60000,
"category": "delivery_pickup",
"description": {
"cart_id": "test_first_cart_id",
"cart_id": "",
"pickup_lot": "test_first_pickup_lot"
}
}
Expand Down Expand Up @@ -580,7 +580,7 @@ describe('Custom deliveries', () => {
"unix_millis_action_duration_estimate": 60000,
"category": "delivery_pickup",
"description": {
"cart_id": "test_second_cart_id",
"cart_id": "",
"pickup_lot": "test_second_pickup_lot"
}
}
Expand Down Expand Up @@ -662,12 +662,11 @@ describe('Custom deliveries', () => {

const description: DoubleComposeDeliveryTaskDescription =
makeDefaultDoubleComposeDeliveryTaskDescription();
let firstPickupPhase = cartPickupPhaseInsertPickup(
const firstPickupPhase = cartPickupPhaseInsertPickup(
description.phases[0],
'test_first_pickup_place',
'test_first_pickup_lot',
);
firstPickupPhase = cartPickupPhaseInsertCartId(firstPickupPhase, 'test_first_cart_id');
let firstDeliveryPhase = deliveryPhaseInsertDropoff(
description.phases[1],
'test_first_dropoff_place',
Expand All @@ -677,12 +676,11 @@ describe('Custom deliveries', () => {
'test_waypoint_2',
'test_waypoint_3',
]);
let secondPickupPhase = cartPickupPhaseInsertPickup(
const secondPickupPhase = cartPickupPhaseInsertPickup(
description.phases[3],
'test_second_pickup_place',
'test_second_pickup_lot',
);
secondPickupPhase = cartPickupPhaseInsertCartId(secondPickupPhase, 'test_second_cart_id');
let secondDeliveryPhase = deliveryPhaseInsertDropoff(
description.phases[4],
'test_second_dropoff_place',
Expand Down
112 changes: 7 additions & 105 deletions packages/react-components/lib/tasks/types/delivery-custom.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -197,14 +197,12 @@ export function makeDoubleComposeDeliveryTaskBookingLabel(

const pickups = `${firstPickupDescription.pickup_lot}(1), ${secondPickupDescription.pickup_lot}(2)`;
const dropoffs = `${task_description.phases[1].activity.description.activities[0].description}(1), ${task_description.phases[4].activity.description.activities[0].description}(2)`;
const cartIds = `${firstPickupDescription.pickup_lot}(1), ${secondPickupDescription.cart_id}(2)`;

return {
description: {
task_definition_id: task_description.category,
pickup: pickups,
destination: dropoffs,
cart_id: cartIds,
},
};
}
Expand Down Expand Up @@ -243,20 +241,14 @@ export function makeDoubleComposeDeliveryTaskShortDescription(
): string {
try {
const firstGoToPickup: GoToPlaceActivity = desc.phases[0].activity.description.activities[0];
const firstPickup: LotPickupActivity = desc.phases[0].activity.description.activities[1];
const firstCartId = firstPickup.description.description.cart_id;
const firstGoToDropoff: GoToPlaceActivity = desc.phases[1].activity.description.activities[0];

const secondGoToPickup: GoToPlaceActivity = desc.phases[3].activity.description.activities[0];
const secondPickup: LotPickupActivity = desc.phases[3].activity.description.activities[1];
const secondCartId = secondPickup.description.description.cart_id;
const secondGoToDropoff: GoToPlaceActivity = desc.phases[4].activity.description.activities[0];

return `[${
taskDisplayName ?? DeliveryPickupTaskDefinition.taskDisplayName
}] payload [${firstCartId}] from [${firstGoToPickup.description}] to [${
firstGoToDropoff.description
}], then payload [${secondCartId}] from [${secondGoToPickup.description}] to [${
return `[${taskDisplayName ?? DeliveryPickupTaskDefinition.taskDisplayName}] from [${
firstGoToPickup.description
}] to [${firstGoToDropoff.description}], then from [${secondGoToPickup.description}] to [${
secondGoToDropoff.description
}]`;
} catch (e) {
Expand Down Expand Up @@ -348,14 +340,12 @@ const isDoubleComposeDeliveryTaskDescriptionValid = (
firstGoToPickup.description.length > 0 &&
Object.keys(pickupPoints).includes(firstGoToPickup.description) &&
pickupPoints[firstGoToPickup.description] === firstPickup.description.description.pickup_lot &&
firstPickup.description.description.cart_id.length > 0 &&
firstGoToDropoff.description.length > 0 &&
Object.keys(dropoffPoints).includes(firstGoToDropoff.description) &&
secondGoToPickup.description.length > 0 &&
Object.keys(pickupPoints).includes(secondGoToPickup.description) &&
pickupPoints[secondGoToPickup.description] ===
secondPickup.description.description.pickup_lot &&
secondPickup.description.description.cart_id.length > 0 &&
secondGoToDropoff.description.length > 0 &&
Object.keys(dropoffPoints).includes(secondGoToDropoff.description)
);
Expand Down Expand Up @@ -607,7 +597,6 @@ export function DeliveryPickupTaskForm({
interface DoubleComposeDeliveryTaskFormProps {
taskDesc: DoubleComposeDeliveryTaskDescription;
pickupPoints: Record<string, string>;
cartIds: string[];
dropoffPoints: Record<string, string>;
onChange(taskDesc: DoubleComposeDeliveryTaskDescription): void;
onValidate(valid: boolean): void;
Expand All @@ -616,7 +605,6 @@ interface DoubleComposeDeliveryTaskFormProps {
export function DoubleComposeDeliveryTaskForm({
taskDesc,
pickupPoints = {},
cartIds = [],
dropoffPoints = {},
onChange,
onValidate,
Expand All @@ -630,7 +618,7 @@ export function DoubleComposeDeliveryTaskForm({

return (
<Grid container spacing={theme.spacing(2)} justifyContent="left" alignItems="center">
<Grid item xs={5}>
<Grid item xs={6}>
<Autocomplete
id="first-pickup-location"
freeSolo
Expand Down Expand Up @@ -679,7 +667,7 @@ export function DoubleComposeDeliveryTaskForm({
)}
/>
</Grid>
<Grid item xs={5}>
<Grid item xs={6}>
<Autocomplete
id="first-dropoff-location"
freeSolo
Expand Down Expand Up @@ -720,50 +708,7 @@ export function DoubleComposeDeliveryTaskForm({
)}
/>
</Grid>
<Grid item xs={2}>
<Autocomplete
id="first-cart-id"
freeSolo
fullWidth
options={cartIds}
value={
taskDesc.phases[0].activity.description.activities[1].description.description.cart_id
}
getOptionLabel={(option) => option}
onInputChange={(_ev, newValue) => {
const newTaskDesc = { ...taskDesc };
newTaskDesc.phases[0] = cartPickupPhaseInsertCartId(newTaskDesc.phases[0], newValue);
onInputChange(newTaskDesc);
}}
onBlur={(ev) => {
const newTaskDesc = { ...taskDesc };
newTaskDesc.phases[0] = cartPickupPhaseInsertCartId(
newTaskDesc.phases[0],
(ev.target as HTMLInputElement).value,
);
onInputChange(newTaskDesc);
}}
sx={{
'& .MuiOutlinedInput-root': {
height: isScreenHeightLessThan800 ? '3rem' : '3.5rem',
fontSize: isScreenHeightLessThan800 ? 14 : 20,
},
}}
renderInput={(params) => (
<TextField
{...params}
label="Cart ID (1)"
required
InputLabelProps={{ style: { fontSize: isScreenHeightLessThan800 ? 14 : 20 } }}
error={
taskDesc.phases[0].activity.description.activities[1].description.description
.cart_id.length === 0
}
/>
)}
/>
</Grid>
<Grid item xs={5}>
<Grid item xs={6}>
<Autocomplete
id="second-pickup-location"
freeSolo
Expand Down Expand Up @@ -812,7 +757,7 @@ export function DoubleComposeDeliveryTaskForm({
)}
/>
</Grid>
<Grid item xs={5}>
<Grid item xs={6}>
<Autocomplete
id="second-dropoff-location"
freeSolo
Expand Down Expand Up @@ -853,49 +798,6 @@ export function DoubleComposeDeliveryTaskForm({
)}
/>
</Grid>
<Grid item xs={2}>
<Autocomplete
id="second-cart-id"
freeSolo
fullWidth
options={cartIds}
value={
taskDesc.phases[3].activity.description.activities[1].description.description.cart_id
}
getOptionLabel={(option) => option}
onInputChange={(_ev, newValue) => {
const newTaskDesc = { ...taskDesc };
newTaskDesc.phases[3] = cartPickupPhaseInsertCartId(newTaskDesc.phases[3], newValue);
onInputChange(newTaskDesc);
}}
onBlur={(ev) => {
const newTaskDesc = { ...taskDesc };
newTaskDesc.phases[3] = cartPickupPhaseInsertCartId(
newTaskDesc.phases[3],
(ev.target as HTMLInputElement).value,
);
onInputChange(newTaskDesc);
}}
sx={{
'& .MuiOutlinedInput-root': {
height: isScreenHeightLessThan800 ? '3rem' : '3.5rem',
fontSize: isScreenHeightLessThan800 ? 14 : 20,
},
}}
renderInput={(params) => (
<TextField
{...params}
label="Cart ID (2)"
required
InputLabelProps={{ style: { fontSize: isScreenHeightLessThan800 ? 14 : 20 } }}
error={
taskDesc.phases[3].activity.description.activities[1].description.description
.cart_id.length === 0
}
/>
)}
/>
</Grid>
</Grid>
);
}
Expand Down

0 comments on commit bf7e10b

Please sign in to comment.