Skip to content

Commit

Permalink
feat: ability to edit or delete journal (monicahq/chandler#442)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored Mar 16, 2023
1 parent fe5b004 commit b33c74f
Show file tree
Hide file tree
Showing 13 changed files with 311 additions and 22 deletions.
3 changes: 0 additions & 3 deletions app/Domains/Vault/ManageJournals/Services/DestroyJournal.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ public function permissions(): array
];
}

/**
* Delete a journal.
*/
public function execute(array $data): void
{
$this->data = $data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
namespace App\Domains\Vault\ManageJournals\Web\Controllers;

use App\Domains\Vault\ManageJournals\Services\CreateJournal;
use App\Domains\Vault\ManageJournals\Services\DestroyJournal;
use App\Domains\Vault\ManageJournals\Services\UpdateJournal;
use App\Domains\Vault\ManageJournals\Web\ViewHelpers\JournalCreateViewHelper;
use App\Domains\Vault\ManageJournals\Web\ViewHelpers\JournalEditViewHelper;
use App\Domains\Vault\ManageJournals\Web\ViewHelpers\JournalIndexViewHelper;
use App\Domains\Vault\ManageJournals\Web\ViewHelpers\JournalShowViewHelper;
use App\Domains\Vault\ManageVault\Web\ViewHelpers\VaultIndexViewHelper;
Expand Down Expand Up @@ -77,4 +80,50 @@ public function year(Request $request, int $vaultId, int $journalId, int $year)
'data' => JournalShowViewHelper::data($journal, $year, Auth::user()),
]);
}

public function edit(Request $request, int $vaultId, int $journalId)
{
$vault = Vault::findOrFail($vaultId);
$journal = Journal::findOrFail($journalId);

return Inertia::render('Vault/Journal/Edit', [
'layoutData' => VaultIndexViewHelper::layoutData($vault),
'data' => JournalEditViewHelper::data($vault, $journal),
]);
}

public function update(Request $request, int $vaultId, int $journalId)
{
$data = [
'account_id' => Auth::user()->account_id,
'author_id' => Auth::id(),
'vault_id' => $vaultId,
'journal_id' => $journalId,
'name' => $request->input('name'),
'description' => $request->input('description'),
];

$journal = (new UpdateJournal())->execute($data);

return Redirect::route('journal.show', [
'vault' => $vaultId,
'journal' => $journal,
]);
}

public function destroy(Request $request, int $vaultId, int $journalId)
{
$data = [
'account_id' => Auth::user()->account_id,
'author_id' => Auth::id(),
'vault_id' => $vaultId,
'journal_id' => $journalId,
];

(new DestroyJournal())->execute($data);

return Redirect::route('journal.index', [
'vault' => $vaultId,
]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Domains\Vault\ManageJournals\Web\ViewHelpers;

use App\Models\Journal;
use App\Models\Vault;

class JournalEditViewHelper
{
public static function data(Vault $vault, Journal $journal): array
{
return [
'id' => $journal->id,
'name' => $journal->name,
'description' => $journal->description,
'url' => [
'update' => route('journal.update', [
'vault' => $vault->id,
'journal' => $journal->id,
]),
'back' => route('journal.show', [
'vault' => $vault->id,
'journal' => $journal->id,
]),
],
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ public static function data(Journal $journal, int $year, User $user): array
'tags' => self::tags($journal),
'slices' => self::slices($journal),
'url' => [
'edit' => route('journal.edit', [
'vault' => $journal->vault_id,
'journal' => $journal->id,
]),
'destroy' => route('journal.destroy', [
'vault' => $journal->vault_id,
'journal' => $journal->id,
]),
'create' => route('post.create', [
'vault' => $journal->vault_id,
'journal' => $journal->id,
Expand Down
1 change: 0 additions & 1 deletion lang/en/vault.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@
'journal_show_years' => 'Years',
'journal_show_tags' => 'All tags',
'journal_show_contacts' => 'Contacts in this post',
'journal_show_options' => 'Options',
'journal_show_blank' => 'The journal lets you document your life with your own words.',
'journal_post_edit_tags' => 'Tags',
'journal_show_mood' => 'Your mood that you logged at this date',
Expand Down
1 change: 1 addition & 0 deletions public/img/journal_blank_index.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 11 additions & 6 deletions resources/js/Pages/Vault/Journal/Create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import PrettyButton from '@/Shared/Form/PrettyButton.vue';
import TextInput from '@/Shared/Form/TextInput.vue';
import TextArea from '@/Shared/Form/TextArea.vue';
import Errors from '@/Shared/Form/Errors.vue';
import { onMounted, nextTick, ref } from 'vue';
const props = defineProps({
layoutData: Object,
Expand All @@ -17,6 +18,14 @@ const form = useForm({
description: '',
});
const nameField = ref(null);
onMounted(() => {
nextTick(() => {
nameField.value.focus();
});
});
const submit = () => {
form.post(props.data.url.store, {
onFinish: () => {},
Expand Down Expand Up @@ -72,6 +81,7 @@ const submit = () => {

<text-input
v-model="form.name"
:ref="'nameField'"
:autofocus="true"
:div-outer-class="'mb-5'"
:input-class="'block w-full'"
Expand All @@ -89,12 +99,7 @@ const submit = () => {
<!-- actions -->
<div class="flex justify-between p-5">
<pretty-link :href="data.url.back" :text="$t('app.cancel')" :classes="'mr-3'" />
<pretty-button
:href="'data.url.vault.create'"
:text="$t('app.add')"
:state="loadingState"
:icon="'check'"
:classes="'save'" />
<pretty-button :text="$t('app.add')" :state="loadingState" :icon="'check'" :classes="'save'" />
</div>
</form>
</div>
Expand Down
Loading

0 comments on commit b33c74f

Please sign in to comment.