feat(web) linked calculator and contact form
This commit is contained in:
@@ -7,6 +7,7 @@ import { AppAlertComponent } from '../../shared/components/app-alert/app-alert.c
|
|||||||
import { UploadFormComponent } from './components/upload-form/upload-form.component';
|
import { UploadFormComponent } from './components/upload-form/upload-form.component';
|
||||||
import { QuoteResultComponent } from './components/quote-result/quote-result.component';
|
import { QuoteResultComponent } from './components/quote-result/quote-result.component';
|
||||||
import { QuoteEstimatorService, QuoteRequest, QuoteResult } from './services/quote-estimator.service';
|
import { QuoteEstimatorService, QuoteRequest, QuoteResult } from './services/quote-estimator.service';
|
||||||
|
import { Router } from '@angular/router';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-calculator-page',
|
selector: 'app-calculator-page',
|
||||||
@@ -56,7 +57,7 @@ import { QuoteEstimatorService, QuoteRequest, QuoteResult } from './services/quo
|
|||||||
<small class="text-muted">Potrebbe richiedere qualche secondo.</small>
|
<small class="text-muted">Potrebbe richiedere qualche secondo.</small>
|
||||||
</app-card>
|
</app-card>
|
||||||
} @else if (result()) {
|
} @else if (result()) {
|
||||||
<app-quote-result [result]="result()!"></app-quote-result>
|
<app-quote-result [result]="result()!" (consult)="onConsult()"></app-quote-result>
|
||||||
} @else {
|
} @else {
|
||||||
<app-card>
|
<app-card>
|
||||||
<h3>{{ 'CALC.BENEFITS_TITLE' | translate }}</h3>
|
<h3>{{ 'CALC.BENEFITS_TITLE' | translate }}</h3>
|
||||||
@@ -146,9 +147,10 @@ export class CalculatorPageComponent {
|
|||||||
result = signal<QuoteResult | null>(null);
|
result = signal<QuoteResult | null>(null);
|
||||||
error = signal<boolean>(false);
|
error = signal<boolean>(false);
|
||||||
|
|
||||||
constructor(private estimator: QuoteEstimatorService) {}
|
constructor(private estimator: QuoteEstimatorService, private router: Router) {}
|
||||||
|
|
||||||
onCalculate(req: QuoteRequest) {
|
onCalculate(req: QuoteRequest) {
|
||||||
|
this.currentRequest = req; // Store request for consultation
|
||||||
this.loading.set(true);
|
this.loading.set(true);
|
||||||
this.error.set(false);
|
this.error.set(false);
|
||||||
this.result.set(null);
|
this.result.set(null);
|
||||||
@@ -164,4 +166,30 @@ export class CalculatorPageComponent {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private currentRequest: QuoteRequest | null = null;
|
||||||
|
|
||||||
|
onConsult() {
|
||||||
|
if (!this.currentRequest) return;
|
||||||
|
|
||||||
|
const req = this.currentRequest;
|
||||||
|
let details = `Richiesta Preventivo:\n`;
|
||||||
|
details += `- Materiale: ${req.material}\n`;
|
||||||
|
details += `- Qualità: ${req.quality}\n`;
|
||||||
|
details += `- Quantità: ${req.quantity}\n`;
|
||||||
|
|
||||||
|
if (req.mode === 'advanced') {
|
||||||
|
if (req.color) details += `- Colore: ${req.color}\n`;
|
||||||
|
if (req.infillDensity) details += `- Infill: ${req.infillDensity}%\n`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (req.notes) details += `\nNote: ${req.notes}`;
|
||||||
|
|
||||||
|
this.estimator.setPendingConsultation({
|
||||||
|
files: req.files,
|
||||||
|
message: details
|
||||||
|
});
|
||||||
|
|
||||||
|
this.router.navigate(['/contact']);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ import { QuoteResult } from '../../services/quote-estimator.service';
|
|||||||
|
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<app-button variant="primary" [fullWidth]="true">{{ 'CALC.ORDER' | translate }}</app-button>
|
<app-button variant="primary" [fullWidth]="true">{{ 'CALC.ORDER' | translate }}</app-button>
|
||||||
<app-button variant="outline" [fullWidth]="true">{{ 'CALC.CONSULT' | translate }}</app-button>
|
<app-button variant="outline" [fullWidth]="true" (click)="consult.emit()">{{ 'CALC.CONSULT' | translate }}</app-button>
|
||||||
</div>
|
</div>
|
||||||
</app-card>
|
</app-card>
|
||||||
`,
|
`,
|
||||||
@@ -53,4 +53,5 @@ import { QuoteResult } from '../../services/quote-estimator.service';
|
|||||||
})
|
})
|
||||||
export class QuoteResultComponent {
|
export class QuoteResultComponent {
|
||||||
result = input.required<QuoteResult>();
|
result = input.required<QuoteResult>();
|
||||||
|
consult = output<void>();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Injectable, inject } from '@angular/core';
|
import { Injectable, inject, signal } from '@angular/core';
|
||||||
import { HttpClient } from '@angular/common/http';
|
import { HttpClient } from '@angular/common/http';
|
||||||
import { Observable, forkJoin, of } from 'rxjs';
|
import { Observable, forkJoin, of } from 'rxjs';
|
||||||
import { map, catchError } from 'rxjs/operators';
|
import { map, catchError } from 'rxjs/operators';
|
||||||
@@ -134,4 +134,17 @@ export class QuoteEstimatorService {
|
|||||||
if (q.includes('high')) return 'extra_fine';
|
if (q.includes('high')) return 'extra_fine';
|
||||||
return 'standard';
|
return 'standard';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Consultation Data Transfer
|
||||||
|
private pendingConsultation = signal<{files: File[], message: string} | null>(null);
|
||||||
|
|
||||||
|
setPendingConsultation(data: {files: File[], message: string}) {
|
||||||
|
this.pendingConsultation.set(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
getPendingConsultation() {
|
||||||
|
const data = this.pendingConsultation();
|
||||||
|
this.pendingConsultation.set(null); // Clear after reading
|
||||||
|
return data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import { ReactiveFormsModule, FormBuilder, FormGroup, Validators } from '@angula
|
|||||||
import { TranslateModule, TranslateService } from '@ngx-translate/core';
|
import { TranslateModule, TranslateService } from '@ngx-translate/core';
|
||||||
import { AppInputComponent } from '../../../../shared/components/app-input/app-input.component';
|
import { AppInputComponent } from '../../../../shared/components/app-input/app-input.component';
|
||||||
import { AppButtonComponent } from '../../../../shared/components/app-button/app-button.component';
|
import { AppButtonComponent } from '../../../../shared/components/app-button/app-button.component';
|
||||||
|
import { QuoteEstimatorService } from '../../../calculator/services/quote-estimator.service';
|
||||||
|
|
||||||
interface FilePreview {
|
interface FilePreview {
|
||||||
file: File;
|
file: File;
|
||||||
@@ -242,7 +243,11 @@ export class ContactFormComponent {
|
|||||||
{ value: 'question', label: 'CONTACT.REQ_TYPE_QUESTION' }
|
{ value: 'question', label: 'CONTACT.REQ_TYPE_QUESTION' }
|
||||||
];
|
];
|
||||||
|
|
||||||
constructor(private fb: FormBuilder, private translate: TranslateService) {
|
constructor(
|
||||||
|
private fb: FormBuilder,
|
||||||
|
private translate: TranslateService,
|
||||||
|
private estimator: QuoteEstimatorService
|
||||||
|
) {
|
||||||
this.form = this.fb.group({
|
this.form = this.fb.group({
|
||||||
requestType: ['custom', Validators.required],
|
requestType: ['custom', Validators.required],
|
||||||
name: ['', Validators.required],
|
name: ['', Validators.required],
|
||||||
@@ -279,6 +284,27 @@ export class ContactFormComponent {
|
|||||||
companyNameControl?.updateValueAndValidity();
|
companyNameControl?.updateValueAndValidity();
|
||||||
refPersonControl?.updateValueAndValidity();
|
refPersonControl?.updateValueAndValidity();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Check for pending consultation data
|
||||||
|
effect(() => {
|
||||||
|
// Use timeout or run in constructor to ensure dependency availability?
|
||||||
|
// Actually best in constructor or ngOnInit. Let's stick to constructor logic but executed immediately.
|
||||||
|
});
|
||||||
|
|
||||||
|
const pending = this.estimator.getPendingConsultation();
|
||||||
|
if (pending) {
|
||||||
|
this.form.patchValue({
|
||||||
|
requestType: 'consult',
|
||||||
|
message: pending.message
|
||||||
|
});
|
||||||
|
|
||||||
|
// Process files
|
||||||
|
const filePreviews: FilePreview[] = [];
|
||||||
|
pending.files.forEach(f => {
|
||||||
|
filePreviews.push({ file: f, type: this.getFileType(f) });
|
||||||
|
});
|
||||||
|
this.files.set(filePreviews);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
setCompanyMode(isCompany: boolean) {
|
setCompanyMode(isCompany: boolean) {
|
||||||
|
|||||||
Reference in New Issue
Block a user