Skip to content

Commit

Permalink
fix: allow delete any reminder + fix reminder edit data (#5582)
Browse files Browse the repository at this point in the history
  • Loading branch information
asbiin authored Oct 9, 2021
1 parent 1b36e48 commit 981a639
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 44 deletions.
14 changes: 12 additions & 2 deletions app/Http/Controllers/Contacts/RemindersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
Expand Down Expand Up @@ -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'),
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ContactsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 0 additions & 10 deletions app/Models/Contact/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
11 changes: 11 additions & 0 deletions app/Models/Contact/Reminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
38 changes: 16 additions & 22 deletions resources/views/people/reminders/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,55 +19,49 @@
<div class="form-group">
<label for="initial_date">{{ trans('people.reminders_add_next_time') }}</label>

@if (is_null($reminder->initial_date))
<input type="date" id="initial_date" name="initial_date" class="form-control"
value="{{ old('initial_date') ?? now(\App\Helpers\DateHelper::getTimezone())->toDateString() }}"
min="{{ now(\App\Helpers\DateHelper::getTimezone())->toDateString() }}"
max="{{ now(\App\Helpers\DateHelper::getTimezone())->addYears(10)->toDateString() }}"
>
@if (is_null($reminder->initial_date))
value="{{ old('initial_date') ?? now(\App\Helpers\DateHelper::getTimezone())->toDateString() }}"
@else
<input type="date" id="initial_date" name="initial_date" class="form-control"
value="{{ old('initial_date') ?? $reminder->initial_date->toDateString() }}"
min="{{ now(\App\Helpers\DateHelper::getTimezone())->toDateString() }}"
max="{{ now(\App\Helpers\DateHelper::getTimezone())->addYears(10)->toDateString() }}"
>
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() }}"
>

<fieldset class="form-group frequency{{ $errors->has('frequency_type') ? ' has-error' : '' }}">

{{-- One time reminder --}}
<div class="form-check">
<label class="form-check-label" for="frequency_type_once">
<input type="radio" id="frequency_type_once" class="form-check-input" name="frequency_type" value="one_time"
v-model="reminders_frequency"
<input type="radio" id="frequency_type_once" class="form-check-input" name="frequency_type"
:value="'one_time'"
:checked="'one_time'"
{{ $reminder->frequency_type === 'one_time' ? 'checked' : '' }}
>
{{ trans('people.reminders_add_once') }}
</label>
</div>

{{-- Recurring reminder --}}
<div class="form-check">
<label class="form-check-label">
<input type="radio" class="form-check-input" name="reminderRecurringFrequency" value="recurring"
v-model="reminders_frequency"
<label class="form-check-label" for="frequency_type_recurrent">
<input type="radio" id="frequency_type_recurrent" class="form-check-input" name="frequency_type"
:value="'recurrent'"
:checked="'recurrent'"
{{ $reminder->frequency_type !== null && $reminder->frequency_type !== 'one_time' ? 'checked' : '' }}
>

{{ trans('people.reminders_add_recurrent') }}

<input type="number" class="form-control frequency-type" name="frequency_number"
value="1"
value="{{ $reminder->frequency_number ?? 1 }}"
min="1"
max="115"
:disabled="reminders_frequency == 'one_time'">

<select name="frequency_type" :disabled="reminders_frequency == 'one_time'">
<option value="week">{{ trans('people.reminders_type_week') }}</option>
<option value="month">{{ trans('people.reminders_type_month') }}</option>
<option value="year">{{ trans('people.reminders_type_year') }}</option>
<select name="frequency_number_select" :disabled="reminders_frequency == 'one_time'">
<option value="week"{{ $reminder->frequency_type === 'week' ? 'selected' : '' }}>{{ trans('people.reminders_type_week') }}</option>
<option value="month"{{ $reminder->frequency_type === 'month' ? 'selected' : '' }}>{{ trans('people.reminders_type_month') }}</option>
<option value="year"{{ $reminder->frequency_type === 'year' ? 'selected' : '' }}>{{ trans('people.reminders_type_year') }}</option>
</select>

{{ trans('people.reminders_add_starting_from') }}
Expand Down
18 changes: 9 additions & 9 deletions resources/views/people/reminders/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,18 +57,18 @@

<div class="table-cell list-actions">
{{-- Only display this if the reminder can be deleted - ie if it's not a reminder added automatically for birthdates --}}
@if ($reminder->delible)
@if ($reminder->delible || ! $reminder->isBirthdayReminder())
<a href="{{ route('people.reminders.edit', [$contact, $reminder]) }}" class="edit">
<i class="fa fa-pencil-square-o" aria-hidden="true"></i>
</a>
<form method="POST" action="{{ route('people.reminders.destroy', [$contact, $reminder]) }}" class="di">
@method('DELETE')
@csrf
<confirm message="{{ trans('people.reminders_delete_confirmation') }}">
<i class="fa fa-trash-o" aria-hidden="true"></i>
</confirm>
</form>
@endif
@endif
<form method="POST" action="{{ route('people.reminders.destroy', [$contact, $reminder]) }}" class="di">
@method('DELETE')
@csrf
<confirm message="{{ trans('people.reminders_delete_confirmation') }}">
<i class="fa fa-trash-o" aria-hidden="true"></i>
</confirm>
</form>
</div>

</li>
Expand Down

0 comments on commit 981a639

Please sign in to comment.