From 5d502fd6a7ec0d8ebb6063c7a2a78085c9c7c424 Mon Sep 17 00:00:00 2001 From: Paul Schneider Date: Sun, 6 Sep 2026 17:16:14 +0100 Subject: [PATCH] postit: preserve manual rdv address with map suggestion --- .../BillingCommandPageViewModelTests.cs | 44 +++++++++++++++++++ .../ViewModels/Commands/RdvViewModel.cs | 42 +++++++++++++++++- .../PostIt/Views/Commands/RdvPage.axaml | 39 +++++++++++----- 3 files changed, 111 insertions(+), 14 deletions(-) diff --git a/src/PostIt/PostIt.Tests/BillingCommandPageViewModelTests.cs b/src/PostIt/PostIt.Tests/BillingCommandPageViewModelTests.cs index da366d284..1da8b4cbd 100644 --- a/src/PostIt/PostIt.Tests/BillingCommandPageViewModelTests.cs +++ b/src/PostIt/PostIt.Tests/BillingCommandPageViewModelTests.cs @@ -135,6 +135,50 @@ public class BillingCommandPageViewModelTests Assert.Contains("Position sélectionnée", vm.StatusMessage, StringComparison.OrdinalIgnoreCase); } + [Fact] + public void ApplyResolvedAddress_populates_empty_address_directly() + { + var api = new RecordingApi(); + var client = new BillingApiClient(api, "https://business.example/api/v1/"); + var vm = + new CommandFormSummary { Id = 12, ActionName = "Rdv", Title = "Rendez-vous" } + .CreateCommandPageViewModel( + new ActivityInfo { Code = "dev", Name = "Développement" }, + new ActivityUserDisplayItem { PerformerId = "perf-1", UserName = "Alice" }, + client) as RdvViewModel; + + vm!.Address = string.Empty; + vm.ApplyResolvedAddress("10 rue de Rivoli, 75001 Paris"); + + Assert.Equal("10 rue de Rivoli, 75001 Paris", vm.Address); + Assert.False(vm.HasSuggestedAddress); + } + + [Fact] + public void ApplyResolvedAddress_preserves_manual_address_and_exposes_suggestion() + { + var api = new RecordingApi(); + var client = new BillingApiClient(api, "https://business.example/api/v1/"); + var vm = + new CommandFormSummary { Id = 12, ActionName = "Rdv", Title = "Rendez-vous" } + .CreateCommandPageViewModel( + new ActivityInfo { Code = "dev", Name = "Développement" }, + new ActivityUserDisplayItem { PerformerId = "perf-1", UserName = "Alice" }, + client) as RdvViewModel; + + vm!.Address = "Saisie manuelle"; + vm.ApplyResolvedAddress("10 rue de Rivoli, 75001 Paris"); + + Assert.Equal("Saisie manuelle", vm.Address); + Assert.True(vm.HasSuggestedAddress); + Assert.Equal("10 rue de Rivoli, 75001 Paris", vm.SuggestedAddress); + + vm.ApplySuggestedAddressCommand.Execute(null); + + Assert.Equal("10 rue de Rivoli, 75001 Paris", vm.Address); + Assert.False(vm.HasSuggestedAddress); + } + [Fact] public async Task InitializeAsync_loads_prestations_for_brush_and_submit_posts_selected_prestation() { diff --git a/src/PostIt/PostIt/ViewModels/Commands/RdvViewModel.cs b/src/PostIt/PostIt/ViewModels/Commands/RdvViewModel.cs index d60aedcc8..8a4ae6cfb 100644 --- a/src/PostIt/PostIt/ViewModels/Commands/RdvViewModel.cs +++ b/src/PostIt/PostIt/ViewModels/Commands/RdvViewModel.cs @@ -17,6 +17,9 @@ public partial class RdvViewModel : BillingCommandPageViewModel [ObservableProperty] public partial string Address { get; set; } = string.Empty; + [ObservableProperty] + public partial string SuggestedAddress { get; set; } = string.Empty; + [ObservableProperty] public partial double? Latitude { get; set; } @@ -33,6 +36,8 @@ public partial class RdvViewModel : BillingCommandPageViewModel EventDate = DateTime.Now.AddDays(1); } + public bool HasSuggestedAddress => !string.IsNullOrWhiteSpace(SuggestedAddress); + protected override void ApplyExistingQuery(BillingQueryDetailsDto existingQuery) { ExistingQueryId = existingQuery.Id; @@ -50,6 +55,7 @@ public partial class RdvViewModel : BillingCommandPageViewModel if (existingQuery.Location is not null) { Address = existingQuery.Location.Address ?? string.Empty; + SuggestedAddress = string.Empty; Latitude = existingQuery.Location.Latitude; Longitude = existingQuery.Location.Longitude; } @@ -132,8 +138,40 @@ public partial class RdvViewModel : BillingCommandPageViewModel if (string.IsNullOrWhiteSpace(address)) return; - Address = address.Trim(); - this.SetInfoStatus("Adresse mise à jour depuis la carte."); + var trimmedAddress = address.Trim(); + if (string.IsNullOrWhiteSpace(Address)) + { + Address = trimmedAddress; + SuggestedAddress = string.Empty; + this.SetInfoStatus("Adresse mise à jour depuis la carte."); + return; + } + + if (string.Equals(Address.Trim(), trimmedAddress, StringComparison.Ordinal)) + { + SuggestedAddress = string.Empty; + return; + } + + SuggestedAddress = trimmedAddress; + this.SetInfoStatus("Adresse suggérée depuis la carte. Appliquez-la si besoin."); + } + + [RelayCommand(CanExecute = nameof(HasSuggestedAddress))] + private void ApplySuggestedAddress() + { + if (string.IsNullOrWhiteSpace(SuggestedAddress)) + return; + + Address = SuggestedAddress.Trim(); + SuggestedAddress = string.Empty; + this.SetInfoStatus("Adresse suggérée appliquée."); + } + + partial void OnSuggestedAddressChanged(string value) + { + OnPropertyChanged(nameof(HasSuggestedAddress)); + ApplySuggestedAddressCommand.NotifyCanExecuteChanged(); } diff --git a/src/PostIt/PostIt/Views/Commands/RdvPage.axaml b/src/PostIt/PostIt/Views/Commands/RdvPage.axaml index a3cb477b1..e6027ed31 100644 --- a/src/PostIt/PostIt/Views/Commands/RdvPage.axaml +++ b/src/PostIt/PostIt/Views/Commands/RdvPage.axaml @@ -7,7 +7,7 @@ x:DataType="cvm:RdvViewModel" Header="Commande billing"> - + - + +