-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(demo): add country form (#2617)
- Loading branch information
Showing
5 changed files
with
117 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 43 additions & 13 deletions
56
.../checkout/components/forms/address-form/components/address-form/address-form.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,59 @@ | ||
import { | ||
Component, | ||
Input, | ||
OnDestroy, | ||
OnInit, | ||
} from '@angular/core'; | ||
import { UntypedFormGroup } from '@angular/forms'; | ||
import { | ||
Observable, | ||
Subject, | ||
of, | ||
takeUntil, | ||
} from 'rxjs'; | ||
|
||
import { | ||
DaffCountry, | ||
DaffSubdivision, | ||
} from '@daffodil/geography'; | ||
import { | ||
DaffCountryList, | ||
DaffCountryLoad, | ||
DaffGeographyFacade, | ||
} from '@daffodil/geography/state'; | ||
|
||
interface RegionOption { | ||
label: string; | ||
value: any; | ||
}; | ||
import { AddressFormGroup } from '../../models/address-form.type'; | ||
|
||
@Component({ | ||
selector: 'demo-address-form', | ||
templateUrl: './address-form.component.html', | ||
styleUrls: ['./address-form.component.scss'], | ||
}) | ||
export class AddressFormComponent { | ||
export class AddressFormComponent implements OnInit, OnDestroy { | ||
private _destroyed$ = new Subject<boolean>(); | ||
|
||
@Input() formGroup: UntypedFormGroup; | ||
@Input() formGroup: AddressFormGroup; | ||
@Input() submitted: boolean; | ||
|
||
constructor() { } | ||
countrySelectValues$: Observable<DaffCountry[]>; | ||
stateSelectValues$: Observable<DaffSubdivision[]> = of([]); | ||
|
||
constructor( | ||
private geographyFacade: DaffGeographyFacade, | ||
) {} | ||
|
||
ngOnInit(): void { | ||
this.geographyFacade.dispatch(new DaffCountryList()); | ||
|
||
this.countrySelectValues$ = this.geographyFacade.countries$; | ||
this.formGroup.controls.country.valueChanges.pipe( | ||
takeUntil(this._destroyed$), | ||
).subscribe((country) => { | ||
this.geographyFacade.dispatch(new DaffCountryLoad(country)); | ||
this.stateSelectValues$ = this.geographyFacade.getCountrySubdivisions(country); | ||
}); | ||
} | ||
|
||
stateSelectValues: RegionOption[] = [ | ||
{ label:'State', value: '' }, | ||
{ label: 'Alabama', value: 'AL' }, | ||
{ label: 'Alaska', value: 'AK' }, | ||
]; | ||
ngOnDestroy(): void { | ||
this._destroyed$.next(true); | ||
} | ||
} |