Skip to content

Commit

Permalink
feat: display upcoming new hires in team page (#785)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss committed Apr 18, 2021
1 parent 3151603 commit c8a01b1
Show file tree
Hide file tree
Showing 8 changed files with 186 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/Http/Controllers/Company/Team/TeamController.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public function show(Request $request, int $companyId, int $teamId)
// morale
$morale = TeamShowViewHelper::morale($team, $loggedEmployee);

// upcoming hiring date anniversaries
$newHiresNextWeek = TeamShowViewHelper::newHiresNextWeek($team, $loggedCompany);

return Inertia::render('Team/Show', [
'notifications' => NotificationHelper::getNotifications(InstanceHelper::getLoggedEmployee()),
'team' => TeamShowViewHelper::team($team),
Expand All @@ -97,6 +100,7 @@ public function show(Request $request, int $companyId, int $teamId)
'links' => TeamUsefulLinkCollection::prepare($team->links),
'recentShips' => $recentShipsCollection,
'morale' => $morale,
'newHiresNextWeek' => $newHiresNextWeek,
]);
}
}
50 changes: 50 additions & 0 deletions app/Http/ViewHelpers/Team/TeamShowViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -281,4 +281,54 @@ private static function emotion(float $percent): string

return $emotion;
}

/**
* Get all hires who will start next week.
*
* @param Team $team
* @param Company $company
* @return Collection
*/
public static function newHiresNextWeek(Team $team, Company $company): Collection
{
$now = Carbon::now();
$employees = $team->employees()
->where('locked', false)
->whereNotNull('hired_at')
->whereDate('hired_at', '>=', $now->copy()->addWeek()->startOfWeek(Carbon::MONDAY))
->whereDate('hired_at', '<=', $now->copy()->addWeek()->endOfWeek(Carbon::SUNDAY))
->with('position')
->orderBy('hired_at', 'asc')
->get();

$newHiresCollection = collect([]);
foreach ($employees as $employee) {
$date = $employee->hired_at;
$position = $employee->position;

if ($position) {
$dateString = trans('dashboard.team_upcoming_hires_with_position', [
'date' => DateHelper::formatDayAndMonthInParenthesis($date),
'position' => $position->title,
]);
} else {
$dateString = trans('dashboard.team_upcoming_hires', [
'date' => DateHelper::formatDayAndMonthInParenthesis($date),
]);
}

$newHiresCollection->push([
'id' => $employee->id,
'url' => route('employees.show', [
'company' => $company,
'employee' => $employee->id,
]),
'name' => $employee->name,
'avatar' => ImageHelper::getAvatar($employee, 35),
'hired_at' => $dateString,
]);
}

return $newHiresCollection;
}
}
2 changes: 1 addition & 1 deletion resources/js/Pages/Team/Partials/Morale.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
</style>

<template>
<div class="mb5">
<div class="mb4">
<div class="cf mw7 center mb2 fw5">
<span class="mr1">
🍻
Expand Down
69 changes: 69 additions & 0 deletions resources/js/Pages/Team/Partials/NewHiresNextWeek.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<style lang="scss" scoped>
.avatar {
left: 1px;
top: 5px;
width: 35px;
}
.person {
padding-left: 44px;
&:last-child {
margin-bottom: 0;
}
.avatar {
top: 2px;
}
}
</style>

<template>
<div class="mb4">
<span class="db fw5 mb2 relative">
<span class="mr1">
😎
</span> {{ $t('team.hires_next_week_title') }}
</span>

<div class="br3 bg-white box z-1 pa3 relative">
<ul v-if="hires.length != 0" class="list pl0 ma0">
<li v-for="hire in hires" :key="hire.id" class="mb3 pl3 db relative person">
<avatar :avatar="hire.avatar" :size="35" :class="'br-100 absolute avatar'" />

<!-- normal mode -->
<inertia-link :href="hire.url" class="mb2">
{{ hire.name }}
</inertia-link>

<!-- position -->
<span class="title db f7 mt1 lh-copy">
{{ hire.hired_at }}
</span>
</li>
</ul>

