Skip to content
This repository has been archived by the owner on Feb 8, 2025. It is now read-only.

Commit

Permalink
feat: cancel company account (#593)
Browse files Browse the repository at this point in the history
  • Loading branch information
djaiss authored Mar 3, 2021
1 parent de54801 commit bf456b3
Show file tree
Hide file tree
Showing 13 changed files with 342 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?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\Services\Company\Adminland\Company\DestroyCompany;

class AdminCancelAccountController extends Controller
{
/**
* Show the Cancel account page.
*
* @return Response
*/
public function index(): Response
{
return Inertia::render('Adminland/General/Cancel/Index', [
'notifications' => NotificationHelper::getNotifications(InstanceHelper::getLoggedEmployee()),
]);
}

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

$data = [
'company_id' => $loggedCompany->id,
'author_id' => $loggedEmployee->id,
];

(new DestroyCompany)->execute($data);

return response()->json([
'data' => true,
], 200);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ public function currency(Request $request, int $companyId): JsonResponse

return response()->json([
'data' => true,
], 201);
], 200);
}
}
57 changes: 57 additions & 0 deletions app/Services/Company/Adminland/Company/DestroyCompany.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

namespace App\Services\Company\Adminland\Company;

use App\Services\BaseService;
use App\Models\Company\Company;

class DestroyCompany 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',
];
}

/**
* Destroy the company.
*
* @param array $data
*/
public function execute(array $data): void
{
$this->data = $data;
$this->validate();

$this->data = $data;
$this->destroy();
}

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 destroy(): void
{
$this->company->delete();
}
}
1 change: 1 addition & 0 deletions config/officelife.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@
'team_recent_ship_create' => 'introduction.html',
'account_general_company_name' => 'introduction.html',
'account_general_currency' => 'introduction.html',
'account_cancellation' => 'manage/company-management.html#account-cancellation',
'employee_hiring_date' => 'manage/employee-management.html#hiring-date',
'employee_work_anniversaries' => 'manage/employee-management.html#work-anniversaries',
'employee_statuses' => 'manage/employee-management.html#employee-statuses',
Expand Down
126 changes: 126 additions & 0 deletions resources/js/Pages/Adminland/General/Cancel/Index.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<style lang="scss" scoped>
.check {
color: #fb8444;
top: 4px;
width: 20px;
}
</style>

<template>
<layout title="Home" :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_cancel_account') }}
</li>
</ul>
</div>

<!-- BODY -->
<div class="mw7 center br3 mb5 bg-white box restricted relative z-1">
<div class="mt5">
<h2 class="tc normal mb4 pt3 relative">
{{ $t('account.cancel_account_title') }}

<help :url="$page.props.help_links.account_cancellation" :top="'1px'" />
</h2>

<div class="ph5 pv3 bb bb-gray">
<p class="mb5">{{ $t('account.cancel_account_thanks') }}</p>

<p class="fw6">{{ $t('account.cancel_account_please_note') }}</p>
<ul class="list ma0 pa0">
<li class="relative mb2-l lh-copy">
<svg class="check relative" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
</svg>
{{ $t('account.cancel_account_company_account_closed') }}
</li>
<li class="relative mb2-l lh-copy">
<svg class="check relative" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
</svg>
{{ $t('account.cancel_account_company_employee_deleted') }}
</li>
<li class="relative mb2-l lh-copy">
<svg class="check relative" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
</svg>
{{ $t('account.cancel_account_company_data_deleted') }}
</li>
<li class="relative mb2-l lh-copy">
<svg class="check relative" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" fill="currentColor">
<path fill-rule="evenodd" d="M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z" clip-rule="evenodd" />
</svg>
{{ $t('account.cancel_account_company_subscription') }}
</li>
</ul>

<p class="lh-copy">{{ $t('account.cancel_account_data_lost_forever') }}</p>
</div>

