-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
227 additions
and
21 deletions.
There are no files selected for viewing
53 changes: 53 additions & 0 deletions
53
src/app/admin/components/ride-price/ride-price.component.html
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
@if (priceList(); as priceList) { | ||
<div class="wrapper"> | ||
<div class="top"> | ||
<span class="title">Price</span> | ||
@if (isEdit()) { | ||
<p-button | ||
icon="pi pi-save" | ||
[rounded]="true" | ||
severity="success" | ||
[disabled]="priceForm.invalid" | ||
(click)="this.isEdit.set(false)" | ||
(click)="submit()" | ||
></p-button> | ||
<p-button | ||
icon="pi pi-arrow-left" | ||
[rounded]="true" | ||
severity="primary" | ||
(click)="this.isEdit.set(false)" | ||
></p-button> | ||
} @else { | ||
<p-button | ||
[disabled]="!isPriceEdited()" | ||
[icon]="!isPriceEdited() ? 'pi pi-spin pi-cog' : 'pi pi-pencil'" | ||
[rounded]="true" | ||
severity="primary" | ||
(click)="this.isEdit.set(true)" | ||
></p-button> | ||
} | ||
</div> | ||
<div class="bottom"> | ||
<form [formGroup]="priceForm"> | ||
<div class="controls" formArrayName="priceList"> | ||
@for (priceControl of priceForm.controls.priceList.controls; track priceControl; let i = $index) { | ||
<div class="control" [formGroupName]="i"> | ||
{{ priceList[i].type }} | ||
@if (isEdit()) { | ||
<p-inputNumber | ||
formControlName="price" | ||
[showButtons]="false" | ||
mode="currency" | ||
currency="USD" | ||
locale="en-US" | ||
></p-inputNumber> | ||
} @else { | ||
<span> - {{ priceList[i].price | currency }}</span> | ||
} | ||
</div> | ||
} | ||
</div> | ||
</form> | ||
</div> | ||
</div> | ||
} |
22 changes: 22 additions & 0 deletions
22
src/app/admin/components/ride-price/ride-price.component.scss
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
.wrapper { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1rem; | ||
} | ||
|
||
.title { | ||
display: block; | ||
margin-right: auto; | ||
} | ||
|
||
.top { | ||
display: flex; | ||
gap: 0.5rem; | ||
align-items: center; | ||
} | ||
|
||
.controls { | ||
display: flex; | ||
flex-direction: column; | ||
gap: 1rem; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/app/admin/components/ride-price/ride-price.component.spec.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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import { ComponentFixture, TestBed } from '@angular/core/testing'; | ||
|
||
import { RidePriceComponent } from './ride-price.component'; | ||
|
||
describe('RidePriceComponent', () => { | ||
let component: RidePriceComponent; | ||
let fixture: ComponentFixture<RidePriceComponent>; | ||
|
||
beforeEach(async () => { | ||
await TestBed.configureTestingModule({ | ||
imports: [RidePriceComponent], | ||
}).compileComponents(); | ||
|
||
fixture = TestBed.createComponent(RidePriceComponent); | ||
component = fixture.componentInstance; | ||
fixture.detectChanges(); | ||
}); | ||
|
||
it('should create', () => { | ||
expect(component).toBeTruthy(); | ||
}); | ||
}); |
61 changes: 61 additions & 0 deletions
61
src/app/admin/components/ride-price/ride-price.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 |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { CurrencyPipe } from '@angular/common'; | ||
import { ChangeDetectionStrategy, Component, EventEmitter, inject, input, OnInit, Output, signal } from '@angular/core'; | ||
import { FormBuilder, FormControl, FormGroup, ReactiveFormsModule, Validators } from '@angular/forms'; | ||
|
||
import { ButtonModule } from 'primeng/button'; | ||
import { InputNumberModule } from 'primeng/inputnumber'; | ||
import { RippleModule } from 'primeng/ripple'; | ||
|
||
import { RidePrice } from '../../models/ride.model'; | ||
|
||
@Component({ | ||
selector: 'app-ride-price', | ||
standalone: true, | ||
imports: [CurrencyPipe, ButtonModule, RippleModule, InputNumberModule, ReactiveFormsModule], | ||
providers: [CurrencyPipe], | ||
templateUrl: './ride-price.component.html', | ||
styleUrl: './ride-price.component.scss', | ||
changeDetection: ChangeDetectionStrategy.OnPush, | ||
}) | ||
export class RidePriceComponent implements OnInit { | ||
private fb = inject(FormBuilder); | ||
public priceList = input<RidePrice[] | null>(null); | ||
public isPriceEdited = input(false); | ||
public isEdit = signal(false); | ||
|
||
public priceForm = this.fb.group({ | ||
priceList: this.fb.array<FormGroup<{ price: FormControl<number> }>>([]), | ||
}); | ||
|
||
@Output() public priceChanged = new EventEmitter<RidePrice[]>(); | ||
|
||
public ngOnInit(): void { | ||
this.priceForm.controls.priceList.clear(); | ||
this.priceList()?.forEach((price) => { | ||
this.priceForm.controls.priceList.push( | ||
this.fb.nonNullable.group({ | ||
price: [price.price, [Validators.required.bind(this), Validators.min(0.01)]], | ||
}), | ||
); | ||
}); | ||
} | ||
|
||
public submit(): void { | ||
this.priceForm.markAsTouched(); | ||
this.priceForm.updateValueAndValidity(); | ||
|
||
if (!this.priceForm.valid) { | ||
return; | ||
} | ||
|
||
const priceList = this.priceList(); | ||
|
||
if (priceList) { | ||
const updatedPriceList = priceList.map((price, index) => ({ | ||
...price, | ||
price: this.priceForm.controls.priceList.controls[index].controls.price.value, | ||
})); | ||
this.priceChanged.emit(updatedPriceList); | ||
} | ||
} | ||
} |
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
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
Empty file.
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