Skip to content

Commit

Permalink
GH-29 recreation of address book page, address card and address form
Browse files Browse the repository at this point in the history
  • Loading branch information
dydome committed Apr 20, 2020
1 parent 72a728a commit 9df4945
Show file tree
Hide file tree
Showing 15 changed files with 490 additions and 39 deletions.
17 changes: 17 additions & 0 deletions src/app/features/dvnt-account/config/account.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
} from '@spartacus/core';
import { LayoutConfig } from '@spartacus/storefront';

import { DvntAddressBookComponent } from '../dvnt-address-book/dvnt-address-book.component';
import { DvntConsentManagementComponent } from '../dvnt-consent-management/dvnt-consent-management.component';
import { DvntForgotPasswordComponent } from '../dvnt-forgot-password/dvnt-forgot-password.component';
import { DvntLoginCustomerComponent } from '../dvnt-login-customer/dvnt-login-customer.component';
Expand Down Expand Up @@ -36,6 +37,9 @@ export const accountCmsConfig = <CmsConfig>{
ConsentManagementComponent: {
component: DvntConsentManagementComponent,
},
AccountAddressBookComponent: {
component: DvntAddressBookComponent,
},
},
};

Expand Down Expand Up @@ -67,6 +71,11 @@ export const staticComponents: {
flexType: 'DvntConsentManagementComponent',
uid: 'DvntConsentManagementComponent',
},
DvntAddressBookComponent: {
typeCode: 'DvntAddressBookComponent',
flexType: 'DvntAddressBookComponent',
uid: 'DvntAddressBookComponent',
},
};

export function cmsStructureConfig(): CmsStructureConfig {
Expand All @@ -87,6 +96,14 @@ const accountTranslationOverwrites = {
'I want to create an account and I am confirming that I have read and agreed with the',
},
},
address: {
addressBook: {
header: {
manage: `Manage all the shipping addresses you want (work place, home address ...)`,
manually: `This way you won't have to enter the shipping address manually with each order.`,
},
},
},
},
};

Expand Down
3 changes: 3 additions & 0 deletions src/app/features/dvnt-account/dvnt-account.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
accountTranslationsConfig,
cmsStructureConfig,
} from './config/account.config';
import { DvntAddressBookComponent } from './dvnt-address-book/dvnt-address-book.component';
import { DvntConsentFormComponent } from './dvnt-consent-management/dvnt-consent-form/dvnt-consent-form.component';
import { DvntConsentManagementComponent } from './dvnt-consent-management/dvnt-consent-management.component';
import { DvntForgotPasswordComponent } from './dvnt-forgot-password/dvnt-forgot-password.component';
Expand All @@ -23,6 +24,7 @@ import { DvntSharedModule } from '../dvnt-shared/dvnt-shared.module';

