This repository has been archived by the owner on Jun 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: pet actions appear in feed (#215)
- Loading branch information
Showing
14 changed files
with
253 additions
and
0 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
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
38 changes: 38 additions & 0 deletions
38
domains/Contact/ManageContactFeed/Web/ViewHelpers/Actions/ActionFeedPet.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,38 @@ | ||
<?php | ||
|
||
namespace App\Contact\ManageContactFeed\Web\ViewHelpers\Actions; | ||
|
||
use App\Models\ContactFeedItem; | ||
|
||
class ActionFeedPet | ||
{ | ||
public static function data(ContactFeedItem $item): array | ||
{ | ||
$contact = $item->contact; | ||
$pet = $item->feedable; | ||
|
||
return [ | ||
'pet' => [ | ||
'object' => $pet ? [ | ||
'id' => $pet->id, | ||
'name' => $pet->name, | ||
'pet_category' => [ | ||
'id' => $pet->petCategory->id, | ||
'name' => $pet->petCategory->name, | ||
], | ||
] : null, | ||
'description' => $item->description, | ||
], | ||
'contact' => [ | ||
'id' => $contact->id, | ||
'name' => $contact->name, | ||
'age' => $contact->age, | ||
'avatar' => $contact->avatar, | ||
'url' => route('contact.show', [ | ||
'vault' => $contact->vault_id, | ||
'contact' => $contact->id, | ||
]), | ||
], | ||
]; | ||
} | ||
} |
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,52 @@ | ||
<template> | ||
<div class="rounded-lg border border-gray-300 dark:border-gray-700"> | ||
<!-- contact information --> | ||
<div | ||
v-if="!contactViewMode" | ||
class="flex items-center border-b border-gray-300 px-3 py-2 text-sm dark:border-gray-700"> | ||
<avatar | ||
:data="data.contact.avatar" | ||
:classes="'rounded-full border-gray-200 dark:border-gray-800 border relative h-5 w-5 mr-2'" /> | ||
|
||
<div class="flex flex-col"> | ||
<inertia-link :href="data.contact.url" class="text-gray-800 hover:underline dark:text-gray-200">{{ | ||
data.contact.name | ||
}}</inertia-link> | ||
</div> | ||
</div> | ||
|
||
<div class="px-3 py-2"> | ||
<!-- the pet still exists in the system --> | ||
<div v-if="data.pet.object" class="flex items-center"> | ||
<span class="mr-2 text-sm text-gray-500">{{ data.pet.object.pet_category.name }}</span> | ||
<span class="mr-2">{{ data.pet.object.name }}</span> | ||
</div> | ||
|
||
<!-- the pet was deleted --> | ||
<span v-else class="mr-2 mb-2"> | ||
<span>{{ data.pet.description }}</span> | ||
</span> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
import Avatar from '@/Shared/Avatar.vue'; | ||
export default { | ||
components: { | ||
Avatar, | ||
}, | ||
props: { | ||
data: { | ||
type: Object, | ||
default: null, | ||
}, | ||
contactViewMode: { | ||
type: Boolean, | ||
default: true, | ||
}, | ||
}, | ||
}; | ||
</script> |
65 changes: 65 additions & 0 deletions
65
tests/Unit/Domains/Contact/ManageContactFeed/Web/ViewHelpers/Actions/ActionFeedPetTest.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,65 @@ | ||
<?php | ||
|
||
namespace Tests\Unit\Domains\Contact\ManageContactFeed\Web\ViewHelpers\Actions; | ||
|
||
use App\Contact\ManageContactFeed\Web\ViewHelpers\Actions\ActionFeedPet; | ||
use App\Models\Contact; | ||
use App\Models\ContactFeedItem; | ||
use App\Models\Pet; | ||
use App\Models\PetCategory; | ||
use Illuminate\Foundation\Testing\DatabaseTransactions; | ||
use Tests\TestCase; | ||
|
||
class ActionFeedPetTest extends TestCase | ||
{ | ||
use DatabaseTransactions; | ||
|
||
/** @test */ | ||
public function it_gets_the_data_needed_for_the_view(): void | ||
{ | ||
$contact = Contact::factory()->create([ | ||
'first_name' => 'John', | ||
'last_name' => 'Doe', | ||
]); | ||
$petCategory = PetCategory::factory()->create([ | ||
'name' => 'Dog', | ||
]); | ||
$pet = Pet::factory()->create([ | ||
'pet_category_id' => $petCategory->id, | ||
'name' => 'Charles', | ||
]); | ||
|
||
$feedItem = ContactFeedItem::factory()->create([ | ||
'contact_id' => $contact->id, | ||
'action' => ContactFeedItem::ACTION_PET_CREATED, | ||
'description' => 'pet', | ||
]); | ||
$pet->feedItem()->save($feedItem); | ||
|
||
$array = ActionFeedPet::data($feedItem); | ||
|
||
$this->assertEquals( | ||
[ | ||
'pet' => [ | ||
'object' => [ | ||
'id' => $pet->id, | ||
'name' => 'Charles', | ||
'pet_category' => [ | ||
'id' => $petCategory->id, | ||
'name' => 'Dog', | ||
], | ||
], | ||
'description' => 'pet', | ||
], | ||
'contact' => [ | ||
'id' => $contact->id, | ||
'name' => 'John Doe', | ||
'age' => null, | ||
'avatar' => $contact->avatar, | ||
'url' => env('APP_URL').'/vaults/'.$contact->vault_id.'/contacts/'.$contact->id, | ||
], | ||
], | ||
$array | ||
); | ||
} | ||
} |
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