diff --git a/app/Http/Controllers/Contacts/CallsController.php b/app/Http/Controllers/Contacts/CallsController.php index a6a7b2c69b1..6f408f36666 100644 --- a/app/Http/Controllers/Contacts/CallsController.php +++ b/app/Http/Controllers/Contacts/CallsController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers\Contacts; +use App\Helpers\DateHelper; use App\Models\Contact\Call; use Illuminate\Http\Request; use App\Models\Contact\Contact; @@ -30,6 +31,25 @@ public function index(Request $request, Contact $contact) return CallResource::collection($calls); } + /** + * Display the timestamp of the last phone contact. + * + * @param Contact $contact + * @return JsonResponse + */ + public function lastCalled(Contact $contact): JsonResponse + { + $lastTalkedTo = $contact->last_talked_to; + + if ($lastTalkedTo !== null) { + $lastTalkedTo = DateHelper::getShortDate($contact->last_talked_to); + } + + return $this->respond([ + 'last_talked_to' => $lastTalkedTo, + ]); + } + /** * Store a call. * diff --git a/resources/js/app.js b/resources/js/app.js index bdfea9993fb..741e6cf17dd 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -181,6 +181,11 @@ Vue.component( require('./components/people/StayInTouch.vue').default ); +Vue.component( + 'LastCalled', + require('./components/people/calls/LastCalled.vue').default +); + Vue.component( 'PhoneCallList', require('./components/people/calls/PhoneCallList.vue').default diff --git a/resources/js/components/people/calls/LastCalled.vue b/resources/js/components/people/calls/LastCalled.vue new file mode 100644 index 00000000000..eba570bc421 --- /dev/null +++ b/resources/js/components/people/calls/LastCalled.vue @@ -0,0 +1,47 @@ + + + diff --git a/resources/js/components/people/calls/PhoneCallList.vue b/resources/js/components/people/calls/PhoneCallList.vue index 058e221a6fa..78bcaf3e605 100644 --- a/resources/js/components/people/calls/PhoneCallList.vue +++ b/resources/js/components/people/calls/PhoneCallList.vue @@ -345,6 +345,7 @@ export default { this.resetFields(); this.displayLogCall = false; this.chosenEmotions = []; + this.updateLastCalled(); this.$notify({ group: 'main', @@ -361,6 +362,7 @@ export default { this.getCalls(); this.editCallId = 0; this.chosenEmotions = []; + this.updateLastCalled(); this.$notify({ group: 'main', @@ -371,6 +373,10 @@ export default { }); }, + updateLastCalled() { + this.$parent.$refs.lastCalledAttribute.getLastCalled(); + }, + showEditBox(call) { this.editCallId = call.id; this.editCall.content = call.content; @@ -390,6 +396,7 @@ export default { axios.delete('people/' + this.hash + '/calls/' + this.destroyCallId) .then(response => { this.calls.splice(this.calls.indexOf(call), 1); + this.updateLastCalled(); }); }, diff --git a/resources/lang/en/people.php b/resources/lang/en/people.php index 68f700bb58e..55195ab2980 100644 --- a/resources/lang/en/people.php +++ b/resources/lang/en/people.php @@ -144,6 +144,7 @@ // Last called 'last_called' => 'Last called: :date', + 'last_talked_to' => 'Last called: {date}', 'last_called_empty' => 'Last called: unknown', 'last_activity_date' => 'Last activity together: :date', 'last_activity_date_empty' => 'Last activity together: unknown', diff --git a/resources/views/people/_header.blade.php b/resources/views/people/_header.blade.php index 4b1fc5b691c..4158576cf2c 100644 --- a/resources/views/people/_header.blade.php +++ b/resources/views/people/_header.blade.php @@ -91,11 +91,11 @@ @if (! $contact->isMe())
  • @include('partials.icons.header_call') - @if (is_null($contact->last_talked_to)) - {{ trans('people.last_called_empty') }} - @else - {{ trans('people.last_called', ['date' => \App\Helpers\DateHelper::getShortDate($contact->last_talked_to)]) }} - @endif + +
  • @endif diff --git a/routes/web.php b/routes/web.php index 5ee89f3e45a..77f570920c6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -3,6 +3,7 @@ use Illuminate\Support\Facades\App; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Route; +use App\Http\Controllers\Contacts\CallsController; /* |-------------------------------------------------------------------------- @@ -156,6 +157,7 @@ Route::resource('people/{contact}/debts', 'Contacts\\DebtController')->except(['index', 'show']); // Phone calls + Route::get('people/{contact}/calls/last', [CallsController::class, 'lastCalled']); Route::resource('people/{contact}/calls', 'Contacts\\CallsController')->except(['show']); // Conversations diff --git a/tests/Feature/CallsTest.php b/tests/Feature/CallsTest.php index b7a8287d629..762e70c9116 100644 --- a/tests/Feature/CallsTest.php +++ b/tests/Feature/CallsTest.php @@ -3,8 +3,10 @@ namespace Tests\Feature; use Tests\FeatureTestCase; +use App\Helpers\DateHelper; use App\Models\Contact\Call; use App\Models\Contact\Contact; +use App\Services\Contact\Call\CreateCall; use Illuminate\Foundation\Testing\DatabaseTransactions; class CallsTest extends FeatureTestCase @@ -57,6 +59,54 @@ public function test_it_gets_the_list_of_calls() ); } + /** @test */ + public function it_gets_last_talked_to() + { + $user = $this->signin(); + + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account_id, + ]); + + $referenceDate = now(); + + app(CreateCall::class)->execute([ + 'account_id' => $user->account_id, + 'contact_id' => $contact->id, + 'called_at' => $referenceDate->format('Y-m-d'), + ]); + + $response = $this->json('GET', "/people/{$contact->hashId()}/calls/last"); + + $response->assertStatus(200); + + $response->assertJsonStructure([ + 'last_talked_to', + ]); + + $this->assertEquals($response->json('last_talked_to'), DateHelper::getShortDate($referenceDate)); + } + + /** @test */ + public function it_gets_a_empty_last_talked_to() + { + $user = $this->signin(); + + $contact = factory(Contact::class)->create([ + 'account_id' => $user->account_id, + ]); + + $response = $this->json('GET', "/people/{$contact->hashId()}/calls/last"); + + $response->assertStatus(200); + + $response->assertJsonStructure([ + 'last_talked_to', + ]); + + $this->assertNull($response->json('last_talked_to')); + } + public function test_dashboard_calls() { $user = $this->signin(); diff --git a/tests/cypress/integration/contacts/calls_spec.js b/tests/cypress/integration/contacts/calls_spec.js index bcbd8869378..fe0ed483b02 100644 --- a/tests/cypress/integration/contacts/calls_spec.js +++ b/tests/cypress/integration/contacts/calls_spec.js @@ -10,12 +10,14 @@ describe('Calls', function () { cy.url().should('include', '/people/h:'); cy.get('[cy-name=calls-blank-state]').should('exist'); cy.get('[cy-name=log-call-form]').should('not.be.visible'); + cy.get('[cy-name=last-talked-to]').should('contain', 'unknown'); // add a call cy.get('[cy-name=add-call-button]').click(); cy.get('[cy-name=log-call-form]').should('be.visible'); cy.get('[cy-name=save-call-button]').click(); cy.get('[cy-name=calls-blank-state]').should('not.exist'); + cy.get('[cy-name=last-talked-to]').should('not.contain', 'unknown'); cy.get('[cy-name=calls-body]').should('be.visible') .invoke('attr', 'cy-items').then(function (items) { @@ -30,6 +32,7 @@ describe('Calls', function () { cy.get('[cy-name=delete-call-confirm-button-'+item+']').should('be.visible'); cy.get('[cy-name=delete-call-confirm-button-'+item+']').click(); cy.get('[cy-name=calls-blank-state]').should('exist'); + cy.get('[cy-name=last-talked-to]').should('contain', 'unknown'); }); }); });