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

Commit 6fbdf68

Browse files
authored
refactor: update avatar upload component (#40)
1 parent 932a6c9 commit 6fbdf68

File tree

4 files changed

+27
-47
lines changed

4 files changed

+27
-47
lines changed

composer.lock

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

resources/lang/en/forms.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,9 @@
4444
'title' => 'Logout Other Browser Sessions',
4545
'content' => 'Please enter your password to confirm you would like to logout of your other browser sessions across all of your devices.',
4646
],
47+
48+
'upload-avatar' => [
49+
'upload_avatar' => 'Upload Avatar',
50+
'delete_avatar' => 'Delete Avatar',
51+
],
4752
];

resources/views/profile/update-profile-photo-form.blade.php

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,31 +6,12 @@
66
class="relative flex flex-col {{ $alignment ?? 'items-center mb-4 md:items-start' }}"
77
>
88
<form wire:submit.prevent="store" id="livewire-form">
9-
<div
10-
style="background-image: url('{{ $this->user->photo }}')"
11-
class="cursor-pointer bg-theme-secondary-200 inline-block bg-contain bg-center bg-no-repeat rounded {{ $dimensions ?? 'w-48 h-48' }}"
12-
role="button"
13-
>
14-
<input
15-
id="photo"
16-
type="file"
17-
class="absolute top-0 hidden block opacity-0 cursor-pointer"
18-
wire:model="photo"
19-
accept="image/jpg,image/jpeg,image/bmp,image/png"
20-
/>
21-
</div>
22-
23-
<div x-show="isUploading" x-cloak>
24-
<x-ark-loading-spinner />
25-
</div>
26-
27-
<div
28-
class="cursor-pointer flex items-center justify-center rounded absolute top-0 opacity-0 hover:opacity-90 transition-default bg-theme-secondary-900 {{ $dimensions ?? 'w-48 h-48' }}"
29-
@click="select()"
30-
role="button"
31-
>
32-
<div>@svg('upload', 'w-4 h-4 text-white')</div>
33-
</div>
9+
<x-ark-upload-image
10+
:image="$this->user->photo"
11+
:upload-text="__('fortify::forms.upload-avatar.upload_avatar')"
12+
:delete-tooltip="__('fortify::forms.upload-avatar.delete_avatar')"
13+
:dimensions="$dimensions"
14+
/>
3415
</form>
3516

3617
@error('photo')

src/Components/UpdateProfilePhotoForm.php

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,11 @@
55
namespace ARKEcosystem\Fortify\Components;
66

77
use ARKEcosystem\Fortify\Components\Concerns\InteractsWithUser;
8-
use Livewire\Component;
9-
use Livewire\WithFileUploads;
8+
use ARKEcosystem\UserInterface\Components\UploadImage;
109

11-
class UpdateProfilePhotoForm extends Component
10+
class UpdateProfilePhotoForm extends UploadImage
1211
{
1312
use InteractsWithUser;
14-
use WithFileUploads;
15-
16-
public $alignment;
17-
18-
public $photo;
19-
20-
public $dimensions;
2113

2214
/**
2315
* Render the component.
@@ -29,19 +21,21 @@ public function render()
2921
return view('ark-fortify::profile.update-profile-photo-form');
3022
}
3123

32-
public function updatedPhoto()
33-
{
34-
$this->store();
35-
}
36-
3724
public function store()
3825
{
3926
$this->validate([
40-
'photo' => ['mimes:jpeg,png,bmp,jpg', 'max:2048'],
27+
'photo' => $this->validators(),
4128
]);
4229

4330
$file = $this->photo->storePubliclyAs('uploads', $this->photo->hashName());
4431

4532
$this->user->addMediaFromDisk($file)->toMediaCollection('photo');
33+
$this->user->refresh();
34+
}
35+
36+
public function delete()
37+
{
38+
$this->user->getFirstMedia('photo')->delete();
39+
$this->user->refresh();
4640
}
4741
}

0 commit comments

Comments
 (0)