From ef4b942976966d3e59b8e6528519094dc1182dff Mon Sep 17 00:00:00 2001 From: Regis Freyd Date: Sun, 5 Feb 2023 20:20:04 -0500 Subject: [PATCH 01/12] feat: list all addresses in vault --- .../ContactModuleAddressController.php | 8 +- .../ModuleContactAddressesViewHelper.php | 16 +- resources/js/Shared/Modules/Addresses.vue | 369 ++++++++++-------- .../ModuleContactAddressesViewHelperTest.php | 28 +- 4 files changed, 247 insertions(+), 174 deletions(-) diff --git a/app/Domains/Contact/ManageContactAddresses/Web/Controllers/ContactModuleAddressController.php b/app/Domains/Contact/ManageContactAddresses/Web/Controllers/ContactModuleAddressController.php index 24e6b6643..4fd33c496 100644 --- a/app/Domains/Contact/ManageContactAddresses/Web/Controllers/ContactModuleAddressController.php +++ b/app/Domains/Contact/ManageContactAddresses/Web/Controllers/ContactModuleAddressController.php @@ -8,6 +8,7 @@ use App\Domains\Vault\ManageAddresses\Services\CreateAddress; use App\Domains\Vault\ManageAddresses\Services\UpdateAddress; use App\Http\Controllers\Controller; +use App\Models\Address; use App\Models\Contact; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -31,7 +32,12 @@ public function store(Request $request, int $vaultId, int $contactId) 'longitude' => null, ]; - $address = (new CreateAddress())->execute($data); + if (! $request->input('existing_address')) { + $address = (new CreateAddress())->execute($data); + } else { + $address = Address::where('vault_id', $vaultId) + ->findOrFail($request->input('existing_address_id')); + } (new AssociateAddressToContact())->execute([ 'account_id' => Auth::user()->account_id, diff --git a/app/Domains/Contact/ManageContactAddresses/Web/ViewHelpers/ModuleContactAddressesViewHelper.php b/app/Domains/Contact/ManageContactAddresses/Web/ViewHelpers/ModuleContactAddressesViewHelper.php index 088c0c9ca..b99f943cc 100644 --- a/app/Domains/Contact/ManageContactAddresses/Web/ViewHelpers/ModuleContactAddressesViewHelper.php +++ b/app/Domains/Contact/ManageContactAddresses/Web/ViewHelpers/ModuleContactAddressesViewHelper.php @@ -12,12 +12,12 @@ class ModuleContactAddressesViewHelper { public static function data(Contact $contact, User $user): array { - $activeAddressesCollection = $contact->addresses() + $contactActiveAddressesCollection = $contact->addresses() ->wherePivot('is_past_address', false) ->get() ->map(fn (Address $address) => self::dto($contact, $address, $user)); - $inactiveAddressesCollection = $contact->addresses() + $contactInactiveAddressesCollection = $contact->addresses() ->wherePivot('is_past_address', true) ->get() ->map(fn (Address $address) => self::dto($contact, $address, $user)); @@ -31,10 +31,18 @@ public static function data(Contact $contact, User $user): array 'selected' => false, ]); + $vaultAddressesCollection = $contact->vault->addresses() + ->get() + ->map(fn (Address $address) => [ + 'id' => $address->id, + 'address' => MapHelper::getAddressAsString($address), + ]); + return [ - 'active_addresses' => $activeAddressesCollection, - 'inactive_addresses' => $inactiveAddressesCollection, + 'active_addresses' => $contactActiveAddressesCollection, + 'inactive_addresses' => $contactInactiveAddressesCollection, 'address_types' => $addressTypesCollection, + 'addresses_in_vault' => $vaultAddressesCollection, 'url' => [ 'store' => route('contact.address.store', [ 'vault' => $contact->vault_id, diff --git a/resources/js/Shared/Modules/Addresses.vue b/resources/js/Shared/Modules/Addresses.vue index 2157d3c9f..928112b5b 100644 --- a/resources/js/Shared/Modules/Addresses.vue +++ b/resources/js/Shared/Modules/Addresses.vue @@ -1,3 +1,144 @@ + + - - diff --git a/resources/js/Pages/Vault/Reports/Address/Index.vue b/resources/js/Pages/Vault/Reports/Address/Index.vue new file mode 100644 index 000000000..15db08ac4 --- /dev/null +++ b/resources/js/Pages/Vault/Reports/Address/Index.vue @@ -0,0 +1,94 @@ + + + + + diff --git a/resources/js/Pages/Vault/Reports/Index.vue b/resources/js/Pages/Vault/Reports/Index.vue index de3417348..c40c04246 100644 --- a/resources/js/Pages/Vault/Reports/Index.vue +++ b/resources/js/Pages/Vault/Reports/Index.vue @@ -15,6 +15,11 @@ defineProps({

All the reports