Skip to content

Commit

Permalink
feat: ability to set company location (#1223)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss committed Jul 30, 2021
1 parent 922830b commit 521729c
Show file tree
Hide file tree
Showing 13 changed files with 373 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/Helpers/LogHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,12 @@ public static function processAuditLog(AuditLog $log): string
]);
break;

case 'company_location_updated':
$sentence = trans('account.log_company_location_updated', [
'location' => $log->object->{'location'},
]);
break;

default:
$sentence = '';
break;
Expand Down
24 changes: 24 additions & 0 deletions app/Http/Controllers/Company/Adminland/AdminGeneralController.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use App\Http\ViewHelpers\Adminland\AdminGeneralViewHelper;
use App\Services\Company\Adminland\Company\UpdateCompanyLogo;
use App\Services\Company\Adminland\Company\UpdateCompanyCurrency;
use App\Services\Company\Adminland\Company\UpdateCompanyLocation;
use App\Services\Company\Adminland\Company\UpdateCompanyFoundedDate;

class AdminGeneralController extends Controller
Expand Down Expand Up @@ -146,4 +147,27 @@ public function date(Request $request, int $companyId): JsonResponse
'data' => true,
], 200);
}

/**
* Update the company’s location.
*
* @param Request $request
* @param int $companyId
* @return JsonResponse
*/
public function location(Request $request, int $companyId): JsonResponse
{
$loggedEmployee = InstanceHelper::getLoggedEmployee();
$loggedCompany = InstanceHelper::getLoggedCompany();

(new UpdateCompanyLocation)->execute([
'company_id' => $loggedCompany->id,
'author_id' => $loggedEmployee->id,
'location' => $request->input('location'),
]);

return response()->json([
'data' => true,
], 200);
}
}
1 change: 1 addition & 0 deletions app/Http/ViewHelpers/Adminland/AdminGeneralViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public static function information($company, Employee $loggedEmployee): ?array
'administrators' => $administratorsCollection,
'creation_date' => $creationDate,
'currency' => $company->currency,
'location' => $company->location,
'total_size' => round($totalSize / 1000, 4),
'logo' => $logo,
'uploadcare_public_key' => config('officelife.uploadcare_public_key'),
Expand Down
1 change: 1 addition & 0 deletions app/Models/Company/Company.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Company extends Model
protected $fillable = [
'name',
'currency',
'location',
'has_dummy_data',
'logo_file_id',
'e_coffee_enabled',
Expand Down
78 changes: 78 additions & 0 deletions app/Services/Company/Adminland/Company/UpdateCompanyLocation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php

namespace App\Services\Company\Adminland\Company;

use Carbon\Carbon;
use App\Jobs\LogAccountAudit;
use App\Services\BaseService;
use App\Models\Company\Company;

class UpdateCompanyLocation extends BaseService
{
protected Company $company;

protected array $data;

/**
* 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',
'location' => 'required|string|max:255',
];
}

/**
* Update the company's location.
*
* @param array $data
* @return Company
*/
public function execute(array $data): Company
{
$this->data = $data;
$this->validate();
$this->updateLocation();
$this->log();

return $this->company;
}

private function validate(): void
{
$this->validateRules($this->data);

$this->author($this->data['author_id'])
->inCompany($this->data['company_id'])
->asAtLeastAdministrator()
->canExecuteService();

$this->company = Company::find($this->data['company_id']);
}

private function updateLocation(): void
{
Company::where('id', $this->company->id)->update([
'location' => $this->data['location'],
]);
}

private function log(): void
{
LogAccountAudit::dispatch([
'company_id' => $this->company->id,
'action' => 'company_location_updated',
'author_id' => $this->author->id,
'author_name' => $this->author->name,
'audited_at' => Carbon::now(),
'objects' => json_encode([
'location' => $this->data['location'],
]),
])->onQueue('low');
}
}
1 change: 1 addition & 0 deletions config/officelife.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,7 @@
'account_general_currency' => 'manage/company-management.html#currency',
'account_general_logo' => 'manage/company-management.html#logo',
'account_general_founded_date' => 'manage/company-management.html#defining-the-company-s-founded-date',
'account_general_location' => 'manage/company-management.html#defining-the-company-s-main-location',
'account_cancellation' => 'manage/company-management.html#account-cancellation',
'one_on_ones' => 'grow/one-on-ones.html#overview',
'project' => 'operate/project-management.html#overview',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class AddCompanyLocationToCompanies extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
// necessary for SQLlite
Schema::enableForeignKeyConstraints();

Schema::table('companies', function (Blueprint $table) {
$table->string('location')->after('currency')->nullable();
});
}
}
7 changes: 7 additions & 0 deletions resources/js/Pages/Adminland/General/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@
:information="information"
/>

<!-- company location -->
<location
:information="information"
/>

