Skip to content

Commit

Permalink
feat: reminders summary (monicahq/chandler#153)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored Jul 22, 2022
1 parent f816284 commit 6aa5267
Show file tree
Hide file tree
Showing 19 changed files with 482 additions and 30 deletions.
10 changes: 5 additions & 5 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,14 @@ public static function dataForTemplatePage(Contact $contact, User $user, Templat
'group_summary_information' => GroupsViewHelper::summary($contact),
'modules' => self::modules($templatePage, $contact, $user),
'options' => [
'can_be_archived' => $user->getContactInVault($contact->vault)->id !== $contact->id,
'can_be_deleted' => $user->getContactInVault($contact->vault)->id !== $contact->id,
],
'url' => [
'toggle_archive' => route('contact.archive.update', [
'vault' => $contact->vault_id,
'contact' => $contact->id,
]),
'update_template' => route('contact.blank', [
'vault' => $contact->vault_id,
'contact' => $contact->id,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace App\Vault\ManageVault\Web\Controllers;

use App\Http\Controllers\Controller;
use App\Models\Vault;
use App\Vault\ManageVault\Web\ViewHelpers\VaultIndexViewHelper;
use App\Vault\ManageVault\Web\ViewHelpers\VaultReminderIndexViewHelper;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Inertia\Inertia;

class VaultReminderController extends Controller
{
public function index(Request $request, int $vaultId)
{
$vault = Vault::findOrFail($vaultId);

return Inertia::render('Vault/Dashboard/Reminder/Index', [
'layoutData' => VaultIndexViewHelper::layoutData($vault),
'data' => VaultReminderIndexViewHelper::data($vault, Auth::user()),
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

namespace App\Vault\ManageVault\Web\ViewHelpers;

use App\Helpers\DateHelper;
use App\Models\ContactReminder;
use App\Models\User;
use App\Models\UserNotificationChannel;
use App\Models\Vault;
use Carbon\Carbon;
use DB;
use Illuminate\Support\Collection;

class VaultReminderIndexViewHelper
{
/**
* Get all the reminders planned in the next 12 months.
*
* @param Vault $vault
* @param User $user
*
* @return Collection
*/
public static function data(Vault $vault, User $user): Collection
{
// this query is a bit long and tough to do, and it could surely
// be optimized if I knew how to properly join queries
// first we get all the users the vault
$usersInVaultIds = $vault->users->pluck('id')->toArray();

// then we get all the user notification channels for those users
$userNotificationChannelIds = UserNotificationChannel::whereIn('user_id', $usersInVaultIds)
->get()
->pluck('id')
->unique('id')
->toArray();

// then we get all the contact reminders scheduled for those channels
$currentDate = Carbon::now()->copy();
$currentDate->second = 0;

$contactRemindersScheduled = DB::table('contact_reminder_scheduled')
->whereDate('scheduled_at', '<=', $currentDate->addDays(365))
->where('triggered_at', null)
->whereIn('user_notification_channel_id', $userNotificationChannelIds)
->get();

// create a loop looping over the next 12 months
$currentDate = Carbon::now()->copy();
$monthsReminderCollection = collect();
for ($month = 0; $month < 12; $month++) {
$date = $currentDate->copy();
$date->addMonth($month);

$remindersCollection = collect();
foreach ($contactRemindersScheduled as $contactReminderScheduled) {
$scheduledAtDate = Carbon::createFromFormat('Y-m-d H:i:s', $contactReminderScheduled->scheduled_at);

if ($scheduledAtDate->month !== $date->month) {
continue;
}

$reminder = ContactReminder::where('id', $contactReminderScheduled->contact_reminder_id)->with('contact')->first();
$contact = $reminder->contact;

$remindersCollection->push([
'id' => $reminder->id,
'label' => $reminder->label,
'scheduled_at' => DateHelper::format($scheduledAtDate, $user),
'contact' => [
'id' => $contact->id,
'name' => $contact->name,
'avatar' => $contact->avatar,
'url' => [
'show' => route('contact.show', [
'vault' => $contact->vault_id,
'contact' => $contact->id,
]),
],
],
]);
}

$monthsReminderCollection->push([
'id' => $month,
'month' => DateHelper::formatMonthAndYear($date),
'reminders' => $remindersCollection,
]);
}

return $monthsReminderCollection;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static function lastUpdatedContacts(Vault $vault): Collection
});
}

public static function upcomingReminders(Vault $vault, User $user): Collection
public static function upcomingReminders(Vault $vault, User $user): array
{
// this query is a bit long and tough to do, and it could surely
// be optimized if I knew how to properly join queries
Expand Down Expand Up @@ -85,6 +85,13 @@ public static function upcomingReminders(Vault $vault, User $user): Collection
]);
}

return $remindersCollection;
return [
'reminders' => $remindersCollection,
'url' => [
'index' => route('vault.reminder.index', [
'vault' => $vault->id,
]),
],
];
}
}
4 changes: 3 additions & 1 deletion lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@

'breadcrumb_location' => 'You are here:',
'breadcrumb_vault_index' => 'All the vaults',
'breadcrumb_vault_create' => 'add a vault',
'breadcrumb_vault_create' => 'Add a vault',
'breadcrumb_dashboard_index' => 'Dashboard',
'breadcrumb_dashboard_reminders' => 'All the planned reminders',
'breadcrumb_contact_index' => 'Contacts',
'breadcrumb_contact_show' => 'Profile of :name',
'breadcrumb_contact_create' => 'Create a contact',
Expand Down
11 changes: 10 additions & 1 deletion lang/en/contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,14 @@
'feed_item_archived' => 'archived the contact',
'feed_item_unarchived' => 'unarchived the contact',

'group_create' => '+ Create a new 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',
];
7 changes: 7 additions & 0 deletions lang/en/vault.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
'dashboard_reminders_title' => 'Reminders for the next 30 days',
'dashboard_reminders_blank' => 'No planned reminders.',

/***************************************************************
* VAULT DASHBOARD REMINDERS
**************************************************************/

'reminders_title' => 'Reminders planned in the next 12 months',
'reminders_blank' => 'No entries for this month',

/***************************************************************
* VAULT SETTINGS
**************************************************************/
Expand Down
2 changes: 2 additions & 0 deletions lang/fr/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
'breadcrumb_location' => 'Vous êtes ici :',
'breadcrumb_vault_index' => 'Toutes les voûtes',
'breadcrumb_vault_create' => 'Ajouter une nouvelle voûte',
'breadcrumb_dashboard_index' => 'Tableau de bord',
'breadcrumb_dashboard_reminders' => 'Tous les rappels planifiés',
'breadcrumb_contact_index' => 'Contacts',
'breadcrumb_contact_show' => 'Profil de :name',
'breadcrumb_contact_create' => 'Créer un contact',
Expand Down
31 changes: 31 additions & 0 deletions lang/fr/contact.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

return [
'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',
'feed_item_important_date_updated' => 'a mis à jour une date importante',
'feed_item_important_date_destroyed' => 'a supprimé une date importante',
'feed_item_label_assigned' => 'a assigné une étiquette',
'feed_item_label_removed' => 'a supprimé une étiquette',
'feed_item_note_created' => 'a écrit une note',
'feed_item_note_updated' => 'a mis à jour une note',
'feed_item_note_destroyed' => 'a supprimé une note',
'feed_item_job_information_updated' => 'a mis à jour les informations professionnelles',
'feed_item_goal_created' => 'a crée un but',
'feed_item_added_to_group' => 'a ajouté le contact à un groupe',
'feed_item_removed_from_group' => 'a supprimé le contact à un groupe',
'feed_item_archived' => 'a archivé le contact',
'feed_item_unarchived' => 'a désarchivé le contact',

'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é',
];
7 changes: 7 additions & 0 deletions lang/fr/vault.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,13 @@
'dashboard_reminders_title' => 'Rappels dans les 30 prochains jours',
'dashboard_reminders_blank' => 'Aucun rappel planifié.',

/***************************************************************
* VAULT DASHBOARD REMINDERS
**************************************************************/

'reminders_title' => 'Rappels planifiés dans les 12 prochains mois',
'reminders_blank' => 'Pas de rappels pour ce mois',

/***************************************************************
* VAULT SETTINGS
**************************************************************/
Expand Down
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
</UnsafeInstantiation>

<UndefinedPropertyAssignment errorLevel="suppress"/>
<PossiblyInvalidArrayOffset errorLevel="suppress"/>

</issueHandlers>
</psalm>
2 changes: 1 addition & 1 deletion resources/js/Pages/Vault/Contact/Notes/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
</nav>

<main class="sm:mt-18 relative">
<div class="mx-auto max-w-6xl px-2 py-2 sm:py-6 sm:px-6 lg:px-8">
<div class="mx-auto max-w-3xl px-2 py-2 sm:py-6 sm:px-6 lg:px-8">
<notes :data="data" :module-mode="false" :paginator="paginator" />
</div>
</main>
Expand Down
32 changes: 17 additions & 15 deletions resources/js/Pages/Vault/Contact/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
<!-- banner if contact is archived -->
<!-- this is based on the `listed` boolean on the contact object -->
<div v-if="!data.listed" class="mb-8 rounded-lg border border-gray-300 px-3 py-2 text-center">
<span class="mr-4">🕸️</span> The contact is archived <span class="ml-4">🕷️</span>
<span class="mr-4">🕸️</span> {{ $t('contact.contact_archived') }} <span class="ml-4">🕷️</span>
</div>

<div class="special-grid grid grid-cols-1 gap-6 sm:grid-cols-3">
Expand All @@ -74,22 +74,24 @@

<ul class="text-xs">
<li v-if="data.listed && data.options.can_be_archived" class="mb-2">
<inertia-link @click.prevent="toggleArchive()" class="cursor-pointer text-blue-500 hover:underline"
>Archive contact</inertia-link
>
<inertia-link @click.prevent="toggleArchive()" class="cursor-pointer text-blue-500 hover:underline">{{
$t('contact.contact_archive_cta')
}}</inertia-link>
</li>
<li v-if="!data.listed" class="mb-2">
<inertia-link @click.prevent="toggleArchive()" class="cursor-pointer text-blue-500 hover:underline"
>Unarchive contact</inertia-link
>
<inertia-link @click.prevent="toggleArchive()" class="cursor-pointer text-blue-500 hover:underline">{{
$t('contact.contact_unarchive_cta')
}}</inertia-link>
</li>
<li class="mb-2">
<inertia-link :href="data.url.update_template" class="cursor-pointer text-blue-500 hover:underline"
>Change template</inertia-link
>
<inertia-link :href="data.url.update_template" class="cursor-pointer text-blue-500 hover:underline">{{
$t('contact.contact_change_template_cta')
}}</inertia-link>
</li>
<li v-if="data.options.can_be_deleted">
<span class="cursor-pointer text-blue-500 hover:underline" @click="destroy">Delete contact</span>
<span class="cursor-pointer text-blue-500 hover:underline" @click="destroy">{{
$t('contact.contact_delete_cta')
}}</span>
</li>
</ul>
</div>
Expand Down Expand Up @@ -331,11 +333,11 @@ export default {
methods: {
destroy() {
if (confirm('Are you sure? This will remove everything we know about this contact.')) {
if (confirm(this.$t('contact.contact_delete_confirm'))) {
axios
.delete(this.data.url.destroy)
.then((response) => {
localStorage.success = 'The contact has been deleted';
localStorage.success = this.$t('contact.contact_delete_success');
this.$inertia.visit(response.data.data);
})
.catch((error) => {
Expand All @@ -345,11 +347,11 @@ export default {
},
toggleArchive() {
if (confirm('Are you sure?')) {
if (confirm(this.$t('contact.contact_toggle_confirm'))) {
axios
.put(this.data.url.toggle_archive)
.then((response) => {
localStorage.success = 'Changes saved';
localStorage.success = this.$t('app.notification_flash_changes_saved');
this.$inertia.visit(response.data.data);
})
.catch((error) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
</h3>

<!-- list of reminders -->
<div v-if="data.length > 0">
<div v-if="data.reminders.length > 0">
<ul class="mb-4 rounded-lg border border-gray-200 bg-white">
<li
v-for="reminder in data"
Expand All @@ -65,13 +65,13 @@
</div>

<!-- blank state -->
<div v-if="data.length == 0" class="mb-6 rounded-lg border border-gray-200 bg-white">
<div v-if="data.reminders.length == 0" class="mb-6 rounded-lg border border-gray-200 bg-white">
<p class="p-5 text-center">{{ $t('vault.dashboard_reminders_blank') }}</p>
</div>

<div class="text-center">
<inertia-link
href=""
:href="data.url.index"
class="rounded border border-gray-200 px-3 py-1 text-sm text-blue-500 hover:border-gray-500">
{{ $t('app.view_all') }}
</inertia-link>
Expand Down
Loading

0 comments on commit 6aa5267

Please sign in to comment.