Skip to content

Commit

Permalink
feat: new hires indicate dates in the past (#746)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss committed Apr 11, 2021
1 parent 253c400 commit ddd5a30
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
21 changes: 19 additions & 2 deletions app/Http/ViewHelpers/Company/CompanyViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,24 @@ public static function newHiresThisWeek(Company $company): Collection
$date = $employee->hired_at;
$position = $employee->position;

if ($position) {
$dateString = $date->isPast() ?
trans('company.new_hires_date_with_position_past', [
'date' => DateHelper::formatDayAndMonthInParenthesis($date),
'position' => $position->title,
]) : trans('company.new_hires_date_with_position_future', [
'date' => DateHelper::formatDayAndMonthInParenthesis($date),
'position' => $position->title,
]);
} else {
$dateString = $date->isPast() ?
trans('company.new_hires_date_past', [
'date' => DateHelper::formatDayAndMonthInParenthesis($date),
]) : trans('company.new_hires_date_future', [
'date' => DateHelper::formatDayAndMonthInParenthesis($date),
]);
}

$newHiresCollection->push([
'id' => $employee->id,
'url' => route('employees.show', [
Expand All @@ -159,8 +177,7 @@ public static function newHiresThisWeek(Company $company): Collection
]),
'name' => $employee->name,
'avatar' => ImageHelper::getAvatar($employee, 35),
'hired_at' => DateHelper::formatDayAndMonthInParenthesis($date),
'position' => (! $position) ? null : $position->title,
'hired_at' => $dateString,
]);
}

Expand Down
7 changes: 2 additions & 5 deletions resources/js/Pages/Company/Partials/NewHires.vue
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@
</inertia-link>

<!-- position -->
<span v-if="hire.position" class="title db f7 mt1 lh-copy">
{{ $t('company.new_hires_date_with_position', { date: hire.hired_at, position: hire.position }) }}
</span>
<span v-else class="title db f7 mt1">
{{ $t('company.new_hires_date', { date: hire.hired_at }) }}
<span class="title db f7 mt1 lh-copy">
{{ hire.hired_at }}
</span>
</li>
</ul>
Expand Down
6 changes: 4 additions & 2 deletions resources/lang/en/company.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,10 @@
'recent_skills_view_all' => 'View all skills ({count})',

'new_hires_title' => 'New hires this week',
'new_hires_date' => 'Starts on {date}',
'new_hires_date_with_position' => 'Starts on {date} as {position}',
'new_hires_date_future' => 'Starts on {date}',
'new_hires_date_past' => 'Started on {date}',
'new_hires_date_with_position_future' => 'Starts on :date as :position',
'new_hires_date_with_position_past' => 'Started on :date as :position',
'new_hires_blank' => 'There are no new hires this week.',

'recent_ships_title' => 'Recent ships',
Expand Down
8 changes: 3 additions & 5 deletions tests/Unit/ViewHelpers/Company/CompanyViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ public function it_gets_the_new_hires_in_the_current_week(): void
'company_id' => $sales->company_id,
]);
$dwight = Employee::factory()->create([
'hired_at' => '2018-01-03',
'hired_at' => '2018-01-05',
'first_name' => 'Dwight',
'last_name' => 'Schrute',
'company_id' => $sales->company_id,
Expand Down Expand Up @@ -197,16 +197,14 @@ public function it_gets_the_new_hires_in_the_current_week(): void
'name' => 'Angela Bernard',
'avatar' => ImageHelper::getAvatar($angela, 35),
'url' => env('APP_URL').'/'.$angela->company_id.'/employees/'.$angela->id,
'hired_at' => 'Monday (Jan 1st)',
'position' => 'Assistant to the regional manager',
'hired_at' => 'Started on Monday (Jan 1st) as Assistant to the regional manager',
],
1 => [
'id' => $dwight->id,
'name' => 'Dwight Schrute',
'avatar' => ImageHelper::getAvatar($dwight, 35),
'url' => env('APP_URL').'/'.$angela->company_id.'/employees/'.$dwight->id,
'hired_at' => 'Wednesday (Jan 3rd)',
'position' => 'Assistant to the regional manager',
'hired_at' => 'Starts on Friday (Jan 5th) as Assistant to the regional manager',
],
],
$collection->toArray()
Expand Down

0 comments on commit ddd5a30

Please sign in to comment.