Skip to content

Commit

Permalink
feat: Use tabs instead of radio group for pickup options
Browse files Browse the repository at this point in the history
  • Loading branch information
sdrozdsap committed Oct 16, 2024
1 parent 4f60be3 commit 32d2719
Show file tree
Hide file tree
Showing 17 changed files with 601 additions and 240 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<ng-template
[cxOutlet]="CartOutlets.ADD_TO_CART_PICKUP_OPTION"
[(cxComponentRef)]="pickupOptionCompRef"
(cxComponentRefChange)="onPickupOptionsCompLoaded()"
></ng-template>
</ng-container>

Expand All @@ -35,7 +36,7 @@
: 'btn btn-primary btn-block'
"
type="submit"
[disabled]="quantity <= 0 || quantity > maxQuantity"
[disabled]="disabled || quantity <= 0 || quantity > maxQuantity"
>
<span
*ngIf="
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import {
Product,
isNotNullable,
} from '@spartacus/core';
import { AugmentedPointOfService } from '@spartacus/pickup-in-store/root';
import {
CmsComponentData,
CurrentProductService,
Expand Down Expand Up @@ -63,7 +64,7 @@ export class AddToCartComponent implements OnInit, OnDestroy {
@ViewChild('addToCartDialogTriggerEl') addToCartDialogTriggerEl: ElementRef;

maxQuantity: number;

disabled: boolean = false;
hasStock: boolean = false;
inventoryThreshold: boolean = false;

Expand All @@ -72,7 +73,7 @@ export class AddToCartComponent implements OnInit, OnDestroy {

quantity = 1;

subscription: Subscription;
subscription = new Subscription();

addToCartForm = new UntypedFormGroup({
quantity: new UntypedFormControl(1, { updateOn: 'blur' }),
Expand Down Expand Up @@ -125,17 +126,18 @@ export class AddToCartComponent implements OnInit, OnDestroy {
this.hasStock = true;
this.cd.markForCheck();
} else {
this.subscription = (
this.productListItemContext
this.subscription.add(
(this.productListItemContext
? this.productListItemContext.product$
: this.currentProductService.getProduct()
)
.pipe(filter(isNotNullable))
.subscribe((product) => {
this.productCode = product.code ?? '';
this.setStockInfo(product);
this.cd.markForCheck();
});
)
.pipe(filter(isNotNullable))
.subscribe((product) => {
this.productCode = product.code ?? '';
this.setStockInfo(product);
this.cd.markForCheck();
})
);
}
}

Expand Down Expand Up @@ -239,9 +241,21 @@ export class AddToCartComponent implements OnInit, OnDestroy {
return newEvent;
}

ngOnDestroy() {
if (this.subscription) {
this.subscription.unsubscribe();
onPickupOptionsCompLoaded() {
if (this.featureConfigService.isEnabled('a11yPickupOptionsTabs')) {
this.subscription.add(
this.pickupOptionCompRef.instance.intendedPickupChange.subscribe(
(intendedPickupLocation: AugmentedPointOfService | undefined) => {
this.disabled =
intendedPickupLocation?.pickupOption === 'pickup' &&
!intendedPickupLocation.displayName;
}
)
);
}
}

ngOnDestroy() {
this.subscription.unsubscribe();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
"changeStore": "Change Store",
"delivery": "Ship It (Free Return)",
"pickup": "Free Pickup In Store",
"selectStore": "Select Store"
"shipIt": "Ship It",
"selectStore": "Select Store",
"freeReturn": "Free Return",
"storeIsNotSelected": "Store for pickup is not selected."
},
"setPreferredStore": {
"makeThisMyStore": "Make This My Store",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,10 @@ export class CartPickupOptionsContainerComponent implements OnInit, OnDestroy {
);
});

if (!this.displayNameIsSet) {
if (
!this.featureConfigService.isEnabled('a11yPickupOptionsTabs') &&
!this.displayNameIsSet
) {
this.openDialog(event.triggerElement);
}
} else if (typeof event === 'string') {
Expand Down Expand Up @@ -344,7 +347,10 @@ export class CartPickupOptionsContainerComponent implements OnInit, OnDestroy {
);
});

if (!this.displayNameIsSet) {
if (
!this.featureConfigService.isEnabled('a11yPickupOptionsTabs') &&
!this.displayNameIsSet
) {
this.openDialog();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import {
Component,
ElementRef,
inject,
EventEmitter,
OnDestroy,
OnInit,
Output,
ViewChild,
ViewContainerRef,
} from '@angular/core';
Expand Down Expand Up @@ -63,6 +65,9 @@ export class PdpPickupOptionsContainerComponent implements OnInit, OnDestroy {
* The 'triggerElement' is passed through 'PickupOptionChange' event instead.
*/
@ViewChild('open') element: ElementRef;
@Output() intendedPickupChange = new EventEmitter<
AugmentedPointOfService | undefined
>();
subscription = new Subscription();

availableForPickup = false;
Expand Down Expand Up @@ -147,6 +152,10 @@ export class PdpPickupOptionsContainerComponent implements OnInit, OnDestroy {
)
);

this.subscription.add(
this.intendedPickupLocation$.subscribe(this.intendedPickupChange)
);

this.subscription.add(
combineLatest([
productCode$,
Expand Down Expand Up @@ -202,6 +211,19 @@ export class PdpPickupOptionsContainerComponent implements OnInit, OnDestroy {
onPickupOptionChange(
event: { option: PickupOption; triggerElement: ElementRef } | PickupOption
): void {
const handleChange = (
option: PickupOption,
triggerElement?: ElementRef
) => {
if (!this.featureConfigService.isEnabled('a11yPickupOptionsTabs')) {
if (option === 'delivery') {
return;
}
if (!this.displayNameIsSet) {
this.openDialog(triggerElement);
}
}
};
if (
this.featureConfigService.isEnabled('a11yDialogTriggerRefocus') &&
typeof event === 'object'
Expand All @@ -211,23 +233,13 @@ export class PdpPickupOptionsContainerComponent implements OnInit, OnDestroy {
this.productCode,
option
);
if (option === 'delivery') {
return;
}
if (!this.displayNameIsSet) {
this.openDialog(triggerElement);
}
handleChange(option, triggerElement);
} else if (typeof event === 'string') {
this.intendedPickupLocationService.setPickupOption(
this.productCode,
event
);
if (event === 'delivery') {
return;
}
if (!this.displayNameIsSet) {
this.openDialog();
}
handleChange(event);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -164,25 +164,27 @@ export class PickupOptionDialogComponent implements OnInit, OnDestroy {
close(reason: string): void {
this.launchDialogService.closeDialog(reason);
if (reason === this.CLOSE_WITHOUT_SELECTION) {
this.intendedPickupLocationService
.getIntendedLocation(this.productCode)
.pipe(
filter(
(store: AugmentedPointOfService | undefined) =>
typeof store !== 'undefined'
),
map((store) => store as AugmentedPointOfService),
filter((store) => !store.name),
take(1),
tap(() =>
this.intendedPickupLocationService.setPickupOption(
this.productCode,
'delivery'
if (!this.featureConfigService.isEnabled('a11yPickupOptionsTabs')) {
this.intendedPickupLocationService
.getIntendedLocation(this.productCode)
.pipe(
filter(
(store: AugmentedPointOfService | undefined) =>
typeof store !== 'undefined'
),
map((store) => store as AugmentedPointOfService),
filter((store) => !store.name),
take(1),
tap(() =>
this.intendedPickupLocationService.setPickupOption(
this.productCode,
'delivery'
)
)
)
)
.subscribe();
this.pickupOptionFacade.setPickupOption(this.entryNumber, 'delivery');
.subscribe();
this.pickupOptionFacade.setPickupOption(this.entryNumber, 'delivery');
}
return;
}
this.subscription.add(
Expand Down
Loading

0 comments on commit 32d2719

Please sign in to comment.