<!-- blank state -->
<div v-if="hires.length == 0" class="tc f6">
{{ $t('company.new_hires_blank') }}
</div>
</div>
</div>
</template>

<script>
import Avatar from '@/Shared/Avatar';
export default {
components: {
Avatar,
},
props: {
hires: {
type: Array,
default: null,
},
},
};
</script>
9 changes: 9 additions & 0 deletions resources/js/Pages/Team/Show.vue
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,9 @@

<!-- morale -->
<morale :morale="morale" />

<!-- hiring date anniversaries -->
<new-hires-next-week :hires="newHiresNextWeek" />
</div>
</div>
</div>
Expand All @@ -140,6 +143,7 @@ import Layout from '@/Shared/Layout';
import vClickOutside from 'v-click-outside';
import Members from '@/Pages/Team/Partials/Members';
import TeamDescription from '@/Pages/Team/Partials/TeamDescription';
import NewHiresNextWeek from '@/Pages/Team/Partials/NewHiresNextWeek';
import TeamLead from '@/Pages/Team/Partials/TeamLead';
import TeamUsefulLink from '@/Pages/Team/Partials/TeamUsefulLink';
import RecentShips from '@/Pages/Team/Partials/RecentShips';
Expand All @@ -151,6 +155,7 @@ export default {
Layout,
Members,
TeamDescription,
NewHiresNextWeek,
TeamLead,
TeamUsefulLink,
RecentShips,
Expand Down Expand Up @@ -211,6 +216,10 @@ export default {
type: Array,
default: null,
},
newHiresNextWeek: {
type: Array,
default: null,
},
},
data() {
Expand Down
3 changes: 3 additions & 0 deletions resources/lang/en/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
'team_dont_exist' => 'This team does not exist.',
'team_viewing' => 'Viewing',

'team_upcoming_hires' => 'Starts on :date',
'team_upcoming_hires_with_position' => 'Starts on :date as :position',

'team_work_from_home_title' => 'Who is working from home today',
'team_work_from_home_blank' => 'No one is working from home today.',

Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/team.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,6 @@

'morale_title' => 'Morale of the team members',
'morale_on_average' => 'On average',

'hires_next_week_title' => 'New hires in the next 7 days',
];
48 changes: 48 additions & 0 deletions tests/Unit/ViewHelpers/Team/TeamShowViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,4 +303,52 @@ public function it_gets_a_collection_of_morale_stats(): void
$array
);
}

/** @test */
public function it_gets_the_new_hires_in_the_next_week(): void
{
Carbon::setTestNow(Carbon::create(2018, 1, 1));
$sales = Team::factory()->create([]);
$michael = Employee::factory()->create([
'hired_at' => null,
'company_id' => $sales->company_id,
]);
$dwight = Employee::factory()->create([
'hired_at' => Carbon::now()->addWeek()->format('Y-m-d'),
'first_name' => 'Dwight',
'last_name' => 'Schrute',
'company_id' => $sales->company_id,
]);
$angela = Employee::factory()->create([
'hired_at' => '2018-01-01',
'first_name' => 'Angela',
'last_name' => 'Bernard',
'company_id' => $sales->company_id,
]);
Employee::factory()->create([
'hired_at' => '2017-12-31',
'company_id' => $sales->company_id,
]);

$sales->employees()->attach([$michael->id]);
$sales->employees()->attach([$dwight->id]);
$sales->employees()->attach([$angela->id]);

$collection = TeamShowViewHelper::newHiresNextWeek($sales, $sales->company);

$this->assertEquals(1, $collection->count());

$this->assertEquals(
[
0 => [
'id' => $dwight->id,
'name' => 'Dwight Schrute',
'avatar' => ImageHelper::getAvatar($dwight, 35),
'url' => env('APP_URL').'/'.$angela->company_id.'/employees/'.$dwight->id,
'hired_at' => 'Starts on Monday (Jan 8th) as Assistant to the regional manager',
],
],
$collection->toArray()
);
}
}

0 comments on commit c8a01b1

Please sign in to comment.