From 133e426578ed0d09581ea6441bc8bcd86f7baba7 Mon Sep 17 00:00:00 2001 From: Alexis Saettler Date: Mon, 12 Jun 2023 23:11:07 +0200 Subject: [PATCH] fix: fix vue refs targets (#6675) --- .../ModuleContactTasksViewHelper.php | 26 +- .../ViewHelpers/VaultTasksIndexViewHelper.php | 24 +- app/Models/ContactTask.php | 10 + .../Components/Jetstream/ConfirmsPassword.vue | 4 +- resources/js/Components/Jetstream/Select.vue | 4 +- .../Pages/Profile/Partials/DeleteUserForm.vue | 4 +- .../LogoutOtherBrowserSessionsForm.vue | 4 +- .../Vault/Contact/ImportantDates/Index.vue | 22 +- .../Partials/CreateOrEditImportantDate.vue | 20 +- .../Vault/Dashboard/Partials/DueTasks.vue | 6 +- .../js/Pages/Vault/Dashboard/Task/Index.vue | 6 +- .../js/Pages/Webauthn/Partials/UpdateKey.vue | 2 +- resources/js/Shared/Form/ContactSelector.vue | 7 +- resources/js/Shared/Modules/Loans.vue | 6 +- resources/js/Shared/Modules/Reminders.vue | 6 +- .../Modules/TaskItems/CreateOrEditTask.vue | 158 ++++++++++ resources/js/Shared/Modules/Tasks.vue | 273 +++++------------- .../ModuleContactTasksViewHelperTest.php | 7 +- .../VaultTasksIndexViewHelperTest.php | 7 +- 19 files changed, 318 insertions(+), 278 deletions(-) create mode 100644 resources/js/Shared/Modules/TaskItems/CreateOrEditTask.vue diff --git a/app/Domains/Contact/ManageTasks/Web/ViewHelpers/ModuleContactTasksViewHelper.php b/app/Domains/Contact/ManageTasks/Web/ViewHelpers/ModuleContactTasksViewHelper.php index d2b460d2995..2b2f7e42833 100644 --- a/app/Domains/Contact/ManageTasks/Web/ViewHelpers/ModuleContactTasksViewHelper.php +++ b/app/Domains/Contact/ManageTasks/Web/ViewHelpers/ModuleContactTasksViewHelper.php @@ -12,15 +12,15 @@ class ModuleContactTasksViewHelper { public static function data(Contact $contact, User $user): array { - $tasks = $contact->tasks()->where('completed', false) + $tasks = $contact->tasks() + ->notCompleted() ->orderBy('id', 'desc') ->get(); - $tasksCollection = $tasks->map(function ($task) use ($contact, $user) { - return self::dtoTask($contact, $task, $user); - }); + $tasksCollection = $tasks->map(fn ($task) => self::dtoTask($contact, $task, $user)); - $completedTasksCount = $contact->tasks()->where('completed', true) + $completedTasksCount = $contact->tasks() + ->completed() ->count(); return [ @@ -41,12 +41,11 @@ public static function data(Contact $contact, User $user): array public static function completed(Contact $contact, User $user): Collection { - return $contact->tasks()->where('completed', true) + return $contact->tasks() + ->completed() ->orderBy('completed_at', 'desc') ->get() - ->map(function ($task) use ($contact, $user) { - return self::dtoTask($contact, $task, $user); - }); + ->map(fn ($task) => self::dtoTask($contact, $task, $user)); } public static function dtoTask(Contact $contact, ContactTask $task, User $user): array @@ -56,9 +55,12 @@ public static function dtoTask(Contact $contact, ContactTask $task, User $user): 'label' => $task->label, 'description' => $task->description, 'completed' => $task->completed, - 'completed_at' => $task->completed_at ? DateHelper::format($task->completed_at, $user) : null, - 'due_at' => $task->due_at ? DateHelper::format($task->due_at, $user) : null, - 'due_at_late' => optional($task->due_at)->isPast() ?? false, + 'completed_at' => $task->completed_at !== null ? DateHelper::format($task->completed_at, $user) : null, + 'due_at' => $task->due_at ? [ + 'formatted' => DateHelper::format($task->due_at, $user), + 'value' => $task->due_at->format('Y-m-d'), + 'is_late' => $task->due_at->isPast(), + ] : null, 'url' => [ 'update' => route('contact.task.update', [ 'vault' => $contact->vault_id, diff --git a/app/Domains/Vault/ManageTasks/Web/ViewHelpers/VaultTasksIndexViewHelper.php b/app/Domains/Vault/ManageTasks/Web/ViewHelpers/VaultTasksIndexViewHelper.php index 38b4d81ac94..97f80f49167 100644 --- a/app/Domains/Vault/ManageTasks/Web/ViewHelpers/VaultTasksIndexViewHelper.php +++ b/app/Domains/Vault/ManageTasks/Web/ViewHelpers/VaultTasksIndexViewHelper.php @@ -3,35 +3,34 @@ namespace App\Domains\Vault\ManageTasks\Web\ViewHelpers; use App\Helpers\DateHelper; +use App\Models\ContactTask; use App\Models\User; use App\Models\Vault; -use Carbon\Carbon; use Illuminate\Support\Collection; -use Illuminate\Support\Facades\DB; class VaultTasksIndexViewHelper { public static function data(Vault $vault, User $user): Collection { $contacts = $vault->contacts() + ->with('tasks') ->get() ->sortByCollator('last_name'); $contactsCollection = collect(); foreach ($contacts as $contact) { - $tasks = DB::table('contact_tasks') - ->where('completed', false) - ->where('contact_id', $contact->id) + $tasksCollection = $contact->tasks() + ->notCompleted() ->orderBy('due_at', 'asc') - ->get(); - - $tasksCollection = collect(); - foreach ($tasks as $task) { - $tasksCollection->push([ + ->get() + ->map(fn (ContactTask $task) => [ 'id' => $task->id, 'label' => $task->label, - 'due_at' => $task->due_at ? DateHelper::format(Carbon::parse($task->due_at), $user) : null, - 'due_at_late' => optional(Carbon::parse($task->due_at))->isPast() ?? false, + 'due_at' => $task->due_at !== null ? [ + 'formatted' => DateHelper::format($task->due_at, $user), + 'value' => $task->due_at->format('Y-m-d'), + 'is_late' => $task->due_at->isPast(), + ] : null, 'url' => [ 'toggle' => route('contact.task.toggle', [ 'vault' => $contact->vault_id, @@ -40,7 +39,6 @@ public static function data(Vault $vault, User $user): Collection ]), ], ]); - } if ($tasksCollection->count() <= 0) { continue; diff --git a/app/Models/ContactTask.php b/app/Models/ContactTask.php index 0da5385e206..8deb428b4ee 100644 --- a/app/Models/ContactTask.php +++ b/app/Models/ContactTask.php @@ -54,4 +54,14 @@ public function author(): BelongsTo { return $this->belongsTo(User::class); } + + public function scopeNotCompleted($query) + { + return $query->where('completed', false); + } + + public function scopeCompleted($query) + { + return $query->where('completed', true); + } } diff --git a/resources/js/Components/Jetstream/ConfirmsPassword.vue b/resources/js/Components/Jetstream/ConfirmsPassword.vue index 5ccf85cf2d2..4002b2141f2 100644 --- a/resources/js/Components/Jetstream/ConfirmsPassword.vue +++ b/resources/js/Components/Jetstream/ConfirmsPassword.vue @@ -41,7 +41,7 @@ const startConfirmingPassword = () => { } else { confirmingPassword.value = true; - setTimeout(() => passwordInput.value.focus(), 250); + nextTick(() => passwordInput.value.focus()); } }); }; @@ -62,7 +62,7 @@ const confirmPassword = () => { .catch((error) => { form.processing = false; form.error = error.response.data.errors.password[0]; - passwordInput.value.focus(); + nextTick(() => passwordInput.value.focus()); }); }; diff --git a/resources/js/Components/Jetstream/Select.vue b/resources/js/Components/Jetstream/Select.vue index c0df67cd137..dcf0a6a1019 100644 --- a/resources/js/Components/Jetstream/Select.vue +++ b/resources/js/Components/Jetstream/Select.vue @@ -82,10 +82,10 @@ const close = () => { onMounted(() => { document.addEventListener('keydown', onKeydown); if (_.find(useAttrs(), (item, key) => key === 'autofocus') > -1) { - setTimeout(() => { + nextTick(() => { select.value.focus(); open.value = true; - }, 100); + }); } }); onUnmounted(() => document.removeEventListener('keydown', onKeydown)); diff --git a/resources/js/Pages/Profile/Partials/DeleteUserForm.vue b/resources/js/Pages/Profile/Partials/DeleteUserForm.vue index 4d4e222b8c8..d87daf25f03 100644 --- a/resources/js/Pages/Profile/Partials/DeleteUserForm.vue +++ b/resources/js/Pages/Profile/Partials/DeleteUserForm.vue @@ -18,14 +18,14 @@ const form = useForm({ const confirmUserDeletion = () => { confirmingUserDeletion.value = true; - setTimeout(() => passwordInput.value.focus(), 250); + nextTick(() => passwordInput.value.focus()); }; const deleteUser = () => { form.delete(route('current-user.destroy'), { preserveScroll: true, onSuccess: () => closeModal(), - onError: () => passwordInput.value.focus(), + onError: () => nextTick(() => passwordInput.value.focus()), onFinish: () => form.reset(), }); }; diff --git a/resources/js/Pages/Profile/Partials/LogoutOtherBrowserSessionsForm.vue b/resources/js/Pages/Profile/Partials/LogoutOtherBrowserSessionsForm.vue index aa70b78623e..c1d9ad42fc4 100644 --- a/resources/js/Pages/Profile/Partials/LogoutOtherBrowserSessionsForm.vue +++ b/resources/js/Pages/Profile/Partials/LogoutOtherBrowserSessionsForm.vue @@ -23,14 +23,14 @@ const form = useForm({ const confirmLogout = () => { confirmingLogout.value = true; - setTimeout(() => passwordInput.value.focus(), 250); + nextTick(() => passwordInput.value.focus()); }; const logoutOtherBrowserSessions = () => { form.delete(route('other-browser-sessions.destroy'), { preserveScroll: true, onSuccess: () => closeModal(), - onError: () => passwordInput.value.focus(), + onError: () => nextTick(() => passwordInput.value.focus()), onFinish: () => form.reset(), }); }; diff --git a/resources/js/Pages/Vault/Contact/ImportantDates/Index.vue b/resources/js/Pages/Vault/Contact/ImportantDates/Index.vue index 94c9ed9604e..a619c83d5e1 100644 --- a/resources/js/Pages/Vault/Contact/ImportantDates/Index.vue +++ b/resources/js/Pages/Vault/Contact/ImportantDates/Index.vue @@ -9,14 +9,8 @@ import CreateOrEditImportantDate from './Partials/CreateOrEditImportantDate.vue' import Errors from '@/Shared/Form/Errors.vue'; const props = defineProps({ - layoutData: { - type: Object, - default: null, - }, - data: { - type: Object, - default: null, - }, + layoutData: Object, + data: Object, }); const editedDateId = ref(0); @@ -32,12 +26,10 @@ const showCreateModal = () => { nextTick(() => createForm.value.reset()); }; -const updateDateModal = (date) => { +const updateDateModal = (date, i) => { editedDateId.value = date.id; - nextTick(() => { - editForm.value[0].reset(); - }); + nextTick(() => editForm.value[i].reset()); }; const created = (date) => { @@ -142,7 +134,7 @@ const destroy = (date) => { v-if="localDates.length > 0" class="mb-6 rounded-lg border border-gray-200 bg-white dark:border-gray-700 dark:bg-gray-900">
  • @@ -159,7 +151,7 @@ const destroy = (date) => {