Skip to content
This repository has been archived by the owner on Oct 1, 2021. It is now read-only.

Commit

Permalink
refactor: move feedback to delete account form (#122)
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaur authored Apr 12, 2021
1 parent 7884011 commit dbf64e3
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 139 deletions.
1 change: 0 additions & 1 deletion config/fortify.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@
*/

'routes' => [
'feedback' => env('ROUTE_FEEDBACK', '/feedback'),
'feedback_thank_you' => env('ROUTE_FEEDBACK_THANK_YOU', '/feedback/thank-you'),
],

Expand Down
9 changes: 4 additions & 5 deletions resources/lang/en/forms.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'2fa_code' => '2FA Verification Code',
'recovery_code' => 'Recovery Code',
'confirm_username' => 'Your Username',
'optional' => 'optional',

'update-password' => [
'requirements_notice' => 'Password must be 12–128 characters, and include a number, a symbol, a lower and an upper case letter.',
Expand All @@ -31,7 +32,7 @@

'delete-user' => [
'title' => 'Delete Account',
'confirmation' => 'Are you sure you want to delete your account? This action cannot be undone. Please input your username to proceed or click cancel to go back.',
'confirmation' => 'Deleting your account will also delete all Projects you own from MarketSquare, and these actions are permanent. Confirm your username below or click Cancel to go back.',
'confirmation_placeholder' => 'Enter your username to confirm deletion',
],

Expand All @@ -53,9 +54,7 @@
],

'feedback' => [
'message' => [
'label' => 'Feedback',
'placeholder' => 'Describe your feedback here',
],
'label' => 'Feedback',
'placeholder' => 'Provide feedback and help us...',
],
];
1 change: 0 additions & 1 deletion resources/lang/en/metatags.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
'register' => 'Register',
'login_with_two_factor' => 'Login With Two Factor',
'verify' => 'Verify',
'feedback' => 'Feedback',
'feedback_thank_you' => 'Thank You',
];
5 changes: 0 additions & 5 deletions resources/lang/en/pages.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@
'password_updated' => 'Password was successfully updated',
],

'feedback' => [
'title' => 'Provide feedback and help us improve!',
'description' => 'We are sad to see you go! Help us improve by providing the reason for your departure.',
],

