-
-
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: display feed on contact page (monicahq/chandler#52)
- Loading branch information
Showing
13 changed files
with
223 additions
and
3 deletions.
There are no files selected for viewing
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 |
---|---|---|
|
@@ -17,3 +17,4 @@ yarn-error.log | |
.DS_Store | ||
/tests/Features/screenshots/ | ||
/tests/Features/videos/ | ||
/data.ms |
34 changes: 34 additions & 0 deletions
34
app/Http/Controllers/Vault/Contact/Modules/Feed/ViewHelpers/ModuleFeedViewHelper.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,34 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Vault\Contact\Modules\Feed\ViewHelpers; | ||
|
||
use App\Models\User; | ||
use App\Models\Contact; | ||
use App\Models\ContactFeedItem; | ||
use App\Http\Controllers\Vault\Contact\Modules\Note\ViewHelpers\ModuleNotesViewHelper; | ||
|
||
class ModuleFeedViewHelper | ||
{ | ||
public static function data(Contact $contact, User $user): array | ||
{ | ||
$items = ContactFeedItem::where('contact_id', $contact->id) | ||
->orderBy('created_at', 'desc') | ||
->get(); | ||
|
||
$itemsCollection = $items->map(function ($item) use ($contact, $user) { | ||
if ($item->action == ContactFeedItem::ACTION_NOTE_CREATED) { | ||
$object = ModuleNotesViewHelper::dto($contact, $item->feedable, $user); | ||
} | ||
|
||
return [ | ||
'id' => $item->id, | ||
'action' => $item->action, | ||
'object' => $object, | ||
]; | ||
}); | ||
|
||
return [ | ||
'items' => $itemsCollection, | ||
]; | ||
} | ||
} |
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
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,77 @@ | ||
<style lang="scss" scoped> | ||
.icon-date { | ||
top: -1px; | ||
} | ||
</style> | ||
|
||
<template> | ||
<div class="relative border border-gray-300 bg-white sm:rounded-lg"> | ||
<span class="absolute rounded border bg-blue-50 px-2 py-0 text-xs text-blue-500" style="top: -10px; left: 10px"> | ||
note | ||
</span> | ||
|
||
<!-- title, if it exists --> | ||
<div v-if="note.title" class="font-semibol mb-1 border-b border-gray-200 p-3 pt-5 text-xs text-gray-600"> | ||
{{ note.title }} | ||
</div> | ||
|
||
<div class="p-3"> | ||
{{ note.body }} | ||
</div> | ||
|
||
<div | ||
class="flex justify-between border-t border-gray-200 px-3 py-1 text-xs text-gray-600 hover:rounded-b hover:bg-slate-50"> | ||
<div> | ||
<!-- emotion --> | ||
<div v-if="note.emotion" class="relative mr-3 inline"> | ||
{{ note.emotion.name }} | ||
</div> | ||
|
||
<!-- date --> | ||
<div class="relative mr-3 inline"> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
class="icon-note relative inline h-3 w-3 text-gray-400" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
stroke="currentColor"> | ||
<path | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="2" | ||
d="M12 8v4l3 3m6-3a9 9 0 11-18 0 9 9 0 0118 0z" /> | ||
</svg> | ||
{{ note.written_at }} | ||
</div> | ||
|
||
<!-- author --> | ||
<div class="relative mr-3 inline"> | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
class="icon-note relative inline h-3 w-3 text-gray-400" | ||
fill="none" | ||
viewBox="0 0 24 24" | ||
stroke="currentColor"> | ||
<path | ||
stroke-linecap="round" | ||
stroke-linejoin="round" | ||
stroke-width="2" | ||
d="M5.121 17.804A13.937 13.937 0 0112 16c2.5 0 4.847.655 6.879 1.804M15 10a3 3 0 11-6 0 3 3 0 016 0zm6 2a9 9 0 11-18 0 9 9 0 0118 0z" /> | ||
</svg> | ||
{{ note.author }} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
props: { | ||
note: { | ||
type: Array, | ||
default: null, | ||
}, | ||
}, | ||
}; | ||
</script> |
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,41 @@ | ||
<style lang="scss" scoped> | ||
.icon-sidebar { | ||
color: #737e8d; | ||
top: -2px; | ||
} | ||
.icon-note { | ||
top: -1px; | ||
} | ||
</style> | ||
|
||
<template> | ||
<div class="mb-4"> | ||
<div v-for="item in data.items" :key="item.id" class="mb-6"> | ||
<!-- note created --> | ||
<note v-if="item.action == 'note_created'" :note="item.object" /> | ||
</div> | ||
|
||
<!-- blank state --> | ||
<div v-if="data.items.length == 0"> | ||
<p class="p-5 text-center">This person doesn't have any activity yet.</p> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import Note from '@/Pages/Vault/Dashboard/Partials/Feed/Note'; | ||
export default { | ||
components: { | ||
Note, | ||
}, | ||
props: { | ||
data: { | ||
type: Object, | ||
default: null, | ||
}, | ||
}, | ||
}; | ||
</script> |
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,5 @@ | ||
<?php | ||
|
||
return [ | ||
'update' => 'Update', | ||
]; |
42 changes: 42 additions & 0 deletions
42
tests/Unit/Controllers/Vault/Contact/Modules/Feed/ViewHelpers/ModuleFeedViewHelperTest.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,42 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Controllers\Vault\Contact\Modules\Feed\ViewHelpers; | ||
|
||
use Tests\TestCase; | ||
use App\Models\Note; | ||
use App\Models\User; | ||
use App\Models\Contact; | ||
use App\Models\ContactFeedItem; | ||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use App\Http\Controllers\Vault\Contact\Modules\Feed\ViewHelpers\ModuleFeedViewHelper; | ||
|
||
class ModuleFeedViewHelperTest extends TestCase | ||
{ | ||
use DatabaseTransactions; | ||
|
||
/** @test */ | ||
public function it_gets_the_data_needed_for_the_view(): void | ||
{ | ||
$contact = Contact::factory()->create(); | ||
$user = User::factory()->create(); | ||
$note = Note::factory()->create(); | ||
ContactFeedItem::factory()->create([ | ||
'contact_id' => $contact->id, | ||
'action' => ContactFeedItem::ACTION_NOTE_CREATED, | ||
'feedable_id' => $note->id, | ||
'feedable_type' => Note::class, | ||
]); | ||
|
||
$array = ModuleFeedViewHelper::data($contact, $user); | ||
|
||
$this->assertEquals( | ||
1, | ||
count($array) | ||
); | ||
|
||
$this->assertArrayHasKey('items', $array); | ||
$this->assertArrayHasKey('id', $array['items']->toArray()[0]); | ||
$this->assertArrayHasKey('action', $array['items']->toArray()[0]); | ||
$this->assertArrayHasKey('object', $array['items']->toArray()[0]); | ||
} | ||
} |