Skip to content

Commit

Permalink
feat: add phone number to employee (#364)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored Nov 3, 2020
1 parent 0880231 commit 876d498
Show file tree
Hide file tree
Showing 13 changed files with 84 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public function show(Request $request, int $companyId, int $employeeId)
'last_name' => $employee->last_name,
'name' => $employee->name,
'email' => $employee->email,
'phone' => $employee->phone_number,
'birthdate' => (! $employee->birthdate) ? null : [
'year' => $employee->birthdate->year,
'month' => $employee->birthdate->month,
Expand Down Expand Up @@ -96,6 +97,7 @@ public function update(Request $request, int $companyId, int $employeeId): JsonR
'first_name' => $request->input('first_name'),
'last_name' => $request->input('last_name'),
'email' => $request->input('email'),
'phone' => $request->input('phone'),
];

(new SetPersonalDetails)->execute($data);
Expand Down
1 change: 1 addition & 0 deletions app/Http/ViewHelpers/Employee/EmployeeShowViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public static function informationAboutEmployee(Employee $employee, array $permi
'last_name' => $employee->last_name,
'avatar' => $employee->avatar,
'email' => $employee->email,
'phone' => $employee->phone_number,
'twitter_handle' => $employee->twitter_handle,
'slack_handle' => $employee->slack_handle,
'locked' => $employee->locked,
Expand Down
1 change: 1 addition & 0 deletions app/Models/Company/Employee.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Employee extends Model
'consecutive_worklog_missed',
'employee_status_id',
'uuid',
'phone_number',
'locked',
'avatar',
'holiday_balance',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public function rules(): array
'first_name' => 'required|string|max:255',
'last_name' => 'required|string|max:255',
'email' => 'required|email:rfc|max:255',
'phone' => 'nullable|max:255',
];
}

Expand Down Expand Up @@ -63,6 +64,7 @@ private function save(array $data): void
$this->employee->first_name = $data['first_name'];
$this->employee->last_name = $data['last_name'];
$this->employee->email = $data['email'];
$this->employee->phone_number = $data['phone'];
$this->employee->save();
}