@NgModule({
declarations: [
DvntAddressBookComponent,
DvntConsentFormComponent,
DvntConsentManagementComponent,
DvntForgotPasswordComponent,
Expand All @@ -47,6 +49,7 @@ import { DvntSharedModule } from '../dvnt-shared/dvnt-shared.module';
ConfigModule.withConfig(accountLayoutConfig),
],
entryComponents: [
DvntAddressBookComponent,
DvntConsentManagementComponent,
DvntForgotPasswordComponent,
DvntLoginCustomerComponent,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<div>
<p
*ngIf="!(showAddAddressForm || showEditAddressForm)"
class="address-book-header-label"
>
{{ 'addressBook.header.manage' | cxTranslate }}
{{ 'addressBook.header.manually' | cxTranslate }}
</p>

<ng-container
*ngIf="
(addresses$ | async).length &&
!(showAddAddressForm || showEditAddressForm)
"
>
<div *ngIf="!(addressesStateLoading$ | async); else loading">
<div *ngFor="let address of addresses$ | async">
<app-dvnt-address-card
(editEvent)="editAddressButtonHandle(address)"
[address]="address"
></app-dvnt-address-card>
</div>
</div>

<div class="add-new-address">
<button (click)="addAddressButtonHandle()" class="btn btn-primary">
{{ 'addressBook.addNewAddress' | cxTranslate }}
</button>
</div>
</ng-container>

<ng-container *ngIf="!(addresses$ | async).length || showAddAddressForm">
<p class="address-book-header-label">
{{ 'addressBook.addNewShippingAddress' | cxTranslate }}
</p>
<app-dvnt-address-form
(backToAddress)="addAddressCancel()"
(submitAddress)="addAddressSubmit($event)"
[setAsDefaultField]="!((addresses$ | async).length === 0)"
[showCancelBtn]="!((addresses$ | async).length === 0)"
actionBtnLabel="{{ 'addressBook.addAddress' | cxTranslate }}"
cancelBtnLabel="{{ 'addressBook.backToAddressList' | cxTranslate }}"
showTitleCode="true"
></app-dvnt-address-form>
</ng-container>

<ng-container *ngIf="showEditAddressForm">
<p class="address-book-header-label">
{{ 'addressBook.editShippingAddress' | cxTranslate }}
</p>
<app-dvnt-address-form
(backToAddress)="editAddressCancel()"
(submitAddress)="editAddressSubmit($event)"
[addressData]="currentAddress"
actionBtnLabel="{{ 'addressBook.updateAddress' | cxTranslate }}"
cancelBtnLabel="{{ 'addressBook.backToAddressList' | cxTranslate }}"
showTitleCode="true"
></app-dvnt-address-form>
</ng-container>
</div>

<ng-template #loading>
<cx-spinner></cx-spinner>
</ng-template>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.address-book-header-label {
border-bottom: 1px solid var(--ssf-light-primary);
margin: 0 0 40px;
padding: 0 0 20px;
}

.add-new-address {
margin-top: 40px;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { Component } from '@angular/core';
import { AddressBookComponent } from '@spartacus/storefront';

@Component({
selector: 'app-dvnt-address-book',
templateUrl: './dvnt-address-book.component.html',
styleUrls: ['./dvnt-address-book.component.scss'],
})
export class DvntAddressBookComponent extends AddressBookComponent {}
47 changes: 23 additions & 24 deletions src/app/features/dvnt-checkout/dvnt-checkout.module.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { DvntShippingAddressComponent } from './dvnt-shipping/dvnt-shipping-address.component';
import { ConfigModule, FeaturesConfigModule } from '@spartacus/core';
import { DvntCheckoutProgressComponent } from './dvnt-checkout-progress/dvnt-checkout-progress.component';
import {
checkoutCmsConfig,
checkoutLayoutConfig,
checkoutTranslationsConfig,
staticCmsConfigFactory,
} from './config/checkout.config';
import { SharedModule } from '../../shared/shared.module';
import {
AddressFormModule,
CardModule,
CartCouponModule,
CartSharedModule,
PAGE_LAYOUT_HANDLER,
PromotionsModule,
SpinnerModule,
} from '@spartacus/storefront';
import { DvntSharedModule } from '../dvnt-shared/dvnt-shared.module';

import {
checkoutCmsConfig,
checkoutLayoutConfig,
checkoutTranslationsConfig,
staticCmsConfigFactory,
} from './config/checkout.config';
import { CheckoutReviewPageLayoutHandler } from './CheckoutReviewPageLayoutHandler';
import { DvntCheckoutOrderSummaryComponent } from './dvnt-order-summary/dvnt-checkout-order-summary.component';
import { DvntCheckoutProgressComponent } from './dvnt-checkout-progress/dvnt-checkout-progress.component';
import { DvntDeliveryModeComponent } from './dvnt-delivery-mode/dvnt-delivery-mode.component';
import { DvntPaymentMethodModule } from './dvnt-payment-method/dvnt-payment-method.module';
import { DvntOrderReviewModule } from './dvnt-order-review/dvnt-order-review.module';
import { DvntOrderConfirmationModule } from './dvnt-order-confirmation/dvnt-order-confirmation.module';
import { CheckoutReviewPageLayoutHandler } from './CheckoutReviewPageLayoutHandler';
import { DvntOrderReviewModule } from './dvnt-order-review/dvnt-order-review.module';
import { DvntPaymentMethodModule } from './dvnt-payment-method/dvnt-payment-method.module';
import { DvntSharedModule } from '../dvnt-shared/dvnt-shared.module';
import { DvntShippingAddressComponent } from './dvnt-shipping/dvnt-shipping-address.component';
import { SharedModule } from '../../shared/shared.module';

@NgModule({
declarations: [
Expand All @@ -37,21 +37,20 @@ import { CheckoutReviewPageLayoutHandler } from './CheckoutReviewPageLayoutHandl
imports: [
CommonModule,
SharedModule,
ConfigModule.withConfig(checkoutTranslationsConfig),
ConfigModule.withConfig(checkoutCmsConfig),
ConfigModule.withConfig(checkoutLayoutConfig),
ConfigModule.withConfigFactory(staticCmsConfigFactory),
CardModule,
AddressFormModule,
SpinnerModule,
DvntSharedModule,
CartCouponModule,
FeaturesConfigModule,
CartSharedModule,
FeaturesConfigModule,
SpinnerModule,
PromotionsModule,
DvntPaymentMethodModule,
DvntOrderReviewModule,
DvntOrderConfirmationModule,
DvntOrderReviewModule,
DvntPaymentMethodModule,
DvntSharedModule,
ConfigModule.withConfig(checkoutTranslationsConfig),
ConfigModule.withConfig(checkoutCmsConfig),
ConfigModule.withConfig(checkoutLayoutConfig),
ConfigModule.withConfigFactory(staticCmsConfigFactory),
],
providers: [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ <h2 class="checkout-step-header">
>
<div (click)="selectAddress(card.address)">
<app-dvnt-card
color="secondary"
[fitToContainer]="true"
[content]="card.card"
(sendCard)="selectAddress(card.address)"
[content]="card.card"
[fitToContainer]="true"
color="secondary"
></app-dvnt-card>
</div>
</div>
Expand All @@ -42,12 +42,12 @@ <h2 class="checkout-step-header">
{{ 'checkout.backToCart' | cxTranslate }}
</button>
<button
class="btn btn-primary"
(click)="next()"
[disabled]="
(!selectedAddress || !selectedAddress.id) &&
!(selectedAddress$ | async)?.shippingAddress
"
(click)="next()"
class="btn btn-primary"
>
{{ 'common.continue' | cxTranslate }}
</button>
Expand All @@ -56,21 +56,21 @@ <h2 class="checkout-step-header">

<ng-template #newAddressForm>
<ng-container *ngIf="cards.length; else initialAddressForm">
<cx-address-form
[showTitleCode]="true"
<app-dvnt-address-form
(backToAddress)="hideNewAddressForm(false)"
(submitAddress)="addAddress($event)"
></cx-address-form>
[showTitleCode]="true"
></app-dvnt-address-form>
</ng-container>
<ng-template #initialAddressForm>
<cx-address-form
[showTitleCode]="true"
[setAsDefaultField]="!isGuestCheckout"
[addressData]="setAddress"
cancelBtnLabel="{{ 'checkout.backToCart' | cxTranslate }}"
<app-dvnt-address-form
(backToAddress)="hideNewAddressForm(true)"
(submitAddress)="addAddress($event)"
></cx-address-form>
[addressData]="setAddress"
[setAsDefaultField]="!isGuestCheckout"
[showTitleCode]="true"
cancelBtnLabel="{{ 'checkout.backToCart' | cxTranslate }}"
></app-dvnt-address-form>
</ng-template>
</ng-template>
</ng-container>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<div class="address-card-container">
<div class="left-container">
<p class="address-card-label-name">
{{ address?.firstName }} {{ address?.lastName }}
</p>
<p class="address-card-label">
{{ address?.line1 }}
</p>
<p class="address-card-label">
{{ address?.line2 }}
</p>
<p class="address-card-label">
{{ address?.town }},
<span *ngIf="!address?.region?.isocode">{{
address?.country?.isocode
}}</span
><span>{{ address?.region?.isocode }}</span>
</p>
<p class="address-card-label">
{{ address?.postalCode }}
</p>
<p class="address-card-label-phone">
{{ address?.phone }}
</p>
</div>

<div [ngClass]="{ 'align-center': editMode }" class="right-container">
<ng-container *ngIf="editMode">
<span>
{{ 'addressBook.areYouSureToDeleteAddress' | cxTranslate }}
</span>

<div class="address-card-action-buttons">
<button (click)="deleteAddress(address.id)" class="btn btn-primary">
{{ 'common.delete' | cxTranslate }}
</button>
<button (click)="cancelEdit()" class="btn btn-secondary">
{{ 'common.cancel' | cxTranslate }}
</button>
</div>
</ng-container>
<ng-container *ngIf="!editMode">
<button
*ngIf="!address?.defaultAddress"
(click)="setAddressAsDefault(address.id)"
class="btn btn-outline address-card-set-default-button"
>
{{ 'addressCard.setAsDefault' | cxTranslate }}
</button>
<div class="address-card-action-buttons">
<button (click)="openEditFormEvent(address.id)" class="btn btn-primary">
{{ 'common.edit' | cxTranslate }}
</button>
<button (click)="setEditMode(address.id)" class="btn btn-clear">
{{ 'common.delete' | cxTranslate }}
</button>
</div>
</ng-container>
</div>
</div>
Loading

0 comments on commit 9df4945

Please sign in to comment.