diff --git a/app/Jobs/SetupAccount.php b/app/Jobs/SetupAccount.php index 67315298fe1..dc52aeb05e7 100644 --- a/app/Jobs/SetupAccount.php +++ b/app/Jobs/SetupAccount.php @@ -86,6 +86,7 @@ public function handle() $this->addTemplate(); $this->addTemplatePageContactInformation(); $this->addTemplatePageFeed(); + $this->addTemplatePageContact(); $this->addTemplatePageSocial(); $this->addTemplatePageLifeEvents(); $this->addTemplatePageInformation(); @@ -287,6 +288,49 @@ private function addTemplatePageFeed(): void ]); } + private function addTemplatePageContact(): void + { + $template = (new CreateTemplatePage())->execute([ + 'account_id' => $this->user->account_id, + 'author_id' => $this->user->id, + 'template_id' => $this->template->id, + 'name' => trans('app.default_template_page_contact'), + 'can_be_deleted' => true, + ]); + + // Addresses + $module = (new CreateModule())->execute([ + 'account_id' => $this->user->account_id, + 'author_id' => $this->user->id, + 'name' => trans('app.module_addresses'), + 'type' => Module::TYPE_ADDRESSES, + 'can_be_deleted' => false, + ]); + (new AssociateModuleToTemplatePage())->execute([ + 'account_id' => $this->user->account_id, + 'author_id' => $this->user->id, + 'template_id' => $this->template->id, + 'template_page_id' => $template->id, + 'module_id' => $module->id, + ]); + + // Contact information + $module = (new CreateModule())->execute([ + 'account_id' => $this->user->account_id, + 'author_id' => $this->user->id, + 'name' => trans('app.module_contact_information'), + 'type' => Module::TYPE_CONTACT_INFORMATION, + 'can_be_deleted' => false, + ]); + (new AssociateModuleToTemplatePage())->execute([ + 'account_id' => $this->user->account_id, + 'author_id' => $this->user->id, + 'template_id' => $this->template->id, + 'template_page_id' => $template->id, + 'module_id' => $module->id, + ]); + } + private function addTemplatePageSocial(): void { $templatePageSocial = (new CreateTemplatePage())->execute([ @@ -383,22 +427,6 @@ private function addTemplatePageInformation(): void 'can_be_deleted' => true, ]); - // Addresses - $module = (new CreateModule())->execute([ - 'account_id' => $this->user->account_id, - 'author_id' => $this->user->id, - 'name' => trans('app.module_addresses'), - 'type' => Module::TYPE_ADDRESSES, - 'can_be_deleted' => false, - ]); - (new AssociateModuleToTemplatePage())->execute([ - 'account_id' => $this->user->account_id, - 'author_id' => $this->user->id, - 'template_id' => $this->template->id, - 'template_page_id' => $templatePageInformation->id, - 'module_id' => $module->id, - ]); - // Notes $module = (new CreateModule())->execute([ 'account_id' => $this->user->account_id, diff --git a/app/Models/ContactInformation.php b/app/Models/ContactInformation.php index 9de7e390e7d..5c57313b9cb 100644 --- a/app/Models/ContactInformation.php +++ b/app/Models/ContactInformation.php @@ -2,6 +2,7 @@ namespace App\Models; +use Illuminate\Database\Eloquent\Casts\Attribute; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Database\Eloquent\Relations\BelongsTo; @@ -42,4 +43,26 @@ public function contactInformationType(): BelongsTo { return $this->belongsTo(ContactInformationType::class, 'type_id'); } + + /** + * Get the content of the contact information. + * If the contact information type is a phone number or an email, return the + * content. If it's something else, return the contact information type's label. + * + * @return Attribute + */ + protected function name(): Attribute + { + return Attribute::make( + get: function ($value) { + $type = $this->contactInformationType; + + if (! $type->can_be_deleted) { + return $this->data; + } else { + return $type->name; + } + } + ); + } } diff --git a/app/Models/Module.php b/app/Models/Module.php index 9b2ac223636..666ff93a00f 100644 --- a/app/Models/Module.php +++ b/app/Models/Module.php @@ -33,6 +33,7 @@ class Module extends Model public const TYPE_GOALS = 'goals'; public const TYPE_ADDRESSES = 'addresses'; public const TYPE_GROUPS = 'groups'; + public const TYPE_CONTACT_INFORMATION = 'contact_information'; /** * The attributes that are mass assignable. diff --git a/domains/Contact/ManageContact/Services/CopyContactToAnotherVault.php b/domains/Contact/ManageContact/Services/CopyContactToAnotherVault.php index 3497784d443..ca7424445ce 100644 --- a/domains/Contact/ManageContact/Services/CopyContactToAnotherVault.php +++ b/domains/Contact/ManageContact/Services/CopyContactToAnotherVault.php @@ -9,6 +9,7 @@ use App\Models\Contact; use App\Models\Vault; use App\Services\BaseService; +use Carbon\Carbon; class CopyContactToAnotherVault extends BaseService implements ServiceInterface { @@ -58,6 +59,7 @@ public function execute(array $data): Contact $this->data = $data; $this->validate(); $this->copy(); + $this->updateLastEditedDate(); $this->log(); return $this->newContact; @@ -89,6 +91,12 @@ private function copy(): void $this->newContact->save(); } + private function updateLastEditedDate(): void + { + $this->contact->last_updated_at = Carbon::now(); + $this->contact->save(); + } + private function log(): void { CreateAuditLog::dispatch([ diff --git a/domains/Contact/ManageContact/Services/CreateContact.php b/domains/Contact/ManageContact/Services/CreateContact.php index 36e6d07e58c..e2bbedaac82 100644 --- a/domains/Contact/ManageContact/Services/CreateContact.php +++ b/domains/Contact/ManageContact/Services/CreateContact.php @@ -67,6 +67,7 @@ public function execute(array $data): Contact $this->validate(); $this->createContact(); $this->generateAvatar(); + $this->updateLastEditedDate(); $this->log(); return $this->contact; @@ -124,6 +125,12 @@ private function generateAvatar(): void $this->contact->save(); } + private function updateLastEditedDate(): void + { + $this->contact->last_updated_at = Carbon::now(); + $this->contact->save(); + } + private function log(): void { CreateAuditLog::dispatch([ diff --git a/domains/Contact/ManageContact/Services/MoveContactToAnotherVault.php b/domains/Contact/ManageContact/Services/MoveContactToAnotherVault.php index 9927815501c..2caf074a72a 100644 --- a/domains/Contact/ManageContact/Services/MoveContactToAnotherVault.php +++ b/domains/Contact/ManageContact/Services/MoveContactToAnotherVault.php @@ -9,6 +9,7 @@ use App\Models\Contact; use App\Models\Vault; use App\Services\BaseService; +use Carbon\Carbon; class MoveContactToAnotherVault extends BaseService implements ServiceInterface { @@ -57,6 +58,7 @@ public function execute(array $data): Contact $this->data = $data; $this->validate(); $this->move(); + $this->updateLastEditedDate(); $this->log(); return $this->contact; @@ -85,6 +87,12 @@ private function move(): void $this->contact->save(); } + private function updateLastEditedDate(): void + { + $this->contact->last_updated_at = Carbon::now(); + $this->contact->save(); + } + private function log(): void { CreateAuditLog::dispatch([ diff --git a/domains/Contact/ManageContact/Services/ToggleArchiveContact.php b/domains/Contact/ManageContact/Services/ToggleArchiveContact.php index c36979e362a..7c15e2ac7cb 100644 --- a/domains/Contact/ManageContact/Services/ToggleArchiveContact.php +++ b/domains/Contact/ManageContact/Services/ToggleArchiveContact.php @@ -6,6 +6,7 @@ use App\Models\Contact; use App\Models\ContactFeedItem; use App\Services\BaseService; +use Carbon\Carbon; class ToggleArchiveContact extends BaseService implements ServiceInterface { @@ -55,6 +56,7 @@ public function execute(array $data): Contact $this->contact->listed = ! $this->contact->listed; $this->contact->save(); + $this->updateLastEditedDate(); $this->createFeedItem(); return $this->contact; @@ -65,6 +67,12 @@ private function validate(): void $this->validateRules($this->data); } + private function updateLastEditedDate(): void + { + $this->contact->last_updated_at = Carbon::now(); + $this->contact->save(); + } + private function createFeedItem(): void { ContactFeedItem::create([ diff --git a/domains/Contact/ManageContact/Services/UpdateContact.php b/domains/Contact/ManageContact/Services/UpdateContact.php index 1e748c0bf4c..26861a472bb 100644 --- a/domains/Contact/ManageContact/Services/UpdateContact.php +++ b/domains/Contact/ManageContact/Services/UpdateContact.php @@ -84,6 +84,7 @@ public function execute(array $data): Contact $this->contact->last_updated_at = Carbon::now(); $this->contact->save(); + $this->updateLastEditedDate(); $this->log(); $this->createFeedItem(); @@ -105,6 +106,12 @@ private function validate(): void } } + private function updateLastEditedDate(): void + { + $this->contact->last_updated_at = Carbon::now(); + $this->contact->save(); + } + private function log(): void { CreateAuditLog::dispatch([ diff --git a/domains/Contact/ManageContact/Services/UpdateContactTemplate.php b/domains/Contact/ManageContact/Services/UpdateContactTemplate.php index 1855d9fc720..30ca4dcced3 100644 --- a/domains/Contact/ManageContact/Services/UpdateContactTemplate.php +++ b/domains/Contact/ManageContact/Services/UpdateContactTemplate.php @@ -58,6 +58,7 @@ public function execute(array $data): Contact $this->validate(); $this->update(); + $this->updateLastEditedDate(); $this->log(); return $this->contact; @@ -78,6 +79,12 @@ private function update(): void $this->contact->save(); } + private function updateLastEditedDate(): void + { + $this->contact->last_updated_at = Carbon::now(); + $this->contact->save(); + } + private function log(): void { CreateAuditLog::dispatch([ diff --git a/domains/Contact/ManageContact/Web/ViewHelpers/ContactShowViewHelper.php b/domains/Contact/ManageContact/Web/ViewHelpers/ContactShowViewHelper.php index 847becdadb1..6248a11e787 100644 --- a/domains/Contact/ManageContact/Web/ViewHelpers/ContactShowViewHelper.php +++ b/domains/Contact/ManageContact/Web/ViewHelpers/ContactShowViewHelper.php @@ -7,6 +7,7 @@ use App\Contact\ManageContactAddresses\Web\ViewHelpers\ModuleContactAddressesViewHelper; use App\Contact\ManageContactFeed\Web\ViewHelpers\ModuleFeedViewHelper; use App\Contact\ManageContactImportantDates\Web\ViewHelpers\ModuleImportantDatesViewHelper; +use App\Contact\ManageContactInformation\Web\ViewHelpers\ModuleContactInformationViewHelper; use App\Contact\ManageContactName\Web\ViewHelpers\ModuleContactNameViewHelper; use App\Contact\ManageGoals\Web\ViewHelpers\ModuleGoalsViewHelper; use App\Contact\ManageGroups\Web\ViewHelpers\GroupsViewHelper; @@ -232,6 +233,10 @@ public static function modules(TemplatePage $page, Contact $contact, User $user) $data = ModuleGroupsViewHelper::data($contact); } + if ($module->type == Module::TYPE_CONTACT_INFORMATION) { + $data = ModuleContactInformationViewHelper::data($contact, $user); + } + $modulesCollection->push([ 'id' => $module->id, 'type' => $module->type, diff --git a/domains/Contact/ManageContactImportantDates/Services/CreateContactImportantDate.php b/domains/Contact/ManageContactImportantDates/Services/CreateContactImportantDate.php index 5715b4fd952..4d9bd299402 100644 --- a/domains/Contact/ManageContactImportantDates/Services/CreateContactImportantDate.php +++ b/domains/Contact/ManageContactImportantDates/Services/CreateContactImportantDate.php @@ -10,6 +10,7 @@ use App\Models\ContactImportantDate; use App\Models\ContactImportantDateType; use App\Services\BaseService; +use Carbon\Carbon; class CreateContactImportantDate extends BaseService implements ServiceInterface { @@ -71,6 +72,7 @@ public function execute(array $data): ContactImportantDate 'year' => $this->valueOrNull($data, 'year'), ]); + $this->updateLastEditedDate(); $this->log(); $this->createFeedItem(); @@ -88,6 +90,12 @@ private function validate(): void } } + private function updateLastEditedDate(): void + { + $this->contact->last_updated_at = Carbon::now(); + $this->contact->save(); + } + private function log(): void { CreateAuditLog::dispatch([ diff --git a/domains/Contact/ManageContactInformation/Services/CreateContactInformation.php b/domains/Contact/ManageContactInformation/Services/CreateContactInformation.php index 0d5cc9c7020..d1393c5493d 100644 --- a/domains/Contact/ManageContactInformation/Services/CreateContactInformation.php +++ b/domains/Contact/ManageContactInformation/Services/CreateContactInformation.php @@ -8,11 +8,13 @@ use App\Models\ContactInformation; use App\Models\ContactInformationType; use App\Services\BaseService; +use Carbon\Carbon; class CreateContactInformation extends BaseService implements ServiceInterface { private ContactInformation $contactInformation; private ContactInformationType $contactInformationType; + private array $data; /** * Get the validation rules that apply to the service. @@ -54,20 +56,36 @@ public function permissions(): array */ public function execute(array $data): ContactInformation { - $this->validateRules($data); + $this->data = $data; + $this->validate(); + $this->create(); + $this->updateLastEditedDate(); + $this->log(); + + return $this->contactInformation; + } - $this->contactInformationType = ContactInformationType::where('account_id', $data['account_id']) - ->findOrFail($data['contact_information_type_id']); + private function validate(): void + { + $this->validateRules($this->data); + + $this->contactInformationType = ContactInformationType::where('account_id', $this->data['account_id']) + ->findOrFail($this->data['contact_information_type_id']); + } + private function create(): void + { $this->contactInformation = ContactInformation::create([ 'contact_id' => $this->contact->id, 'type_id' => $this->contactInformationType->id, - 'data' => $data['data'], + 'data' => $this->data['data'], ]); + } - $this->log(); - - return $this->contactInformation; + private function updateLastEditedDate(): void + { + $this->contact->last_updated_at = Carbon::now(); + $this->contact->save(); } private function log(): void diff --git a/domains/Contact/ManageContactInformation/Services/DestroyContactInformation.php b/domains/Contact/ManageContactInformation/Services/DestroyContactInformation.php index 7c9f17eb789..428844b62a7 100644 --- a/domains/Contact/ManageContactInformation/Services/DestroyContactInformation.php +++ b/domains/Contact/ManageContactInformation/Services/DestroyContactInformation.php @@ -3,11 +3,10 @@ namespace App\Contact\ManageContactInformation\Services; use App\Interfaces\ServiceInterface; -use App\Jobs\CreateAuditLog; -use App\Jobs\CreateContactLog; use App\Models\ContactInformation; use App\Models\ContactInformationType; use App\Services\BaseService; +use Carbon\Carbon; class DestroyContactInformation extends BaseService implements ServiceInterface { @@ -26,7 +25,6 @@ public function rules(): array 'vault_id' => 'required|integer|exists:vaults,id', 'author_id' => 'required|integer|exists:users,id', 'contact_id' => 'required|integer|exists:contacts,id', - 'contact_information_type_id' => 'required|integer|exists:contact_information_types,id', 'contact_information_id' => 'required|integer|exists:contact_information,id', ]; } @@ -53,42 +51,28 @@ public function permissions(): array */ public function execute(array $data): void { - $this->validateRules($data); - - $this->contactInformationType = ContactInformationType::where('account_id', $data['account_id']) - ->findOrFail($data['contact_information_type_id']); - - $this->contactInformation = ContactInformation::where('contact_id', $this->contact->id) - ->where('type_id', $data['contact_information_type_id']) - ->findOrFail($data['contact_information_id']); + $this->data = $data; + $this->validate(); $this->contactInformation->delete(); - $this->log(); + $this->updateLastEditedDate(); } - private function log(): void + private function validate(): void { - CreateAuditLog::dispatch([ - 'account_id' => $this->author->account_id, - 'author_id' => $this->author->id, - 'author_name' => $this->author->name, - 'action_name' => 'contact_information_destroyed', - 'objects' => json_encode([ - 'contact_id' => $this->contact->id, - 'contact_name' => $this->contact->name, - 'contact_information_type_name' => $this->contactInformationType->name, - ]), - ])->onQueue('low'); + $this->validateRules($this->data); + + $this->contactInformation = ContactInformation::where('contact_id', $this->contact->id) + ->findOrFail($this->data['contact_information_id']); + + ContactInformationType::where('account_id', $this->data['account_id']) + ->findOrFail($this->contactInformation->contactInformationType->id); + } - CreateContactLog::dispatch([ - 'contact_id' => $this->contact->id, - 'author_id' => $this->author->id, - 'author_name' => $this->author->name, - 'action_name' => 'contact_information_destroyed', - 'objects' => json_encode([ - 'contact_information_type_name' => $this->contactInformationType->name, - ]), - ])->onQueue('low'); + private function updateLastEditedDate(): void + { + $this->contact->last_updated_at = Carbon::now(); + $this->contact->save(); } } diff --git a/domains/Contact/ManageContactInformation/Services/UpdateContactInformation.php b/domains/Contact/ManageContactInformation/Services/UpdateContactInformation.php index 01409eaec56..93d7d90f54b 100644 --- a/domains/Contact/ManageContactInformation/Services/UpdateContactInformation.php +++ b/domains/Contact/ManageContactInformation/Services/UpdateContactInformation.php @@ -8,6 +8,7 @@ use App\Models\ContactInformation; use App\Models\ContactInformationType; use App\Services\BaseService; +use Carbon\Carbon; class UpdateContactInformation extends BaseService implements ServiceInterface { @@ -55,21 +56,37 @@ public function permissions(): array */ public function execute(array $data): ContactInformation { - $this->validateRules($data); + $this->data = $data; + $this->validate(); + $this->update(); + $this->updateLastEditedDate(); + $this->log(); - $this->contactInformationType = ContactInformationType::where('account_id', $data['account_id']) - ->findOrFail($data['contact_information_type_id']); + return $this->contactInformation; + } + + private function validate(): void + { + $this->validateRules($this->data); + + $this->contactInformationType = ContactInformationType::where('account_id', $this->data['account_id']) + ->findOrFail($this->data['contact_information_type_id']); $this->contactInformation = ContactInformation::where('contact_id', $this->contact->id) - ->where('type_id', $data['contact_information_type_id']) - ->findOrFail($data['contact_information_id']); + ->findOrFail($this->data['contact_information_id']); + } - $this->contactInformation->data = $data['data']; + private function update(): void + { + $this->contactInformation->data = $this->data['data']; + $this->contactInformation->type_id = $this->data['contact_information_type_id']; $this->contactInformation->save(); + } - $this->log(); - - return $this->contactInformation; + private function updateLastEditedDate(): void + { + $this->contact->last_updated_at = Carbon::now(); + $this->contact->save(); } private function log(): void diff --git a/domains/Contact/ManageContactInformation/Web/Controllers/ContactInformationController.php b/domains/Contact/ManageContactInformation/Web/Controllers/ContactInformationController.php new file mode 100644 index 00000000000..4e676652285 --- /dev/null +++ b/domains/Contact/ManageContactInformation/Web/Controllers/ContactInformationController.php @@ -0,0 +1,70 @@ +execute([ + 'account_id' => Auth::user()->account_id, + 'author_id' => Auth::user()->id, + 'vault_id' => $vaultId, + 'contact_id' => $contactId, + 'contact_information_type_id' => $request->input('contact_information_type_id'), + 'data' => $request->input('data'), + ]); + + $contact = Contact::find($contactId); + + return response()->json([ + 'data' => ModuleContactInformationViewHelper::dto($contact, $info), + ], 201); + } + + public function update(Request $request, int $vaultId, int $contactId, int $infoId) + { + $data = [ + 'account_id' => Auth::user()->account_id, + 'author_id' => Auth::user()->id, + 'vault_id' => $vaultId, + 'contact_id' => $contactId, + 'contact_information_id' => $infoId, + 'contact_information_type_id' => $request->input('contact_information_type_id'), + 'data' => $request->input('data'), + ]; + + $info = (new UpdateContactInformation())->execute($data); + $contact = Contact::find($contactId); + + return response()->json([ + 'data' => ModuleContactInformationViewHelper::dto($contact, $info), + ], 200); + } + + public function destroy(Request $request, int $vaultId, int $contactId, int $infoId) + { + $data = [ + 'account_id' => Auth::user()->account_id, + 'author_id' => Auth::user()->id, + 'vault_id' => $vaultId, + 'contact_id' => $contactId, + 'contact_information_id' => $infoId, + ]; + + (new DestroyContactInformation())->execute($data); + + return response()->json([ + 'data' => true, + ], 200); + } +} diff --git a/domains/Contact/ManageContactInformation/Web/ViewHelpers/ModuleContactInformationViewHelper.php b/domains/Contact/ManageContactInformation/Web/ViewHelpers/ModuleContactInformationViewHelper.php new file mode 100644 index 00000000000..a2165ac2688 --- /dev/null +++ b/domains/Contact/ManageContactInformation/Web/ViewHelpers/ModuleContactInformationViewHelper.php @@ -0,0 +1,65 @@ +contactInformation()->with('contactInformationType')->get(); + + $infosCollection = $infos->map(function ($info) use ($contact) { + return self::dto($contact, $info); + }); + + $infoTypesCollection = $user->account + ->contactInformationTypes() + ->get() + ->map(function ($contactInformationType) { + return [ + 'id' => $contactInformationType->id, + 'name' => $contactInformationType->name, + ]; + }); + + return [ + 'contact_information' => $infosCollection, + 'contact_information_types' => $infoTypesCollection, + 'url' => [ + 'store' => route('contact.contact_information.store', [ + 'vault' => $contact->vault_id, + 'contact' => $contact->id, + ]), + ], + ]; + } + + public static function dto(Contact $contact, ContactInformation $info): array + { + return [ + 'id' => $info->id, + 'label' => $info->name, + 'data' => $info->contactInformationType->protocol ? $info->contactInformationType->protocol.$info->data : $info->data, + 'contact_information_type' => [ + 'id' => $info->contactInformationType->id, + 'name' => $info->contactInformationType->name, + ], + 'url' => [ + 'update' => route('contact.contact_information.update', [ + 'vault' => $contact->vault_id, + 'contact' => $contact->id, + 'info' => $info->id, + ]), + 'destroy' => route('contact.contact_information.destroy', [ + 'vault' => $contact->vault_id, + 'contact' => $contact->id, + 'info' => $info->id, + ]), + ], + ]; + } +} diff --git a/domains/Contact/ManageGroups/Services/AddContactToGroup.php b/domains/Contact/ManageGroups/Services/AddContactToGroup.php index c08ad604387..2aea5b78f29 100644 --- a/domains/Contact/ManageGroups/Services/AddContactToGroup.php +++ b/domains/Contact/ManageGroups/Services/AddContactToGroup.php @@ -9,6 +9,7 @@ use App\Models\GroupType; use App\Models\GroupTypeRole; use App\Services\BaseService; +use Carbon\Carbon; class AddContactToGroup extends BaseService implements ServiceInterface { @@ -69,6 +70,7 @@ public function execute(array $data): Group } $this->createFeedItem(); + $this->updateLastEditedDate(); return $this->group; } @@ -88,6 +90,12 @@ private function validate(): void } } + private function updateLastEditedDate(): void + { + $this->contact->last_updated_at = Carbon::now(); + $this->contact->save(); + } + private function createFeedItem(): void { $feedItem = ContactFeedItem::create([ diff --git a/domains/Contact/ManageGroups/Services/RemoveContactFromGroup.php b/domains/Contact/ManageGroups/Services/RemoveContactFromGroup.php index 3660161fa1e..12dfd2787c3 100644 --- a/domains/Contact/ManageGroups/Services/RemoveContactFromGroup.php +++ b/domains/Contact/ManageGroups/Services/RemoveContactFromGroup.php @@ -7,6 +7,7 @@ use App\Models\ContactFeedItem; use App\Models\Group; use App\Services\BaseService; +use Carbon\Carbon; class RemoveContactFromGroup extends BaseService implements ServiceInterface { @@ -59,6 +60,7 @@ public function execute(array $data): Group $this->contact->id, ]); + $this->updateLastEditedDate(); $this->createFeedItem(); return $this->group; @@ -72,6 +74,12 @@ private function validate(): void ->findOrFail($this->data['group_id']); } + private function updateLastEditedDate(): void + { + $this->contact->last_updated_at = Carbon::now(); + $this->contact->save(); + } + private function createFeedItem(): void { $feedItem = ContactFeedItem::create([ diff --git a/domains/Contact/ManageJobInformation/Services/UpdateJobInformation.php b/domains/Contact/ManageJobInformation/Services/UpdateJobInformation.php index 35e35e28f13..bdf53fb6875 100644 --- a/domains/Contact/ManageJobInformation/Services/UpdateJobInformation.php +++ b/domains/Contact/ManageJobInformation/Services/UpdateJobInformation.php @@ -7,6 +7,7 @@ use App\Models\Contact; use App\Models\ContactFeedItem; use App\Services\BaseService; +use Carbon\Carbon; class UpdateJobInformation extends BaseService implements ServiceInterface { @@ -63,6 +64,8 @@ public function execute(array $data): Contact $this->contact->job_position = $this->valueOrNull($data, 'job_position'); $this->contact->save(); + $this->updateLastEditedDate(); + ContactFeedItem::create([ 'author_id' => $this->author->id, 'contact_id' => $this->contact->id, @@ -71,4 +74,10 @@ public function execute(array $data): Contact return $this->contact; } + + private function updateLastEditedDate(): void + { + $this->contact->last_updated_at = Carbon::now(); + $this->contact->save(); + } } diff --git a/domains/Contact/ManageLifeContactEvents/Services/CreateContactLifeEvent.php b/domains/Contact/ManageLifeContactEvents/Services/CreateContactLifeEvent.php index 9ca3fb88153..e95fa23fafa 100644 --- a/domains/Contact/ManageLifeContactEvents/Services/CreateContactLifeEvent.php +++ b/domains/Contact/ManageLifeContactEvents/Services/CreateContactLifeEvent.php @@ -59,6 +59,7 @@ public function execute(array $data): ContactLifeEvent { $this->data = $data; $this->validate(); + $this->updateLastEditedDate(); $this->store(); return $this->contactLifeEvent; @@ -74,6 +75,12 @@ private function validate(): void ->findOrFail($lifeEventType->lifeEventCategory->id); } + private function updateLastEditedDate(): void + { + $this->contact->last_updated_at = Carbon::now(); + $this->contact->save(); + } + private function store(): void { $this->contactLifeEvent = ContactLifeEvent::create([ diff --git a/domains/Contact/ManagePronouns/Services/RemovePronoun.php b/domains/Contact/ManagePronouns/Services/RemovePronoun.php index 7a1131a4567..74397df57fd 100644 --- a/domains/Contact/ManagePronouns/Services/RemovePronoun.php +++ b/domains/Contact/ManagePronouns/Services/RemovePronoun.php @@ -7,6 +7,7 @@ use App\Jobs\CreateContactLog; use App\Models\Pronoun; use App\Services\BaseService; +use Carbon\Carbon; class RemovePronoun extends BaseService implements ServiceInterface { @@ -58,10 +59,17 @@ public function execute(array $data): void $this->contact->pronoun_id = null; $this->contact->save(); + $this->updateLastEditedDate(); $this->log(); } + private function updateLastEditedDate(): void + { + $this->contact->last_updated_at = Carbon::now(); + $this->contact->save(); + } + private function log(): void { CreateAuditLog::dispatch([ diff --git a/domains/Contact/ManageRelationships/Services/SetRelationship.php b/domains/Contact/ManageRelationships/Services/SetRelationship.php index 84c0f29b765..05d1e801022 100644 --- a/domains/Contact/ManageRelationships/Services/SetRelationship.php +++ b/domains/Contact/ManageRelationships/Services/SetRelationship.php @@ -8,6 +8,7 @@ use App\Models\Contact; use App\Models\RelationshipType; use App\Services\BaseService; +use Carbon\Carbon; use Illuminate\Database\Eloquent\ModelNotFoundException; class SetRelationship extends BaseService implements ServiceInterface @@ -66,6 +67,7 @@ public function execute(array $data): void // create the relationships $this->setRelationship($this->contact, $otherContact, $relationshipType); + $this->updateLastEditedDate(); $this->log($otherContact, $relationshipType); } @@ -78,6 +80,12 @@ private function setRelationship(Contact $contact, Contact $otherContact, Relati ]); } + private function updateLastEditedDate(): void + { + $this->contact->last_updated_at = Carbon::now(); + $this->contact->save(); + } + private function log(Contact $otherContact, RelationshipType $relationshipType): void { CreateAuditLog::dispatch([ diff --git a/domains/Contact/ManageRelationships/Services/UnsetRelationship.php b/domains/Contact/ManageRelationships/Services/UnsetRelationship.php index c104c53a151..d7ac927fd1d 100644 --- a/domains/Contact/ManageRelationships/Services/UnsetRelationship.php +++ b/domains/Contact/ManageRelationships/Services/UnsetRelationship.php @@ -8,6 +8,7 @@ use App\Models\Contact; use App\Models\RelationshipType; use App\Services\BaseService; +use Carbon\Carbon; use Illuminate\Database\Eloquent\ModelNotFoundException; class UnsetRelationship extends BaseService implements ServiceInterface @@ -75,6 +76,13 @@ public function execute(array $data): void } $this->log($otherContact); + $this->updateLastEditedDate(); + } + + private function updateLastEditedDate(): void + { + $this->contact->last_updated_at = Carbon::now(); + $this->contact->save(); } private function unsetRelationship(Contact $contact, Contact $otherContact): void diff --git a/lang/en/app.php b/lang/en/app.php index 1b65fb1739d..59e4341eaca 100644 --- a/lang/en/app.php +++ b/lang/en/app.php @@ -32,6 +32,7 @@ 'breadcrumb_settings_personalize' => 'Personalize your account', 'breadcrumb_settings_personalize_templates' => 'Templates', 'breadcrumb_settings_personalize_relationship_types' => 'Relationship types', + 'breadcrumb_settings_personalize_contact_information_types' => 'Contact information types', 'notification_flash_changes_saved' => 'Changes saved', @@ -58,6 +59,7 @@ 'previous' => 'Previous', 'next' => 'Next', 'view_all' => 'View all', + 'view_map' => 'View on map', 'error_title' => '👇 Oops. An error occured.', @@ -72,6 +74,7 @@ 'default_template_page_feed' => 'Feed', 'default_template_page_information' => 'Information', 'default_template_page_life_events' => 'Life events & goals', + 'default_template_page_contact' => 'Ways to connect', 'module_names' => 'Contact name', 'module_avatar' => 'Avatar', @@ -91,6 +94,7 @@ 'module_goals' => 'Goals', 'module_addresses' => 'Addresses', 'module_groups' => 'Groups', + 'module_contact_information' => 'Contact information', 'module_option_default_number_of_items_to_display' => 'Default number of items to display', diff --git a/lang/en/contact.php b/lang/en/contact.php index e79eeea70e0..c17814977db 100644 --- a/lang/en/contact.php +++ b/lang/en/contact.php @@ -1,6 +1,23 @@ 'Archive contact', + 'contact_unarchive_cta' => 'Unarchive contact', + 'contact_change_template_cta' => 'Change template', + 'contact_delete_cta' => 'Delete contact', + 'contact_archived' => 'The contact is archived', + 'contact_toggle_confirm' => 'Are you sure?', + 'contact_delete_confirm' => 'Are you sure? This will remove everything we know about this contact.', + 'contact_delete_success' => 'The contact has been deleted', + + /*************************************************************** + * MODULE: FEED + **************************************************************/ + 'feed_item_author_deleted' => 'Deleted user', 'feed_item_contact_information_updated' => 'updated the contact information', 'feed_item_important_date_created' => 'added an important date', @@ -18,14 +35,43 @@ 'feed_item_archived' => 'archived the contact', 'feed_item_unarchived' => 'unarchived the contact', + /*************************************************************** + * MODULE: GROUP + **************************************************************/ + 'group_create' => '+ Create a group', - 'contact_archive_cta' => 'Archive contact', - 'contact_unarchive_cta' => 'Unarchive contact', - 'contact_change_template_cta' => 'Change template', - 'contact_delete_cta' => 'Delete contact', - 'contact_archived' => 'The contact is archived', - 'contact_toggle_confirm' => 'Are you sure?', - 'contact_delete_confirm' => 'Are you sure? This will remove everything we know about this contact.', - 'contact_delete_success' => 'The contact has been deleted', + /*************************************************************** + * MODULE: ADDRESSES + **************************************************************/ + + 'addresses_title' => 'Addresses', + 'addresses_cta' => 'Add an address', + 'addresses_address_type' => 'Address type', + 'addresses_street' => 'Street', + 'addresses_city' => 'City', + 'addresses_province' => 'Province', + 'addresses_postal_code' => 'Postal code', + 'addresses_country' => 'Country', + 'addresses_inactive' => 'This address is not active anymore', + 'addresses_blank' => 'There are no active addresses yet.', + 'addresses_previous' => 'Previous addresses', + 'addresses_new_success' => 'The address has been created', + 'addresses_edit_success' => 'The address has been edited', + 'addresses_delete_confirm' => 'Are you sure? This will delete the address permanently.', + 'addresses_delete_success' => 'The address has been deleted', + + /*************************************************************** + * MODULE: CONTACT INFORMATION + **************************************************************/ + + 'contact_information_title' => 'Contact information', + 'contact_information_cta' => 'Add a contact information', + 'contact_information_blank' => 'There are no contact information yet.', + 'contact_information_name' => 'Content', + 'contact_information_type' => 'Type', + 'contact_information_new_success' => 'The contact information has been created', + 'contact_information_edit_success' => 'The contact information has been edited', + 'contact_information_delete_confirm' => 'Are you sure? This will delete the contact information permanently.', + 'contact_information_delete_success' => 'The contact information has been deleted', ]; diff --git a/lang/en/settings.php b/lang/en/settings.php index 27a18bbcbf9..c0780455c0f 100644 --- a/lang/en/settings.php +++ b/lang/en/settings.php @@ -189,4 +189,20 @@ 'personalize_relationship_types_update_success' =>'The relationship type has been updated', 'personalize_relationship_types_destroy_confirm' => 'Are you sure? This will delete all the relationships of this type for all the contacts that were using it.', 'personalize_relationship_types_destroy_success' =>'The relationship type has been deleted', + + /*************************************************************** + * PERSONNALIZE CONTACT TYPE INFORMATION + **************************************************************/ + + 'personalize_contact_information_types_title' => 'All the contact information types', + 'personalize_contact_information_types_cta' => 'Add a type', + 'personalize_contact_information_types_new_name' => 'Name', + 'personalize_contact_information_types_new_protocol' => 'Protocol', + 'personalize_contact_information_types_new_protocol_help' => 'A contact information can be clickable. For instance, a phone number can be clickable and launch the default application in your computer. If you do not know the protocol for the type you are adding, you can simply omit this field.', + 'personalize_contact_information_types_protocol' => 'Protocol: :name', + 'personalize_contact_information_types_blank' => 'Contact information types let you define how you can contact all your contacts (phone, email, 
).', + 'personalize_contact_information_types_new_success' => 'The contact information type has been created', + 'personalize_contact_information_types_edit_success' => 'The contact information type has been updated', + 'personalize_contact_information_types_delete_success' => 'The contact information type has been deleted', + 'personalize_contact_information_types_blank' => 'Are you sure? This will remove the contact information types from all contacts, but won’t delete the contacts themselves.', ]; diff --git a/lang/fr/app.php b/lang/fr/app.php index cd34450ee51..d77f881d523 100644 --- a/lang/fr/app.php +++ b/lang/fr/app.php @@ -32,6 +32,7 @@ 'breadcrumb_settings_personalize' => 'Personalisation du compte', 'breadcrumb_settings_personalize_templates' => 'ModĂšles', 'breadcrumb_settings_personalize_relationship_types' => 'Types de relation', + 'breadcrumb_settings_personalize_contact_information_types' => 'Types d’information de contact', 'notification_flash_changes_saved' => 'Changements effectuĂ©s', @@ -58,6 +59,7 @@ 'previous' => 'PrĂ©cĂ©dent', 'next' => 'Suivant', 'view_all' => 'Tout voir', + 'view_map' => 'Voir sur la carte', 'error_title' => '👇 Oops. Une erreur est survenue.', @@ -72,6 +74,7 @@ 'default_template_page_feed' => 'Flux', 'default_template_page_information' => 'Information', 'default_template_page_life_events' => 'ÉvĂšnements de vie et objectifs', + 'default_template_page_contact' => 'Connecter', 'module_names' => 'Nom du contact', 'module_avatar' => 'Avatar', @@ -91,6 +94,7 @@ 'module_goals' => 'Objectifs', 'module_addresses' => 'Adresses', 'module_groups' => 'Groupes', + 'module_contact_information' => 'Information de contact', 'module_option_default_number_of_items_to_display' => 'Nombre par dĂ©faut d’élĂ©ments Ă  afficher', diff --git a/lang/fr/contact.php b/lang/fr/contact.php index ade69e5172e..f7633e90a75 100644 --- a/lang/fr/contact.php +++ b/lang/fr/contact.php @@ -1,6 +1,23 @@ 'Archiver le contact', + 'contact_unarchive_cta' => 'DĂ©sarchiver le contact', + 'contact_change_template_cta' => 'Changer le modĂšle', + 'contact_delete_cta' => 'Supprimer le contact', + 'contact_archived' => 'Le contact est archivĂ©', + 'contact_toggle_confirm' => 'Êtes vous sĂ»r ?', + 'contact_delete_confirm' => 'Êtes vous sĂ»r ? Cela va supprimer tout ce que l’on connaĂźt du contact.', + 'contact_delete_success' => 'Le contact a Ă©tĂ© supprimĂ©', + + /*************************************************************** + * MODULE: FEED + **************************************************************/ + 'feed_item_author_deleted' => 'Utilisateur supprimĂ©', 'feed_item_contact_information_updated' => 'a mis Ă  jour les informations de contact', 'feed_item_important_date_created' => 'a ajoutĂ© une date importante', @@ -18,14 +35,43 @@ 'feed_item_archived' => 'a archivĂ© le contact', 'feed_item_unarchived' => 'a dĂ©sarchivĂ© le contact', + /*************************************************************** + * MODULE: GROUP + **************************************************************/ + 'group_create' => '+ CrĂ©er un groupe', - 'contact_archive_cta' => 'Archiver le contact', - 'contact_unarchive_cta' => 'DĂ©sarchiver le contact', - 'contact_change_template_cta' => 'Changer le modĂšle', - 'contact_delete_cta' => 'Supprimer le contact', - 'contact_archived' => 'Le contact est archivĂ©', - 'contact_toggle_confirm' => 'Êtes vous sĂ»r ?', - 'contact_delete_confirm' => 'Êtes vous sĂ»r ? Cela va supprimer tout ce que l’on connaĂźt du contact.', - 'contact_delete_success' => 'Le contact a Ă©tĂ© supprimĂ©', + /*************************************************************** + * MODULE: ADDRESSES + **************************************************************/ + + 'addresses_title' => 'Adresses', + 'addresses_cta' => 'Ajouter une adresse', + 'addresses_address_type' => 'Type d’adresse', + 'addresses_street' => 'Rue', + 'addresses_city' => 'Ville', + 'addresses_province' => 'Province', + 'addresses_postal_code' => 'Code postal', + 'addresses_country' => 'Pays', + 'addresses_inactive' => 'Cette adresse n’est plus active', + 'addresses_blank' => 'Il n’y a pas encore d’adresses actives.', + 'addresses_previous' => 'Adresses prĂ©cĂ©dentes', + 'addresses_new_success' => 'L’adresse a Ă©tĂ© crĂ©e', + 'addresses_edit_success' => 'L’adresse a Ă©tĂ© mise Ă  jour', + 'addresses_delete_confirm' => 'Êtes vous sĂ»r ? Cela va supprimer l’adresse de façon permanente.', + 'addresses_delete_success' => 'L’adresse a Ă©tĂ© supprimĂ©e', + + /*************************************************************** + * MODULE: CONTACT INFORMATION + **************************************************************/ + + 'contact_information_title' => 'Information de contact', + 'contact_information_cta' => 'Ajouter une information de contact', + 'contact_information_blank' => 'Il n’y a pas encore d’information de contact.', + 'contact_information_name' => 'Contenu', + 'contact_information_type' => 'Type', + 'contact_information_new_success' => 'L’information de contact a Ă©tĂ© crĂ©e', + 'contact_information_edit_success' => 'L’information de contact a Ă©tĂ© mise Ă  jour', + 'contact_information_delete_confirm' => 'Êtes vous sĂ»r ? Cela va supprimer l’information de contact de façon permanente.', + 'contact_information_delete_success' => 'L’information de contact a Ă©tĂ© supprimĂ©e', ]; diff --git a/lang/fr/settings.php b/lang/fr/settings.php index cbdbcb5c3c6..0f84d6bd6ca 100644 --- a/lang/fr/settings.php +++ b/lang/fr/settings.php @@ -189,4 +189,20 @@ 'personalize_relationship_types_update_success' => 'Le type de relation a Ă©tĂ© mis Ă  jour', 'personalize_relationship_types_destroy_confirm' => 'Êtes-vous sĂ»r ? Cela va supprimer toutes les relations de ce type pour tous les contacts qui l’utilisaient.', 'personalize_relationship_types_destroy_success' => 'Le type de relation a Ă©tĂ© supprimĂ©', + + /*************************************************************** + * PERSONNALIZE CONTACT TYPE INFORMATION + **************************************************************/ + + 'personalize_contact_information_types_title' => 'Tous les types d’information de contact', + 'personalize_contact_information_types_cta' => 'Ajouter un type', + 'personalize_contact_information_types_new_name' => 'Nom', + 'personalize_contact_information_types_new_protocol' => 'Protocole', + 'personalize_contact_information_types_new_protocol_help' => 'Une information de contact peut ĂȘtre cliquable. Par exemple, un numĂ©ro de tĂ©lĂ©phone peut ĂȘtre cliquable et ouvrir l’application par dĂ©faut sur votre ordinateur. Si vous ne connaissez pas le protocole pour le type que vous ajoutez, vous pouvez simplement omettre ce champ.', + 'personalize_contact_information_types_protocol' => 'Protocole : :name', + 'personalize_contact_information_types_blank' => 'Les types d’information de contact vous permettent de dĂ©finir les moyens de communication avec vos contacts (tĂ©lĂ©phone, courriel, 
).', + 'personalize_contact_information_types_new_success' => 'Le type d’information de contact a Ă©tĂ© crĂ©e', + 'personalize_contact_information_types_edit_success' => 'Le type d’information de contact a Ă©tĂ© mis Ă  jour', + 'personalize_contact_information_types_delete_success' => 'Le type d’information de contact a Ă©tĂ© supprimĂ©', + 'personalize_contact_information_types_blank' => 'Êtes-vous sĂ»r ? Cela va supprimer toutes les informations de contact de ce type pour tous les contacts qui l’utilisaient, sans supprimer les contacts eux mĂȘmes.', ]; diff --git a/resources/js/Pages/Settings/Personalize/ContactInformationTypes/Index.vue b/resources/js/Pages/Settings/Personalize/ContactInformationTypes/Index.vue index 34c0b7d9f63..8e894979431 100644 --- a/resources/js/Pages/Settings/Personalize/ContactInformationTypes/Index.vue +++ b/resources/js/Pages/Settings/Personalize/ContactInformationTypes/Index.vue @@ -54,7 +54,7 @@ -
  • Contact information types
  • +
  • {{ $t('app.breadcrumb_settings_personalize_contact_information_types') }}
  • @@ -64,10 +64,12 @@
    -

    ☎ All the contact information types

    +

    + ☎ {{ $t('settings.personalize_contact_information_types_title') }} +

    @@ -83,7 +85,7 @@
    @@ -110,7 +112,7 @@ :text="$t('app.cancel')" :classes="'mr-3'" @click="createContactInformationTypeModalShown = false" /> - + @@ -127,7 +129,11 @@
    {{ contactInformationType.name }} [Protocol: {{ contactInformationType.protocol }}][{{ + $t('settings.personalize_contact_information_types_protocol', { + name: contactInformationType.protocol, + }) + }}]
    @@ -136,13 +142,13 @@
  • - Rename + {{ $t('app.rename') }}
  • - Delete + {{ $t('app.delete') }}
  • @@ -158,7 +164,7 @@

    - Contact information types let you define how you can contact all your contacts (phone, email, 
). + {{ $t('settings.personalize_contact_information_types_blank') }}

    @@ -274,7 +280,7 @@ export default { axios .post(this.data.url.contact_information_type_store, this.form) .then((response) => { - this.flash('The contact information type has been created', 'success'); + this.flash(this.$t('settings.personalize_contact_information_types_new_success'), 'success'); this.localContactInformationTypes.unshift(response.data.data); this.loadingState = null; this.createContactInformationTypeModalShown = false; @@ -291,7 +297,7 @@ export default { axios .put(contactInformationType.url.update, this.form) .then((response) => { - this.flash('The contact information type has been updated', 'success'); + this.flash(this.$t('settings.personalize_contact_information_types_edit_success'), 'success'); this.localContactInformationTypes[ this.localContactInformationTypes.findIndex((x) => x.id === contactInformationType.id) ] = response.data.data; @@ -305,15 +311,11 @@ export default { }, destroy(contactInformationType) { - if ( - confirm( - "Are you sure? This will remove the contact information types from all contacts, but won't delete the contacts themselves.", - ) - ) { + if (confirm(this.$t('settings.personalize_contact_information_types_blank'))) { axios .delete(contactInformationType.url.destroy) .then((response) => { - this.flash('The contact information type has been deleted', 'success'); + this.flash(this.$t('settings.personalize_contact_information_types_delete_success'), 'success'); var id = this.localContactInformationTypes.findIndex((x) => x.id === contactInformationType.id); this.localContactInformationTypes.splice(id, 1); }) diff --git a/resources/js/Pages/Vault/Contact/Show.vue b/resources/js/Pages/Vault/Contact/Show.vue index ee560348f03..7872c427cb8 100644 --- a/resources/js/Pages/Vault/Contact/Show.vue +++ b/resources/js/Pages/Vault/Contact/Show.vue @@ -115,17 +115,17 @@ -
    -
      -
    • +
      +
      +
      + class="inline-block border-b-2 border-transparent px-2 pb-2 hover:border-gray-200"> {{ page.name }} -
    • -
    +
    + @@ -152,6 +152,8 @@ + + @@ -181,6 +183,7 @@ import Pets from '@/Shared/Modules/Pets'; import Goals from '@/Shared/Modules/Goals'; import Addresses from '@/Shared/Modules/Addresses'; import Groups from '@/Shared/Modules/Groups'; +import ContactInformation from '@/Shared/Modules/ContactInformation'; export default { components: { @@ -203,6 +206,7 @@ export default { Goals, Addresses, Groups, + ContactInformation, }, props: { @@ -236,6 +240,7 @@ export default { goals: [], addresses: [], groups: [], + contactInformation: [], }; }, @@ -328,6 +333,11 @@ export default { if (this.data.modules.findIndex((x) => x.type == 'groups') > -1) { this.groups = this.data.modules[this.data.modules.findIndex((x) => x.type == 'groups')].data; } + + if (this.data.modules.findIndex((x) => x.type == 'contact_information') > -1) { + this.contactInformation = + this.data.modules[this.data.modules.findIndex((x) => x.type == 'contact_information')].data; + } } }, diff --git a/resources/js/Shared/Modules/Addresses.vue b/resources/js/Shared/Modules/Addresses.vue index 633fee3dce4..3e3bd1746c2 100644 --- a/resources/js/Shared/Modules/Addresses.vue +++ b/resources/js/Shared/Modules/Addresses.vue @@ -37,14 +37,15 @@ + d="M17.657 16.657L13.414 20.9a1.998 1.998 0 01-2.827 0l-4.244-4.243a8 8 0 1111.314 0z" /> + - Addresses + {{ $t('contact.addresses_title') }} @@ -68,7 +69,7 @@ :required="false" :placeholder="$t('app.choose_value')" :dropdown-class="'block w-full'" - :label="'Address type'" /> + :label="$t('contact.addresses_address_type')" /> @@ -76,7 +77,7 @@ @@ -173,15 +174,15 @@ @@ -200,7 +201,7 @@ :required="false" :placeholder="$t('app.choose_value')" :dropdown-class="'block w-full'" - :label="'Address type'" /> + :label="$t('contact.addresses_address_type')" /> @@ -208,7 +209,7 @@ @@ -289,7 +290,7 @@
    -

    There are no active addresses yet.

    +

    {{ $t('contact.addresses_blank') }}

    @@ -297,7 +298,7 @@ v-if="localInactiveAddresses.length > 0" @click="toggleInactiveAdresses" class="mx-4 mb-2 cursor-pointer text-xs text-blue-500 hover:underline"> - Previous addresses ({{ localInactiveAddresses.length }}) + {{ $t('contact.addresses_previous') }} ({{ localInactiveAddresses.length }})

    @@ -322,15 +323,15 @@ @@ -349,7 +350,7 @@ :required="false" :placeholder="$t('app.choose_value')" :dropdown-class="'block w-full'" - :label="'Address type'" /> + :label="$t('contact.addresses_address_type')" /> @@ -357,7 +358,7 @@ @@ -536,7 +537,7 @@ export default { axios .post(this.data.url.store, this.form) .then((response) => { - this.flash('The address has been created', 'success'); + this.flash(this.$t('contact.addresses_new_success'), 'success'); if (this.form.is_past_address) { this.localInactiveAddresses.unshift(response.data.data); @@ -560,7 +561,7 @@ export default { .put(address.url.update, this.form) .then((response) => { this.loadingState = ''; - this.flash('The address has been edited', 'success'); + this.flash(this.$t('contact.addresses_edit_success'), 'success'); if (this.form.is_past_address) { this.localInactiveAddresses[this.localInactiveAddresses.findIndex((x) => x.id === address.id)] = @@ -578,11 +579,11 @@ export default { }, destroy(address) { - if (confirm('Are you sure? This will delete the address permanently.')) { + if (confirm(this.$t('contact.addresses_delete_confirm'))) { axios .delete(address.url.destroy) .then((response) => { - this.flash('The address has been deleted', 'success'); + this.flash(this.$t('contact.addresses_delete_success'), 'success'); var id = this.localActiveAddresses.findIndex((x) => x.id === address.id); if (address.is_past_address) { diff --git a/resources/js/Shared/Modules/ContactInformation.vue b/resources/js/Shared/Modules/ContactInformation.vue new file mode 100644 index 00000000000..bd076afba4e --- /dev/null +++ b/resources/js/Shared/Modules/ContactInformation.vue @@ -0,0 +1,288 @@ + + + + + diff --git a/resources/js/Shared/Modules/Pets.vue b/resources/js/Shared/Modules/Pets.vue index 4e4a7bc78a4..38e50f784f9 100644 --- a/resources/js/Shared/Modules/Pets.vue +++ b/resources/js/Shared/Modules/Pets.vue @@ -242,15 +242,15 @@ export default { }); }, - update(reminder) { + update(pet) { this.loadingState = 'loading'; axios - .put(reminder.url.update, this.form) + .put(pet.url.update, this.form) .then((response) => { this.loadingState = ''; this.flash('The pet has been edited', 'success'); - this.localPets[this.localPets.findIndex((x) => x.id === reminder.id)] = response.data.data; + this.localPets[this.localPets.findIndex((x) => x.id === pet.id)] = response.data.data; this.editedPetId = 0; }) .catch((error) => { @@ -259,13 +259,13 @@ export default { }); }, - destroy(reminder) { + destroy(pet) { if (confirm('Are you sure? This will delete the pet permanently.')) { axios - .delete(reminder.url.destroy) + .delete(pet.url.destroy) .then((response) => { this.flash('The pet has been deleted', 'success'); - var id = this.localPets.findIndex((x) => x.id === reminder.id); + var id = this.localPets.findIndex((x) => x.id === pet.id); this.localPets.splice(id, 1); }) .catch((error) => { diff --git a/routes/web.php b/routes/web.php index 0017b50ff28..3da9b988973 100644 --- a/routes/web.php +++ b/routes/web.php @@ -9,6 +9,7 @@ use App\Contact\ManageContact\Web\Controllers\ContactTemplateController; use App\Contact\ManageContactAddresses\Web\Controllers\ContactModuleAddressController; use App\Contact\ManageContactImportantDates\Web\Controllers\ContactImportantDatesController; +use App\Contact\ManageContactInformation\Web\Controllers\ContactInformationController; use App\Contact\ManageGoals\Web\Controllers\ContactModuleGoalController; use App\Contact\ManageGoals\Web\Controllers\ContactModuleStreakController; use App\Contact\ManageGroups\Web\Controllers\ContactModuleGroupController; @@ -170,6 +171,11 @@ Route::put('addresses/{address}', [ContactModuleAddressController::class, 'update'])->name('contact.address.update'); Route::delete('addresses/{address}', [ContactModuleAddressController::class, 'destroy'])->name('contact.address.destroy'); + // contact information + Route::post('contactInformation', [ContactInformationController::class, 'store'])->name('contact.contact_information.store'); + Route::put('contactInformation/{info}', [ContactInformationController::class, 'update'])->name('contact.contact_information.update'); + Route::delete('contactInformation/{info}', [ContactInformationController::class, 'destroy'])->name('contact.contact_information.destroy'); + // loans Route::post('loans', [ContactModuleLoanController::class, 'store'])->name('contact.loan.store'); Route::put('loans/{loan}', [ContactModuleLoanController::class, 'update'])->name('contact.loan.update'); diff --git a/tests/Unit/Domains/Contact/ManageContactInformation/Services/DestroyContactInformationTest.php b/tests/Unit/Domains/Contact/ManageContactInformation/Services/DestroyContactInformationTest.php index a7f3ba6aa77..3f7dd657fab 100644 --- a/tests/Unit/Domains/Contact/ManageContactInformation/Services/DestroyContactInformationTest.php +++ b/tests/Unit/Domains/Contact/ManageContactInformation/Services/DestroyContactInformationTest.php @@ -4,8 +4,6 @@ use App\Contact\ManageContactInformation\Services\DestroyContactInformation; use App\Exceptions\NotEnoughPermissionException; -use App\Jobs\CreateAuditLog; -use App\Jobs\CreateContactLog; use App\Models\Account; use App\Models\Contact; use App\Models\ContactInformation; @@ -146,7 +144,6 @@ private function executeService(User $author, Account $account, Vault $vault, Co 'vault_id' => $vault->id, 'author_id' => $author->id, 'contact_id' => $contact->id, - 'contact_information_type_id' => $type->id, 'contact_information_id' => $information->id, ]; @@ -155,13 +152,5 @@ private function executeService(User $author, Account $account, Vault $vault, Co $this->assertDatabaseMissing('contact_information', [ 'id' => $information->id, ]); - - Queue::assertPushed(CreateAuditLog::class, function ($job) { - return $job->auditLog['action_name'] === 'contact_information_destroyed'; - }); - - Queue::assertPushed(CreateContactLog::class, function ($job) { - return $job->contactLog['action_name'] === 'contact_information_destroyed'; - }); } } diff --git a/tests/Unit/Domains/Contact/ManageContactInformation/Web/ViewHelpers/ModuleContactInformationViewHelperTest.php b/tests/Unit/Domains/Contact/ManageContactInformation/Web/ViewHelpers/ModuleContactInformationViewHelperTest.php new file mode 100644 index 00000000000..9795bd788f9 --- /dev/null +++ b/tests/Unit/Domains/Contact/ManageContactInformation/Web/ViewHelpers/ModuleContactInformationViewHelperTest.php @@ -0,0 +1,94 @@ +create(); + $user = User::factory()->create(); + $type = ContactInformationType::factory()->create([ + 'account_id' => $user->account_id, + 'name' => 'Facebook shit', + 'protocol' => 'mailto:', + ]); + ContactInformation::factory()->create([ + 'contact_id' => $contact->id, + 'type_id' => $type->id, + ]); + + $array = ModuleContactInformationViewHelper::data($contact, $user); + + $this->assertEquals( + 3, + count($array) + ); + + $this->assertArrayHasKey('contact_information', $array); + $this->assertArrayHasKey('contact_information_types', $array); + $this->assertArrayHasKey('url', $array); + + $this->assertEquals( + [ + 0 => [ + 'id' => $type->id, + 'name' => $type->name, + ], + ], + $array['contact_information_types']->toArray() + ); + + $this->assertEquals( + [ + 'store' => env('APP_URL') . '/vaults/' . $contact->vault->id . '/contacts/' . $contact->id . '/contactInformation', + ], + $array['url'] + ); + } + + /** @test */ + public function it_gets_the_data_transfer_object(): void + { + $contact = Contact::factory()->create(); + $type = ContactInformationType::factory()->create([ + 'name' => 'Facebook shit', + 'protocol' => 'mailto:', + 'can_be_deleted' => true + ]); + $info = ContactInformation::factory()->create([ + 'contact_id' => $contact->id, + 'type_id' => $type->id, + ]); + + $array = ModuleContactInformationViewHelper::dto($contact, $info); + + $this->assertEquals( + [ + 'id' => $info->id, + 'label' => 'Facebook shit', + 'data' => 'mailto:'.$info->data, + 'contact_information_type' => [ + 'id' => $type->id, + 'name' => 'Facebook shit', + ], + 'url' => [ + 'update' => env('APP_URL') . '/vaults/' . $contact->vault->id . '/contacts/' . $contact->id . '/contactInformation/' . $info->id, + 'destroy' => env('APP_URL') . '/vaults/' . $contact->vault->id . '/contacts/' . $contact->id . '/contactInformation/' . $info->id, + ], + ], + $array + ); + } +} diff --git a/tests/Unit/Models/ContactInformationTest.php b/tests/Unit/Models/ContactInformationTest.php index d38f00599ca..8d20c01be20 100644 --- a/tests/Unit/Models/ContactInformationTest.php +++ b/tests/Unit/Models/ContactInformationTest.php @@ -3,6 +3,7 @@ namespace Tests\Unit\Models; use App\Models\ContactInformation; +use App\Models\ContactInformationType; use Illuminate\Foundation\Testing\DatabaseTransactions; use Tests\TestCase; @@ -25,4 +26,36 @@ public function it_has_one_type() $this->assertTrue($info->contactInformationType()->exists()); } + + /** @test */ + public function it_gets_the_name(): void + { + $contactInformationType = ContactInformationType::factory()->create([ + 'can_be_deleted' => true, + 'name' => 'Facebook', + ]); + $contactInformation = ContactInformation::factory()->create([ + 'type_id' => $contactInformationType->id, + 'data' => 'Test', + ]); + + $this->assertEquals( + 'Facebook', + $contactInformation->name + ); + + $contactInformationType = ContactInformationType::factory()->create([ + 'can_be_deleted' => false, + 'name' => 'Facebook', + ]); + $contactInformation = ContactInformation::factory()->create([ + 'type_id' => $contactInformationType->id, + 'data' => 'Test', + ]); + + $this->assertEquals( + 'Test', + $contactInformation->name + ); + } }