Expand Down
1 change: 1 addition & 0 deletions database/factories/CompanyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'avatar' => 'https://api.adorable.io/avatars/285/abott@adorable.png',
'permission_level' => config('officelife.permission_level.administrator'),
'email' => 'dwigth@dundermifflin.com',
'phone_number' => '1234567',
'first_name' => 'Dwight',
'last_name' => 'Schrute',
'birthdate' => $faker->dateTimeThisCentury()->format('Y-m-d H:i:s'),
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 AddPhoneNumberToEmployees extends Migration
{
/**
* Run the migrations.
*/
public function up()
{
// necessary for SQLlite
Schema::enableForeignKeyConstraints();

Schema::table('employees', function (Blueprint $table) {
$table->string('phone_number')->after('uuid')->nullable();
});
}
}
18 changes: 15 additions & 3 deletions resources/js/Pages/Employee/Edit.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<style lang="scss" scoped>
.edit-information-menu {
a {
border-bottom: 0;
border-bottom: 1px solid #fff;
}
.selected {
Expand Down Expand Up @@ -104,6 +104,16 @@
:type="'email'"
:help="$t('employee.edit_information_email_help')"
/>

<!-- phone number -->
<text-input :id="'phone'"
v-model="form.phone"
:name="'phone'"
:errors="$page.props.errors.phone"
:label="$t('employee.edit_information_phone')"
:type="'text'"
:help="$t('employee.edit_information_phone_help')"
/>
</div>
</div>

Expand Down Expand Up @@ -313,6 +323,7 @@ export default {
first_name: null,
last_name: null,
email: null,
phone: null,
year: null,
month: null,
day: null,
Expand All @@ -332,6 +343,7 @@ export default {
this.form.first_name = this.employee.first_name;
this.form.last_name = this.employee.last_name;
this.form.email = this.employee.email;
this.form.phone = this.employee.phone;
this.form.twitter = this.employee.twitter_handle;
this.form.slack = this.employee.slack_handle;
Expand All @@ -352,10 +364,10 @@ export default {
submit() {
this.loadingState = 'loading';
axios.post('/' + this.$page.props.auth.company.id + '/employees/' + this.employee.id + '/update', this.form)
axios.post(`/${this.$page.props.auth.company.id}/employees/${this.employee.id}/update`, this.form)
.then(response => {
localStorage.success = this.$t('employee.edit_information_success');
this.$inertia.visit('/' + this.$page.props.auth.company.id + '/employees/' + this.employee.id);
this.$inertia.visit(`/${this.$page.props.auth.company.id}/employees/${this.employee.id}`);
})
.catch(error => {
this.loadingState = null;
Expand Down
6 changes: 3 additions & 3 deletions resources/js/Pages/Employee/Edit/Address.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<style lang="scss" scoped>
.edit-information-menu {
a {
border-bottom: 0;
border-bottom: 1px solid #fff;
}
.selected {
Expand Down Expand Up @@ -209,10 +209,10 @@ export default {
this.loadingState = 'loading';
this.form.country_id = this.form.country_id.value;
axios.post('/' + this.$page.props.auth.company.id + '/employees/' + this.employee.id + '/address/update', this.form)
axios.post(`/${this.$page.props.auth.company.id}/employees/${this.employee.id}/address/update`, this.form)
.then(response => {
localStorage.success = this.$t('employee.edit_information_success');
this.$inertia.visit('/' + this.$page.props.auth.company.id + '/employees/' + this.employee.id);
this.$inertia.visit(`/${this.$page.props.auth.company.id}/employees/${this.employee.id}`);
})
.catch(error => {
this.loadingState = null;
Expand Down
21 changes: 21 additions & 0 deletions resources/js/Pages/Employee/Partials/EmployeePhone.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<template>
<div class="di relative">
<span v-if="employee.phone" data-cy="employee-phone">
{{ employee.phone }}
</span>
<span v-else>
{{ $t('employee.phone_undefined') }}
</span>
</div>
</template>

<script>
export default {
props: {
employee: {
type: Object,
default: null,
},
},
};
</script>
9 changes: 9 additions & 0 deletions resources/js/Pages/Employee/Partials/HeaderEmployee.vue
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,13 @@
</p>
</div>
<div class="pr5">
<p class="mt0 f6">
<span class="f7 gray">{{ $t('employee.phone') }}</span>

<employee-phone
:employee="employee"
/>
</p>
<p class="mt0 f6">
<span class="f7 gray">{{ $t('employee.email') }}</span>

Expand Down Expand Up @@ -177,6 +184,7 @@ import EmployeeTeam from '@/Pages/Employee/Partials/EmployeeTeam';
import EmployeeBirthdate from '@/Pages/Employee/Partials/EmployeeBirthdate';
import EmployeeEmail from '@/Pages/Employee/Partials/EmployeeEmail';
import EmployeeTwitter from '@/Pages/Employee/Partials/EmployeeTwitter';
import EmployeePhone from '@/Pages/Employee/Partials/EmployeePhone';
import EmployeeSlack from '@/Pages/Employee/Partials/EmployeeSlack';
import EmployeeHiredDate from '@/Pages/Employee/Partials/EmployeeHiredDate';
Expand All @@ -189,6 +197,7 @@ export default {
EmployeeBirthdate,
EmployeeEmail,
EmployeeTwitter,
EmployeePhone,
EmployeeSlack,
EmployeeHiredDate,
},
Expand Down
6 changes: 5 additions & 1 deletion resources/lang/en/employee.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
'email' => 'Email',
'twitter' => 'Twitter',
'twitter_undefined' => 'No Twitter handle set',
'phone' => 'Phone number',
'phone_undefined' => 'No phone number set',
'slack' => 'Slack',
'slack_undefined' => 'No Slack handle set',

Expand Down Expand Up @@ -118,7 +120,7 @@
'edit_information_postal_code' => 'Postal code',
'edit_information_country' => 'Country',
'edit_information_success' => 'Information has been updated',
'edit_information_name' => 'Name and email address',
'edit_information_name' => 'Name, email address and phone number',
'edit_information_name_help' => 'These information will be used throughout OfficeLife.',
'edit_information_social' => 'Social network presence',
'edit_information_social_help' => 'Use those fields to help your coworkers communicate with you.',
Expand All @@ -130,6 +132,8 @@
'edit_information_lastname' => 'Last name',
'edit_information_email' => 'Email address',
'edit_information_email_help' => 'This should be an email address at work.',
'edit_information_phone' => 'Phone number at work',
'edit_information_phone_help' => 'This should be a phone number used for work purposes.',
'edit_information_birthdate' => 'Birthdate',
'edit_information_birthdate_help' => 'The year will be only seen by the employee and people with the HR role. However, the month and day will be public to everyone in the company.',
'edit_information_year' => 'Year',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ private function executeService(Employee $michael, Employee $dwight): void
'first_name' => 'michael',
'last_name' => 'scott',
'email' => 'michael@dundermifflin.com',
'phone' => '123456789',
];

$dwight = (new SetPersonalDetails)->execute($request);
Expand All @@ -100,6 +101,7 @@ private function executeService(Employee $michael, Employee $dwight): void
'first_name' => 'michael',
'last_name' => 'scott',
'email' => 'michael@dundermifflin.com',
'phone_number' => '123456789',
]);

Queue::assertPushed(LogAccountAudit::class, function ($job) use ($michael, $dwight) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public function it_gets_the_information_about_the_employee(): void
$this->assertArrayHasKey('slack_handle', $array);
$this->assertArrayHasKey('hired_at', $array);
$this->assertArrayHasKey('email', $array);
$this->assertArrayHasKey('phone', $array);
$this->assertArrayHasKey('locked', $array);
$this->assertArrayHasKey('birthdate', $array);
$this->assertArrayHasKey('raw_description', $array);
Expand Down

0 comments on commit 876d498

Please sign in to comment.