<form class="cf pa3" @submit.prevent="destroy">
<div class="flex-ns justify-between">
<div>
<inertia-link :href="'/' + $page.props.auth.company.id + '/account'" class="btn dib tc w-auto-ns w-100 pv2 ph3 mb0-ns mb2">
{{ $t('app.cancel') }}
</inertia-link>
</div>
<loading-button :classes="'btn destroy w-auto-ns w-100 pv2 ph3'" :state="loadingState" :text="$t('account.cancel_cta')" />
</div>
</form>
</div>
</div>
</div>
</layout>
</template>

<script>
import Layout from '@/Shared/Layout';
import LoadingButton from '@/Shared/LoadingButton';
import Help from '@/Shared/Help';
export default {
components: {
Layout,
LoadingButton,
Help,
},
props: {
notifications: {
type: Array,
default: null,
},
},
data() {
return {
loadingState: '',
};
},
methods: {
destroy() {
this.loadingState = 'loading';
axios.delete(`/${this.$page.props.auth.company.id}/account/cancel`)
.then(response => {
this.$inertia.visit('/home');
})
.catch(error => {
this.loadingState = null;
});
},
}
};
</script>
4 changes: 2 additions & 2 deletions resources/js/Pages/Adminland/General/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@

<script>
import Layout from '@/Shared/Layout';
import Name from '@/Pages/Adminland/General/Name';
import Currency from '@/Pages/Adminland/General/Currency';
import Name from '@/Pages/Adminland/General/Partials/Name';
import Currency from '@/Pages/Adminland/General/Partials/Currency';
export default {
components: {
Expand Down
5 changes: 5 additions & 0 deletions resources/js/Pages/Adminland/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,11 @@
{{ $t('account.home_audit_log') }}
</inertia-link>
</li>
<li class="pa2 pl0 relative">
🗑 <inertia-link :href="'/' + $page.props.auth.company.id + '/account/cancel'" data-cy="audit-cancel-link">
{{ $t('account.home_cancel_account') }}
</inertia-link>
</li>
</ul>
</div>
</div>
Expand Down
11 changes: 11 additions & 0 deletions resources/lang/en/account.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'home_manage_expenses' => 'Manage expenses',
'home_general_settings' => 'General settings',
'home_manage_ecoffee' => 'Manage eCoffee process',
'home_cancel_account' => 'Cancel this account',

'employees_title' => 'Manage the employees in {company}',
'employees_all_title' => 'All the employees in {company}',
Expand Down Expand Up @@ -555,4 +556,14 @@
'import_employees_show_title_number_entries_errors' => 'Entries in errors',
'import_employees_show_title_number_entries_import' => 'Entries we can import',
'import_employees_import_success' => 'Employees have been imported',

'cancel_account_title' => 'Are you sure you want to cancel your account?',
'cancel_account_thanks' => 'Thanks for giving OfficeLife a try!',
'cancel_account_please_note' => 'Please note that...',
'cancel_account_company_account_closed' => 'This company’s account will be immediately closed.',
'cancel_account_company_employee_deleted' => 'All employees information will be immediately deleted.',
'cancel_account_company_data_deleted' => 'All data in this account will be deleted from our servers immediately, and from our backups in 60 days.',
'cancel_account_company_subscription' => 'If you are a subscriber, your subscription will be immediately cancelled.',
'cancel_account_data_lost_forever' => 'This process is irreversible. You will lose all the data associated with this company, forever.',
'cancel_cta' => 'Cancel the account',
];
1 change: 1 addition & 0 deletions resources/lang/en/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
'breadcrumb_account_import_employees' => 'Import employees',
'breadcrumb_account_manage_past_archives' => 'Past imports',
'breadcrumb_account_manage_past_archives_detail' => 'Detail of a past import',
'breadcrumb_account_manage_cancel_account' => 'Cancel the account',

'header_welcome' => 'Welcome',
'header_home' => 'Home',
Expand Down
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,9 @@
Route::get('account/general', 'Company\\Adminland\\AdminGeneralController@index');
Route::post('account/general/rename', 'Company\\Adminland\\AdminGeneralController@rename');
Route::post('account/general/currency', 'Company\\Adminland\\AdminGeneralController@currency');

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

// only available to hr role or administrator
Expand Down
Loading

0 comments on commit bf456b3

Please sign in to comment.