Skip to content

Commit

Permalink
feat: show job openings for which i am sponsor of on dashboard (#1285)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss committed Sep 5, 2021
1 parent 03b77b7 commit 9abee95
Show file tree
Hide file tree
Showing 10 changed files with 187 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public function index(): Response
'morale' => DashboardMeViewHelper::morale($employee),
'workFromHome' => DashboardMeViewHelper::workFromHome($employee),
'question' => DashboardMeViewHelper::question($employee),
'jobOpeningsAsSponsor' => DashboardMeViewHelper::jobOpeningsAsSponsor($company, $employee),
]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Helpers\InstanceHelper;
use Illuminate\Http\JsonResponse;
use App\Models\Company\JobOpening;
use Illuminate\Support\Facades\DB;
use App\Helpers\NotificationHelper;
use App\Http\Controllers\Controller;
use Illuminate\Database\Eloquent\ModelNotFoundException;
Expand Down Expand Up @@ -240,16 +241,23 @@ public function update(Request $request, int $companyId, int $jobOpeningId): Jso
*/
public function show(Request $request, int $companyId, int $jobOpeningId): mixed
{
$company = InstanceHelper::getLoggedCompany();
$employee = InstanceHelper::getLoggedEmployee();
$loggedCompany = InstanceHelper::getLoggedCompany();
$loggedEmployee = InstanceHelper::getLoggedEmployee();

// is this person HR?
if ($employee->permission_level > config('officelife.permission_level.hr')) {
return redirect('home');
// is this person the sponsor of the job?
$isSponsor = DB::table('job_opening_sponsor')->where('employee_id', $loggedEmployee->id)
->where('job_opening_id', $jobOpeningId)
->count() === 1;

if (! $isSponsor) {
// is this person HR?
if ($loggedEmployee->permission_level > config('officelife.permission_level.hr')) {
return redirect('home');
}
}

try {
$jobOpening = JobOpening::where('company_id', $company->id)
$jobOpening = JobOpening::where('company_id', $loggedCompany->id)
->with('team')
->with('position')
->with('position.employees')
Expand All @@ -261,13 +269,13 @@ public function show(Request $request, int $companyId, int $jobOpeningId): mixed
return redirect('recruiting.openings.index');
}

$jobOpeningDetail = RecruitingJobOpeningsViewHelper::show($company, $jobOpening);
$sponsors = RecruitingJobOpeningsViewHelper::sponsors($company, $jobOpening);
$stats = RecruitingJobOpeningsViewHelper::stats($company, $jobOpening);
$candidates = RecruitingJobOpeningsViewHelper::toSort($company, $jobOpening);
$jobOpeningDetail = RecruitingJobOpeningsViewHelper::show($loggedCompany, $jobOpening);
$sponsors = RecruitingJobOpeningsViewHelper::sponsors($loggedCompany, $jobOpening);
$stats = RecruitingJobOpeningsViewHelper::stats($loggedCompany, $jobOpening);
$candidates = RecruitingJobOpeningsViewHelper::toSort($loggedCompany, $jobOpening);

return Inertia::render('Recruiting/Show', [
'notifications' => NotificationHelper::getNotifications($employee),
'notifications' => NotificationHelper::getNotifications($loggedEmployee),
'jobOpening' => $jobOpeningDetail,
'sponsors' => $sponsors,
'stats' => $stats,
Expand All @@ -287,11 +295,18 @@ public function show(Request $request, int $companyId, int $jobOpeningId): mixed
public function showRejected(Request $request, int $companyId, int $jobOpeningId): mixed
{
$company = InstanceHelper::getLoggedCompany();
$employee = InstanceHelper::getLoggedEmployee();
$loggedEmployee = InstanceHelper::getLoggedEmployee();

// is this person HR?
if ($employee->permission_level > config('officelife.permission_level.hr')) {
return redirect('home');
// is this person the sponsor of the job?
$isSponsor = DB::table('job_opening_sponsor')->where('employee_id', $loggedEmployee->id)
->where('job_opening_id', $jobOpeningId)
->count() === 1;

if (! $isSponsor) {
// is this person HR?
if ($loggedEmployee->permission_level > config('officelife.permission_level.hr')) {
return redirect('home');
}
}

try {
Expand All @@ -313,7 +328,7 @@ public function showRejected(Request $request, int $companyId, int $jobOpeningId
$candidates = RecruitingJobOpeningsViewHelper::rejected($company, $jobOpening);

return Inertia::render('Recruiting/Show', [
'notifications' => NotificationHelper::getNotifications($employee),
'notifications' => NotificationHelper::getNotifications($loggedEmployee),
'jobOpening' => $jobOpeningDetail,
'sponsors' => $sponsors,
'stats' => $stats,
Expand All @@ -333,11 +348,18 @@ public function showRejected(Request $request, int $companyId, int $jobOpeningId
public function showSelected(Request $request, int $companyId, int $jobOpeningId): mixed
{
$company = InstanceHelper::getLoggedCompany();
$employee = InstanceHelper::getLoggedEmployee();
$loggedEmployee = InstanceHelper::getLoggedEmployee();

// is this person HR?
if ($employee->permission_level > config('officelife.permission_level.hr')) {
return redirect('home');
// is this person the sponsor of the job?
$isSponsor = DB::table('job_opening_sponsor')->where('employee_id', $loggedEmployee->id)
->where('job_opening_id', $jobOpeningId)
->count() === 1;

if (! $isSponsor) {
// is this person HR?
if ($loggedEmployee->permission_level > config('officelife.permission_level.hr')) {
return redirect('home');
}
}

try {
Expand All @@ -359,7 +381,7 @@ public function showSelected(Request $request, int $companyId, int $jobOpeningId
$candidates = RecruitingJobOpeningsViewHelper::selected($company, $jobOpening);

return Inertia::render('Recruiting/Show', [
'notifications' => NotificationHelper::getNotifications($employee),
'notifications' => NotificationHelper::getNotifications($loggedEmployee),
'jobOpening' => $jobOpeningDetail,
'sponsors' => $sponsors,
'stats' => $stats,
Expand Down
30 changes: 30 additions & 0 deletions app/Http/ViewHelpers/Dashboard/DashboardMeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,4 +480,34 @@ public static function workFromHome(Employee $employee): ?array
'has_worked_from_home_today' => WorkFromHomeHelper::hasWorkedFromHomeOnDate($employee, Carbon::now()),
];
}

/**
* Get the information about the job openings as a sponsor.
*
* @param Company $company
* @param Employee $employee
* @return Collection
*/
public static function jobOpeningsAsSponsor(Company $company, Employee $employee): Collection
{
$jobOpenings = $employee->jobOpeningsAsSponsor()
->where('fulfilled', false)
->orderBy('job_openings.created_at', 'desc')
->get();

$jobsOpeningCollection = collect();
foreach ($jobOpenings as $jobOpening) {
$jobsOpeningCollection->push([
'id' => $jobOpening->id,
'title' => $jobOpening->title,
'reference_number' => $jobOpening->reference_number,
'url' => route('recruiting.openings.show', [
'company' => $company,
'jobOpening' => $jobOpening,
]),
]);
}

return $jobsOpeningCollection;
}
}
19 changes: 15 additions & 4 deletions resources/js/Pages/Dashboard/Me/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,21 @@
:projects="projects"
/>

<contract-renewal-date
v-if="contractRenewal"
:employee="employee"
:contract-renewal="contractRenewal"
/>

<e-coffee
v-if="eCoffee"
:employee="employee"
:e-coffee="eCoffee"
/>

<contract-renewal-date
v-if="contractRenewal"
:employee="employee"
:contract-renewal="contractRenewal"
<job-openings-as-sponsor
v-if="jobOpeningsAsSponsor.length > 0"
:job-openings="jobOpeningsAsSponsor"
/>

<one-on-one-with-manager
Expand Down Expand Up @@ -80,6 +85,7 @@ import Layout from '@/Shared/Layout';
import DashboardMenu from '@/Pages/Dashboard/Partials/DashboardMenu';
import ECoffee from '@/Pages/Dashboard/Me/Partials/ECoffee';
import Projects from '@/Pages/Dashboard/Me/Partials/Projects';
import JobOpeningsAsSponsor from '@/Pages/Dashboard/Me/Partials/JobOpeningSponsor';
export default {
components: {
Expand All @@ -95,6 +101,7 @@ export default {
DashboardMenu,
ECoffee,
Projects,
JobOpeningsAsSponsor,
},
props: {
Expand Down Expand Up @@ -166,6 +173,10 @@ export default {
type: Object,
default: null,
},
jobOpeningsAsSponsor: {
type: Object,
default: null,
},
},
mounted() {
Expand Down
Empty file.
67 changes: 67 additions & 0 deletions resources/js/Pages/Dashboard/Me/Partials/JobOpeningSponsor.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<style lang="scss" scoped>
.job-opening-item:first-child:hover {
border-top-left-radius: 10px;
border-top-right-radius: 10px;
}
.job-opening-item:last-child {
border-bottom: 0;
&:hover {
border-bottom-left-radius: 10px;
border-bottom-right-radius: 10px;
}
}
.reference-number {
padding: 2px 6px;
border-radius: 6px;
top: -4px;
background-color: #ddf4ff;
color: #0969da;
}
</style>

<template>
<div class="mb5">
<div class="cf mw7 center mb2 fw5">
<span class="mr1">
🧑‍🎓
</span> {{ $t('dashboard.job_opening_sponsor_title') }}

<help :url="$page.props.help_links.worklogs" />
</div>

<div class="cf mw7 center br3 mb3 bg-white box">
<ul class="list ma0 pl0">
<li v-for="jobOpening in jobOpenings" :key="jobOpening.id" class="pa3 job-opening-item bb bb-gray bb-gray-hover">
<div>
<div :class="jobOpening.team ? 'mb2': ''" class="db">
<inertia-link :href="jobOpening.url" class="mr2">{{ jobOpening.title }}</inertia-link>
<span v-if="jobOpening.reference_number" class="reference-number f7 code fw4">{{ jobOpening.reference_number }}</span>
</div>

<p v-if="jobOpening.team" class="ma0 f7 gray">For <inertia-link :href="jobOpening.team.url">{{ jobOpening.team.name }}</inertia-link></p>
</div>
</li>
</ul>
</div>
</div>
</template>

<script>
import Help from '@/Shared/Help';
export default {
components: {
Help,
},
props: {
jobOpenings: {
type: Object,
default: null,
},
},
};
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@

<!-- add a new participant cta -->
<li v-if="!modal" class="ph2 pv3 list bb bb-gray bb-gray-hover tc">
<a class="bb b--dotted bt-0 bl-0 br-0 pointer f6" @click="showSearch()">Ask employee to assist and give feedback</a>
<a class="bb b--dotted bt-0 bl-0 br-0 pointer f6" @click="showSearch()">{{ trans('dashboard.job_opening_stage_participants_cta') }}</a>
</li>

<!-- modal to add -->
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Recruiting/Partials/Information.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
{{ $t('app.no') }}
</a>
</li>
<li v-else class="di">
<li v-if="!deleteMode" class="di">
<a class="bb b--dotted bt-0 bl-0 br-0 pointer c-delete" @click.prevent="deleteMode = true">
{{ $t('app.delete') }}
</a>
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/en/dashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
'tab_hr' => 'HR area',
'tab_timesheets' => 'Your timesheets',
'blank_state' => 'You are not associated with a team at the moment.',
'job_opening_sponsor_title' => 'Job openings you are sponsor of',
'morale_title' => 'How do you feel?',
'morale_success_message' => 'Thanks for telling us how you feel.',
'morale_already_logged' => 'You have already indicated how you felt today. Come back tomorrow!',
Expand Down Expand Up @@ -302,6 +303,7 @@
'job_opening_stage_participants_help' => 'Participants can assist you in the recruitment process, give feedback. Also, they will be able to read any document uploaded by the candidate.',
'job_opening_stage_participants_feedback' => 'feedback given',
'job_opening_stage_participants_no_feedback' => 'no feedback provided yet',
'job_opening_stage_participants_cta' => 'Ask employee to assist and give feedback',
'job_opening_stage_notes_title' => 'Notes',
'job_opening_stage_notes_cta' => 'Add a new note',
'job_opening_stage_notes_update_success' => 'The note has been updated.',
Expand Down
27 changes: 27 additions & 0 deletions tests/Unit/ViewHelpers/Dashboard/DashboardMeViewHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Models\Company\Worklog;
use App\Models\Company\Employee;
use App\Models\Company\Question;
use App\Models\Company\JobOpening;
use App\Models\Company\ECoffeeMatch;
use App\Models\Company\WorkFromHome;
use App\Models\Company\OneOnOneEntry;
Expand Down Expand Up @@ -564,4 +565,30 @@ public function it_gets_information_about_working_from_home(): void
DashboardMeViewHelper::workFromHome($michael)
);
}

/** @test */
public function it_gets_the_job_openings_the_employee_is_a_sponsor_of(): void
{
Carbon::setTestNow(Carbon::create(2018, 1, 1));

$company = Company::factory()->create();
$jobOpening = JobOpening::factory()->create([
'company_id' => $company->id,
'activated_at' => Carbon::now(),
]);
$michael = Employee::factory()->create();
$jobOpening->sponsors()->syncWithoutDetaching([$michael->id]);

$this->assertEquals(
[
0 => [
'id' => $jobOpening->id,
'title' => $jobOpening->title,
'reference_number' => $jobOpening->reference_number,
'url' => env('APP_URL').'/'.$company->id.'/recruiting/job-openings/'.$jobOpening->id,
],
],
DashboardMeViewHelper::jobOpeningsAsSponsor($company, $michael)->toArray()
);
}
}

0 comments on commit 9abee95

Please sign in to comment.