-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add ability to disable work from home feature (#1113)
- Loading branch information
Showing
22 changed files
with
449 additions
and
8 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
59 changes: 59 additions & 0 deletions
59
app/Http/Controllers/Company/Adminland/AdminWorkFromHomeController.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,59 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Company\Adminland; | ||
|
||
use Inertia\Inertia; | ||
use Inertia\Response; | ||
use Illuminate\Http\Request; | ||
use App\Helpers\InstanceHelper; | ||
use Illuminate\Http\JsonResponse; | ||
use App\Helpers\NotificationHelper; | ||
use App\Http\Controllers\Controller; | ||
use App\Http\ViewHelpers\Adminland\AdminWorkFromHomeViewHelper; | ||
use App\Services\Company\Adminland\WorkFromHome\ToggleWorkFromHomeProcess; | ||
|
||
class AdminWorkFromHomeController extends Controller | ||
{ | ||
/** | ||
* Show the work from home page. | ||
* | ||
* @return Response | ||
*/ | ||
public function index(): Response | ||
{ | ||
$company = InstanceHelper::getLoggedCompany(); | ||
|
||
$details = AdminWorkFromHomeViewHelper::index($company); | ||
|
||
return Inertia::render('Adminland/WorkFromHome/Index', [ | ||
'notifications' => NotificationHelper::getNotifications(InstanceHelper::getLoggedEmployee()), | ||
'process' => $details, | ||
]); | ||
} | ||
|
||
/** | ||
* Toggle the work from home setting in the company. | ||
* | ||
* @param Request $request | ||
* @param int $companyId | ||
* @return JsonResponse | ||
*/ | ||
public function update(Request $request, int $companyId): JsonResponse | ||
{ | ||
$loggedEmployee = InstanceHelper::getLoggedEmployee(); | ||
$company = InstanceHelper::getLoggedCompany(); | ||
|
||
$data = [ | ||
'company_id' => $company->id, | ||
'author_id' => $loggedEmployee->id, | ||
]; | ||
|
||
$company = (new ToggleWorkFromHomeProcess)->execute($data); | ||
|
||
return response()->json([ | ||
'data' => [ | ||
'enabled' => $company->work_from_home_enabled, | ||
], | ||
], 200); | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
app/Http/ViewHelpers/Adminland/AdminWorkFromHomeViewHelper.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,22 @@ | ||
<?php | ||
|
||
namespace App\Http\ViewHelpers\Adminland; | ||
|
||
use App\Models\Company\Company; | ||
|
||
class AdminWorkFromHomeViewHelper | ||
{ | ||
/** | ||
* Get the information about the work from home process | ||
* used in the company. | ||
* | ||
* @param Company $company | ||
* @return array|null | ||
*/ | ||
public static function index(Company $company): ?array | ||
{ | ||
return [ | ||
'enabled' => $company->work_from_home_enabled, | ||
]; | ||
} | ||
} |
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
57 changes: 57 additions & 0 deletions
57
app/Services/Company/Adminland/WorkFromHome/ToggleWorkFromHomeProcess.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,57 @@ | ||
<?php | ||
|
||
namespace App\Services\Company\Adminland\WorkFromHome; | ||
|
||
use Carbon\Carbon; | ||
use App\Jobs\LogAccountAudit; | ||
use App\Services\BaseService; | ||
use App\Models\Company\Company; | ||
|
||
class ToggleWorkFromHomeProcess extends BaseService | ||
{ | ||
/** | ||
* Get the validation rules that apply to the service. | ||
* | ||
* @return array | ||
*/ | ||
public function rules(): array | ||
{ | ||
return [ | ||
'company_id' => 'required|integer|exists:companies,id', | ||
'author_id' => 'required|integer|exists:employees,id', | ||
]; | ||
} | ||
|
||
/** | ||
* Toggle the work from home process in the company. | ||
* | ||
* @param array $data | ||
* @return Company | ||
*/ | ||
public function execute(array $data): Company | ||
{ | ||
$this->validateRules($data); | ||
|
||
$this->author($data['author_id']) | ||
->inCompany($data['company_id']) | ||
->asAtLeastHR() | ||
->canExecuteService(); | ||
|
||
$company = Company::findOrFail($data['company_id']); | ||
|
||
$company->work_from_home_enabled = ! $company->work_from_home_enabled; | ||
$company->save(); | ||
$company->refresh(); | ||
|
||
LogAccountAudit::dispatch([ | ||
'company_id' => $data['company_id'], | ||
'action' => 'toggle_work_from_home_process', | ||
'author_id' => $this->author->id, | ||
'author_name' => $this->author->name, | ||
'audited_at' => Carbon::now(), | ||
'objects' => json_encode([]), | ||
])->onQueue('low'); | ||
|
||
return $company; | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
database/migrations/2021_06_19_211855_add_toggle_work_from_home.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,18 @@ | ||
<?php | ||
|
||
use Illuminate\Support\Facades\Schema; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Database\Migrations\Migration; | ||
|
||
class AddToggleWorkFromHome extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
*/ | ||
public function up() | ||
{ | ||
Schema::table('companies', function (Blueprint $table) { | ||
$table->boolean('work_from_home_enabled')->default(true)->after('e_coffee_enabled'); | ||
}); | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,139 @@ | ||
<style lang="scss" scoped> | ||
.status-active { | ||
background-color: #dcf7ee; | ||
.dot { | ||
background-color: #00b760; | ||
} | ||
} | ||
.status-inactive { | ||
background-color: #ffe9e3; | ||
.dot { | ||
background-color: #ff3400; | ||
} | ||
} | ||
.dot { | ||
height: 8px; | ||
top: 3px; | ||
} | ||
</style> | ||
|
||
<template> | ||
<layout :notifications="notifications"> | ||
<div class="ph2 ph0-ns"> | ||
<!-- BREADCRUMB --> | ||
<div class="mt4-l mt1 mw6 br3 bg-white box center breadcrumb relative z-0 f6 pb2"> | ||
<ul class="list ph0 tc-l tl"> | ||
<li class="di"> | ||
<inertia-link :href="'/' + $page.props.auth.company.id + '/dashboard'">{{ $t('app.breadcrumb_dashboard') }}</inertia-link> | ||
</li> | ||
<li class="di"> | ||
<inertia-link :href="'/' + $page.props.auth.company.id + '/account'">{{ $t('app.breadcrumb_account_home') }}</inertia-link> | ||
</li> | ||
<li class="di"> | ||
{{ $t('app.breadcrumb_account_manage_work_from_home') }} | ||
</li> | ||
</ul> | ||
</div> | ||
|
||
<!-- BODY --> | ||
<div class="mw7 center br3 mb5 bg-white box restricted relative z-1"> | ||
<div class="pa3 mt5"> | ||
<h2 class="tc normal mb4"> | ||
{{ $t('account.work_from_home_title') }} | ||
|
||
<help :url="$page.props.help_links.work_from_home" :datacy="'help-icon-general'" :top="'2px'" /> | ||
</h2> | ||
|
||
<div class="relative"> | ||
<img loading="lazy" src="/img/streamline-icon-cat-house@140x140.png" alt="work from home symbol" class="absolute left-1 mr1" height="80" | ||
width="80" | ||
/> | ||
|
||
<div class="ml6"> | ||
<p class="lh-copy">{{ $t('account.work_from_home_desc') }}</p> | ||
|
||
<p v-if="localWorkFromHome.enabled" data-cy="message-enable" class="status-active dib pa3 br3"> | ||
<span class="br3 f7 fw3 ph2 pv1 dib relative mr1 dot"></span> | ||
{{ $t('account.work_from_home_enabled') }} | ||
</p> | ||
|
||
<p v-if="!localWorkFromHome.enabled" data-cy="message-disable" class="status-inactive dib pa3 br3"> | ||
<span class="br3 f7 fw3 ph2 pv1 dib relative mr1 dot"></span> | ||
{{ $t('account.work_from_home_disabled') }} | ||
</p> | ||
|
||
<form @submit.prevent="toggleProcess"> | ||
<errors :errors="form.errors" /> | ||
|
||
<loading-button v-if="!localWorkFromHome.enabled" :class="'btn w-auto-ns w-100 mb2 pv2 ph3'" :state="loadingState" :text="$t('app.enable')" :cypress-selector="'enable-ecoffee-process'" /> | ||
<loading-button v-else :class="'btn w-auto-ns w-100 mb2 pv2 ph3'" :state="loadingState" :text="$t('app.disable')" :cypress-selector="'disable-ecoffee-process'" /> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</layout> | ||
</template> | ||
|
||
<script> | ||
import LoadingButton from '@/Shared/LoadingButton'; | ||
import Layout from '@/Shared/Layout'; | ||
import Errors from '@/Shared/Errors'; | ||
import Help from '@/Shared/Help'; | ||
export default { | ||
components: { | ||
Layout, | ||
LoadingButton, | ||
Errors, | ||
Help, | ||
}, | ||
props: { | ||
notifications: { | ||
type: Array, | ||
default: null, | ||
}, | ||
process: { | ||
type: Object, | ||
default: null, | ||
}, | ||
}, | ||
data() { | ||
return { | ||
loadingState: null, | ||
localWorkFromHome: null, | ||
form: { | ||
errors: [], | ||
}, | ||
}; | ||
}, | ||
created() { | ||
this.localWorkFromHome = this.process; | ||
}, | ||
methods: { | ||
toggleProcess() { | ||
this.loadingState = 'loading'; | ||
axios.put(`${this.$page.props.auth.company.id}/account/workFromHome`, this.form) | ||
.then(response => { | ||
this.loadingState = null; | ||
this.localWorkFromHome = response.data.data; | ||
}) | ||
.catch(error => { | ||
this.loadingState = null; | ||
this.form.errors = error.response.data; | ||
}); | ||
}, | ||
} | ||
}; | ||
</script> |
Oops, something went wrong.