From 9c69884cc9b5d391e84b5cc666a7aa74c5d31ace Mon Sep 17 00:00:00 2001 From: MarcoE Date: Thu, 24 Jul 2025 15:51:01 +0200 Subject: [PATCH] Aggiunta ricerca indirizzo --- .../Components/Layout/HeaderLayout.razor.css | 8 + .../BottomSheet/SearchAddress.razor | 124 ++++++ .../BottomSheet/SearchAddress.razor.css | 1 + .../SingleElements/Modal/ContactForm.razor | 413 ++++++++++-------- .../Modal/ContactForm.razor.css | 10 + .../Core/Dto/AutoCompleteAddressDTO.cs | 12 + salesbook.Shared/Core/Dto/IndirizzoDTO.cs | 36 ++ .../Core/Interface/IIntegryApiService.cs | 5 + .../Core/Services/IntegryApiService.cs | 34 ++ salesbook.Shared/wwwroot/css/app.css | 3 +- .../wwwroot/css/default-theme.css | 3 +- 11 files changed, 453 insertions(+), 196 deletions(-) create mode 100644 salesbook.Shared/Components/SingleElements/BottomSheet/SearchAddress.razor create mode 100644 salesbook.Shared/Components/SingleElements/BottomSheet/SearchAddress.razor.css create mode 100644 salesbook.Shared/Core/Dto/AutoCompleteAddressDTO.cs create mode 100644 salesbook.Shared/Core/Dto/IndirizzoDTO.cs diff --git a/salesbook.Shared/Components/Layout/HeaderLayout.razor.css b/salesbook.Shared/Components/Layout/HeaderLayout.razor.css index 146d09f..82cd2a6 100644 --- a/salesbook.Shared/Components/Layout/HeaderLayout.razor.css +++ b/salesbook.Shared/Components/Layout/HeaderLayout.razor.css @@ -1,4 +1,12 @@ +.header { + min-height: var(--mh-header); + width: 100%; + display: flex; + align-items: center; +} + .header-content { + width: 100%; line-height: normal; display: flex; justify-content: space-between; diff --git a/salesbook.Shared/Components/SingleElements/BottomSheet/SearchAddress.razor b/salesbook.Shared/Components/SingleElements/BottomSheet/SearchAddress.razor new file mode 100644 index 0000000..9ec722a --- /dev/null +++ b/salesbook.Shared/Components/SingleElements/BottomSheet/SearchAddress.razor @@ -0,0 +1,124 @@ +@using salesbook.Shared.Components.Layout.Spinner +@using salesbook.Shared.Core.Dto +@using salesbook.Shared.Core.Interface +@using salesbook.Shared.Components.Layout.Overlay +@inject IIntegryApiService IntegryApiService + +
+ +
+
+
+ + Cerca indirizzo + + +
+ +
+ + + +
+ +
+ @if (Loading) + { + + } + else + { + if (Addresses != null) + { + foreach (var address in Addresses) + { + @address.Description + +
+ } + } + else + { + + } + } +
+
+
+ + + +@code { + [Parameter] public string Region { get; set; } + + [Parameter] public IndirizzoDTO Indirizzo { get; set; } + [Parameter] public EventCallback IndirizzoChanged { get; set; } + + [Parameter] public bool IsSheetVisible { get; set; } + [Parameter] public EventCallback IsSheetVisibleChanged { get; set; } + + private bool Loading { get; set; } + + private string? Address { get; set; } + private List? Addresses { get; set; } + + private string? Uuid { get; set; } + + //Overlay for save + private bool VisibleOverlay { get; set; } + private bool SuccessAnimation { get; set; } + + protected override async Task OnParametersSetAsync() + { + if (IsSheetVisible) + { + Uuid = Guid.NewGuid().ToString(); + Address = null; + Addresses = null; + } + } + + private void CloseBottomSheet() + { + IsSheetVisible = false; + IsSheetVisibleChanged.InvokeAsync(IsSheetVisible); + } + + private async Task SearchAllAddress() + { + if (Address == null || Uuid == null) return; + + Loading = true; + StateHasChanged(); + + Addresses = await IntegryApiService.AutoCompleteAddress(Address, Region, Uuid); + + Loading = false; + StateHasChanged(); + } + + private async Task OnSelectAddress(string placeId) + { + CloseBottomSheet(); + + VisibleOverlay = true; + StateHasChanged(); + + try + { + Indirizzo = await IntegryApiService.PlaceDetails(placeId, Uuid); + await IndirizzoChanged.InvokeAsync(Indirizzo); + } + catch (Exception e) + { + Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter; + Snackbar.Clear(); + + Snackbar.Add("Impossibile selezionare questo indirizzo", Severity.Error); + } + + VisibleOverlay = false; + StateHasChanged(); + } + +} \ No newline at end of file diff --git a/salesbook.Shared/Components/SingleElements/BottomSheet/SearchAddress.razor.css b/salesbook.Shared/Components/SingleElements/BottomSheet/SearchAddress.razor.css new file mode 100644 index 0000000..5f28270 --- /dev/null +++ b/salesbook.Shared/Components/SingleElements/BottomSheet/SearchAddress.razor.css @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor b/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor index be17acc..380b8a6 100644 --- a/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor +++ b/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor @@ -3,6 +3,7 @@ @using salesbook.Shared.Core.Interface @using salesbook.Shared.Components.Layout.Overlay @using salesbook.Shared.Core.Entity +@using salesbook.Shared.Components.SingleElements.BottomSheet @inject IManageDataService ManageData @inject INetworkService NetworkService @inject IIntegryApiService IntegryApiService @@ -13,141 +14,21 @@
-
- -
- -
-
- P. IVA - +
-
- -
- -
- Cod. Fiscale - -
-
- -
-
- Tipo cliente - - @if (VtbTipi.IsNullOrEmpty()) - { - Nessun tipo cliente trovato - } - else - { - - @foreach (var tipo in VtbTipi) - { - @($"{tipo.CodVtip} - {tipo.Descrizione}") - } - - } -
-
- -
-
- Indirizzo - - -
- -
- -
- CAP - - -
- -
- -
- Città - - -
- -
- -
- Provincia - - -
- -
- -
- Nazione + +
+
+ Nazione @if (Nazioni.IsNullOrEmpty()) { @@ -164,85 +45,215 @@ } } -
-
- -
-
- PEC - - +
-
+
+
+ P. IVA -
- E-Mail + +
- +
+ +
+ Cod. Fiscale + + +
-
+
+
+ Tipo cliente -
- Telefono - - -
-
- - @if (IsNew) - { -
- @if (!PersRifList.IsNullOrEmpty()) - { - foreach (var item in PersRifList!.Select((p, index) => new { p, index })) + @if (VtbTipi.IsNullOrEmpty()) { - - @item.p.PersonaRif - + Nessun tipo cliente trovato } - } + else + { + + @foreach (var tipo in VtbTipi) + { + @($"{tipo.CodVtip} - {tipo.Descrizione}") + } + + } +
+
+ + @if (!IsView) + { +
+ Cerca indirizzo + +
+ } + + +
+
+ Indirizzo + + +
+ +
+ +
+ CAP + + +
+ +
+ +
+ Città + + +
+ +
+ +
+ Provincia + + +
-
- - Persona di riferimento - +
+
+ PEC + + +
+ +
+ +
+ E-Mail + + +
+ +
+ +
+ Telefono + + +
- } + + @if (IsNew) + { +
+ @if (!PersRifList.IsNullOrEmpty()) + { + foreach (var item in PersRifList!.Select((p, index) => new { p, index })) + { + + @item.p.PersonaRif + + } + } +
+ +
+ + Persona di riferimento + +
+ }
@@ -268,6 +279,8 @@ + + @code { [CascadingParameter] private IMudDialogInstance MudDialog { get; set; } @@ -292,6 +305,10 @@ private string VatMessage { get; set; } = ""; private bool VatAlreadyRegistered { get; set; } + //BottomSeath + private bool OpenSearchAddress { get; set; } + private IndirizzoDTO Address { get; set; } + protected override async Task OnInitializedAsync() { Snackbar.Configuration.PositionClass = Defaults.Classes.Position.TopCenter; @@ -467,4 +484,12 @@ OnAfterChangeValue(); } + + private void OnAddressSet() + { + ContactModel.Citta = Address.Citta; + ContactModel.Indirizzo = Address.Indirizzo; + ContactModel.Prov = Address.Prov; + ContactModel.Cap = Address.Cap; + } } \ No newline at end of file diff --git a/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor.css b/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor.css index 17ef28b..8661b27 100644 --- a/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor.css +++ b/salesbook.Shared/Components/SingleElements/Modal/ContactForm.razor.css @@ -6,4 +6,14 @@ .container-chip-persrif { width: 100%; margin-bottom: 1rem; +} + +.search-address { + width: 100%; + display: flex; + justify-content: space-between; + margin-bottom: 0.65rem; + color: var(--mud-palette-primary); + font-weight: 600; + align-items: center; } \ No newline at end of file diff --git a/salesbook.Shared/Core/Dto/AutoCompleteAddressDTO.cs b/salesbook.Shared/Core/Dto/AutoCompleteAddressDTO.cs new file mode 100644 index 0000000..796b7a0 --- /dev/null +++ b/salesbook.Shared/Core/Dto/AutoCompleteAddressDTO.cs @@ -0,0 +1,12 @@ +using System.Text.Json.Serialization; + +namespace salesbook.Shared.Core.Dto; + +public class AutoCompleteAddressDTO +{ + [JsonPropertyName("description")] + public string Description { get; set; } + + [JsonPropertyName("placeId")] + public string PlaceId { get; set; } +} \ No newline at end of file diff --git a/salesbook.Shared/Core/Dto/IndirizzoDTO.cs b/salesbook.Shared/Core/Dto/IndirizzoDTO.cs new file mode 100644 index 0000000..aa3a31a --- /dev/null +++ b/salesbook.Shared/Core/Dto/IndirizzoDTO.cs @@ -0,0 +1,36 @@ +using System.Text.Json.Serialization; + +namespace salesbook.Shared.Core.Dto; + +public class IndirizzoDTO +{ + [JsonPropertyName("idPosizione")] + public int IdPosizione { get; set; } + + [JsonPropertyName("via")] + public string? Via { get; set; } + + [JsonPropertyName("numeroCivico")] + public string? NumeroCivico { get; set; } + + [JsonPropertyName("indirizzo")] + public string? Indirizzo { get; set; } + + [JsonPropertyName("cap")] + public string? Cap { get; set; } + + [JsonPropertyName("citta")] + public string? Citta { get; set; } + + [JsonPropertyName("prov")] + public string? Prov { get; set; } + + [JsonPropertyName("nazione")] + public string? Nazione { get; set; } + + [JsonPropertyName("lat")] + public decimal? Lat { get; set; } + + [JsonPropertyName("lng")] + public decimal? Lng { get; set; } +} \ No newline at end of file diff --git a/salesbook.Shared/Core/Interface/IIntegryApiService.cs b/salesbook.Shared/Core/Interface/IIntegryApiService.cs index efcab36..783d80e 100644 --- a/salesbook.Shared/Core/Interface/IIntegryApiService.cs +++ b/salesbook.Shared/Core/Interface/IIntegryApiService.cs @@ -16,4 +16,9 @@ public interface IIntegryApiService Task?> SaveActivity(ActivityDTO activity); Task SaveContact(CRMCreateContactRequestDTO request); Task CheckVat(CheckVatRequestDTO request); + + //Google + Task?> Geocode(string address); + Task?> AutoCompleteAddress(string address, string language, string uuid); + Task PlaceDetails(string placeId, string uuid); } \ No newline at end of file diff --git a/salesbook.Shared/Core/Services/IntegryApiService.cs b/salesbook.Shared/Core/Services/IntegryApiService.cs index 379aee5..6abef61 100644 --- a/salesbook.Shared/Core/Services/IntegryApiService.cs +++ b/salesbook.Shared/Core/Services/IntegryApiService.cs @@ -74,4 +74,38 @@ public class IntegryApiService(IIntegryApiRestClient integryApiRestClient, IUser public Task CheckVat(CheckVatRequestDTO request) => integryApiRestClient.Post("checkPartitaIva", request)!; + + public Task?> Geocode(string address) + { + var queryParams = new Dictionary + { + {"address", address}, + {"retrieveAll", true} + }; + + return integryApiRestClient.Get>("geocode", queryParams); + } + + public Task?> AutoCompleteAddress(string address, string language, string uuid) + { + var queryParams = new Dictionary + { + {"address", address}, + {"language", language}, + {"uuid", uuid} + }; + + return integryApiRestClient.Get>("google/places/autoCompleteAddress", queryParams); + } + + public Task PlaceDetails(string placeId, string uuid) + { + var queryParams = new Dictionary + { + { "placeId", placeId }, + { "uuid", uuid } + }; + + return integryApiRestClient.Get("google/places/placeDetails", queryParams); + } } \ No newline at end of file diff --git a/salesbook.Shared/wwwroot/css/app.css b/salesbook.Shared/wwwroot/css/app.css index f274c42..e224251 100644 --- a/salesbook.Shared/wwwroot/css/app.css +++ b/salesbook.Shared/wwwroot/css/app.css @@ -31,7 +31,7 @@ a, .btn-link { .btn:focus, .btn:active:focus, .btn-link.nav-link:focus, .form-control:focus, .form-check-input:focus { box-shadow: 0 0 0 0.1rem white, 0 0 0 0.25rem #258cfb; } .content { - padding-top: 1.1rem; + /*padding-top: 1.1rem;*/ display: flex; align-items: center; flex-direction: column; @@ -176,6 +176,7 @@ h1:focus { outline: none; } .customDialog-form .mud-dialog-content { padding: 0 .75rem; margin: 0; + overflow: hidden; } .custom-item-select { padding: 6px 16px; } diff --git a/salesbook.Shared/wwwroot/css/default-theme.css b/salesbook.Shared/wwwroot/css/default-theme.css index 7a0a818..9422456 100644 --- a/salesbook.Shared/wwwroot/css/default-theme.css +++ b/salesbook.Shared/wwwroot/css/default-theme.css @@ -6,5 +6,6 @@ --exception-box-shadow: 1px 2px 5px rgba(0, 0, 0, 0.3); --custom-box-shadow: 1px 2px 5px var(--gray-for-shadow); --mud-default-borderradius: 12px !important; - --m-page-x: 1.25rem; + --m-page-x: 1rem; + --mh-header: 4rem; }