<!-- Currency -->
<currency
:information="information"
Expand All @@ -62,13 +67,15 @@ import Layout from '@/Shared/Layout';
import Name from '@/Pages/Adminland/General/Partials/Name';
import Currency from '@/Pages/Adminland/General/Partials/Currency';
import Stat from '@/Pages/Adminland/General/Partials/Stat';
import Location from '@/Pages/Adminland/General/Partials/Location';
import Logo from '@/Pages/Adminland/General/Partials/Logo';
import FoundedDate from '@/Pages/Adminland/General/Partials/FoundedDate';
export default {
components: {
Layout,
Name,
Location,
Currency,
Stat,
Logo,
Expand Down
137 changes: 137 additions & 0 deletions resources/js/Pages/Adminland/General/Partials/Location.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<style lang="scss" scoped>
.title {
min-width: 230px;
}
</style>

<template>
<div class="bb bb-gray">
<h3 class="ph3 fw5">
{{ $t('account.general_location_information') }}

<help :url="$page.props.help_links.account_general_location" :top="'2px'" />
</h3>

<!-- location of the company -->
<ul v-if="!editMode" class="list ph3">
<li class="mb3 flex items-start">
<span class="dib title mr3">{{ $t('account.general_location_label') }}</span>
<span v-if="localLocation" class="fw6">{{ localLocation }}</span>
<span v-else class="fw6">{{ $t('account.general_location_blank') }}</span>
</li>
</ul>

<div v-if="!editMode" class="ph3 mb3">
<a data-cy="update-currency-company-button" class="btn tc relative dib" @click.prevent="displayEditMode()">
{{ $t('account.general_location_cta') }}
</a>
</div>

<!-- change date -->
<div v-if="editMode" class="ph3">
<form @submit.prevent="submit">
<errors :errors="form.errors" :class="'mb3'" />

<ul class="list pl0">
<li class="mb3 flex-ns items-center">
<span class="dib-ns db mb0-ns mb2 title">{{ $t('account.general_location_label') }}</span>
<span>
<text-input
:id="'name'"
:ref="'setLocation'"
v-model="form.location"
:name="'name'"
:extra-class-upper-div="'mb0'"
:errors="$page.props.errors.title"
:required="true"
:autofocus="true"
:maxlength="191"
autocomplete="off"
@esc-key-pressed="editMode = false"
/>
</span>
</li>
</ul>

<!-- Actions -->
<div class="mt4 mb3">
<div class="flex-ns justify-between">
<div>
<a href="#" class="btn dib tc w-auto-ns w-100 pv2 ph3" @click.prevent="editMode = false">
{{ $t('app.cancel') }}
</a>
</div>
<loading-button :class="'btn add w-auto-ns w-100 pv2 ph3'" :state="loadingState" :text="$t('app.update')" />
</div>
</div>
</form>
</div>
</div>
</template>

<script>
import Errors from '@/Shared/Errors';
import LoadingButton from '@/Shared/LoadingButton';
import Help from '@/Shared/Help';
import TextInput from '@/Shared/TextInput';
export default {
components: {
Errors,
Help,
LoadingButton,
TextInput,
},
props: {
information: {
type: Object,
default: null,
},
},
data() {
return {
localLocation: '',
editMode: false,
form: {
id: 0,
location: null,
errors: [],
},
loadingState: '',
};
},
mounted: function() {
this.localLocation = this.information.location;
},
methods: {
displayEditMode() {
this.editMode = true;
if (this.localLocation) {
this.form.location = this.localLocation;
}
this.$nextTick(() => {
this.$refs.setLocation.focus();
});
},
submit() {
axios.post('/' + this.$page.props.auth.company.id + '/account/general/location', this.form)
.then(response => {
this.localLocation = this.form.location;
this.editMode = false;
this.flash(this.$t('account.general_location_success'), 'success');
})
.catch(error => {
this.editMode = true;
this.form.errors = error.response.data;
});
},
}
};
</script>
6 changes: 6 additions & 0 deletions resources/lang/en/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@
'log_recruiting_stage_destroyed' => 'Deleted the recruiting stage called :recruiting_stage_name.',
'log_recruiting_stage_template_created' => 'Created a recruiting stage template called :recruiting_stage_template_name.',
'log_recruiting_stage_template_updated' => 'Updated the recruiting stage template called :recruiting_stage_name.',
'log_company_location_updated' => 'Updated the location of the company to :location.',
// employee logs
'employee_log_employee_created' => 'Created this employee entry.',
'employee_log_employee_locked' => 'Locked this employee entry.',
Expand Down Expand Up @@ -589,6 +590,11 @@
'general_founded_date_no_date' => 'No date yet',
'general_founded_date_success' => 'The founded date has been changed.',
'general_invitation_code' => 'Code that employees can use to join the company',
'general_location_information' => 'Headquarter’s location',
'general_location_label' => 'City and country',
'general_location_blank' => 'Not defined yet',
'general_location_cta' => 'Set location',
'general_location_success' => 'The location has been set',
'ecoffee_title' => 'E-Coffee sessions in the company',
'ecoffee_desc' => 'E-Coffees are a great way for employees to take some time with another colleague and spend 15 minutes in a week to get to know him/her. The goal is to talk about everything but work. The more you know your colleagues, the more powerful their bonds.',
'ecoffee_enabled' => 'e-Coffees are enabled',
Expand Down
1 change: 1 addition & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@
Route::post('account/general/currency', 'Company\\Adminland\\AdminGeneralController@currency');
Route::post('account/general/logo', 'Company\\Adminland\\AdminGeneralController@logo');
Route::post('account/general/date', 'Company\\Adminland\\AdminGeneralController@date');
Route::post('account/general/location', 'Company\\Adminland\\AdminGeneralController@location');

Route::get('account/cancel', 'Company\\Adminland\\AdminCancelAccountController@index');
Route::delete('account/cancel', 'Company\\Adminland\\AdminCancelAccountController@destroy');
Expand Down

0 comments on commit 521729c

Please sign in to comment.