From 981a639013e4b3124a84450b6aeca97dcf0208c2 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Sat, 9 Oct 2021 13:01:00 +0200 Subject: [PATCH] fix: allow delete any reminder + fix reminder edit data (#5582) --- .../Contacts/RemindersController.php | 14 ++++++- app/Http/Controllers/ContactsController.php | 2 +- app/Models/Contact/Contact.php | 10 ----- app/Models/Contact/Reminder.php | 11 ++++++ .../views/people/reminders/form.blade.php | 38 ++++++++----------- .../views/people/reminders/index.blade.php | 18 ++++----- 6 files changed, 49 insertions(+), 44 deletions(-) diff --git a/app/Http/Controllers/Contacts/RemindersController.php b/app/Http/Controllers/Contacts/RemindersController.php index 62f5ab056f8..c48fdbc0a79 100644 --- a/app/Http/Controllers/Contacts/RemindersController.php +++ b/app/Http/Controllers/Contacts/RemindersController.php @@ -36,11 +36,16 @@ public function create(Contact $contact) */ public function store(Request $request, Contact $contact) { + $frequency_type = $request->input('frequency_type'); + if ($frequency_type === 'recurrent') { + $frequency_type = $request->input('frequency_number_select'); + } + $data = [ 'account_id' => auth()->user()->account_id, 'contact_id' => $contact->id, 'initial_date' => $request->input('initial_date'), - 'frequency_type' => $request->input('frequency_type'), + 'frequency_type' => $frequency_type, 'frequency_number' => is_null($request->input('frequency_number')) ? 1 : $request->input('frequency_number'), 'title' => $request->input('title'), 'description' => $request->input('description'), @@ -77,12 +82,17 @@ public function edit(Contact $contact, Reminder $reminder) */ public function update(Request $request, Contact $contact, Reminder $reminder) { + $frequency_type = $request->input('frequency_type'); + if ($frequency_type === 'recurrent') { + $frequency_type = $request->input('frequency_number_select'); + } + $data = [ 'account_id' => auth()->user()->account_id, 'contact_id' => $contact->id, 'reminder_id' => $reminder->id, 'initial_date' => $request->input('initial_date'), - 'frequency_type' => $request->input('frequency_type'), + 'frequency_type' => $frequency_type, 'frequency_number' => is_null($request->input('frequency_number')) ? 1 : $request->input('frequency_number'), 'title' => $request->input('title'), 'description' => $request->input('description'), diff --git a/app/Http/Controllers/ContactsController.php b/app/Http/Controllers/ContactsController.php index 1ac218eb091..fc76cb43669 100644 --- a/app/Http/Controllers/ContactsController.php +++ b/app/Http/Controllers/ContactsController.php @@ -281,7 +281,7 @@ public function show(Contact $contact) $workRelationships->sortByCollator('relationshipTypeLocalized'); // reminders - $reminders = $contact->activeReminders; + $reminders = $contact->reminders()->active()->get(); $relevantRemindersFromRelatedContacts = $contact->getBirthdayRemindersAboutRelatedContacts(); $reminders = $reminders->merge($relevantRemindersFromRelatedContacts); // now we need to sort the reminders by next date they will be triggered diff --git a/app/Models/Contact/Contact.php b/app/Models/Contact/Contact.php index 500d6e0b14d..0ff757ac7fb 100644 --- a/app/Models/Contact/Contact.php +++ b/app/Models/Contact/Contact.php @@ -271,16 +271,6 @@ public function reminders() return $this->hasMany(Reminder::class); } - /** - * Get only the active reminder records associated with the contact. - * - * @return HasMany - */ - public function activeReminders() - { - return $this->hasMany(Reminder::class)->active(); - } - /** * Get the task records associated with the contact. * diff --git a/app/Models/Contact/Reminder.php b/app/Models/Contact/Reminder.php index 8cef4f5d7eb..99f9ebbe7b8 100644 --- a/app/Models/Contact/Reminder.php +++ b/app/Models/Contact/Reminder.php @@ -88,6 +88,17 @@ public function scopeActive($query) return $query->where('inactive', false); } + /** + * Test if this reminder is the contact's birthday reminder. + * + * @return bool + */ + public function isBirthdayReminder(): bool + { + return $this->contact !== null + && $this->contact->birthday_reminder_id === $this->id; + } + /** * Calculate the next expected date for this reminder. * diff --git a/resources/views/people/reminders/form.blade.php b/resources/views/people/reminders/form.blade.php index 69b488e9f0e..b0816cc91ff 100644 --- a/resources/views/people/reminders/form.blade.php +++ b/resources/views/people/reminders/form.blade.php @@ -19,29 +19,24 @@
- @if (is_null($reminder->initial_date)) + @if (is_null($reminder->initial_date)) + value="{{ old('initial_date') ?? now(\App\Helpers\DateHelper::getTimezone())->toDateString() }}" @else - + value="{{ old('initial_date') ?? $reminder->initial_date->toDateString() }}" @endif + min="{{ now(\App\Helpers\DateHelper::getTimezone())->toDateString() }}" + max="{{ now(\App\Helpers\DateHelper::getTimezone())->addYears(10)->toDateString() }}" + >
{{-- One time reminder --}}
@@ -49,25 +44,24 @@ {{-- Recurring reminder --}}
-