-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: reminders summary (monicahq/chandler#153)
- Loading branch information
Showing
19 changed files
with
482 additions
and
30 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
domains/Vault/ManageVault/Web/Controllers/VaultReminderController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()), | ||
]); | ||
} | ||
} |
93 changes: 93 additions & 0 deletions
93
domains/Vault/ManageVault/Web/ViewHelpers/VaultReminderIndexViewHelper.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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é', | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.