'feedback_thank_you' => [
'title' => 'Thank you for your feedback',
'description' => 'We\'re sorry to see you go. You can return anytime by creating a new account.',
Expand Down
34 changes: 29 additions & 5 deletions resources/views/profile/delete-user-form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,52 @@
<x-slot name="description">
<div class="flex flex-col mt-4">
<div class="flex justify-center w-full">
@svg('fortify-modal.delete-account', 'text-theme-primary-600 w-2/3')
<x-ark-icon name="fortify-modal.delete-account" class="text-theme-primary-600 w-2/3 h-auto"/>
</div>
<div class="mt-4">
@lang('fortify::forms.delete-user.confirmation')
</div>
</div>
<form class="mt-8">
<div class="space-y-2">
<x-ark-input input-class="text-center" type="text" name="username" model="username" :label="trans('fortify::forms.confirm_username')" readonly />
<x-ark-input type="text" name="username_confirmation" model="usernameConfirmation" :palceholder="trans('fortify::forms.delete-user.confirmation_placeholder')" :errors="$errors" hide-label />
<x-ark-input
input-class="text-center"
type="text"
name="username"
model="username"
:label="trans('fortify::forms.confirm_username')"
readonly
/>
<x-ark-input
type="text"
name="username_confirmation"
model="usernameConfirmation"
:placeholder="trans('fortify::forms.delete-user.confirmation_placeholder')"
:errors="$errors"
hide-label
/>
</div>
<div class="mt-4">
<x-ark-textarea
name="feedback"
model="feedback"
:label="trans('fortify::forms.feedback.label')"
:placeholder="trans('fortify::forms.feedback.placeholder')"
:auxiliary-title="trans('fortify::forms.optional')"
rows="5"
/>
</div>
</form>
</x-slot>

<x-slot name="buttons">
<div class="flex flex-col w-full sm:flex-row justify-end space-y-4 sm:space-y-0 sm:space-x-3">
<div class="flex flex-col w-full sm:flex-row justify-end space-y-4 space-y-reverse sm:space-y-0 sm:space-x-3">
<button dusk="delete-user-form-cancel" class="button-secondary" wire:click="closeModal">
@lang('fortify::actions.cancel')
</button>

<button dusk="delete-user-form-submit" class="inline-flex justify-center items-center button-cancel" wire:click="deleteUser" {{ ! $this->hasConfirmedName() ? 'disabled' : ''}}>
@svg('trash', 'h-4 w-4')
<x-ark-icon name="trash" size="sm"/>
<span class="ml-2">@lang('fortify::actions.delete')</span>
</button>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/profile/feedback-thank-you.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

<x-ark-container>
<div class="mx-auto flex flex-col items-center w-full text-center">
<img src="{{ asset('/images/profile/feedback/thank-you.svg') }}" alt="">
@svg('fortify-profile.feedback.thank-you')

<h1 class="px-8 mt-8 max-w-xs sm:max-w-none">@lang('fortify::pages.feedback_thank_you.title')</h1>
<p class="mt-4 max-w-xs leading-relaxed sm:max-w-lg sm:px-4 lg:max-w-none lg:px-0">@lang('fortify::pages.feedback_thank_you.description')</p>
Expand Down
18 changes: 0 additions & 18 deletions resources/views/profile/feedback.blade.php

This file was deleted.

8 changes: 0 additions & 8 deletions resources/views/profile/send-feedback-form.blade.php

This file was deleted.

23 changes: 22 additions & 1 deletion src/Components/DeleteUserForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
namespace ARKEcosystem\Fortify\Components;

use ARKEcosystem\Fortify\Contracts\DeleteUser;
use ARKEcosystem\Fortify\Mail\SendFeedback;
use ARKEcosystem\UserInterface\Http\Livewire\Concerns\HasModal;
use Illuminate\Contracts\Auth\StatefulGuard;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\URL;
use Livewire\Component;

Expand All @@ -19,6 +21,12 @@ class DeleteUserForm extends Component

public string $usernameConfirmation = '';

public string $feedback = '';

protected $rules = [
'feedback' => 'present|string|min:5|max:500',
];

public function mount()
{
$this->username = Auth::user()->username;
Expand All @@ -40,14 +48,27 @@ public function hasConfirmedName(): bool
public function deleteUser(DeleteUser $deleter, StatefulGuard $auth)
{
if ($this->hasConfirmedName()) {
$redirect = $this->sendFeedback();

$deleter->delete(Auth::user()->fresh());

$auth->logout();

$this->redirect(URL::temporarySignedRoute('profile.feedback', now()->addMinutes(15)));
$this->redirect($redirect);
}
}

private function sendFeedback(): string
{
if ($this->feedback !== '' && $this->validate()) {
Mail::to(config('fortify.mail.feedback.address'))->send(new SendFeedback($this->feedback));

return URL::temporarySignedRoute('profile.feedback.thank-you', now()->addMinutes(15));
}

return route('home');
}

public function render()
{
return view('ark-fortify::profile.delete-user-form');
Expand Down
33 changes: 0 additions & 33 deletions src/Components/SendFeedbackForm.php

This file was deleted.

9 changes: 2 additions & 7 deletions src/FortifyServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use ARKEcosystem\Fortify\Components\LogoutOtherBrowserSessionsForm;
use ARKEcosystem\Fortify\Components\RegisterForm;
use ARKEcosystem\Fortify\Components\ResetPasswordForm;
use ARKEcosystem\Fortify\Components\SendFeedbackForm;
use ARKEcosystem\Fortify\Components\TwoFactorAuthenticationForm;
use ARKEcosystem\Fortify\Components\UpdatePasswordForm;
use ARKEcosystem\Fortify\Components\UpdateProfileInformationForm;
Expand Down Expand Up @@ -128,7 +127,6 @@ public function registerLivewireComponents(): void
Livewire::component('profile.update-profile-information-form', UpdateProfileInformationForm::class);
Livewire::component('profile.update-profile-photo-form', UpdateProfilePhotoForm::class);
Livewire::component('profile.update-timezone-form', UpdateTimezoneForm::class);
Livewire::component('profile.send-feedback-form', SendFeedbackForm::class);
Livewire::component('auth.register-form', RegisterForm::class);
Livewire::component('auth.reset-password-form', ResetPasswordForm::class);
Livewire::component('newsletter.footer-subscription-form', FooterEmailSubscriptionForm::class);
Expand Down Expand Up @@ -252,12 +250,9 @@ private function registerResponseBindings()
public function registerRoutes(): void
{
Route::middleware('web')->group(function () {
Route::view(config('fortify.routes.feedback'), 'ark-fortify::profile.feedback')
->name('profile.feedback')
->middleware('signed');

Route::view(config('fortify.routes.feedback_thank_you'), 'ark-fortify::profile.feedback-thank-you')
->name('profile.feedback.thank-you');
->name('profile.feedback.thank-you')
->middleware('signed');
});
}
}
32 changes: 31 additions & 1 deletion tests/Components/DeleteUserFormTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,36 @@

use ARKEcosystem\Fortify\Components\DeleteUserForm;
use ARKEcosystem\Fortify\Contracts\DeleteUser;
use ARKEcosystem\Fortify\Mail\SendFeedback;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\URL;
use Livewire\Livewire;
use function Tests\createUserModel;

it('can interact with the form', function () {
Route::get('/', fn () => [])->name('home');

$user = createUserModel();

$this->mock(DeleteUser::class)
->shouldReceive('delete');

Livewire::actingAs($user)
->test(DeleteUserForm::class)
->assertViewIs('ark-fortify::profile.delete-user-form')
->call('confirmUserDeletion')
->assertSee(trans('fortify::pages.user-settings.delete_account_description'))
->set('usernameConfirmation', $user->username)
->call('deleteUser')
->assertRedirect('/');
$this->assertNull(Auth::user());
});

it('can interact with the form and leave a feedback', function () {
Mail::fake();

$user = createUserModel();

$this->mock(DeleteUser::class)
Expand All @@ -23,9 +47,15 @@
->call('confirmUserDeletion')
->assertSee(trans('fortify::pages.user-settings.delete_account_description'))
->set('usernameConfirmation', $user->username)
->set('feedback', 'my feedback here')
->call('deleteUser')
->assertRedirect(URL::temporarySignedRoute('profile.feedback', now()->addMinutes(15)));
->assertRedirect(URL::temporarySignedRoute('profile.feedback.thank-you', now()->addMinutes(15)));
$this->assertNull(Auth::user());

Mail::assertQueued(SendFeedback::class, function ($mail) {
return $mail->hasTo(config('fortify.mail.feedback.address')) &&
$mail->message === 'my feedback here';
});
});

it('cant delete user without filling in the username', function () {
Expand Down
53 changes: 0 additions & 53 deletions tests/Components/SendFeedbackFormTest.php

This file was deleted.

0 comments on commit dbf64e3

Please sign in to comment.