Skip to content

Commit

Permalink
- upgrade media-manager
Browse files Browse the repository at this point in the history
- update withStripe livewire component to livewire 3 dispatch
  • Loading branch information
joshtorres committed Sep 30, 2023
1 parent 6ea9e59 commit 7e7a291
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 35 deletions.
69 changes: 35 additions & 34 deletions resources/views/components/input/media-manager.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,34 +7,13 @@
'id'
])

<div
x-data="{
showMediaManager(file, metadata) {
// Send data back to media manager to pre-fill data.
this.$wire.emitTo(
'media-manager',
'media-manager:show',
{
id: '{{ $id }}',
file: file,
metadata: metadata
}
);
},
setImage(event) {
if (event.detail.id === '{{ $id }}') {
this.$wire.call('{{ $setImageAction }}', event.detail);
}
}
}"
x-on:media-manager:file-selected.window="setImage"
>
<div x-data="mediaManager"
x-on:media-manager:file-selected.window="setImage">
@if (empty($file))
<button
x-on:click.prevent="showMediaManager(null, {})"
type="button"
class="relative block w-full border-2 border-gray-300 border-dashed rounded-lg p-8 text-center hover:border-gray-400 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500"
>
x-on:click.prevent="showMediaManager(null, {})"
type="button"
class="relative block w-full border-2 border-gray-300 border-dashed rounded-lg p-8 text-center hover:border-gray-400 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-gray-500">
<x-library::icons.icon name="fa fa-image" class="mx-auto h-8 w-8 text-light-text-color"/>
<span class="mt-2 block text-sm font-medium text-base-text-color">
{{ $label }}
Expand All @@ -43,19 +22,41 @@ class="relative block w-full border-2 border-gray-300 border-dashed rounded-lg p
@else
<div class="relative">
<button
wire:click.prevent="{{ $removeImageAction }}"
type="button"
class="absolute -top-2 -right-2 z-10 bg-red-100 rounded-full p-1 inline-flex items-center justify-center hover:bg-red-200 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-red-500"
>
wire:click.prevent="{{ $removeImageAction }}"
type="button"
class="absolute -top-2 -right-2 z-10 bg-red-100 rounded-full p-1 inline-flex items-center justify-center hover:bg-red-200 focus:outline-none focus:ring-2 focus:ring-inset focus:ring-red-500">
<x-heroicon-o-x class="w-5 h-5 text-red-500 hover:text-red-400"/>
</button>

<div
x-on:click.prevent="showMediaManager('{{ $file }}', {{ Illuminate\Support\Js::from($metadata) }})"
class="block w-full aspect-w-10 aspect-h-7 rounded-lg overflow-hidden cursor-pointer"
>
<div x-on:click.prevent="showMediaManager('{{ $file }}', {{ Illuminate\Support\Js::from($metadata) }})"
class="block w-full aspect-w-10 aspect-h-7 rounded-lg overflow-hidden cursor-pointer">
<img src="{{ $file }}" alt="" class="object-cover">
</div>
</div>
@endif
</div>


<script>
document.addEventListener('alpine:init', () => {
Alpine.data('mediaManager', () => ({
showMediaManager(file, metadata) {
// Send data back to media manager to pre-fill data.
$wire.dispatchTo(
'media-manager',
'media-manager:show',
{
id: '{{ $id }}',
file: file,
metadata: metadata
}
);
},
setImage(event) {
if (event.detail.id === '{{ $id }}') {
$wire.call('{{ $setImageAction }}', event.detail);
}
}
}));
}
</script>
2 changes: 1 addition & 1 deletion src/Livewire/WithStripe.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function updateStripePaymentMethod(string $event, string $message)
$billable->updateDefaultPaymentMethod($this->stripeToken);

// Let Livewire knows Stripe payment method updated.
$this->emitSelf('stripePaymentMethodUpdated', $billable);
$this->dispatch('stripePaymentMethodUpdated', $billable)->self();

// Let Alpinejs now Stripe payment method updated.
$this->dispatch('stripe-payment-method-updated');
Expand Down

0 comments on commit 7e7a291

Please sign in to comment.